Changeset 22 for branches/gbitmap/ColorFormats/UColorRGB8.pas
- Timestamp:
- Dec 22, 2016, 1:13:04 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gbitmap/ColorFormats/UColorRGB8.pas
r21 r22 6 6 7 7 uses 8 Classes, SysUtils, G raphics, GPixmap, GImage;8 Classes, SysUtils, GPixmap, GImage, Graphics; 9 9 10 10 type … … 14 14 constructor Create; override; 15 15 end; 16 17 { TColorRGB8 } 18 19 TColorRGB8 = record 20 R: Byte; 21 B: Byte; 22 G: Byte; 23 function Create(R, G, B: Byte): TColorRGB8; 24 end; 25 26 TPixmapRGB8 = class(TGPixmap<TColorRGB8>) 27 function RGB8ToColor(Value: TColorRGB8): TColor; 28 end; 29 30 { TBColorRGB8 } 31 32 TBColorRGB8 = class(TBColor) 33 Value: TColorRGB8; 34 constructor Create(Color: TColorRGB8); 35 procedure SetColorName(ColorName: TColorName); override; 36 procedure SetRandom; override; 37 end; 38 39 { TBImageRGB8 } 40 41 TBImageRGB8 = class(TBImage) 42 private 43 FillCallBack: TGetColorPos; 44 function FillGetColor(Position: TPoint): TColorRGB8; 45 protected 46 procedure SetSize(AValue: TPoint); override; 47 public 48 Pixmap: TPixmapRGB8; 49 procedure Fill(Color: IBColor); override; 50 procedure Fill(Func: TGetColorPos); override; 51 procedure PaintToCanvas(Canvas: TCanvas); override; 52 function GetDataSize: Integer; override; 53 constructor Create; override; 54 destructor Destroy; override; 55 end; 56 16 57 17 58 … … 25 66 BitDepth := 24; 26 67 Name := 'RGB8'; 68 BackendImageClass := TBImageRGB8; 69 BackendColorClass := TBColorRGB8; 27 70 AddChannel('Red', 0, 8); 28 71 AddChannel('Green', 8, 8); … … 30 73 end; 31 74 75 { TColorRGB8 } 76 77 function TColorRGB8.Create(R, G, B: Byte): TColorRGB8; 78 begin 79 Result.R := R; 80 Result.G := G; 81 Result.B := B; 82 end; 83 84 { TPixmapRGB8 } 85 86 function TPixmapRGB8.RGB8ToColor(Value: TColorRGB8): TColor; 87 begin 88 Result := (Value.R shl 16) or (Value.G shl 8) or (Value.B shl 0); 89 end; 90 91 { TBColorRGB8 } 92 93 constructor TBColorRGB8.Create(Color: TColorRGB8); 94 begin 95 Value := Color; 96 end; 97 98 procedure TBColorRGB8.SetColorName(ColorName: TColorName); 99 begin 100 case ColorName of 101 cnBlack: Value := TColorRGB8.Create(0, 0, 0); 102 cnGray: Value := TColorRGB8.Create($80, $80, $80); 103 cnSilver: Value := TColorRGB8.Create($C0, $C0, $C0); 104 cnWhite: Value := TColorRGB8.Create($ff, $ff, $ff); 105 else Value := TColorRGB8.Create(0, 0, 0);; 106 end; 107 end; 108 109 procedure TBColorRGB8.SetRandom; 110 begin 111 Value := TColorRGB8.Create(Random(256), Random(256), Random(256)); 112 end; 113 114 { TBImageRGB8 } 115 116 function TBImageRGB8.FillGetColor(Position: TPoint): TColorRGB8; 117 begin 118 Result := (FillCallBack(Position) as TBColorRGB8).Value; 119 end; 120 121 procedure TBImageRGB8.SetSize(AValue: TPoint); 122 begin 123 inherited; 124 Pixmap.Size := AValue; 125 end; 126 127 procedure TBImageRGB8.Fill(Color: IBColor); 128 begin 129 if Color is TBColorRGB8 then 130 Pixmap.Fill((Color as TBColorRGB8).Value); 131 end; 132 133 procedure TBImageRGB8.Fill(Func: TGetColorPos); 134 begin 135 FillCallBack := Func; 136 Pixmap.Fill(FillGetColor); 137 end; 138 139 procedure TBImageRGB8.PaintToCanvas(Canvas: TCanvas); 140 begin 141 Pixmap.PaintToCanvas(Canvas, Pixmap.RGB8ToColor); 142 end; 143 144 function TBImageRGB8.GetDataSize: Integer; 145 begin 146 Result := Pixmap.GetDataSize; 147 end; 148 149 constructor TBImageRGB8.Create; 150 begin 151 Pixmap := TPixmapRGB8.Create; 152 end; 153 154 destructor TBImageRGB8.Destroy; 155 begin 156 FreeAndNil(Pixmap); 157 inherited Destroy; 158 end; 159 160 32 161 end. 33 162
Note:
See TracChangeset
for help on using the changeset viewer.