Changeset 68 for trunk


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.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Help.pas

    r55 r68  
    960960            inc(p)
    961961          until (p > length(s)) or (s[p] = '\');
    962           if LoadLocalizedGraphicFile(ExtPic, 'Help' + DirectorySeparator + copy(s, 2, p - 2)) then
     962          if LoadGraphicFile(ExtPic, LocalizedFilePath('Help' +
     963            DirectorySeparator + copy(s, 2, p - 2))) then
    963964          begin
    964965            MainText.AddLine('', pkExternal);
  • trunk/LocalPlayer/IsoEngine.pas

    r58 r68  
    104104
    105105function ApplyTileSize(xxtNew, yytNew: integer): boolean;
    106 type
    107   TLine = array [0 .. INFIN, 0 .. 2] of Byte;
    108106var
    109107  i, x, y, xSrc, ySrc, HGrTerrainNew, HGrCitiesNew, age, size: integer;
    110108  LandMore, OceanMore, DitherMask, Mask24: TBitmap;
    111   MaskLine: array [0 .. 32 * 3 - 1] of ^TLine; // 32 = assumed maximum for yyt
     109  MaskLine: array [0 .. 32 * 3 - 1] of TPixelPointer; // 32 = assumed maximum for yyt
    112110  Border: boolean;
    113111begin
     
    346344  begin
    347345    for i := 0 to yyt * 3 - 1 do
    348       MaskLine[i] := Mask24.ScanLine[1 + ySrc * (yyt * 3 + 1) + i];
     346      MaskLine[i].Init(Mask24, 0, 1 + ySrc * (yyt * 3 + 1) + i);
    349347    for xSrc := 0 to 9 - 1 do
    350348    begin
     
    353351      repeat
    354352        Border := true;
    355         for y := 0 to yyt * 3 - 1 do
    356           if MaskLine[y]^[1 + xSrc * (xxt * 2 + 1) + TSpriteSize[i].Left, 0] = 0
    357           then
    358             Border := false;
    359         if Border then
    360           inc(TSpriteSize[i].Left);
     353        for y := 0 to yyt * 3 - 1 do begin
     354          MaskLine[y].SetX(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[i].Left);
     355          if MaskLine[y].Pixel^.B = 0 then Border := false;
     356        end;
     357        if Border then Inc(TSpriteSize[i].Left);
    361358      until not Border or (TSpriteSize[i].Left = xxt * 2 - 1);
    362359      TSpriteSize[i].Top := 0;
    363360      repeat
    364361        Border := true;
    365         for x := 0 to xxt * 2 - 1 do
    366           if MaskLine[TSpriteSize[i].Top]^[1 + xSrc * (xxt * 2 + 1) + x, 0] = 0
    367           then
    368             Border := false;
    369         if Border then
    370           inc(TSpriteSize[i].Top);
     362        for x := 0 to xxt * 2 - 1 do begin
     363          MaskLine[TSpriteSize[i].Top].SetX(1 + xSrc * (xxt * 2 + 1) + x);
     364          if MaskLine[TSpriteSize[i].Top].Pixel^.B = 0 then Border := false;
     365        end;
     366        if Border then inc(TSpriteSize[i].Top);
    371367      until not Border or (TSpriteSize[i].Top = yyt * 3 - 1);
    372368      TSpriteSize[i].Right := xxt * 2;
    373369      repeat
    374370        Border := true;
    375         for y := 0 to yyt * 3 - 1 do
    376           if MaskLine[y]^[xSrc * (xxt * 2 + 1) + TSpriteSize[i].Right, 0] = 0
    377           then
    378             Border := false;
    379         if Border then
    380           dec(TSpriteSize[i].Right);
     371        for y := 0 to yyt * 3 - 1 do begin
     372          MaskLine[y].SetX(xSrc * (xxt * 2 + 1) + TSpriteSize[i].Right);
     373          if MaskLine[y].Pixel^.B = 0 then Border := false;
     374        end;
     375        if Border then Dec(TSpriteSize[i].Right);
    381376      until not Border or (TSpriteSize[i].Right = TSpriteSize[i].Left);
    382377      TSpriteSize[i].Bottom := yyt * 3;
    383378      repeat
    384379        Border := true;
    385         for x := 0 to xxt * 2 - 1 do
    386           if MaskLine[TSpriteSize[i].Bottom - 1]^[1 + xSrc * (xxt * 2 + 1) + x,
    387             0] = 0 then
    388             Border := false;
    389         if Border then
    390           dec(TSpriteSize[i].Bottom);
     380        for x := 0 to xxt * 2 - 1 do begin
     381          MaskLine[TSpriteSize[i].Bottom - 1].SetX(1 + xSrc * (xxt * 2 + 1) + x);
     382          if MaskLine[TSpriteSize[i].Bottom - 1].Pixel^.B = 0 then Border := false;
     383        end;
     384        if Border then Dec(TSpriteSize[i].Bottom);
    391385      until not Border or (TSpriteSize[i].Bottom = TSpriteSize[i].Top);
    392386    end
     
    930924procedure TIsoMap.PaintTileObjects(x, y, Loc, CityLoc, CityOwner: integer;
    931925  UseBlink: boolean);
    932 type
    933   TLine = array [0 .. 9 * 65, 0 .. 2] of Byte;
    934926var
    935927  p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: integer;
     
    12991291
    13001292  procedure ShadeOutside(x0, y0, x1, y1, xm, ym: integer);
     1293
     1294    procedure MakeDark(Line: PPixelPointer; Length: Integer);
     1295    var
     1296      I: Integer;
     1297    begin
     1298      for I := 0 to Length - 1 do begin
     1299        Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7f;
     1300        Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7f;
     1301        Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7f;
     1302        Line^.NextPixel;
     1303      end;
     1304    end;
     1305
    13011306  const
    13021307    rShade = 3.75;
    1303 
    1304     procedure MakeDark(Line: pointer; length: integer);
    1305     type
    1306       TCardArray = array [0 .. 9999] of Cardinal;
    1307       PCardArray = ^TCardArray;
    1308       TByteArray = array [0 .. 9999] of Byte;
    1309       PByteArray = ^TByteArray;
    1310     var
    1311       i, rest: integer;
    1312     begin
    1313       for i := length * 3 div 4 - 1 downto 0 do
    1314         PCardArray(Line)[i] := PCardArray(Line)[i] shr 1 and $7F7F7F7F;
    1315       rest := (length * 3 div 4) * 4;
    1316       for i := length * 3 mod 4 - 1 downto 0 do
    1317         PByteArray(Line)[rest + i] := PByteArray(Line)[rest + i] shr 1 and $7F;
    1318     end;
    1319 
    1320   type
    1321     TLine = array [0 .. 99999, 0 .. 2] of Byte;
    13221308  var
    13231309    y, wBright: integer;
    13241310    y_n, w_n: single;
    1325     Line: ^TLine;
     1311    Line: TPixelPointer;
    13261312  begin
    13271313    FOutput.BeginUpdate;
    1328     for y := y0 to y1 - 1 do
    1329     begin
    1330       Line := FOutput.ScanLine[y];
     1314    for y := y0 to y1 - 1 do begin
     1315      Line.Init(FOutput, 0, y);
    13311316      y_n := (y - ym) / yyt;
    1332       if abs(y_n) < rShade then
    1333       begin
     1317      if abs(y_n) < rShade then begin
     1318        // Darken left and right parts of elipsis
    13341319        w_n := sqrt(sqr(rShade) - sqr(y_n));
    13351320        wBright := trunc(w_n * xxt + 0.5);
    1336         MakeDark(@Line[x0], xm - x0 - wBright);
    1337         MakeDark(@Line[xm + wBright], x1 - xm - wBright);
    1338       end
    1339       else
    1340         MakeDark(@Line[x0], x1 - x0);
     1321        Line.SetX(x0);
     1322        MakeDark(@Line, xm - x0 - wBright);
     1323        Line.SetX(xm + wBright);
     1324        MakeDark(@Line, x1 - xm - wBright);
     1325      end else begin
     1326        // Darken entire line
     1327        Line.SetX(x0);
     1328        MakeDark(@Line, x1 - x0);
     1329      end;
    13411330    end;
    13421331    FOutput.EndUpdate;
  • 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.