Changeset 19 for branches/gbitmap/GImage.pas
- Timestamp:
- Dec 20, 2016, 6:02:51 PM (8 years ago)
- Location:
- branches/gbitmap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gbitmap
- Property svn:ignore
-
old new 3 3 project1.lps 4 4 project1.res 5 project1.exe
-
- Property svn:ignore
-
branches/gbitmap/GImage.pas
r18 r19 6 6 7 7 uses 8 Classes, SysUtils, G Pixmap;8 Classes, SysUtils, Graphics, GPixmap, UPixmapSpecialized; 9 9 10 10 type 11 TColorGray8 = Byte;12 13 { TRGB8 }14 15 TRGB8 = record16 R: Byte;17 B: Byte;18 G: Byte;19 function Create(R, G, B: Byte): TRGB8;20 end;21 22 23 11 TBColor = class 24 12 end; 25 13 26 14 TBColorGray1 = class(TBColor) 27 Value: TColorGray8; 15 Value: TColorGray1; 16 end; 17 18 TBColorGray2 = class(TBColor) 19 Value: TColorGray2; 28 20 end; 29 21 30 22 TBColorRGB8 = class(TBColor) 31 Value: T RGB8;23 Value: TColorRGB8; 32 24 end; 33 25 … … 35 27 36 28 TBImage = class 37 procedure Fill(Color: TBColor); virtual; 29 public 30 type 31 TGetColorPos = function (Position: TPoint): TBColor of object; 32 private 33 FSize: TPoint; 34 protected 35 procedure SetSize(AValue: TPoint); virtual; 36 public 37 procedure Fill(Color: TBColor); virtual; overload; 38 procedure Fill(Func: TGetColorPos); virtual; overload; 39 procedure PaintToCanvas(Canvas: TCanvas); virtual; 40 property Size: TPoint read FSize write SetSize; 38 41 end; 39 42 … … 41 44 42 45 TBImageGray1 = class(TBImage) 43 Pixmap: TGPixmap<TColorGray8>; 46 protected 47 procedure SetSize(AValue: TPoint); override; 48 public 49 Pixmap: TPixmapGray1; 44 50 procedure Fill(Color: TBColor); override; 51 procedure Fill(Func: TGetColorPos); override; 52 procedure PaintToCanvas(Canvas: TCanvas); override; 53 constructor Create; 54 destructor Destroy; override; 55 end; 56 57 { TBImageGray2 } 58 59 TBImageGray2 = class(TBImage) 60 protected 61 procedure SetSize(AValue: TPoint); override; 62 public 63 Pixmap: TPixmapGray2; 64 procedure Fill(Color: TBColor); override; 65 procedure PaintToCanvas(Canvas: TCanvas); override; 66 constructor Create; 67 destructor Destroy; override; 45 68 end; 46 69 … … 48 71 49 72 TBImageRGB8 = class(TBImage) 50 Pixmap: TGPixmap<TRGB8>; 73 protected 74 procedure SetSize(AValue: TPoint); override; 75 public 76 Pixmap: TGPixmap<TColorRGB8>; 51 77 procedure Fill(Color: TBColor); override; 52 end; 53 54 55 TColorFormat = (cfNone, cfGray1, cfRGB8); 56 57 { TImage } 58 59 TImage = class 78 constructor Create; 79 destructor Destroy; override; 80 end; 81 82 83 TColorFormat = (cfNone, cfGray1, cfGray2, cfGray4, cfGray8, cfGray16, cfGray32, 84 cfRGB8, cfRGB16); 85 86 { TGImage } 87 88 TGImage = class 89 public 90 type 91 TGetColorPos = function (Position: TPoint): TBColor of object; 60 92 private 61 93 FBackend: TBImage; 62 94 FColorFormat: TColorFormat; 95 FSize: TPoint; 63 96 procedure SetColorFormat(AValue: TColorFormat); 97 procedure SetSize(AValue: TPoint); 64 98 public 65 99 property Backend: TBImage read FBackend; 66 100 property ColorFormat: TColorFormat read FColorFormat write SetColorFormat; 67 procedure Fill(Color: TBColor); 68 constructor Create; 69 destructor Destroy; override; 70 end; 101 property Size: TPoint read FSize write SetSize; 102 procedure Fill(Color: TBColor); overload; 103 procedure Fill(Func: TGetColorPos); overload; 104 procedure PaintToCanvas(Canvas: TCanvas); 105 constructor Create; 106 destructor Destroy; override; 107 end; 108 71 109 72 110 implementation 73 111 74 { TRGB8 } 75 76 function TRGB8.Create(R, G, B: Byte): TRGB8; 77 begin 78 Result.R := R; 79 Result.G := G; 80 Result.B := B; 81 end; 112 { TBImageGray2 } 113 114 procedure TBImageGray2.SetSize(AValue: TPoint); 115 begin 116 inherited; 117 Pixmap.Size := AValue; 118 end; 119 120 procedure TBImageGray2.Fill(Color: TBColor); 121 begin 122 if Color is TBColorGray2 then 123 Pixmap.Fill((Color as TBColorGray2).Value); 124 end; 125 126 procedure TBImageGray2.PaintToCanvas(Canvas: TCanvas); 127 begin 128 Pixmap.PaintToCanvas(Canvas, Pixmap.Gray2ToColor); 129 end; 130 131 constructor TBImageGray2.Create; 132 begin 133 Pixmap := TPixmapGray2.Create; 134 end; 135 136 destructor TBImageGray2.Destroy; 137 begin 138 Pixmap.Free; 139 inherited Destroy; 140 end; 141 82 142 83 143 { TBImageRGB8 } 144 145 procedure TBImageRGB8.SetSize(AValue: TPoint); 146 begin 147 inherited; 148 Pixmap.Size := AValue; 149 end; 84 150 85 151 procedure TBImageRGB8.Fill(Color: TBColor); … … 89 155 end; 90 156 157 constructor TBImageRGB8.Create; 158 begin 159 Pixmap := TGPixmap<TColorRGB8>.Create; 160 end; 161 162 destructor TBImageRGB8.Destroy; 163 begin 164 Pixmap.Free; 165 inherited Destroy; 166 end; 167 91 168 { TBImage } 92 169 170 procedure TBImage.SetSize(AValue: TPoint); 171 begin 172 if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit; 173 FSize := AValue; 174 end; 175 93 176 procedure TBImage.Fill(Color: TBColor); 94 177 begin 95 178 end; 96 179 180 procedure TBImage.Fill(Func: TGetColorPos); 181 begin 182 end; 183 184 procedure TBImage.PaintToCanvas(Canvas: TCanvas); 185 begin 186 end; 187 97 188 { TBImageGray1 } 189 190 procedure TBImageGray1.SetSize(AValue: TPoint); 191 begin 192 inherited; 193 Pixmap.Size := AValue; 194 end; 98 195 99 196 procedure TBImageGray1.Fill(Color: TBColor); … … 103 200 end; 104 201 105 { TImage } 106 107 procedure TImage.SetColorFormat(AValue: TColorFormat); 202 procedure TBImageGray1.Fill(Func: TGetColorPos); 203 begin 204 //Pixmap.Fill(); 205 end; 206 207 procedure TBImageGray1.PaintToCanvas(Canvas: TCanvas); 208 begin 209 Pixmap.PaintToCanvas(Canvas, Pixmap.Gray1ToColor); 210 end; 211 212 constructor TBImageGray1.Create; 213 begin 214 Pixmap := TPixmapGray1.Create; 215 end; 216 217 destructor TBImageGray1.Destroy; 218 begin 219 Pixmap.Free; 220 inherited Destroy; 221 end; 222 223 { TGImage } 224 225 procedure TGImage.SetColorFormat(AValue: TColorFormat); 108 226 begin 109 227 if FColorFormat = AValue then Exit; 110 228 FBackend.Free; 111 if FColorFormat = cfGray1 then 112 FBackend := TBImageGray1.Create; 113 if FColorFormat = cfRGB8 then 114 FBackend := TBImageRGB8.Create; 229 if AValue = cfGray1 then FBackend := TBImageGray1.Create 230 else if AValue = cfGray2 then FBackend := TBImageGray2.Create 231 else if AValue = cfRGB8 then FBackend := TBImageRGB8.Create 232 else FBackend := nil; 233 if Assigned(FBackend) then FBackend.Size := FSize; 115 234 FColorFormat := AValue; 116 235 end; 117 236 118 procedure TImage.Fill(Color: TBColor); 119 begin 120 if Assigned(Backend) then 121 Backend.Fill(Color); 122 end; 123 124 constructor TImage.Create; 237 procedure TGImage.SetSize(AValue: TPoint); 238 begin 239 if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit; 240 FSize := AValue; 241 if Assigned(FBackend) then 242 FBackend.Size := AValue; 243 end; 244 245 procedure TGImage.Fill(Color: TBColor); 246 begin 247 if Assigned(FBackend) then FBackend.Fill(Color); 248 end; 249 250 procedure TGImage.Fill(Func: TGetColorPos); 251 begin 252 // if Assigned(FBackend) then FBackend.Fill(Func: TGetColorPos); 253 end; 254 255 procedure TGImage.PaintToCanvas(Canvas: TCanvas); 256 begin 257 if Assigned(FBackend) then FBackend.PaintToCanvas(Canvas); 258 end; 259 260 constructor TGImage.Create; 125 261 begin 126 262 FBackend := nil; 127 263 end; 128 264 129 destructor T Image.Destroy;265 destructor TGImage.Destroy; 130 266 begin 131 267 if Assigned(FBackend) then FreeAndNil(FBackend);
Note:
See TracChangeset
for help on using the changeset viewer.