Changeset 9
- Timestamp:
- Sep 21, 2014, 8:11:48 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 LibrePaint 3 3 lib 4 backup
-
- Property svn:ignore
-
trunk/ColorFormats/UColorGray1.pas
r7 r9 17 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 19 function ColorToTColor(Color: TGColor): TColor; override;20 procedure ColorFromTColor(GColor: TGColor; Color: TColor); override;21 function GetColorClass: TGColorClass; override;22 19 end; 23 20 … … 56 53 end; 57 54 58 function TGColorFormatGray1.ColorToTColor(Color: TGColor): TColor;59 begin60 Result := $ffffff * (PByte(Color.Data + GetChannelBitPos(ccGray))^ and 1);61 end;62 63 procedure TGColorFormatGray1.ColorFromTColor(GColor: TGColor; Color: TColor);64 begin65 PByte(GColor.Data + GetChannelBitPos(ccGray))^ := (((Color and $ff) +66 ((Color shr 8) and $ff) +67 ((Color shr 16) and $ff)) div 3) shr 7;68 end;69 70 function TGColorFormatGray1.GetColorClass: TGColorClass;71 begin72 Result := TGColor;73 end;74 75 55 76 56 end. -
trunk/ColorFormats/UColorGray8.pas
r7 r9 17 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 19 function ColorToTColor(Color: TGColor): TColor; override;20 procedure ColorFromTColor(GColor: TGColor; Color: TColor); override;21 function GetColorClass: TGColorClass; override;22 19 end; 23 20 … … 28 25 function TGColorFormatGray8.GetPixelSize: Integer; 29 26 begin 30 Result := 1;27 Result := 8; 31 28 end; 32 29 … … 45 42 case Channel of 46 43 ccGray: Result := 0; 47 else raise Exception.Create('Unsupported color channel');44 else Result := 0; 48 45 end; 49 46 end; … … 56 53 end; 57 54 58 function TGColorFormatGray8.ColorToTColor(Color: TGColor): TColor;59 begin60 Result := $010101 * PByte(Color.Data + (GetChannelBitPos(ccGray) shr 3))^;61 end;62 63 procedure TGColorFormatGray8.ColorFromTColor(GColor: TGColor; Color: TColor);64 begin65 PByte(GColor.Data + (GetChannelBitPos(ccGray) shr 3))^ := ((Color and $ff) +66 ((Color shr 8) and $ff) +67 ((Color shr 16) and $ff)) div 3;68 end;69 70 function TGColorFormatGray8.GetColorClass: TGColorClass;71 begin72 Result := TGColor;73 end;74 75 55 76 56 end. -
trunk/ColorFormats/UColorRGBA8.pas
r7 r9 6 6 7 7 uses 8 Classes, SysUtils, Graphics, UGraphic ;8 Classes, SysUtils, Graphics, UGraphic, UMemory; 9 9 10 10 type … … 17 17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 19 function ColorToTColor(Color: TGColor): TColor; override;20 procedure ColorFromTColor(GColor: TGColor; Color: TColor); override;21 function GetColorClass: TGColorClass; override;22 19 end; 23 20 … … 29 26 function TGColorFormatRGBA8.GetPixelSize: Integer; 30 27 begin 31 Result := 4;28 Result := 32; 32 29 end; 33 30 … … 49 46 ccBlue: Result := 16; 50 47 ccOpacity: Result := 24; 51 else raise Exception.Create('Unsupported color channel');48 else Result := 0; 52 49 end; 53 50 end; … … 60 57 end; 61 58 62 function TGColorFormatRGBA8.ColorToTColor(Color: TGColor): TColor;63 begin64 Result := PByte(Color.Data + (GetChannelBitPos(ccRed) shr 3))^ or65 (PByte(Color.Data + (GetChannelBitPos(ccGreen) shr 3))^ shl 8) or66 (PByte(Color.Data + (GetChannelBitPos(ccBlue) shr 3))^ shl 16);67 end;68 69 procedure TGColorFormatRGBA8.ColorFromTColor(GColor: TGColor; Color: TColor);70 begin71 PByte(GColor.Data + (GetChannelBitPos(ccRed) shr 3))^ := Color and $ff;72 PByte(GColor.Data + (GetChannelBitPos(ccGreen) shr 3))^ := (Color shr 8) and $ff;73 PByte(GColor.Data + (GetChannelBitPos(ccBlue) shr 3))^ := (Color shr 16) and $ff;74 end;75 76 function TGColorFormatRGBA8.GetColorClass: TGColorClass;77 begin78 Result := TGColor;79 end;80 81 82 59 end. 83 60 -
trunk/LibrePaint.lpi
r8 r9 71 71 </Item1> 72 72 </RequiredPackages> 73 <Units Count=" 9">73 <Units Count="10"> 74 74 <Unit0> 75 75 <Filename Value="LibrePaint.lpr"/> … … 99 99 <HasResources Value="True"/> 100 100 <ResourceBaseClass Value="Form"/> 101 <UnitName Value="UFormNew"/>102 101 </Unit4> 103 102 <Unit5> … … 112 111 <HasResources Value="True"/> 113 112 <ResourceBaseClass Value="Form"/> 114 <UnitName Value="UFormMain"/>115 113 </Unit6> 116 114 <Unit7> … … 124 122 <UnitName Value="UColorGray1"/> 125 123 </Unit8> 124 <Unit9> 125 <Filename Value="UMemory.pas"/> 126 <IsPartOfProject Value="True"/> 127 <UnitName Value="UMemory"/> 128 </Unit9> 126 129 </Units> 127 130 </ProjectOptions> -
trunk/LibrePaint.lpr
r7 r9 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UCore, UGraphic, UProject, U FormNew, UFormMain, UColorRGBA8,11 UColorGray8, UColorGray110 Forms, UCore, UGraphic, UProject, UBitStream, UMemory, UFormNew, UFormMain, 11 UColorRGBA8, UColorGray8, UColorGray1 12 12 { you can add units after this }; 13 13 -
trunk/UCore.pas
r8 r9 66 66 67 67 // Set default 68 Project.Bitmap.Size := Point( 800, 600);68 Project.Bitmap.Size := Point(200, 100); 69 69 if ColorManager.FormatCount > 0 then 70 70 Project.Bitmap.ColorFormat := ColorManager.Formats[0]; … … 79 79 Project.Bitmap.Size := Point(FormNew.SpinEditWidth.Value, FormNew.SpinEditHeight.Value); 80 80 Project.Bitmap.ColorFormat := ColorManager.Formats[FormNew.ComboBoxColorFormat.ItemIndex]; 81 Project.Bitmap.BackgroundColor.FromTColor(clBlack); 81 82 Project.Bitmap.DPI := FormNew.SpinEditDPI.Value; 82 83 FormMain.Redraw; … … 112 113 Project.Bitmap.Canvas.Pen.Color.Format := Project.Bitmap.ColorFormat; 113 114 Project.Bitmap.Canvas.Pen.Color.FromTColor(clWhite); 114 Project.Bitmap.Canvas.Pen.MoveTo(Point( 100, 100));115 Project.Bitmap.Canvas.Pen.LineTo(Point( 700, 500));115 Project.Bitmap.Canvas.Pen.MoveTo(Point(80, 80)); 116 Project.Bitmap.Canvas.Pen.LineTo(Point(50, 20)); 116 117 FormMain.Redraw; 117 118 end; -
trunk/UGraphic.pas
r8 r9 6 6 7 7 uses 8 Classes, SysUtils, Graphics, Contnrs ;8 Classes, SysUtils, Graphics, Contnrs, UMemory; 9 9 10 10 type … … 13 13 TGColor = class; 14 14 TGCanvas = class; 15 16 TGColorClass = class of TGColor; 15 TGBitmap = class; 17 16 18 17 { TGColorFormat } … … 24 23 function GetChannelBitPos(Channel: TGColorChannel): Integer; virtual; 25 24 function GetChannelBitWidth(Channel: TGColorChannel): Integer; virtual; 25 function GetChannelStateCount(Channel: TGColorChannel): Integer; virtual; 26 26 function ChannelUsed(Channel: TGColorChannel): Boolean; 27 27 function ColorToTColor(Color: TGColor): TColor; virtual; 28 28 procedure ColorFromTColor(GColor: TGColor; Color: TColor); virtual; 29 function GetColorClass: TGColorClass; virtual;30 29 end; 31 30 … … 37 36 private 38 37 FColorFormat: TGColorFormat; 39 FData: PByte;38 FData: TBitMemory; 40 39 function GetChannel(Channel: TGColorChannel): TGColor; 41 40 procedure SetColorFormat(AValue: TGColorFormat); 42 procedure LoadData(Bitmap Data: Pointer); virtual;43 procedure SaveData(Bitmap Data: Pointer); virtual;41 procedure LoadData(Bitmap: TGBitmap; Position: Integer); virtual; 42 procedure SaveData(Bitmap: TGBitmap; Position: Integer); virtual; 44 43 public 45 44 function ToTColor: TColor; … … 48 47 constructor Create; 49 48 property Channels[Channel: TGColorChannel]: TGColor read GetChannel; 50 property Data: PByteread FData;49 property Data: TBitMemory read FData; 51 50 published 52 51 property Format: TGColorFormat read FColorFormat write SetColorFormat; … … 62 61 FDPI: Integer; 63 62 FSize: TPoint; 64 FData: PByte;63 FData: TBitMemory; 65 64 function GetPixel(X, Y: Integer): TGColor; 66 65 function GetSize: TPoint; … … 69 68 procedure SetPixel(X, Y: Integer; AValue: TGColor); 70 69 procedure SetSize(AValue: TPoint); 71 function GetPixelDataPos(X, Y: Integer): Pointer; 70 function GetPixelDataPos(X, Y: Integer): Integer; 71 procedure CheckLimits(X, Y: Integer); 72 72 public 73 73 function GetDataSize: Integer; … … 79 79 constructor Create; virtual; 80 80 destructor Destroy; override; 81 property Data: TBitMemory read FData; 81 82 property BackgroundColor: TGColor read FBackgroundColor write SetBackgroundColor; 82 83 property DPI: Integer read FDPI write FDPI; … … 253 254 end; 254 255 256 function TGColorFormat.GetChannelStateCount(Channel: TGColorChannel): Integer; 257 begin 258 Result := 1 shl GetChannelBitWidth(Channel); 259 end; 260 255 261 function TGColorFormat.ChannelUsed(Channel: TGColorChannel): Boolean; 256 262 begin … … 259 265 260 266 function TGColorFormat.ColorToTColor(Color: TGColor): TColor; 261 begin 262 Result := clBlack; 267 var 268 Channel: TBitMemory; 269 begin 270 Result := 0; 271 Channel := TBitMemory.Create; 272 273 if GetChannelBitWidth(ccRed) > 0 then begin 274 Channel.Size := GetChannelBitWidth(ccRed); 275 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccRed)); 276 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccRed) - 1)) shl 0); 277 end; 278 279 if GetChannelBitWidth(ccGreen) > 0 then begin 280 Channel.Size := GetChannelBitWidth(ccGreen); 281 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccGreen)); 282 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccGreen) - 1)) shl 8); 283 end; 284 285 if GetChannelBitWidth(ccBlue) > 0 then begin 286 Channel.Size := GetChannelBitWidth(ccBlue); 287 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccBlue)); 288 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccBlue) - 1)) shl 16); 289 end; 290 291 if GetChannelBitWidth(ccGray) > 0 then begin 292 Channel.Size := GetChannelBitWidth(ccGray); 293 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccGray)); 294 Result := $010101 * Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccGray) - 1)); 295 end; 296 297 Channel.Free; 263 298 end; 264 299 265 300 procedure TGColorFormat.ColorFromTColor(GColor: TGColor; Color: TColor); 266 begin 267 FillChar(GColor.Data^, GetPixelSize, 0); 268 end; 269 270 function TGColorFormat.GetColorClass: TGColorClass; 271 begin 272 Result := TGColor; 301 var 302 Channel: TBitMemory; 303 begin 304 GColor.Data.Clear(0); 305 Channel := TBitMemory.Create; 306 307 if GetChannelBitWidth(ccRed) > 0 then begin 308 Channel.Size := GetChannelBitWidth(ccRed); 309 Channel.SetInteger(((Color shr 0) and $ff) * GetChannelStateCount(ccRed) div 256); 310 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccRed)); 311 end; 312 313 if GetChannelBitWidth(ccGreen) > 0 then begin 314 Channel.Size := GetChannelBitWidth(ccGreen); 315 Channel.SetInteger(((Color shr 8) and $ff) * GetChannelStateCount(ccGreen) div 256); 316 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccGreen)); 317 end; 318 319 if GetChannelBitWidth(ccBlue) > 0 then begin 320 Channel.Size := GetChannelBitWidth(ccBlue); 321 Channel.SetInteger(((Color shr 16) and $ff) * GetChannelStateCount(ccBlue) div 256); 322 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccBlue)); 323 end; 324 325 if GetChannelBitWidth(ccGray) > 0 then begin 326 Channel.Size := GetChannelBitWidth(ccGray); 327 Channel.SetInteger((((Color shr 16) and $ff) + ((Color shr 8) and $ff) + ((Color shr 0) and $ff)) 328 * GetChannelStateCount(ccGray) div (3 * 256)); 329 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccGray)); 330 end; 331 332 Channel.Free; 273 333 end; 274 334 … … 284 344 if FColorFormat = AValue then Exit; 285 345 FColorFormat := AValue; 286 ReAllocMem(FData, FColorFormat.GetPixelSize);287 end; 288 289 procedure TGColor.LoadData(Bitmap Data: Pointer);290 begin 291 Move(BitmapData^, FData^, FColorFormat.GetPixelSize);292 end; 293 294 procedure TGColor.SaveData(Bitmap Data: Pointer);295 begin 296 Move(FData^, BitmapData^, FColorFormat.GetPixelSize);346 FData.Size := FColorFormat.GetPixelSize; 347 end; 348 349 procedure TGColor.LoadData(Bitmap: TGBitmap; Position: Integer); 350 begin 351 Bitmap.Data.ReadBlock(FData, Position); 352 end; 353 354 procedure TGColor.SaveData(Bitmap: TGBitmap; Position: Integer); 355 begin 356 Bitmap.Data.WriteBlock(FData, Position); 297 357 end; 298 358 … … 313 373 constructor TGColor.Create; 314 374 begin 375 FData := TBitMemory.Create; 315 376 Format := TGColorFormat.Create; 316 377 end; … … 320 381 function TGBitmap.GetPixel(X, Y: Integer): TGColor; 321 382 begin 383 CheckLimits(X, Y); 322 384 Result := TGColor.Create; 323 385 Result.Format := ColorFormat; 324 Result.LoadData( GetPixelDataPos(X, Y));386 Result.LoadData(Self, GetPixelDataPos(X, Y)); 325 387 end; 326 388 … … 340 402 if FColorFormat = AValue then Exit; 341 403 FColorFormat := AValue; 342 ReAllocMem(FData, GetDataSize);404 FData.Size := GetDataSize; 343 405 FBackgroundColor.Format := ColorFormat; 344 406 end; … … 346 408 procedure TGBitmap.SetPixel(X, Y: Integer; AValue: TGColor); 347 409 begin 348 AValue.SaveData(GetPixelDataPos(X, Y)); 410 CheckLimits(X, Y); 411 FData.WriteBlock(AValue.Data, GetPixelDataPos(X, Y)); 349 412 end; 350 413 … … 353 416 if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit; 354 417 FSize := AValue; 355 ReAllocMem(FData, GetDataSize); 356 end; 357 358 function TGBitmap.GetPixelDataPos(X, Y: Integer): Pointer; 359 begin 360 Result := FData + X * FColorFormat.GetPixelSize + Y * FColorFormat.GetPixelSize * FSize.X; 418 FData.Size := GetDataSize; 419 end; 420 421 function TGBitmap.GetPixelDataPos(X, Y: Integer): Integer; 422 begin 423 Result := X * FColorFormat.GetPixelSize + Y * FColorFormat.GetPixelSize * FSize.X; 424 end; 425 426 procedure TGBitmap.CheckLimits(X, Y: Integer); 427 begin 428 if (X < 0) or (Y < 0) or (X >= Size.X) or (Y >= Size.Y) then 429 raise Exception.Create('Out of range'); 361 430 end; 362 431 … … 399 468 X, Y: Integer; 400 469 Color: TGColor; 470 F: Cardinal; 401 471 begin 402 472 Color := TGColor.Create; … … 405 475 for X := 0 to Size.X - 1 do begin 406 476 Color.FromTColor(System.Random($ffffff)); 477 F := Cardinal(Color.Data.GetInteger); 478 407 479 Pixels[X, Y] := Color; 408 480 end; … … 440 512 constructor TGBitmap.Create; 441 513 begin 442 FData := GetMem(0);514 FData := TBitMemory.Create; 443 515 FBackgroundColor := TGColor.Create; 444 516 ColorFormat := TGColorFormat.Create; … … 451 523 destructor TGBitmap.Destroy; 452 524 begin 525 Size := Point(0, 0); 526 FData.Free; 453 527 inherited Destroy; 454 Size := Point(0, 0);455 528 end; 456 529
Note:
See TracChangeset
for help on using the changeset viewer.