@@ -453,13 +453,43 @@ TRegisteredCaptureSource = class(TStringList)
453
453
end ;
454
454
455
455
function GetRegisteredCaptureSource : TRegisteredCaptureSource;
456
- function CV_FOURCC (const c1, c2, c3, c4: AnsiChar): Integer; overload;
457
- { $IFDEF USE_INLINE} inline; { $ENDIF}
458
- function CV_FOURCC (const c: AnsiString): Integer; overload;
459
- { $IFDEF USE_INLINE} inline; { $ENDIF}
456
+ function CV_FOURCC (const c1, c2, c3, c4: AnsiChar): Integer; overload; { $IFDEF USE_INLINE} inline; { $ENDIF}
457
+ function CV_FOURCC (const c: AnsiString): Integer; overload; { $IFDEF USE_INLINE} inline; { $ENDIF}
460
458
461
459
implementation
462
460
461
+ Uses
462
+ System.UITypes;
463
+
464
+ (*
465
+ function ipDraw1(dc: HDC; img: TMat; const rect: System.Types.TRect; const Stretch: Boolean = True): Boolean;
466
+ Var
467
+ B: TBitmap;
468
+ begin
469
+ B := TBitmap.Create;
470
+ Result := False;
471
+ try
472
+ case img.channels of
473
+ 1:
474
+ B.PixelFormat := pf8bit;
475
+ 3:
476
+ B.PixelFormat := pf24bit;
477
+ 4:
478
+ B.PixelFormat := pf32bit;
479
+ end;
480
+ B.SetSize(img.cols, img.rows);
481
+ for Var i := 0 to img.rows - 1 do
482
+ Move(pbyte(img.Data)[i * img.cols * img.channels], B.ScanLine[i]^, img.cols * img.channels);
483
+ // B.SaveToFile('1.bmp');
484
+ // StretchBlt(
485
+ BitBlt(dc, 0, 0, img.cols, img.rows, B.Canvas.Handle, 0, 0, SRCCOPY);
486
+ Result := True;
487
+ finally
488
+ B.Free;
489
+ end;
490
+ end;
491
+ *)
492
+
463
493
function ipDraw (dc: HDC; img: TMat; const rect: System.Types.TRect; const Stretch: Boolean = True): Boolean;
464
494
465
495
(*
@@ -469,94 +499,88 @@ function ipDraw(dc: HDC; img: TMat; const rect: System.Types.TRect; const Stretc
469
499
LuminanceMultG = 184;
470
500
LuminanceMultB = 18;
471
501
472
- function Desaturate(Color: TColor ): TColor ;
502
+ function Desaturate(Color: UInt32 ): UInt32 ;
473
503
var
474
504
Luminance: byte;
475
505
begin
476
- Luminance := (((Color and $00FF0000) shr 16 * LuminanceMultR) + ((Color and $0000FF00) shr 8 * LuminanceMultG) +
506
+ Luminance := //
507
+ (((Color and $00FF0000) shr 16 * LuminanceMultR) + //
508
+ ((Color and $0000FF00) shr 8 * LuminanceMultG) + //
477
509
((Color and $000000FF) * LuminanceMultB)) shr 8;
478
510
Result := (Color and $FF000000) or (Luminance shl 16) or (Luminance shl 8) or Luminance;
479
511
end;
480
512
*)
481
513
482
514
Type
483
- pCOLORREF = ^COLORREF ;
484
- pBITMAPINFOHEADER = ^BITMAPINFOHEADER ;
515
+ pColorRef = ^TColorRef ;
516
+ pBitmapInfoHeader = ^TBitmapInfoHeader ;
485
517
486
518
Var
487
519
// isrgb: Boolean;
488
- isgray: Boolean;
489
- buf: array [1 .. SizeOf(BITMAPINFOHEADER) + SizeOf(RGBQUAD) * 256 ] of byte;
490
- dibhdr: pBITMAPINFOHEADER;
491
- _dibhdr: TBitmapInfo ABSOLUTE buf;
492
- _rgb: pCOLORREF;
493
- i: Integer;
494
- iResult: Integer;
520
+ // isgray: Boolean;
521
+ buf: array [1 .. SizeOf(TBitmapInfoHeader) + SizeOf(TRGBQuad) * 256 ] of byte;
522
+ BitmapInfo: TBitmapInfo ABSOLUTE buf;
523
+ pDIBHdr: pBitmapInfoHeader;
524
+ pCR: pColorRef;
525
+ i: UInt32;
495
526
begin
496
527
if img.empty then
497
528
Exit(False);
498
529
499
- // isrgb := ('R' = upcase(img^.colorModel[0])) and ('G' = upcase(img^.colorModel[1])) and ('B' = upcase(img^.colorModel[2]));
500
- // isgray := 'G' = upcase(img^.colorModel[0]);
501
- isgray := img.channels = 1 ;
502
- // if (not isgray) and (not isrgb) then
503
- // Exit(false);
504
- // if (1 = img^.nChannels) and (not isgray) then
505
- // Exit(false);
506
-
507
- dibhdr := pBITMAPINFOHEADER(@buf);
508
- _rgb := pCOLORREF(@buf[SizeOf(BITMAPINFOHEADER)]);
530
+ FillChar(buf, SizeOf(buf), 0 );
531
+ pDIBHdr := pBitmapInfoHeader(@buf);
532
+ pCR := pColorRef(@buf[SizeOf(TBitmapInfoHeader)]);
509
533
510
- if (isgray) then
534
+ if img.channels = 1 then
511
535
begin
536
+ { .$DEFINE ONE }
512
537
{ $IFDEF ONE}
513
538
const
514
539
_NumColors = 256 ;
515
540
for i := 0 to 255 do
516
541
begin
517
542
Var
518
- Grey := i * 255 div (_NumColors - 1 );
519
- _rgb [i] := Rgb(Grey, Grey, Grey); // rgb(i, i, i);
543
+ Grey := ( i * 255 ) div (_NumColors - 1 );
544
+ pCR [i] := Rgb(Grey, Grey, Grey); // rgb(i, i, i);
520
545
end ;
521
546
{ $ELSE}
522
547
for i := 0 to 255 do
523
- _rgb[i] :=
548
+ begin
549
+ pCR[i] :=
524
550
// Desaturate(Rgb(i, i, i));
525
551
// Trunc(0.2126 * i + 0.7152 * i + 0.0722 * i);
526
- Rgb(i, i, i);
552
+ // R,G,B
553
+ // Rgb(Trunc(0.2126 * i), Trunc(0.7152 * i), Trunc(0.0722 * i));
554
+ Rgb(0 , i, i);
555
+ // i or (i shl 8) or (i shl 16) or (i shl 32);
556
+ end ;
527
557
{ $ENDIF}
528
558
end ;
529
559
530
- dibhdr^.biSize := SizeOf(BITMAPINFOHEADER);
531
- dibhdr^.biWidth := img.cols;
532
- // Check origin for display
533
- // if img^.Origin = 0 then
534
- dibhdr^.biHeight := -img.rows;
535
- // else
536
- // dibhdr^.biHeight := img^.Height;
537
-
538
- dibhdr^.biPlanes := 1 ;
539
- dibhdr^.biBitCount := 8 * img.channels;
540
- dibhdr^.biCompression := BI_RGB;
541
- dibhdr^.biSizeImage := 0 ; // img^.imageSize;
542
- dibhdr^.biXPelsPerMeter := 0 ;
543
- dibhdr^.biYPelsPerMeter := 0 ;
544
- dibhdr^.biClrUsed := 0 ;
545
- dibhdr^.biClrImportant := 0 ;
560
+ pDIBHdr^.biSize := SizeOf(TBitmapInfoHeader);
561
+ pDIBHdr^.biWidth := img.cols;
562
+ pDIBHdr^.biHeight := -img.rows;
563
+ pDIBHdr^.biPlanes := 1 ;
564
+ pDIBHdr^.biBitCount := 8 * img.channels;
565
+ pDIBHdr^.biCompression := BI_RGB;
566
+ // pDIBHdr^.biClrUsed := 256;
546
567
547
568
if Stretch then
548
569
begin
549
570
SetStretchBltMode(dc, COLORONCOLOR);
550
571
SetMapMode(dc, MM_TEXT);
551
572
// Stretch the image to fit the rectangle
552
- iResult := StretchDIBits(dc, rect.Left, rect.Top, rect.Width, rect.Height, 0 , 0 , img.cols, img.rows, img.Data, _dibhdr,
553
- DIB_RGB_COLORS, SRCCOPY);
573
+ Var
574
+ iResult: Integer := StretchDIBits( //
575
+ dc, rect.Left, rect.Top, rect.Width, rect.Height, 0 , 0 , img.cols, img.rows, img.Data, BitmapInfo, DIB_RGB_COLORS, SRCCOPY);
554
576
Result := (iResult > 0 ); // and (iResult <> GDI_ERROR);
555
577
end
556
578
else
557
579
begin
558
580
// Draw without scaling
559
- iResult := SetDIBitsToDevice(dc, rect.Left, rect.Top, img.cols, img.rows, 0 , 0 , 0 , img.rows, img.Data, _dibhdr, DIB_RGB_COLORS);
581
+ Var
582
+ iResult: Integer := SetDIBitsToDevice( //
583
+ dc, rect.Left, rect.Top, img.cols, img.rows, 0 , 0 , 0 , img.rows, img.Data, BitmapInfo, DIB_RGB_COLORS);
560
584
Result := (iResult > 0 ); // and (iResult <> GDI_ERROR);
561
585
end ;
562
586
end ;
0 commit comments