Changeset 3 for trunk/UGraphic.pas
- Timestamp:
- Sep 15, 2014, 11:13:21 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGraphic.pas
r2 r3 30 30 TGColorFormatClass = class of TGColorFormat; 31 31 32 { TGColorFormatRGBA8 }33 34 TGColorFormatRGBA8 = class(TGColorFormat)35 function GetPixelSize: Integer; override;36 function GetBitDepth: Integer; override;37 function GetName: string; override;38 function GetChannelBytePos(Channel: TGColorChannel): Integer; override;39 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override;40 function ColorToTColor(Color: TGColor): TColor; override;41 function GetColorClass: TGColorClass; override;42 end;43 44 32 { TGColor } 45 33 46 34 TGColor = class 47 35 private 36 FColorFormat: TGColorFormatClass; 48 37 FData: PByte; 49 FColorFormat: TGColorFormatClass;50 38 function GetChannel(Channel: TGColorChannel): TGColor; 51 39 procedure SetColorFormat(AValue: TGColorFormatClass); … … 56 44 procedure Assign(Source: TGColor); virtual; 57 45 property Channels[Channel: TGColorChannel]: TGColor read GetChannel; 46 property Data: PByte read FData; 58 47 published 59 48 property Format: TGColorFormatClass read FColorFormat write SetColorFormat; … … 64 53 TGBitmap = class 65 54 private 55 FBackgroundColor: TGColor; 66 56 FColorFormat: TGColorFormatClass; 67 57 FDPI: Integer; … … 70 60 function GetPixel(X, Y: Integer): TGColor; 71 61 function GetSize: TPoint; 62 procedure SetBackgroundColor(AValue: TGColor); 72 63 procedure SetColorFormat(AValue: TGColorFormatClass); 73 64 procedure SetPixel(X, Y: Integer; AValue: TGColor); … … 77 68 function GetDataSize: Integer; 78 69 procedure PaintToCanvas(Canvas: TCanvas); 70 procedure Clear; 79 71 constructor Create; virtual; 80 72 destructor Destroy; override; 73 property BackgroundColor: TGColor read FBackgroundColor write SetBackgroundColor; 81 74 property DPI: Integer read FDPI write FDPI; 82 75 property ColorFormat: TGColorFormatClass read FColorFormat write SetColorFormat; … … 134 127 end; 135 128 136 { TGColorFormatRGBA8 }137 138 function TGColorFormatRGBA8.GetPixelSize: Integer;139 begin140 Result := 4;141 end;142 143 function TGColorFormatRGBA8.GetBitDepth: Integer;144 begin145 Result := 32;146 end;147 148 function TGColorFormatRGBA8.GetName: string;149 begin150 Result := 'RGBA8';151 end;152 153 function TGColorFormatRGBA8.GetChannelBytePos(Channel: TGColorChannel): Integer;154 begin155 case Channel of156 ccRed: Result := 0;157 ccGreen: Result := 1;158 ccBlue: Result := 2;159 ccOpacity: Result := 3;160 else raise Exception.Create('Unsupported color channel');161 end;162 end;163 164 function TGColorFormatRGBA8.GetChannelBitWidth(Channel: TGColorChannel165 ): Integer;166 begin167 if (Channel = ccBlue) or (Channel = ccRed) or (Channel = ccGreen) then168 Result := 8 else Result := 0;169 end;170 171 function TGColorFormatRGBA8.ColorToTColor(Color: TGColor): TColor;172 begin173 Result := PByte(Color.FData + GetChannelBytePos(ccRed))^ or174 (PByte(Color.FData + GetChannelBytePos(ccGreen))^ shl 8) or175 (PByte(Color.FData + GetChannelBytePos(ccBlue))^ shl 16);176 end;177 178 function TGColorFormatRGBA8.GetColorClass: TGColorClass;179 begin180 Result := TGColor;181 end;182 183 129 { TGColorFormat } 184 130 … … 286 232 end; 287 233 234 procedure TGBitmap.SetBackgroundColor(AValue: TGColor); 235 begin 236 if FBackgroundColor = AValue then Exit; 237 FBackgroundColor := AValue; 238 end; 239 288 240 procedure TGBitmap.SetColorFormat(AValue: TGColorFormatClass); 289 241 begin … … 291 243 FColorFormat := AValue; 292 244 ReAllocMem(FData, GetDataSize); 245 FBackgroundColor.Format := ColorFormat; 293 246 end; 294 247 … … 328 281 Pixel: TGColor; 329 282 begin 283 try 284 Canvas.Lock; 330 285 for Y := 0 to Size.Y - 1 do 331 286 for X := 0 to Size.X - 1 do begin … … 334 289 Pixel.Free; 335 290 end; 291 292 finally 293 Canvas.Unlock; 294 end; 295 end; 296 297 procedure TGBitmap.Clear; 298 var 299 X, Y: Integer; 300 begin 301 for Y := 0 to Size.Y - 1 do 302 for X := 0 to Size.X - 1 do begin 303 Pixels[X, Y] := BackgroundColor; 304 end; 336 305 end; 337 306 … … 339 308 begin 340 309 FData := GetMem(0); 341 ColorFormat := TGColorFormatRGBA8; 310 FBackgroundColor := TGColor.Create; 311 ColorFormat := TGColorFormat; 312 FBackgroundColor.Format := ColorFormat; 342 313 end; 343 314
Note:
See TracChangeset
for help on using the changeset viewer.