Changeset 7
- Timestamp:
- Sep 19, 2014, 9:25:56 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ColorFormats/UColorGray8.pas
r5 r7 15 15 function GetBitDepth: Integer; override; 16 16 function GetName: string; override; 17 function GetChannelB ytePos(Channel: TGColorChannel): Integer; override;17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 19 19 function ColorToTColor(Color: TGColor): TColor; override; … … 41 41 end; 42 42 43 function TGColorFormatGray8.GetChannelB ytePos(Channel: TGColorChannel): Integer;43 function TGColorFormatGray8.GetChannelBitPos(Channel: TGColorChannel): Integer; 44 44 begin 45 45 case Channel of … … 58 58 function TGColorFormatGray8.ColorToTColor(Color: TGColor): TColor; 59 59 begin 60 Result := $010101 * PByte(Color.Data + GetChannelBytePos(ccGray))^;60 Result := $010101 * PByte(Color.Data + (GetChannelBitPos(ccGray) shr 3))^; 61 61 end; 62 62 63 63 procedure TGColorFormatGray8.ColorFromTColor(GColor: TGColor; Color: TColor); 64 64 begin 65 PByte(GColor.Data + GetChannelBytePos(ccGray))^ := ((Color and $ff) +65 PByte(GColor.Data + (GetChannelBitPos(ccGray) shr 3))^ := ((Color and $ff) + 66 66 ((Color shr 8) and $ff) + 67 67 ((Color shr 16) and $ff)) div 3; -
trunk/ColorFormats/UColorRGBA8.pas
r4 r7 15 15 function GetBitDepth: Integer; override; 16 16 function GetName: string; override; 17 function GetChannelB ytePos(Channel: TGColorChannel): Integer; override;17 function GetChannelBitPos(Channel: TGColorChannel): Integer; override; 18 18 function GetChannelBitWidth(Channel: TGColorChannel): Integer; override; 19 19 function ColorToTColor(Color: TGColor): TColor; override; … … 42 42 end; 43 43 44 function TGColorFormatRGBA8.GetChannelB ytePos(Channel: TGColorChannel): Integer;44 function TGColorFormatRGBA8.GetChannelBitPos(Channel: TGColorChannel): Integer; 45 45 begin 46 46 case Channel of 47 47 ccRed: Result := 0; 48 ccGreen: Result := 1;49 ccBlue: Result := 2;50 ccOpacity: Result := 3;48 ccGreen: Result := 8; 49 ccBlue: Result := 16; 50 ccOpacity: Result := 24; 51 51 else raise Exception.Create('Unsupported color channel'); 52 52 end; … … 62 62 function TGColorFormatRGBA8.ColorToTColor(Color: TGColor): TColor; 63 63 begin 64 Result := PByte(Color.Data + GetChannelBytePos(ccRed))^ or65 (PByte(Color.Data + GetChannelBytePos(ccGreen))^ shl 8) or66 (PByte(Color.Data + GetChannelBytePos(ccBlue))^ shl 16);64 Result := PByte(Color.Data + (GetChannelBitPos(ccRed) shr 3))^ or 65 (PByte(Color.Data + (GetChannelBitPos(ccGreen) shr 3))^ shl 8) or 66 (PByte(Color.Data + (GetChannelBitPos(ccBlue) shr 3))^ shl 16); 67 67 end; 68 68 69 69 procedure TGColorFormatRGBA8.ColorFromTColor(GColor: TGColor; Color: TColor); 70 70 begin 71 PByte(GColor.Data + GetChannelBytePos(ccRed))^ := Color and $ff;72 PByte(GColor.Data + GetChannelBytePos(ccGreen))^ := (Color shr 8) and $ff;73 PByte(GColor.Data + GetChannelBytePos(ccBlue))^ := (Color shr 16) and $ff;71 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 74 end; 75 75 -
trunk/Forms/UFormMain.lfm
r6 r7 5 5 Width = 920 6 6 Caption = 'LibrePaint' 7 ClientHeight = 61 17 ClientHeight = 614 8 8 ClientWidth = 920 9 9 Menu = MainMenu1 … … 11 11 object PaintBox1: TPaintBox 12 12 Left = 0 13 Height = 58 213 Height = 588 14 14 Top = 0 15 15 Width = 920 … … 20 20 object StatusBar1: TStatusBar 21 21 Left = 0 22 Height = 2 923 Top = 58 222 Height = 26 23 Top = 588 24 24 Width = 920 25 25 Panels = <> … … 76 76 Action = Core.AImageClear 77 77 end 78 object MenuItem14: TMenuItem 79 Action = Core.AImageRandom 80 end 81 object MenuItem17: TMenuItem 82 Action = Core.AImageMirror 83 end 84 object MenuItem18: TMenuItem 85 Action = Core.AImageFlip 86 end 78 87 end 79 88 end -
trunk/Forms/UFormMain.pas
r6 r7 20 20 MenuItem12: TMenuItem; 21 21 MenuItem13: TMenuItem; 22 MenuItem14: TMenuItem; 23 MenuItem17: TMenuItem; 24 MenuItem18: TMenuItem; 22 25 MenuItemRecentFiles: TMenuItem; 23 26 MenuItem15: TMenuItem; -
trunk/LibrePaint.lpi
r6 r7 71 71 </Item1> 72 72 </RequiredPackages> 73 <Units Count=" 7">73 <Units Count="9"> 74 74 <Unit0> 75 75 <Filename Value="LibrePaint.lpr"/> … … 92 92 <Filename Value="UProject.pas"/> 93 93 <IsPartOfProject Value="True"/> 94 <UnitName Value="UProject"/>95 94 </Unit3> 96 95 <Unit4> … … 100 99 <HasResources Value="True"/> 101 100 <ResourceBaseClass Value="Form"/> 102 <UnitName Value="UFormNew"/>103 101 </Unit4> 104 102 <Unit5> … … 115 113 <UnitName Value="UFormMain"/> 116 114 </Unit6> 115 <Unit7> 116 <Filename Value="ColorFormats/UColorGray8.pas"/> 117 <IsPartOfProject Value="True"/> 118 <UnitName Value="UColorGray8"/> 119 </Unit7> 120 <Unit8> 121 <Filename Value="ColorFormats/UColorGray1.pas"/> 122 <IsPartOfProject Value="True"/> 123 <UnitName Value="UColorGray1"/> 124 </Unit8> 117 125 </Units> 118 126 </ProjectOptions> … … 143 151 <StackChecks Value="True"/> 144 152 </Checks> 145 <VerifyObjMethodCallValidity Value="True"/>146 153 </CodeGeneration> 147 154 <Linking> -
trunk/LibrePaint.lpr
r5 r7 9 9 Interfaces, // this includes the LCL widgetset 10 10 Forms, UCore, UGraphic, UProject, UFormNew, UFormMain, UColorRGBA8, 11 UColorGray8 11 UColorGray8, UColorGray1 12 12 { you can add units after this }; 13 13 -
trunk/UCore.lfm
r6 r7 20 20 end 21 21 object AImageClear: TAction 22 Category = 'Image' 22 23 Caption = 'Clear' 23 24 OnExecute = AImageClearExecute … … 60 61 Caption = 'Save as...' 61 62 end 63 object AImageRandom: TAction 64 Category = 'Image' 65 Caption = 'Random' 66 OnExecute = AImageRandomExecute 67 end 68 object AImageFlip: TAction 69 Category = 'Image' 70 Caption = 'Flip' 71 OnExecute = AImageFlipExecute 72 end 73 object AImageMirror: TAction 74 Category = 'Image' 75 Caption = 'Mirror' 76 OnExecute = AImageMirrorExecute 77 end 62 78 end 63 79 object ImageList1: TImageList -
trunk/UCore.pas
r6 r7 13 13 14 14 TCore = class(TDataModule) 15 AImageMirror: TAction; 16 AImageFlip: TAction; 17 AImageRandom: TAction; 15 18 AFileSaveAs: TAction; 16 19 AFileSave: TAction; … … 21 24 AZoomIn: TAction; 22 25 AZoomOut: TAction; 23 AImageRandom: TAction;24 26 AImageClear: TAction; 25 27 AExit: TAction; … … 29 31 procedure AExitExecute(Sender: TObject); 30 32 procedure AImageClearExecute(Sender: TObject); 33 procedure AImageFlipExecute(Sender: TObject); 34 procedure AImageMirrorExecute(Sender: TObject); 31 35 procedure AImageRandomExecute(Sender: TObject); 32 36 procedure AFileNewExecute(Sender: TObject); … … 49 53 50 54 uses 51 UFormNew, UFormMain, Forms, UColorRGBA8, UColorGray8 ;55 UFormNew, UFormMain, Forms, UColorRGBA8, UColorGray8, UColorGray1; 52 56 53 57 { TCore } … … 59 63 ColorManager.RegisterFormat(TGColorFormatRGBA8); 60 64 ColorManager.RegisterFormat(TGColorFormatGray8); 65 ColorManager.RegisterFormat(TGColorFormatGray1); 61 66 62 67 // Set default … … 112 117 end; 113 118 119 procedure TCore.AImageFlipExecute(Sender: TObject); 120 begin 121 Project.Bitmap.Flip; 122 FormMain.Redraw; 123 end; 124 125 procedure TCore.AImageMirrorExecute(Sender: TObject); 126 begin 127 Project.Bitmap.Mirror; 128 FormMain.Redraw; 129 end; 130 114 131 procedure TCore.AImageRandomExecute(Sender: TObject); 115 132 begin -
trunk/UGraphic.pas
r5 r7 22 22 function GetPixelSize: Integer; virtual; 23 23 function GetName: string; virtual; 24 function GetChannelB ytePos(Channel: TGColorChannel): Integer; virtual;24 function GetChannelBitPos(Channel: TGColorChannel): Integer; virtual; 25 25 function GetChannelBitWidth(Channel: TGColorChannel): Integer; virtual; 26 26 function ChannelUsed(Channel: TGColorChannel): Boolean; … … 75 75 procedure Clear; 76 76 procedure Random; 77 procedure Flip; 78 procedure Mirror; 77 79 constructor Create; virtual; 78 80 destructor Destroy; override; … … 242 244 end; 243 245 244 function TGColorFormat.GetChannelB ytePos(Channel: TGColorChannel): Integer;246 function TGColorFormat.GetChannelBitPos(Channel: TGColorChannel): Integer; 245 247 begin 246 248 … … 437 439 end; 438 440 441 procedure TGBitmap.Flip; 442 var 443 X, Y: Integer; 444 Color: TGColor; 445 begin 446 for Y := 0 to Size.Y div 2 - 1 do 447 for X := 0 to Size.X - 1 do begin 448 Color := Pixels[X, Y]; 449 Pixels[X, Y] := Pixels[X, Size.Y - 1 - Y]; 450 Pixels[X, Size.Y - 1 - Y] := Color; 451 Color.Free; 452 end; 453 end; 454 455 procedure TGBitmap.Mirror; 456 var 457 X, Y: Integer; 458 Color: TGColor; 459 begin 460 for Y := 0 to Size.Y - 1 do 461 for X := 0 to Size.X div 2 - 1 do begin 462 Color := Pixels[X, Y]; 463 Pixels[X, Y] := Pixels[Size.X - 1 - X, Y]; 464 Pixels[Size.X - 1 - X, Y] := Color; 465 Color.Free; 466 end; 467 end; 468 439 469 constructor TGBitmap.Create; 440 470 begin
Note:
See TracChangeset
for help on using the changeset viewer.