source: trunk/Packages/bgrabitmap/bgramacbitmap.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 2.0 KB
Line 
1unit BGRAMacBitmap;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, BGRALCLBitmap, BGRAGraphics, BGRABitmapTypes;
9
10type
11
12 { TBGRAMacBitmap }
13
14 TBGRAMacBitmap = class(TBGRALCLBitmap)
15 procedure DataDrawOpaque(ACanvas: TCanvas; Rect: TRect; AData: Pointer;
16 ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer); override;
17 end;
18
19implementation
20
21uses LCLType, GraphType, LCLIntf, FPimage;
22
23procedure DataDrawOpaqueImplementation(ACanvas: TCanvas; Rect: TRect;
24 AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
25type
26 PARGB = ^TARGB;
27 TARGB = packed record
28 alpha,red,green,blue: byte;
29 end;
30
31var
32 Temp: TBitmap;
33 RawImage: TRawImage;
34 BitmapHandle, MaskHandle: HBitmap;
35 CreateResult: boolean;
36 psrc: PBGRAPixel;
37 pdest: PARGB;
38 n: Integer;
39begin
40 if (AHeight = 0) or (AWidth = 0) then
41 exit;
42
43 RawImage.Init;
44 RawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth,AHeight);
45 RawImage.Description.Depth := 24;
46 RawImage.Description.AlphaPrec := 0;
47 RawImage.Description.LineOrder := ALineOrder;
48 RawImage.Description.LineEnd := rileDWordBoundary;
49 RawImage.CreateData(False);
50 psrc := PBGRAPixel(AData);
51 pdest := PARGB(RawImage.Data);
52 for n := AWidth*AHeight-1 downto 0 do
53 begin
54 pdest^.alpha := 255;
55 pdest^.red := psrc^.red;
56 pdest^.green := psrc^.green;
57 pdest^.blue := psrc^.blue;
58 inc(pdest);
59 inc(psrc);
60 end;
61 CreateResult := RawImage_CreateBitmaps(RawImage, BitmapHandle, MaskHandle, False);
62 RawImage.FreeData;
63
64 if not CreateResult then
65 raise FPImageException.Create('Failed to create bitmap handle');
66
67 Temp := TBitmap.Create;
68 Temp.Handle := BitmapHandle;
69 Temp.MaskHandle := MaskHandle;
70 ACanvas.StretchDraw(Rect, Temp);
71 Temp.Free;
72end;
73
74{ TBGRAMacBitmap }
75
76procedure TBGRAMacBitmap.DataDrawOpaque(ACanvas: TCanvas; Rect: TRect;
77 AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
78begin
79 DataDrawOpaqueImplementation(ACanvas, Rect, AData, ALineOrder, AWidth, AHeight);
80end;
81
82end.
83
Note: See TracBrowser for help on using the repository browser.