Changeset 14
- Timestamp:
- Sep 22, 2014, 5:40:17 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ColorFormats/UColorGray1.pas
r10 r14 12 12 13 13 TGColorFormatGray1 = class(TGColorFormat) 14 function GetPixelSize: Integer; override; 15 function GetBitDepth: Integer; override; 16 function GetName: string; override; 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 14 constructor Create; override; 19 15 end; 20 16 … … 23 19 { TGColorFormatGray1 } 24 20 25 function TGColorFormatGray1.GetPixelSize: Integer;21 constructor TGColorFormatGray1.Create; 26 22 begin 27 Result := 1; 28 end; 29 30 function TGColorFormatGray1.GetBitDepth: Integer; 31 begin 32 Result := 1; 33 end; 34 35 function TGColorFormatGray1.GetName: string; 36 begin 37 Result := 'Gray1'; 38 end; 39 40 function TGColorFormatGray1.GetChannelBitPos(Channel: TGColorChannel): Integer; 41 begin 42 case Channel of 43 ccGray: Result := 0; 44 else Result := 0; 45 end; 46 end; 47 48 function TGColorFormatGray1.GetChannelBitWidth(Channel: TGColorChannel 49 ): Integer; 50 begin 51 if Channel = ccGray then 52 Result := 1 else Result := 0; 23 inherited; 24 Name := 'Gray1'; 25 BitDepth := 1; 26 Channels[ccGray].Position := 0; 27 Channels[ccGray].BitWidth := 1; 53 28 end; 54 29 -
trunk/ColorFormats/UColorGray4.pas
r10 r14 12 12 13 13 TGColorFormatGray4 = class(TGColorFormat) 14 function GetPixelSize: Integer; override; 15 function GetBitDepth: Integer; override; 16 function GetName: string; override; 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 14 constructor Create; override; 19 15 end; 20 16 … … 23 19 { TGColorFormatGray4 } 24 20 25 function TGColorFormatGray4.GetPixelSize: Integer; 21 22 23 constructor TGColorFormatGray4.Create; 26 24 begin 27 Result := 4; 25 inherited Create; 26 inherited; 27 Name := 'Gray4'; 28 BitDepth := 4; 29 Channels[ccGray].Position := 0; 30 Channels[ccGray].BitWidth := 4; 28 31 end; 29 30 function TGColorFormatGray4.GetBitDepth: Integer;31 begin32 Result := 4;33 end;34 35 function TGColorFormatGray4.GetName: string;36 begin37 Result := 'Gray4';38 end;39 40 function TGColorFormatGray4.GetChannelBitPos(Channel: TGColorChannel): Integer;41 begin42 case Channel of43 ccGray: Result := 0;44 else Result := 0;45 end;46 end;47 48 function TGColorFormatGray4.GetChannelBitWidth(Channel: TGColorChannel49 ): Integer;50 begin51 if Channel = ccGray then52 Result := 4 else Result := 0;53 end;54 55 32 56 33 end. -
trunk/ColorFormats/UColorGray8.pas
r9 r14 12 12 13 13 TGColorFormatGray8 = class(TGColorFormat) 14 function GetPixelSize: Integer; override; 15 function GetBitDepth: Integer; override; 16 function GetName: string; override; 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 14 constructor Create; override; 19 15 end; 20 16 … … 23 19 { TGColorFormatGray8 } 24 20 25 function TGColorFormatGray8.GetPixelSize: Integer; 21 22 23 constructor TGColorFormatGray8.Create; 26 24 begin 27 Result := 8; 25 inherited Create; 26 inherited; 27 Name := 'Gray8'; 28 BitDepth := 8; 29 Channels[ccGray].Position := 0; 30 Channels[ccGray].BitWidth := 8; 28 31 end; 29 30 function TGColorFormatGray8.GetBitDepth: Integer;31 begin32 Result := 8;33 end;34 35 function TGColorFormatGray8.GetName: string;36 begin37 Result := 'Gray8';38 end;39 40 function TGColorFormatGray8.GetChannelBitPos(Channel: TGColorChannel): Integer;41 begin42 case Channel of43 ccGray: Result := 0;44 else Result := 0;45 end;46 end;47 48 function TGColorFormatGray8.GetChannelBitWidth(Channel: TGColorChannel49 ): Integer;50 begin51 if Channel = ccGray then52 Result := 8 else Result := 0;53 end;54 55 32 56 33 end. -
trunk/ColorFormats/UColorRGB565.pas
r11 r14 6 6 7 7 uses 8 Classes, SysUtils, Graphics, UGraphic , UMemory;8 Classes, SysUtils, Graphics, UGraphic; 9 9 10 10 type … … 12 12 13 13 TGColorFormatRGB565 = class(TGColorFormat) 14 function GetPixelSize: Integer; override; 15 function GetBitDepth: Integer; override; 16 function GetName: string; override; 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 14 constructor Create; override; 19 15 end; 20 16 … … 24 20 { TGColorFormatRGB565 } 25 21 26 function TGColorFormatRGB565.GetPixelSize: Integer;22 constructor TGColorFormatRGB565.Create; 27 23 begin 28 Result := 16; 29 end; 30 31 function TGColorFormatRGB565.GetBitDepth: Integer; 32 begin 33 Result := 16; 34 end; 35 36 function TGColorFormatRGB565.GetName: string; 37 begin 38 Result := 'RGB565'; 39 end; 40 41 function TGColorFormatRGB565.GetChannelBitPos(Channel: TGColorChannel): Integer; 42 begin 43 case Channel of 44 ccRed: Result := 0; 45 ccGreen: Result := 5; 46 ccBlue: Result := 11; 47 else Result := 0; 48 end; 49 end; 50 51 function TGColorFormatRGB565.GetChannelBitWidth(Channel: TGColorChannel 52 ): Integer; 53 begin 54 case Channel of 55 ccRed: Result := 5; 56 ccGreen: Result := 6; 57 ccBlue: Result := 5; 58 else Result := 0; 59 end; 24 inherited Create; 25 BitDepth := 16; 26 Name := 'RGB565'; 27 Channels[ccRed].Position := 0; 28 Channels[ccRed].BitWidth := 5; 29 Channels[ccGreen].Position := 5; 30 Channels[ccGreen].BitWidth := 6; 31 Channels[ccBlue].Position := 9; 32 Channels[ccBlue].BitWidth := 6; 60 33 end; 61 34 -
trunk/ColorFormats/UColorRGBA8.pas
r9 r14 12 12 13 13 TGColorFormatRGBA8 = class(TGColorFormat) 14 function GetPixelSize: Integer; override; 15 function GetBitDepth: Integer; override; 16 function GetName: string; override; 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 14 constructor Create; override; 19 15 end; 20 16 … … 24 20 { TGColorFormatRGBA8 } 25 21 26 function TGColorFormatRGBA8.GetPixelSize: Integer;22 constructor TGColorFormatRGBA8.Create; 27 23 begin 28 Result := 32; 29 end; 30 31 function TGColorFormatRGBA8.GetBitDepth: Integer; 32 begin 33 Result := 32; 34 end; 35 36 function TGColorFormatRGBA8.GetName: string; 37 begin 38 Result := 'RGBA8'; 39 end; 40 41 function TGColorFormatRGBA8.GetChannelBitPos(Channel: TGColorChannel): Integer; 42 begin 43 case Channel of 44 ccRed: Result := 0; 45 ccGreen: Result := 8; 46 ccBlue: Result := 16; 47 ccOpacity: Result := 24; 48 else Result := 0; 49 end; 50 end; 51 52 function TGColorFormatRGBA8.GetChannelBitWidth(Channel: TGColorChannel 53 ): Integer; 54 begin 55 if (Channel = ccBlue) or (Channel = ccRed) or (Channel = ccGreen) then 56 Result := 8 else Result := 0; 24 inherited Create; 25 BitDepth := 32; 26 Name := 'RGBA8'; 27 Channels[ccRed].Position := 0; 28 Channels[ccRed].BitWidth := 8; 29 Channels[ccGreen].Position := 8; 30 Channels[ccGreen].BitWidth := 8; 31 Channels[ccBlue].Position := 16; 32 Channels[ccBlue].BitWidth := 8; 33 Channels[ccOpacity].Position := 24; 34 Channels[ccOpacity].BitWidth := 8; 57 35 end; 58 36 -
trunk/Forms/UFormNew.pas
r10 r14 49 49 ColorFormat := ColorManager.Formats[ComboBoxColorFormat.ItemIndex]; 50 50 LabelMemRequire.Caption := IntToStr(SpinEditWidth.Value * SpinEditHeight.Value * 51 ColorFormat. GetBitDepth div 8) + ' bytes';51 ColorFormat.BitDepth div 8) + ' bytes'; 52 52 end; 53 53 … … 60 60 for I := 0 to ColorManager.FormatCount - 1 do begin 61 61 ColorFormat := ColorManager.Formats[I]; 62 ComboBoxColorFormat.AddItem(ColorFormat. GetName, nil);62 ComboBoxColorFormat.AddItem(ColorFormat.Name, nil); 63 63 end; 64 64 if ComboBoxColorFormat.Items.Count > 0 then -
trunk/LibrePaint.lpi
r13 r14 118 118 <Filename Value="ColorFormats/UColorGray8.pas"/> 119 119 <IsPartOfProject Value="True"/> 120 <UnitName Value="UColorGray8"/> 120 121 </Unit7> 121 122 <Unit8> -
trunk/UGraphic.pas
r13 r14 15 15 TGBitmap = class; 16 16 17 TGColorFormatChannel = record 18 BitWidth: Integer; 19 Position: Integer; 20 end; 21 17 22 { TGColorFormat } 18 23 19 24 TGColorFormat = class 20 function GetBitDepth: Integer; virtual; 21 function GetPixelSize: Integer; virtual; 22 function GetName: string; virtual; 23 function GetChannelBitPos(Channel: TGColorChannel): Integer; virtual; 24 function GetChannelBitWidth(Channel: TGColorChannel): Integer; virtual; 25 BitDepth: Integer; 26 Name: string; 27 Channels: array[TGColorChannel] of TGColorFormatChannel; 28 constructor Create; virtual; 25 29 function GetChannelStateCount(Channel: TGColorChannel): Integer; virtual; 26 30 function ChannelUsed(Channel: TGColorChannel): Boolean; … … 233 237 { TGColorFormat } 234 238 235 function TGColorFormat.GetBitDepth: Integer; 236 begin 237 Result := 0; 238 end; 239 240 function TGColorFormat.GetPixelSize: Integer; 241 begin 242 Result := 0; 243 end; 244 245 function TGColorFormat.GetName: string; 246 begin 247 Result := ''; 248 end; 249 250 function TGColorFormat.GetChannelBitPos(Channel: TGColorChannel): Integer; 251 begin 252 253 end; 254 255 function TGColorFormat.GetChannelBitWidth(Channel: TGColorChannel): Integer; 256 begin 257 Result := 0; 239 constructor TGColorFormat.Create; 240 var 241 Channel: TGColorChannel; 242 begin 243 Name := ''; 244 BitDepth := 0; 245 for Channel := Low(TGColorChannel) to High(TGColorChannel) do begin 246 Channels[Channel].BitWidth := 0; 247 Channels[Channel].Position := 0; 248 end; 258 249 end; 259 250 260 251 function TGColorFormat.GetChannelStateCount(Channel: TGColorChannel): Integer; 261 252 begin 262 Result := 1 shl GetChannelBitWidth(Channel);253 Result := 1 shl Channels[Channel].BitWidth; 263 254 end; 264 255 265 256 function TGColorFormat.ChannelUsed(Channel: TGColorChannel): Boolean; 266 257 begin 267 Result := GetChannelBitWidth(Channel)> 0;258 Result := Channels[Channel].BitWidth > 0; 268 259 end; 269 260 … … 275 266 Channel := TBitMemory.Create; 276 267 277 if GetChannelBitWidth(ccRed)> 0 then begin278 Channel.Size := GetChannelBitWidth(ccRed);279 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccRed));268 if Channels[ccRed].BitWidth > 0 then begin 269 Channel.Size := Channels[ccRed].BitWidth; 270 Color.Data.ReadBlock(Channel, Channels[ccRed].Position); 280 271 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccRed) - 1)) shl 0); 281 272 end; 282 273 283 if GetChannelBitWidth(ccGreen)> 0 then begin284 Channel.Size := GetChannelBitWidth(ccGreen);285 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccGreen));274 if Channels[ccGreen].BitWidth > 0 then begin 275 Channel.Size := Channels[ccGreen].BitWidth; 276 Color.Data.ReadBlock(Channel, Channels[ccGreen].Position); 286 277 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccGreen) - 1)) shl 8); 287 278 end; 288 279 289 if GetChannelBitWidth(ccBlue)> 0 then begin290 Channel.Size := GetChannelBitWidth(ccBlue);291 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccBlue));280 if Channels[ccBlue].BitWidth > 0 then begin 281 Channel.Size := Channels[ccBlue].BitWidth; 282 Color.Data.ReadBlock(Channel, Channels[ccBlue].Position); 292 283 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccBlue) - 1)) shl 16); 293 284 end; 294 285 295 if GetChannelBitWidth(ccGray)> 0 then begin296 Channel.Size := GetChannelBitWidth(ccGray);297 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccGray));286 if Channels[ccGray].BitWidth > 0 then begin 287 Channel.Size := Channels[ccGray].BitWidth; 288 Color.Data.ReadBlock(Channel, Channels[ccGray].Position); 298 289 Result := $010101 * Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccGray) - 1)); 299 290 end; … … 309 300 Channel := TBitMemory.Create; 310 301 311 if GetChannelBitWidth(ccRed)> 0 then begin312 Channel.Size := GetChannelBitWidth(ccRed);302 if Channels[ccRed].BitWidth > 0 then begin 303 Channel.Size := Channels[ccRed].BitWidth; 313 304 Channel.SetInteger(((Color shr 0) and $ff) * GetChannelStateCount(ccRed) div 256); 314 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccRed));315 end; 316 317 if GetChannelBitWidth(ccGreen)> 0 then begin318 Channel.Size := GetChannelBitWidth(ccGreen);305 GColor.Data.WriteBlock(Channel, Channels[ccRed].Position); 306 end; 307 308 if Channels[ccGreen].BitWidth > 0 then begin 309 Channel.Size := Channels[ccGreen].BitWidth; 319 310 Channel.SetInteger(((Color shr 8) and $ff) * GetChannelStateCount(ccGreen) div 256); 320 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccGreen));321 end; 322 323 if GetChannelBitWidth(ccBlue)> 0 then begin324 Channel.Size := GetChannelBitWidth(ccBlue);311 GColor.Data.WriteBlock(Channel, Channels[ccGreen].Position); 312 end; 313 314 if Channels[ccBlue].BitWidth > 0 then begin 315 Channel.Size := Channels[ccBlue].BitWidth; 325 316 Channel.SetInteger(((Color shr 16) and $ff) * GetChannelStateCount(ccBlue) div 256); 326 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccBlue));327 end; 328 329 if GetChannelBitWidth(ccGray)> 0 then begin330 Channel.Size := GetChannelBitWidth(ccGray);317 GColor.Data.WriteBlock(Channel, Channels[ccBlue].Position); 318 end; 319 320 if Channels[ccGray].BitWidth > 0 then begin 321 Channel.Size := Channels[ccGray].BitWidth; 331 322 Channel.SetInteger((((Color shr 16) and $ff) + ((Color shr 8) and $ff) + ((Color shr 0) and $ff)) 332 323 * GetChannelStateCount(ccGray) div (3 * 256)); 333 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccGray));324 GColor.Data.WriteBlock(Channel, Channels[ccGray].Position); 334 325 end; 335 326 … … 348 339 if FColorFormat = AValue then Exit; 349 340 FColorFormat := AValue; 350 FData.Size := FColorFormat. GetPixelSize;341 FData.Size := FColorFormat.BitDepth; 351 342 end; 352 343 … … 377 368 Channel := TBitMemory.Create; 378 369 379 if Format. GetChannelBitWidth(ccRed)> 0 then begin380 Channel.Size := Format. GetChannelBitWidth(ccRed);381 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccRed));370 if Format.Channels[ccRed].BitWidth > 0 then begin 371 Channel.Size := Format.Channels[ccRed].BitWidth; 372 Data.ReadBlock(Channel, Format.Channels[ccRed].Position); 382 373 Channel.Invert; 383 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccRed));384 end; 385 386 if Format. GetChannelBitWidth(ccGreen)> 0 then begin387 Channel.Size := Format. GetChannelBitWidth(ccGreen);388 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccGreen));374 Data.WriteBlock(Channel, Format.Channels[ccRed].Position); 375 end; 376 377 if Format.Channels[ccGreen].BitWidth > 0 then begin 378 Channel.Size := Format.Channels[ccGreen].BitWidth; 379 Data.ReadBlock(Channel, Format.Channels[ccGreen].Position); 389 380 Channel.Invert; 390 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccGreen));391 end; 392 393 if Format. GetChannelBitWidth(ccBlue)> 0 then begin394 Channel.Size := Format. GetChannelBitWidth(ccBlue);395 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccBlue));381 Data.WriteBlock(Channel, Format.Channels[ccGreen].Position); 382 end; 383 384 if Format.Channels[ccBlue].BitWidth > 0 then begin 385 Channel.Size := Format.Channels[ccBlue].BitWidth; 386 Data.ReadBlock(Channel, Format.Channels[ccBlue].Position); 396 387 Channel.Invert; 397 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccBlue));398 end; 399 400 if Format. GetChannelBitWidth(ccGray)> 0 then begin401 Channel.Size := Format. GetChannelBitWidth(ccGray);402 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccGray));388 Data.WriteBlock(Channel, Format.Channels[ccBlue].Position); 389 end; 390 391 if Format.Channels[ccGray].BitWidth > 0 then begin 392 Channel.Size := Format.Channels[ccGray].BitWidth; 393 Data.ReadBlock(Channel, Format.Channels[ccGray].Position); 403 394 Channel.Invert; 404 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccGray));395 Data.WriteBlock(Channel, Format.Channels[ccGray].Position); 405 396 end; 406 397 … … 462 453 function TGBitmap.GetPixelDataPos(X, Y: Integer): Integer; 463 454 begin 464 Result := X * FColorFormat. GetPixelSize + Y * FColorFormat.GetPixelSize* FSize.X;455 Result := X * FColorFormat.BitDepth + Y * FColorFormat.BitDepth * FSize.X; 465 456 end; 466 457 … … 496 487 function TGBitmap.GetDataSize: Integer; 497 488 begin 498 Result := Size.X * Size.Y * FColorFormat. GetPixelSize;489 Result := Size.X * Size.Y * FColorFormat.BitDepth; 499 490 end; 500 491
Note:
See TracChangeset
for help on using the changeset viewer.