Changeset 68 for trunk/ScreenTools.pas
- Timestamp:
- Jan 14, 2017, 8:42:46 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ScreenTools.pas
r64 r68 43 43 procedure Init(Bitmap: TBitmap; X: Integer = 0; Y: Integer = 0); inline; 44 44 end; 45 PPixelPointer = ^TPixelPointer; 45 46 46 47 {$IFDEF WINDOWS} … … 59 60 function HexStringToColor(s: string): integer; 60 61 function LoadGraphicFile(bmp: TBitmap; Path: string; 61 Options: integer = 0): boolean;62 function LoadLocalizedGraphicFile(bmp: TBitmap; Path: string;63 62 Options: integer = 0): boolean; 64 63 function LoadGraphicSet(Name: string): integer; … … 417 416 end; 418 417 419 procedure ApplyGamma(Start, Stop: pbyte);420 begin421 while Start < Stop do422 begin423 Start^ := GammaLUT[Start^];424 inc(Start);425 end;426 end;427 428 418 function LoadGraphicFile(bmp: TBitmap; Path: string; Options: integer): boolean; 429 type 430 TLine = array [0 .. 9999, 0 .. 2] of Byte; 431 var 432 FirstLine, LastLine: ^TLine; 419 var 420 PixelPtr: TPixelPointer; 433 421 jtex: tjpegimage; 422 X, Y: Integer; 434 423 begin 435 424 result := true; … … 474 463 if (Options and gfNoGamma = 0) and (Gamma <> 100) then 475 464 begin 476 bmp.BeginUpdate; 477 FirstLine := bmp.ScanLine[0]; 478 LastLine := bmp.ScanLine[bmp.Height - 1]; 479 if FirstLine < LastLine then 480 ApplyGamma(pointer(FirstLine), @LastLine[bmp.Width]) 481 else 482 ApplyGamma(pointer(LastLine), @FirstLine[bmp.Width]); 483 bmp.EndUpdate; 484 end 485 end; 486 487 function LoadLocalizedGraphicFile(bmp: TBitmap; Path: string; 488 Options: integer): boolean; 489 type 490 TLine = array [0 .. 9999, 0 .. 2] of Byte; 491 var 492 FirstLine, LastLine: ^TLine; 493 jtex: tjpegimage; 494 begin 495 result := true; 496 if Options and gfJPG <> 0 then 497 begin 498 jtex := tjpegimage.create; 499 try 500 jtex.loadfromfile(LocalizedFilePath(Path + '.jpg')); 501 except 502 result := false; 503 end; 504 if result then 505 begin 506 if Options and gfNoGamma = 0 then 507 bmp.PixelFormat := pf24bit; 508 bmp.Width := jtex.Width; 509 bmp.Height := jtex.Height; 510 bmp.Canvas.draw(0, 0, jtex); 511 end; 512 jtex.Free; 513 end 514 else 515 begin 516 try 517 bmp.loadfromfile(LocalizedFilePath(Path + '.bmp')); 518 except 519 result := false; 520 end; 521 if result then 522 begin 523 if Options and gfNoGamma = 0 then 524 bmp.PixelFormat := pf24bit; 525 end 526 end; 527 if not result then 528 begin 529 if Options and gfNoError = 0 then 530 Application.MessageBox(PChar(Format(Phrases.Lookup('FILENOTFOUND'), 531 [Path])), 'C-evo', 0); 532 exit; 533 end; 534 if (Options and gfNoGamma = 0) and (Gamma <> 100) then 535 begin 536 bmp.BeginUpdate; 537 FirstLine := bmp.ScanLine[0]; 538 LastLine := bmp.ScanLine[bmp.Height - 1]; 539 if FirstLine < LastLine then 540 ApplyGamma(Pointer(FirstLine), @LastLine[bmp.Width]) 541 else 542 ApplyGamma(Pointer(LastLine), @FirstLine[bmp.Width]); 543 bmp.EndUpdate; 465 Bmp.BeginUpdate; 466 PixelPtr.Init(bmp, 0, 0); 467 for Y := 0 to Bmp.Height - 1 do begin 468 for X := 0 to Bmp.Width - 1 do begin 469 PixelPtr.Pixel^.B := GammaLUT[PixelPtr.Pixel^.B]; 470 PixelPtr.Pixel^.G := GammaLUT[PixelPtr.Pixel^.G]; 471 PixelPtr.Pixel^.R := GammaLUT[PixelPtr.Pixel^.R]; 472 PixelPtr.NextPixel; 473 end; 474 PixelPtr.NextLine; 475 end; 476 Bmp.EndUpdate; 544 477 end 545 478 end;
Note:
See TracChangeset
for help on using the changeset viewer.