forked from konvikkor/TFFMPEG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uMediaDisplay.pas
681 lines (629 loc) · 21.3 KB
/
uMediaDisplay.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
unit uMediaDisplay;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
uMediaConstant,
Winapi.GDIPOBJ, Winapi.GDIPAPI, OpenGL, System.TimeSpan,
//Winapi.D3D11Shader, Winapi.D3D11,
Vcl.ExtCtrls,Math,System.SyncObjs,System.Generics.Collections,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FFTypes, FFUtils, System.DateUtils,
libavcodec, libavcodec_avfft, libavdevice, libavfilter, libavfilter_avcodec,
libavfilter_buffersink, libavfilter_buffersrc, libavfilter_formats,
libavformat, libavformat_avio, libavformat_url, libavutil,
libavutil_audio_fifo, libavutil_avstring, libavutil_bprint, libavutil_buffer,
libavutil_channel_layout, libavutil_common, libavutil_cpu, libavutil_dict,
libavutil_display, libavutil_error, libavutil_eval, libavutil_fifo,
libavutil_file, libavutil_frame, libavutil_imgutils, libavutil_log,
libavutil_mathematics, libavutil_md5, libavutil_mem, libavutil_motion_vector,
libavutil_opt, libavutil_parseutils, libavutil_pixdesc, libavutil_pixfmt,
libavutil_rational, libavutil_samplefmt, libavutil_time, libavutil_timestamp,
libswresample, libswscale, sdl2, {SDL2_ttf,{sdl, {uResourcePaths,} System.Threading;
//const
//GL_BGR = $80E0;
type
TMediaDisplay = class (TCustomPanel)
private
FSDLPantalla: PSDLPantalla;
FFlags: UInt32;
FRenderInfo: PSDL_RendererInfo;
MooseTexture: PSDL_Texture;
FProportionally: Boolean;
Timer: TTimer;
CS:TCriticalSection;
FAutoInitSDL: Boolean;
RenderBMP:TBitmap;
FASCIICharList: GLuint;
GlobalTime,PackTime:Cardinal;
FDrawInfo: Boolean;
CalcFPS:Double;
protected
procedure Paint; override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
//Function CaslcSize(Sourse:TSDL_Rect):TSDL_Rect;
//procedure OnRenderVideo(var Data:PMediaBufferInfo);
Procedure InitSDL;
Procedure DeInitSDL;
procedure setupPixelFormat(DC:HDC);
Procedure OnTimer(Sender:TObject);
Procedure WMUpdateRender(var Message: TWMEraseBkgnd);message WM_PAINT_FRAME;
public
HDC:HDC;
RC:HGLRC;
Function GetSDLInfo:PSDLPantalla;
function GetCanvas:TCanvas;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
//procedure UpdateRender;
//procedure RenderVideoFrame(w,h:SInt32;Data:Array of PByte;linesize: Array of Integer; pix_fmt:TAVPixelFormat);
procedure EraseBackground(var Message: TWMEraseBkgnd);message WM_ERASEBKGND;
procedure Render(w,h:SInt32;Data:Array of PByte;linesize: Array of Integer);
Function DrawBitmap(bmp: TBitmap; x, y: Integer; xZoom: Single = 1.0; yZoom: Single = 1.0):TMediaDisplay;
function BuildTexture(bmp: TBitmap; var texId: GLuint):TMediaDisplay;
function DeleteTexture(texId: GLuint): TMediaDisplay;
function DrawBitmapTex(texId: GLuint; x, y, w, h: Integer): TMediaDisplay; overload;
function DrawBitmapTex(bmp: TBitmap; x, y, w, h: Integer): TMediaDisplay; overload;
Procedure BeginRender;
Procedure UpdateRender;
Procedure SetBitmap(BMP:TBitmap;GlobalTime,PackTime:Cardinal);
function TextOut(const text: WideString; x, y: Integer; red, green, blue, alpha: Single): TMediaDisplay;
Procedure EndRender;
published
//Property AutoInitSDL:Boolean Read FAutoInitSDL Write FAutoInitSDL default true;
Property DrawInfo:Boolean Read FDrawInfo Write FDrawInfo default false;
property Anchors;
property OnContextPopup;
property PopupMenu;
property OnResize;
property OnDblClick;
property OnClick;
property OnKeyUp;
property OnKeyPress;
property OnKeyDown;
property Align;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MY Media',[TMediaDisplay]);
end;
{ TMediaDisplay }
(*function TMediaDisplay.CaslcSize(Sourse: TSDL_Rect): TSDL_Rect;
var rect:TSDL_Rect;
WinRect:TRect;
pw,ph,p:Double;
begin
WinRect:=GetClientRect;
Result.x := 0;
Result.y := 0;
Result.w := Sourse.w;
Result.h := Sourse.h;
p := (WinRect.Width * 100) / Result.w;
Result.w := round((Result.w * p) / 100);
Result.h := round((Result.h * p) / 100);
if Result.h > rect.h then begin
p := (rect.h * 100) / Result.h;
Result.w := round((Result.w * p) / 100);
Result.h := round((Result.h * p) / 100);
end;
end;*)
procedure TMediaDisplay.BeginRender;
begin
CS.Enter;
end;
function TMediaDisplay.BuildTexture(bmp: TBitmap;
var texId: GLuint): TMediaDisplay;
var
bmpInfo: BITMAP;
begin
GetObject(bmp.Handle, SizeOf(bmpInfo), @bmpInfo);
glGenTextures(1, @texId); // Create The Texture
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texId); // Bind To The Texture ID
(* TEST ADD > *)
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
(* TEST ADD < *)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Min Filter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Mag Filter
if bmpInfo.bmBitsPixel = 32 then
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, bmpInfo.bmWidth, bmpInfo.bmHeight, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits)
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR_EXT, bmpInfo.bmWidth, bmpInfo.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits);
(* TEST > *)
//glGenerateMipmap(GL_TEXTURE_2D);
(* TEST < *)
Result := Self;
end;
constructor TMediaDisplay.Create(AOwner: TComponent);
begin
inherited;
CS:=TCriticalSection.Create;
Self.Height:=200;
Self.Width:=200;
Self.Align:=alNone;
//Self.OnCanResize:=CanResize;
FSDLPantalla := nil;
//if FSDLPantalla = nil then New(FSDLPantalla);
FProportionally:=true;//False;
//SDL_Init(SDL_INIT_VIDEO);
//InitSDL;
RenderBMP:=TBitmap.Create;
end;
procedure TMediaDisplay.CreateWnd;
begin
inherited CreateWnd;
hdc:=GetDC(Self.Handle);
SetupPixelFormat(hdc);
RC:=wglCreateContext(hdc); //makes OpenGL window out of DC
wglMakeCurrent(hdc, RC); //makes OpenGL window active
//glMatrixMode(GL_PROJECTION);
//glFrustum(-0.1, 0.1, -0.1, 0.1, 0.3, 25.0);
//glFrustum ( -50 , 50 , -50 , 50 , 0.3{1.25} , 100.0 ); //Îáëàñòü âèäèìîñòè
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity;
//gluLookAt(0,0,5,0,0,0,0,0,1); //Ïîçèöèÿ íàáëþäåíèÿ
glEnable(GL_DEPTH_TEST);
//glEnable(GL_ALPHA_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
{Timer:=TTimer.Create(self);
Timer.OnTimer:=OnTimer;
Timer.Interval:=20;}
(*glClearColor (0.5, 0.5, 0.75, 1.0); //Öâåò ôîíà
glClear (GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT); //Î÷èñòêà áóôåðà öâåòà è ãëóáèíû
glLoadIdentity;
glViewport(0,0,ClientWidth,ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluOrtho2D(0,ClientWidth,0,ClientHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;*)
end;
procedure TMediaDisplay.DeInitSDL;
begin
if FSDLPantalla = nil then exit;
if FSDLPantalla.Renderer <> nil then
begin
SDL_DestroyRenderer(FSDLPantalla.Renderer);
FSDLPantalla.Renderer := nil;
end;
if FSDLPantalla.Window <> nil then
begin
SDL_DestroyWindow(FSDLPantalla.Window);
FSDLPantalla.Window := nil;
end;
Dispose(FSDLPantalla);
FSDLPantalla:=nil;
SDL_Quit;
end;
function TMediaDisplay.DeleteTexture(texId: GLuint): TMediaDisplay;
begin
glDeleteTextures(1, @texId);
Result := Self;
end;
destructor TMediaDisplay.Destroy;
begin
FreeAndNil(RenderBMP);
FreeAndNil(CS);
DeInitSDL;
inherited;
end;
procedure TMediaDisplay.DestroyWnd;
begin
FreeAndNil(Timer);
DeInitSDL;
(* Deinit OpenGL > *)
wglMakeCurrent(HDC, 0);
wglDeleteContext(RC);
ReleaseDC(Self.Handle, HDC);
(* Deinit OpenGL < *)
inherited;
end;
function TMediaDisplay.DrawBitmap(bmp: TBitmap; x, y: Integer; xZoom,
yZoom: Single): TMediaDisplay;
var
bmpInfo: BITMAP;
begin
GetObject(bmp.Handle, SizeOf(bmpInfo), @bmpInfo);
glPixelZoom(xZoom, yZoom);
glPushMatrix;
glLoadIdentity;
glRasterPos2i(x, y);
if bmpInfo.bmBitsPixel = 32 then
glDrawPixels(bmp.Width, bmp.Height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits)
else
glDrawPixels(bmp.Width, bmp.Height, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmpInfo.bmBits);
glPopMatrix;
Result := Self;
end;
function TMediaDisplay.DrawBitmapTex(bmp: TBitmap; x, y, w,
h: Integer): TMediaDisplay;
var
tex: GLuint;
begin
glColor3f(1.0, 1.0, 1.0);
//glDisable(GL_BLEND);
//glEnable(GL_TEXTURE_2D);
BuildTexture(bmp, tex);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3i(x, y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(x + w, y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(x + w, y + h, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(x, y + h, 0);
glEnd;
glDeleteTextures(1, @tex);
//glDisable(GL_TEXTURE_2D);
//glEnable(GL_BLEND);
//SetBlendState(FBlend);
//glColor4fv(@FPenColor); // Restore color
Result := Self;
end;
function TMediaDisplay.DrawBitmapTex(texId: GLuint; x, y, w,
h: Integer): TMediaDisplay;
begin
glColor3f(1.0, 1.0, 1.0);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texid); // Bind To The Texture ID
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3i(x, y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(x + w, y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(x + w, y + h, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(x, y + h, 0);
glEnd;
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
//glColor4fv(@FPenColor); // Restore color
Result := Self;
end;
procedure TMediaDisplay.EndRender;
begin
CS.Leave;
end;
procedure TMediaDisplay.EraseBackground(var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;
function TMediaDisplay.GetCanvas: TCanvas;
begin
Result:=Self.Canvas;
end;
function TMediaDisplay.GetSDLInfo: PSDLPantalla;
begin
Result:=FSDLPantalla;
end;
procedure TMediaDisplay.InitSDL;
begin
//if not Self.Showing then exit;
if SDL_WasInit(SDL_INIT_VIDEO) <> SDL_INIT_VIDEO then
SDL_InitSubSystem(SDL_INIT_VIDEO);
FSDLPantalla.Window := SDL_CreateWindowFrom(Pointer(Self.Handle));
if FSDLPantalla.Window <> nil then
begin
FSDLPantalla.Renderer := SDL_CreateRenderer(FSDLPantalla.Window, -1, 0{SDL_RENDERER_PRESENTVSYNC});
// no forzamos ningún tipo de render (0) para que el sistema coja el que pueda Hard-Soft
if FSDLPantalla.Renderer <> nil then
begin
New(FRenderInfo);
if SDL_GetRendererInfo(FSDLPantalla.Renderer, FRenderInfo) = 0 then
begin
FSDLPantalla.max_texture_width := FRenderInfo.max_texture_width;
FSDLPantalla.max_texture_height := FRenderInfo.max_texture_height;
FSDLPantalla.hardware :=
((FRenderInfo.Flags and SDL_RENDERER_ACCELERATED) > 0);
FSDLPantalla.render_name := FRenderInfo.name;
// PAnsiChar(FRenderInfo.name);
SDL_ShowWindow(FSDLPantalla.Window);
if SDL_SetRenderDrawColor(FSDLPantalla.Renderer, 0, 0, 0,
SDL_ALPHA_OPAQUE) = 0 then
begin
if SDL_RenderFillRect(FSDLPantalla.Renderer, nil) = 0 then
FFlags := SDL_GetWindowFlags(FSDLPantalla.Window)
else
ShowMessage('Error clearing render context');
end
else
ShowMessage('Error setting render draw color');
end
else
ShowMessage('Error getting information about rendering context');
end
else
ShowMessage('Error crearting SDL2 Render');
end
else
ShowMessage('Error creating SDL2 Window.');
end;
procedure TMediaDisplay.OnTimer(Sender: TObject);
begin
Self.UpdateRender;
end;
procedure TMediaDisplay.Paint;
var Rect: TRect;
Text:string;
begin
//glClearColor (0.5, 0.5, 0.75, 1.0); //Öâåò ôîíà
glClearColor (0, 0, 0, 1.0); //Öâåò ôîíà
glClear (GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT); //Î÷èñòêà áóôåðà öâåòà è ãëóáèíû
glLoadIdentity;
glViewport(0,0,ClientWidth,ClientHeight); // ðàçìåðû ýêðàíà ÷òî áóäåì ïîêàçûâàòü
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glOrtho(-ClientWidth div 2,ClientWidth div 2,-ClientHeight div 2,ClientHeight div 2,-800,800); //öåíòðîâêà â íîëü ïî öåíòðó ýêðàíà*)
//gluOrtho2D(-ClientWidth div 2,ClientWidth div 2,-ClientHeight div 2,ClientHeight div 2); //öåíòðîâêà â íîëü ïî öåíòðó ýêðàíà*)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
//glTranslatef(0.0,0.0,-10.0);
(* Test OpenGL > *)
(*glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glVertex2i(0,0);
glColor3f(0.0, 0.0, 1.0);
glVertex2i(0,ClientWidth);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(ClientWidth,ClientHeight);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(ClientWidth,0);
glEnd;*)
(* Test OpenGL < *)
SwapBuffers(wglGetCurrentDC); //---------------------------
(*Canvas.Lock;
try
(* Message Pain frame *
Text:=' Video Canvas ';
Rect := GetClientRect;
with Canvas do begin
Brush.Color:=clBlack;
FillRect(Rect);
Brush.Color:=clRed;
Font.Name := 'arial';
Font.Color := clBlack;
Font.Style := [];
Font.Height := 24;
TextOut((Self.Width div 2)-(TextWidth(Text) div 2),(Self.Height div 2)-(TextHeight(Text) div 2),Text);
Text:=' Display ['+IntToStr(Self.Tag)+'] '+Self.Caption+' ';//+FormatDateTime('hh.mm.ss.zzz',Time);
Brush.Color:=clBlack;
Font.Name := 'arial';
Font.Color := clGreen;
Font.Style := [];
Font.Height := 16;
TextOut((Self.Width div 2)-(TextWidth(Text) div 2),2,Text);
end;
finally
Canvas.Unlock;
end; *)
end;
procedure TMediaDisplay.Render(w, h: SInt32; Data: array of PByte;
linesize: array of Integer);
var
BMPFile:TMemoryStream;//TFileStream;
BMPHeader:BITMAPFILEHEADER;
BMPInfo:TBitmapV4Header;
ret:Integer;
bmp:TBitmap;
Graphics : TGPGraphics;
Img:TGPBitmap;
Text:string;
TextureID:LongInt;
Buffer:BITMAP;
begin
if Assigned(CS) then CS.Enter;
try
bmpheader.bfReserved1 := 0;
bmpheader.bfReserved2 := 0;
bmpheader.bfType := $4d42;
bmpheader.bfOffBits := sizeof(BITMAPFILEHEADER) + sizeof(BITMAPV4HEADER);
bmpheader.bfSize := bmpheader.bfOffBits + w*h*32 div 8;
bmpinfo.bV4Size := sizeof(BITMAPV4HEADER);
bmpinfo.bV4Width := w;
bmpinfo.bV4Height := -h;
bmpinfo.bV4Planes := 1;
bmpinfo.bV4BitCount := 32;//24;
bmpinfo.bV4V4Compression := BI_BITFIELDS;
bmpinfo.bV4SizeImage := 0;
bmpinfo.bV4XPelsPerMeter := 100;//2835; // ResolutionHorizontal
bmpinfo.bV4YPelsPerMeter := 100;//2835; //ResolutionVertical
bmpinfo.bV4ClrUsed := 0;
bmpinfo.bV4ClrImportant := 0;
BMPInfo.bV4RedMask:=$00FF0000;
BMPInfo.bV4GreenMask:=$0000FF00;
BMPInfo.bV4BlueMask:=$000000FF;
BMPInfo.bV4AlphaMask:=$FF000000;
BMPInfo.bV4CSType:=$206E6957;
BMPInfo.bV4GammaRed:=0;
BMPInfo.bV4GammaGreen:=0;
BMPInfo.bV4GammaBlue:=0;
//BMPFile:=TFileStream.Create(ExtractFilePath(GetCurrentDir)+'TEST'+IntToStr(Random(500))+'.jpg',fmCreate);
BMPFile:=TMemoryStream.Create;
bmp:=TBitmap.Create;
//FBitMap.Lock;
//Graphics := TGPGraphics.Create(FBitMap.Handle);
try
BMPFile.WriteBuffer(bmpheader,SizeOf(bmpheader));
BMPFile.WriteBuffer(bmpinfo,SizeOf(bmpinfo));
BMPFile.WriteBuffer(data[0]^,w*h*32 div 8);
BMPFile.Position:=0;
BMP.LoadFromStream(BMPFile);
glClear(GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT);//GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
Self.DrawBitmap(BMP,0,0);
(*img:=TGPBitmap.Create(TStreamAdapter.Create(BMPFile));
try
//FMediaDisplay.RenderBitMap(bmp);
Graphics.DrawImage(Img,0,0,w,h);
{$ifdef SHOW_MEDIA}
Text:=FormatDateTime('hh.mm.ss.zzz',IncMilliSecond(MinDateTime,Ceil(FAVPacked.dts * av_q2d(FVideoStrem.time_base)*1000)))+' [FRAME ]';
GPEasyTextout(Graphics, Text, MakeRect(1, 1, w*1.0, h*1.0), MakeColor(0, 255, 0), StringAlignmentNear, StringAlignmentNear, 15);
Text:=FormatDateTime('hh.mm.ss.zzz',IncMilliSecond(MinDateTime,GT))+' [GLOBAL]';
GPEasyTextout(Graphics, Text, MakeRect(1, 15, w*1.0, h*1.0), MakeColor(0, 255, 255), StringAlignmentNear, StringAlignmentNear, 15);
//GPEasyTextout(Graphics, 'TVideoThread:'+IntToStr(Self.Tag), MakeRect(1, 20, w*1.0, h*1.0), MakeColor(0, 0, 255), StringAlignmentNear, StringAlignmentNear, 10);
GPEasyTextout(Graphics, 'Media Component v2.0', MakeRect(1, 1, w*1.0, h*1.0), MakeColor(255, 0, 0), StringAlignmentCenter, StringAlignmentNear, 10);
{$endif}
finally
FreeAndNil(Img);
end;*)
finally
//FBitMap.Unlock;
FreeAndNil(BMPFile);
FreeAndNil(bmp);
FreeAndNil(Graphics);
end;
finally
if Assigned(CS) then CS.Leave;
end;
end;
procedure TMediaDisplay.SetBitmap(BMP: TBitmap;GlobalTime,PackTime:Cardinal);
var Stream:TMemoryStream;
begin
if not Assigned(RenderBMP) then Exit;
CS.Enter;
Self.GlobalTime:=GlobalTime;
Self.PackTime:=PackTime;
Stream:=TMemoryStream.Create;
try
BMP.SaveToStream(Stream);
Stream.Position:=0;
RenderBMP.FreeImage;
RenderBMP.LoadFromStream(Stream);
finally
FreeAndNil(Stream);
CS.Leave;
end;
end;
procedure TMediaDisplay.setupPixelFormat(DC: HDC);
const
pfd:TPIXELFORMATDESCRIPTOR = (
nSize:sizeof(TPIXELFORMATDESCRIPTOR); // size
nVersion:1; // version
dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or
PFD_DOUBLEBUFFER; // support double-buffering
iPixelType:PFD_TYPE_RGBA; // color type
cColorBits:32; // preferred color depth
cRedBits:0; cRedShift:0; // color bits (ignored)
cGreenBits:0; cGreenShift:0;
cBlueBits:0; cBlueShift:0;
cAlphaBits:0; cAlphaShift:0; // no alpha buffer
cAccumBits: 0;
cAccumRedBits: 0; // no accumulation buffer,
cAccumGreenBits: 0; // accum bits (ignored)
cAccumBlueBits: 0;
cAccumAlphaBits: 0;
cDepthBits:24; // depth buffer
cStencilBits:0; // no stencil buffer
cAuxBuffers:0; // no auxiliary buffers
iLayerType:PFD_MAIN_PLANE; // main layer
bReserved: 0;
dwLayerMask: 0;
dwVisibleMask: 0;
dwDamageMask: 0; // no layer, visible, damage masks
);
var pixelFormat:integer;
begin
pixelFormat := ChoosePixelFormat(DC, @pfd);
if (pixelFormat = 0) then
exit;
if (SetPixelFormat(DC, pixelFormat, @pfd) <> TRUE) then
exit;
end;
function TMediaDisplay.TextOut(const text: WideString; x,
y: Integer; red, green, blue, alpha: Single): TMediaDisplay;
var
i: Integer;
GLList: GLuint;
Font:TFont;
begin
Font:=TFont.Create;
try
Font.Style:=[fsBold];
Font.Size:=10;
Font.Color:=clGreen;
SelectObject(HDC, Font.Handle);
GLList := glGenLists(MaxChar);
wglUseFontBitmaps(HDC, 0, MaxChar, GLList);
glPushMatrix;
glLoadIdentity;
glColor4f(red, green, blue, alpha);
glRasterPos2i(x, y);
for i := 1 to Length(text) do
glCallList(GLList + Ord(text[i]));
glPopMatrix;
glDeleteLists(GLList, MaxChar);
//glColor4fv(@FPenColor);
Result := Self;
finally
FreeAndNil(Font);
end;
end;
procedure TMediaDisplay.UpdateRender;
var x,y:Integer;
Text:AnsiString;
Texture:Cardinal;
FPS:Double;
bmpInfo: BITMAP;
begin x:=0; y:=0; Texture:=0;
//glColor3f(1.0,0.0,0.0);
glClear (GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT or GL_COLOR_BUFFER_BIT); //Î÷èñòêà áóôåðà öâåòà è ãëóáèíû
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
FPS:=Round(TTimeSpan.Subtract(GetTime,Self.CalcFPS).Milliseconds);
Self.CalcFPS:=GetTime;
TextOut('Media Display ['+FormatDateTime('hh.mm.ss.zzz',Time)+'] FPS:'+FloatToStr(FPS),-ClientWidth div 2 + 5,ClientHeight div 2 - 15,-128,11,0,0);
if FDrawInfo then begin
TextOut('['+FormatDateTime('hh.mm.ss.zzz',IncMilliSecond(MinDateTime,GlobalTime))+'] Global',-ClientWidth div 2 + 5,ClientHeight div 2 - 30,1,0,1,0);
TextOut('['+FormatDateTime('hh.mm.ss.zzz',IncMilliSecond(MinDateTime,PackTime))+'] Packed',-ClientWidth div 2 + 5,ClientHeight div 2 - 45,1,1,0,0);
end;
if Assigned(RenderBMP) then begin
BeginRender;
try
if not RenderBMP.Empty then begin
(* Draw IMG > *)
x:=-RenderBMP.Width div 2;
y:=-RenderBMP.Height div 2;
DrawBitmap(RenderBMP,x,y);
{x:=RenderBMP.Width;
y:=RenderBMP.Height;
glColor3f(0.7,0.7,0.7);
glEnable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
glGenTextures(1,@Texture);
glBindTexture(GL_TEXTURE_2D,Texture);
GetObject(RenderBMP.Handle, SizeOf(bmpInfo), @bmpInfo);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0,GL_RGBA, GL_UNSIGNED_BYTE, bmpInfo.bmBits);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-x/2, -y/2, 0);
glTexCoord2f(1, 0);
glVertex3f(x/2, -y/2, 0);
glTexCoord2f(1, 1);
glVertex3f(x/2, y/2, 0);
glTexCoord2f(0, 1);
glVertex3f(-x/2, y/2, 0);
glEnd;}
//DrawBitmapTex(RenderBMP,-x div 2,-y div 2,x,y);
//gluLookAt(0,0,-10,0,0,0,0,0,0);
(* Draw IMG < *)
(*BuildTexture(RenderBMP,Texture);
DrawBitmapTex(Texture,-x div 2,-y div 2,x,y);
DeleteTexture(Texture);*)
end;
finally
EndRender;
end;
end;
//SwapBuffers(wglGetCurrentDC);
//glFlush;
//Application.ProcessMessages;
SwapBuffers(HDC);
end;
procedure TMediaDisplay.WMUpdateRender(var Message: TWMEraseBkgnd);
begin
UpdateRender;
end;
end.