Changeset 13
- Timestamp:
- Sep 22, 2014, 5:25:11 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r10 r13 102 102 Action = Core.AImageGradient 103 103 end 104 object MenuItem20: TMenuItem 105 Action = Core.AImageNegative 106 end 104 107 end 105 108 end -
trunk/Forms/UFormMain.pas
r10 r13 24 24 MenuItem18: TMenuItem; 25 25 MenuItem19: TMenuItem; 26 MenuItem20: TMenuItem; 26 27 MenuItemRecentFiles: TMenuItem; 27 28 MenuItem15: TMenuItem; -
trunk/LibrePaint.lpi
r11 r13 105 105 <Filename Value="ColorFormats/UColorRGBA8.pas"/> 106 106 <IsPartOfProject Value="True"/> 107 <UnitName Value="UColorRGBA8"/> 107 108 </Unit5> 108 109 <Unit6> … … 126 127 <Filename Value="UMemory.pas"/> 127 128 <IsPartOfProject Value="True"/> 129 <UnitName Value="UMemory"/> 128 130 </Unit9> 129 131 <Unit10> -
trunk/LibrePaint.lpr
r11 r13 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UCore, UGraphic, UProject, U BitStream, UMemory, UFormNew, UFormMain,10 Forms, UCore, UGraphic, UProject, UMemory, UFormNew, UFormMain, 11 11 UColorRGBA8, UColorGray8, UColorGray1, UColorGray4, UColorRGB565 12 12 { you can add units after this }; -
trunk/UCore.lfm
r10 r13 49 49 Category = 'File' 50 50 Caption = 'Open...' 51 OnExecute = AFileOpenExecute 51 52 end 52 53 object AFileClose: TAction 53 54 Category = 'File' 54 55 Caption = 'Close' 56 OnExecute = AFileCloseExecute 55 57 end 56 58 object AFileSave: TAction 57 59 Category = 'File' 58 60 Caption = 'Save' 61 OnExecute = AFileSaveExecute 59 62 end 60 63 object AFileSaveAs: TAction 61 64 Category = 'File' 62 65 Caption = 'Save as...' 66 OnExecute = AFileSaveAsExecute 63 67 end 64 68 object AImageRandom: TAction … … 82 86 OnExecute = AImageGradientExecute 83 87 end 88 object AImageNegative: TAction 89 Category = 'Image' 90 Caption = 'Negative' 91 OnExecute = AImageNegativeExecute 92 end 84 93 end 85 94 object ImageList1: TImageList … … 87 96 top = 240 88 97 end 98 object OpenPictureDialog1: TOpenPictureDialog 99 left = 462 100 top = 126 101 end 102 object SavePictureDialog1: TSavePictureDialog 103 left = 462 104 top = 208 105 end 89 106 end -
trunk/UCore.pas
r11 r13 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, ActnList, UProject, UGraphic, Controls, Graphics; 8 Classes, SysUtils, FileUtil, ActnList, UProject, UGraphic, Controls, Graphics, 9 ExtDlgs, ExtCtrls; 9 10 10 11 const … … 19 20 20 21 TCore = class(TDataModule) 22 AImageNegative: TAction; 21 23 AImageGradient: TAction; 22 24 AImageMirror: TAction; … … 36 38 ActionList1: TActionList; 37 39 ImageList1: TImageList; 40 OpenPictureDialog1: TOpenPictureDialog; 41 SavePictureDialog1: TSavePictureDialog; 38 42 procedure AExitExecute(Sender: TObject); 43 procedure AFileCloseExecute(Sender: TObject); 44 procedure AFileOpenExecute(Sender: TObject); 45 procedure AFileSaveAsExecute(Sender: TObject); 46 procedure AFileSaveExecute(Sender: TObject); 39 47 procedure AImageClearExecute(Sender: TObject); 40 48 procedure AImageFlipExecute(Sender: TObject); 41 49 procedure AImageGradientExecute(Sender: TObject); 42 50 procedure AImageMirrorExecute(Sender: TObject); 51 procedure AImageNegativeExecute(Sender: TObject); 43 52 procedure AImageRandomExecute(Sender: TObject); 44 53 procedure AFileNewExecute(Sender: TObject); … … 146 155 end; 147 156 157 procedure TCore.AFileCloseExecute(Sender: TObject); 158 begin 159 if not Project.Saved then AFileSave.Execute; 160 Project.Free; 161 FormMain.Redraw; 162 end; 163 164 procedure TCore.AFileOpenExecute(Sender: TObject); 165 var 166 Image: TImage; 167 begin 168 if OpenPictureDialog1.Execute then begin 169 Image := TImage.Create(nil); 170 Image.Picture.LoadFromFile(OpenPictureDialog1.FileName); 171 Image.Picture.Bitmap.BeginUpdate(True); 172 Project.Bitmap.LoadFromCanvas(Image.Picture.Bitmap.Canvas, 173 Point(Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height)); 174 Image.Picture.Bitmap.EndUpdate; 175 Image.Free; 176 FormMain.Redraw; 177 Project.FileName := OpenPictureDialog1.FileName; 178 end; 179 end; 180 181 procedure TCore.AFileSaveAsExecute(Sender: TObject); 182 begin 183 SavePictureDialog1.FileName := Project.FileName; 184 if SavePictureDialog1.Execute then begin 185 Project.FileName := SavePictureDialog1.FileName; 186 AFileSave.Execute; 187 end; 188 end; 189 190 procedure TCore.AFileSaveExecute(Sender: TObject); 191 var 192 Image: TImage; 193 begin 194 if Project.FileName = '' then AFileSaveAs.Execute 195 else begin 196 Image := TImage.Create(nil); 197 Image.Picture.Bitmap.SetSize(Project.Bitmap.Size.X, Project.Bitmap.Size.Y); 198 Project.Bitmap.PaintToCanvas(Image.Picture.Bitmap.Canvas, 199 Rect(0, 0, Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height)); 200 Image.Picture.SaveToFile(SavePictureDialog1.FileName); 201 Image.Free; 202 Project.Saved := True; 203 end; 204 end; 205 148 206 procedure TCore.AImageClearExecute(Sender: TObject); 149 207 begin … … 174 232 end; 175 233 234 procedure TCore.AImageNegativeExecute(Sender: TObject); 235 begin 236 Project.Bitmap.Negative; 237 FormMain.Redraw; 238 end; 239 176 240 procedure TCore.AImageRandomExecute(Sender: TObject); 177 241 begin -
trunk/UGraphic.pas
r10 r13 44 44 function ToTColor: TColor; 45 45 procedure FromTColor(Color: TColor); 46 procedure Invert; 46 47 procedure Assign(Source: TGColor); virtual; 47 48 constructor Create; … … 71 72 procedure CheckLimits(X, Y: Integer); 72 73 public 74 procedure LoadFromCanvas(Canvas: TCanvas; ASize: TPoint); 73 75 function GetDataSize: Integer; 74 76 procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); … … 78 80 procedure Flip; 79 81 procedure Mirror; 82 procedure Negative; 80 83 constructor Create; virtual; 81 84 destructor Destroy; override; … … 368 371 end; 369 372 373 procedure TGColor.Invert; 374 var 375 Channel: TBitMemory; 376 begin 377 Channel := TBitMemory.Create; 378 379 if Format.GetChannelBitWidth(ccRed) > 0 then begin 380 Channel.Size := Format.GetChannelBitWidth(ccRed); 381 Data.ReadBlock(Channel, Format.GetChannelBitPos(ccRed)); 382 Channel.Invert; 383 Data.WriteBlock(Channel, Format.GetChannelBitPos(ccRed)); 384 end; 385 386 if Format.GetChannelBitWidth(ccGreen) > 0 then begin 387 Channel.Size := Format.GetChannelBitWidth(ccGreen); 388 Data.ReadBlock(Channel, Format.GetChannelBitPos(ccGreen)); 389 Channel.Invert; 390 Data.WriteBlock(Channel, Format.GetChannelBitPos(ccGreen)); 391 end; 392 393 if Format.GetChannelBitWidth(ccBlue) > 0 then begin 394 Channel.Size := Format.GetChannelBitWidth(ccBlue); 395 Data.ReadBlock(Channel, Format.GetChannelBitPos(ccBlue)); 396 Channel.Invert; 397 Data.WriteBlock(Channel, Format.GetChannelBitPos(ccBlue)); 398 end; 399 400 if Format.GetChannelBitWidth(ccGray) > 0 then begin 401 Channel.Size := Format.GetChannelBitWidth(ccGray); 402 Data.ReadBlock(Channel, Format.GetChannelBitPos(ccGray)); 403 Channel.Invert; 404 Data.WriteBlock(Channel, Format.GetChannelBitPos(ccGray)); 405 end; 406 407 Channel.Free; 408 end; 409 370 410 procedure TGColor.Assign(Source: TGColor); 371 411 begin … … 429 469 if (X < 0) or (Y < 0) or (X >= Size.X) or (Y >= Size.Y) then 430 470 raise Exception.Create('Out of range'); 471 end; 472 473 procedure TGBitmap.LoadFromCanvas(Canvas: TCanvas; ASize: TPoint); 474 var 475 X, Y: Integer; 476 Pixel: TGColor; 477 begin 478 Pixel := TGColor.Create; 479 Pixel.Format := ColorFormat; 480 Size := ASize; 481 try 482 Canvas.Lock; 483 for Y := 0 to Size.Y - 1 do 484 for X := 0 to Size.X do 485 if (X >= 0) and (X < Size.X) and (Y >= 0) and (Y < Size.Y) then begin 486 Pixel.FromTColor(Canvas.Pixels[X, Y]); 487 Pixels[X, Y] := Pixel; 488 end; 489 490 finally 491 Canvas.Unlock; 492 end; 493 Pixel.Free; 431 494 end; 432 495 … … 536 599 end; 537 600 601 procedure TGBitmap.Negative; 602 var 603 X, Y: Integer; 604 Color: TGColor; 605 begin 606 for Y := 0 to Size.Y - 1 do 607 for X := 0 to Size.X - 1 do begin 608 Color := Pixels[X, Y]; 609 Color.Invert; 610 Pixels[X, Y] := Color; 611 Color.Free; 612 end; 613 end; 614 538 615 constructor TGBitmap.Create; 539 616 begin -
trunk/UMemory.pas
r9 r13 67 67 procedure SetSize(AValue: Integer); virtual; 68 68 public 69 procedure Invert; virtual; 69 70 function GetInteger: Integer; virtual; 70 71 procedure SetInteger(Value: Integer); virtual; … … 83 84 FData: PByte; 84 85 FSize: Integer; 85 function GetInteger: Integer; override;86 procedure SetInteger(Value: Integer); override;87 86 function GetSize: Integer; override; 88 87 procedure SetSize(AValue: Integer); override; … … 90 89 procedure SetItem(Index: Integer; AValue: Byte); override; 91 90 public 91 function GetInteger: Integer; override; 92 procedure SetInteger(Value: Integer); override; 93 procedure Clear(Value: Byte = 0); override; 94 procedure ReadBlock(Block: TBitBlock; Position: Integer); override; 95 procedure WriteBlock(Block: TBitBlock; Position: Integer); override; 96 property Data: PByte read FData; 97 procedure Invert; override; 92 98 end; 93 99 … … 96 102 97 103 { TBitMemory } 104 105 procedure TBitMemory.Clear(Value: Byte); 106 begin 107 if (Size and 7) = 0 then begin 108 if Value = 0 then FillChar(FData^, Size shr 3, 0) 109 else FillChar(FData^, Size shr 3, $ff); 110 end else inherited; 111 end; 112 113 procedure TBitMemory.ReadBlock(Block: TBitBlock; Position: Integer); 114 begin 115 if Block is TBitMemory then begin 116 if (Position and 7) = 0 then begin 117 if (Block.Size and 7) = 0 then 118 Move(PByte(FData + Position shr 3)^, TBitMemory(Block).Data^, Block.Size shr 3) 119 else inherited; 120 end else inherited; 121 end else inherited; 122 end; 123 124 procedure TBitMemory.WriteBlock(Block: TBitBlock; Position: Integer); 125 begin 126 if Block is TBitMemory then begin 127 if (Position and 7) = 0 then begin 128 if (Block.Size and 7) = 0 then 129 Move(TBitMemory(Block).Data^, PByte(FData + Position shr 3)^, Block.Size shr 3) 130 else inherited; 131 end else inherited; 132 end else inherited; 133 end; 134 135 procedure TBitMemory.Invert; 136 var 137 I: Integer; 138 begin 139 if (Size and 7) = 0 then begin 140 for I := 0 to (Size shr 3) - 1 do 141 PByte(FData + I)^ := PByte(FData + I)^ xor $ff; 142 end 143 else inherited; 144 145 end; 98 146 99 147 function TBitMemory.GetInteger: Integer; … … 176 224 end; 177 225 226 procedure TBitBlock.Invert; 227 var 228 I: Integer; 229 begin 230 for I := 0 to Size - 1 do 231 Items[I] := not Items[I]; 232 end; 233 178 234 function TBitBlock.GetInteger: Integer; 179 235 begin -
trunk/UProject.pas
r10 r13 36 36 Bitmap: TGBitmap; 37 37 View: TView; 38 Saved: Boolean; 38 39 constructor Create; 39 40 destructor Destroy; override;
Note:
See TracChangeset
for help on using the changeset viewer.