Changeset 278 for branches/AlphaChannel/Packages/CevoComponents
- Timestamp:
- Sep 6, 2020, 11:44:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/AlphaChannel/Packages/CevoComponents/ScreenTools.pas
r256 r278 397 397 end; 398 398 399 procedure FillRectBitmap(Bitmap: TBitmap; Color: TColor32); 400 var 401 Ptr: TPixelPointer; 402 X, Y: Integer; 403 begin 404 Bitmap.BeginUpdate; 405 Ptr := PixelPointer(Bitmap); 406 for Y := 0 to Bitmap.Height - 1 do begin 407 for X := 0 to Bitmap.Width - 1 do begin 408 Ptr.Pixel^.ARGB := Color; 409 Ptr.NextPixel; 410 end; 411 Ptr.NextLine; 412 end; 413 Bitmap.EndUpdate; 414 end; 415 399 416 function LoadGraphicFile(bmp: TBitmap; Path: string; Options: Integer): Boolean; 400 417 var … … 424 441 if ExtractFileExt(Path) = '.png' then begin 425 442 Png := TPortableNetworkGraphic.Create; 426 Png.PixelFormat := Bmp.PixelFormat;427 443 try 428 444 Png.LoadFromFile(Path); … … 432 448 if Result then 433 449 begin 434 if Options and gfNoGamma = 0 then 435 bmp.PixelFormat := pf24bit; 436 bmp.SetSize(Png.Width, Png.Height); 450 Bmp.Assign(Png); 451 //Bmp.SetSize(Png.Width, Png.Height); 452 //Bmp.PixelFormat := Png.PixelFormat; 453 //Bmp.Canvas.FillRect(0, 0, Bmp.Width, Bmp.Height); 454 //FillRectBitmap(Bmp, $00000000); 437 455 if (Png.RawImage.Description.Format = ricfGray) then 438 456 begin … … 440 458 Bmp.PixelFormat := pf24bit; 441 459 CopyGray8BitTo24bitBitmap(Bmp, Png); 442 end 443 else 444 Bmp.Canvas.draw(0, 0, Png); 460 end; 461 //else 462 //Bmp.Canvas.Draw(0, 0, Png); 463 //Bmp.SaveToFile(Path + '.bmp'); 445 464 end; 446 465 Png.Free; … … 475 494 FileName: string; 476 495 Source: TBitmap; 477 DataPixel, MaskPixel: TPixelPointer; 496 SourcePixel: TPixelPointer; 497 DataPixel: TPixelPointer; 498 MaskPixel: TPixelPointer; 478 499 begin 479 500 I := 0; … … 483 504 if I = nGrExt then begin 484 505 Source := TBitmap.Create; 485 Source.PixelFormat := pf24bit;486 506 FileName := GetGraphicsDir + DirectorySeparator + Name; 487 507 if not LoadGraphicFile(Source, FileName) then begin … … 493 513 GrExt[nGrExt].Name := Name; 494 514 495 xmax := Source.Width - 1; // allows 4-byte access even for last pixel515 //xmax := Source.Width - 1; // allows 4-byte access even for last pixel 496 516 // Why there was that limit? 497 517 //if xmax > 970 then 498 518 // xmax := 970; 499 519 500 GrExt[nGrExt].Data := Source;520 GrExt[nGrExt].Data := TBitmap.Create; 501 521 GrExt[nGrExt].Data.PixelFormat := pf24bit; 522 GrExt[nGrExt].Data.SetSize(Source.Width, Source.Height); 502 523 GrExt[nGrExt].Mask := TBitmap.Create; 503 524 GrExt[nGrExt].Mask.PixelFormat := pf24bit; 504 525 GrExt[nGrExt].Mask.SetSize(Source.Width, Source.Height); 505 526 527 // Extract data and mask from transparent image 528 Source.BeginUpdate; 506 529 GrExt[nGrExt].Data.BeginUpdate; 507 530 GrExt[nGrExt].Mask.BeginUpdate; 531 SourcePixel := PixelPointer(Source); 508 532 DataPixel := PixelPointer(GrExt[nGrExt].Data); 509 533 MaskPixel := PixelPointer(GrExt[nGrExt].Mask); 510 534 for y := 0 to ScaleToNative(Source.Height) - 1 do begin 511 for x := 0 to ScaleToNative(xmax) - 1 do begin 512 OriginalColor := DataPixel.Pixel^.ARGB and $FFFFFF; 513 if (OriginalColor = $FF00FF) or (OriginalColor = $7F007F) then 514 begin // transparent 535 for x := 0 to ScaleToNative(Source.Width) - 1 do begin 536 if SourcePixel.Pixel^.ARGB = $00000000 then begin // transparent 515 537 MaskPixel.Pixel^.ARGB := $FFFFFF; 516 DataPixel.Pixel^.ARGB := DataPixel.Pixel^.ARGB and $FF000000;538 DataPixel.Pixel^.ARGB := 0; 517 539 end 518 540 else begin 519 541 MaskPixel.Pixel^.ARGB := $000000; // non-transparent 542 DataPixel.Pixel^.ARGB := SourcePixel.Pixel^.ARGB and $FFFFFF; 520 543 if Gamma <> 100 then 521 544 DataPixel.Pixel^ := ApplyGammaToPixel(DataPixel.Pixel^); 522 545 end; 546 SourcePixel.NextPixel; 523 547 DataPixel.NextPixel; 524 548 MaskPixel.NextPixel; 525 549 end; 550 SourcePixel.NextLine; 526 551 DataPixel.NextLine; 527 552 MaskPixel.NextLine; 528 553 end; 554 Source.EndUpdate; 529 555 GrExt[nGrExt].Data.EndUpdate; 530 556 GrExt[nGrExt].Mask.EndUpdate; … … 532 558 FillChar(GrExt[nGrExt].pixUsed, GrExt[nGrExt].Data.Height div 49 * 10, 0); 533 559 Inc(nGrExt); 560 561 Source.Free; 534 562 end; 535 563 end; … … 1544 1572 for Y := 0 to ScaleToNative(Dest.Height) - 1 do begin 1545 1573 for X := 0 to ScaleToNative(Dest.Width) - 1 do begin 1546 if (DstPixel.Pixel^.ARGB and $ FFFFFF) = TransparentColor then begin1574 if (DstPixel.Pixel^.ARGB and $ffffff) = TransparentColor then begin 1547 1575 SrcPixel.SetXY(X mod TexWidth, Y mod TexHeight); 1548 1576 DstPixel.Pixel^.B := SrcPixel.Pixel^.B;
Note:
See TracChangeset
for help on using the changeset viewer.