Changeset 22
- Timestamp:
- Dec 22, 2016, 1:13:04 PM (8 years ago)
- Location:
- branches/gbitmap
- Files:
-
- 4 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 -
branches/gbitmap/GImage.pas
r21 r22 24 24 25 25 IBColorClass = class of TBColor; 26 27 { TBColorRGB8 }28 29 TBColorRGB8 = class(TBColor)30 Value: TColorRGB8;31 constructor Create(Color: TColorRGB8);32 procedure SetColorName(ColorName: TColorName); override;33 procedure SetRandom; override;34 end;35 26 36 27 { TBImage } … … 57 48 58 49 TBPixmapClass = class of TBImage; 59 60 { TBImageRGB8 }61 62 TBImageRGB8 = class(TBImage)63 protected64 procedure SetSize(AValue: TPoint); override;65 public66 Pixmap: TGPixmap<TColorRGB8>;67 procedure Fill(Color: IBColor); override;68 constructor Create;69 destructor Destroy; override;70 end;71 50 72 51 { TColorFormatChannel } … … 267 246 end; 268 247 269 { TBColorRGB8 }270 271 constructor TBColorRGB8.Create(Color: TColorRGB8);272 begin273 Value := Color;274 end;275 276 procedure TBColorRGB8.SetColorName(ColorName: TColorName);277 begin278 case ColorName of279 cnBlack: Value := TColorRGB8.Create(0, 0, 0);280 cnGray: Value := TColorRGB8.Create($80, $80, $80);281 cnSilver: Value := TColorRGB8.Create($C0, $C0, $C0);282 cnWhite: Value := TColorRGB8.Create($ff, $ff, $ff);283 else Value := TColorRGB8.Create(0, 0, 0);;284 end;285 end;286 287 procedure TBColorRGB8.SetRandom;288 begin289 Value := TColorRGB8.Create(Random(256), Random(256), Random(256));290 end;291 292 { TBImageRGB8 }293 294 procedure TBImageRGB8.SetSize(AValue: TPoint);295 begin296 inherited;297 Pixmap.Size := AValue;298 end;299 300 procedure TBImageRGB8.Fill(Color: IBColor);301 begin302 if Color is TBColorRGB8 then303 Pixmap.Fill((Color as TBColorRGB8).Value);304 end;305 306 constructor TBImageRGB8.Create;307 begin308 Pixmap := TGPixmap<TColorRGB8>.Create;309 end;310 311 destructor TBImageRGB8.Destroy;312 begin313 FreeAndNil(Pixmap);314 inherited Destroy;315 end;316 317 248 { TBImage } 318 249 -
branches/gbitmap/UFormMain.pas
r21 r22 276 276 with Image do begin 277 277 Size := Point(100, 100); 278 ColorFormat := ColorFormatManager.Formats[ 1];278 ColorFormat := ColorFormatManager.Formats[5]; 279 279 Fill(GImage.TColor.Create(ColorFormat, cnWhite)); 280 280 Pixels[0, 0] := GImage.TColor.Create(ColorFormat, cnBlack); -
branches/gbitmap/UPixmapSpecialized.pas
r21 r22 11 11 TColorGray16 = Word; 12 12 TColorGray32 = Cardinal; 13 14 { TColorRGB8 }15 16 TColorRGB8 = record17 R: Byte;18 B: Byte;19 G: Byte;20 function Create(R, G, B: Byte): TColorRGB8;21 end;22 13 23 14 { TColorRGB16 } … … 40 31 TPixmapGray32 = class(TGPixmap<TColorGray32>) 41 32 function Gray32ToColor(Value: TColorGray32): TColor; 42 end;43 44 TPixmapRGB8 = class(TGPixmap<TColorRGB8>)45 function RGB8ToColor(Value: TColorRGB8): TColor;46 33 end; 47 34 … … 68 55 end; 69 56 70 { TColorRGB8 }71 72 function TColorRGB8.Create(R, G, B: Byte): TColorRGB8;73 begin74 Result.R := R;75 Result.G := G;76 Result.B := B;77 end;78 79 57 function TPixmapGray16.Gray16ToColor(Value: TColorGray16): TColor; 80 58 begin … … 87 65 Value := (Value shr 24) and $ff; 88 66 Result := (Value shl 16) or (Value shl 8) or (Value shl 0); 89 end;90 91 function TPixmapRGB8.RGB8ToColor(Value: TColorRGB8): TColor;92 begin93 Result := (Value.R shl 16) or (Value.G shl 8) or (Value.B shl 0);94 67 end; 95 68
Note:
See TracChangeset
for help on using the changeset viewer.