Changeset 13 for trunk/UGraphic.pas
- Timestamp:
- Sep 22, 2014, 5:25:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.