Changeset 68 for trunk/ScreenTools.pas


Ignore:
Timestamp:
Jan 14, 2017, 8:42:46 PM (7 years ago)
Author:
chronos
Message:
  • Fixed: Removed last occurences of Bitmap.ScanLine usage and adjusted to support Linux 32-bit RAW image format.
  • Modified: Simplified LoadLocalizedGraphicFile function as it do same thing as LoadGraphicFile just with localized directory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ScreenTools.pas

    r64 r68  
    4343    procedure Init(Bitmap: TBitmap; X: Integer = 0; Y: Integer = 0); inline;
    4444  end;
     45  PPixelPointer = ^TPixelPointer;
    4546
    4647{$IFDEF WINDOWS}
     
    5960function HexStringToColor(s: string): integer;
    6061function LoadGraphicFile(bmp: TBitmap; Path: string;
    61   Options: integer = 0): boolean;
    62 function LoadLocalizedGraphicFile(bmp: TBitmap; Path: string;
    6362  Options: integer = 0): boolean;
    6463function LoadGraphicSet(Name: string): integer;
     
    417416end;
    418417
    419 procedure ApplyGamma(Start, Stop: pbyte);
    420 begin
    421   while Start < Stop do
    422   begin
    423     Start^ := GammaLUT[Start^];
    424     inc(Start);
    425   end;
    426 end;
    427 
    428418function 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;
     419var
     420  PixelPtr: TPixelPointer;
    433421  jtex: tjpegimage;
     422  X, Y: Integer;
    434423begin
    435424  result := true;
     
    474463  if (Options and gfNoGamma = 0) and (Gamma <> 100) then
    475464  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;
    544477  end
    545478end;
Note: See TracChangeset for help on using the changeset viewer.