Changeset 315 for trunk/Packages


Ignore:
Timestamp:
Mar 18, 2021, 10:58:28 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Gamma was incorrectly applied to images with transparency colors.
  • Modified: Change Templates to GraphicSet so it can also have description of its items.
  • Modified: Use TextExtent instead of both TextWidth and TextHeight.
Location:
trunk/Packages/CevoComponents
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/ButtonA.pas

    r290 r315  
    44
    55uses
    6   ButtonBase, Classes, Graphics, LCLIntf, LCLType, ScreenTools;
     6  ButtonBase, Classes, Graphics, LCLIntf, LCLType, ScreenTools, Types;
    77
    88type
     
    4141
    4242procedure TButtonA.Paint;
     43var
     44  TextSize: TSize;
    4345begin
    4446  with Canvas do
    45     if FGraphic <> nil then
    46     begin
     47    if FGraphic <> nil then begin
    4748      BitBltCanvas(Canvas, 0, 0, 100, 25, Graphic.Canvas, 195,
    4849        243 + 26 * Byte(Down));
    4950      Canvas.Brush.Style := bsClear;
    50       Textout(50 - (TextWidth(FCaption) + 1) div 2, 12 - textheight(FCaption)
    51         div 2, FCaption);
    52     end
    53     else
    54     begin
     51      TextSize := TextExtent(FCaption);
     52      TextOut(50 - (TextSize.Width + 1) div 2,
     53        12 - TextSize.Height div 2, FCaption);
     54    end else begin
    5555      Brush.Color := $0000FF;
    5656      FrameRect(Rect(0, 0, 100, 25))
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r314 r315  
    4040function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): boolean;
    4141function LoadGraphicSet(const Name: string): TGraphicSet;
     42function LoadGraphicSet2(const Name: string): TGraphicSet;
    4243procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
    4344procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     
    107108
    108109const
     110  TransparentColor1 = $FF00FF;
     111  TransparentColor2 = $7F007F;
     112
    109113  wMainTexture = 640;
    110114  hMainTexture = 480;
    111115
    112   // template positions in Template.bmp
     116  // template positions in Templates.png
    113117  xLogo = 1;
    114118  yLogo = 1;
     
    172176  CityMark2: TGraphicSetItem;
    173177  Ornament: TGraphicSetItem;
     178  Logo: TGraphicSetItem;
    174179  ClickFrameColor: Integer;
    175180  MainTextureAge: Integer;
    176181  MainTexture: TTexture;
    177   Templates: TBitmap;
     182  Templates: TGraphicSet;
    178183  Colors: TBitmap;
    179184  Paper: TBitmap;
     
    474479  x: Integer;
    475480  y: Integer;
    476   xmax: Integer;
    477481  OriginalColor: Integer;
    478482  FileName: string;
     
    484488    Result := GrExt.AddNew(Name);
    485489    FileName := GetGraphicsDir + DirectorySeparator + Name;
    486     if not LoadGraphicFile(Result.Data, FileName) then begin
     490    // Do not apply gamma during file load as it would affect also transparency colors
     491    if not LoadGraphicFile(Result.Data, FileName, [gfNoGamma]) then begin
    487492      Result := nil;
    488493      Exit;
     
    494499
    495500    Result.ResetPixUsed;
    496 
    497     xmax := Result.Data.Width - 1; // allows 4-byte access even for last pixel
    498     // Why there was that limit?
    499     //if xmax > 970 then
    500     //  xmax := 970;
    501501
    502502    Result.Mask.SetSize(Result.Data.Width, Result.Data.Height);
     
    507507    MaskPixel := PixelPointer(Result.Mask);
    508508    for y := 0 to ScaleToNative(Result.Data.Height) - 1 do begin
    509       for x := 0 to ScaleToNative(xmax) - 1 do begin
     509      for x := 0 to ScaleToNative(Result.Data.Width) - 1 do begin
    510510        OriginalColor := DataPixel.Pixel^.ARGB and $FFFFFF;
    511         if (OriginalColor = $FF00FF) or (OriginalColor = $7F007F) then
    512         begin // transparent
    513           MaskPixel.Pixel^.ARGB := $FFFFFF;
    514           DataPixel.Pixel^.ARGB := DataPixel.Pixel^.ARGB and $FF000000;
    515         end
    516         else begin
    517           MaskPixel.Pixel^.ARGB := $000000; // non-transparent
    518           if Gamma <> 100 then
    519             DataPixel.Pixel^ := ApplyGammaToPixel(DataPixel.Pixel^);
     511        if (OriginalColor = TransparentColor1) or (OriginalColor = TransparentColor2) then begin
     512          MaskPixel.Pixel^.R := $FF;
     513          MaskPixel.Pixel^.G := $FF;
     514          MaskPixel.Pixel^.B := $FF;
     515          DataPixel.Pixel^.R := 0;
     516          DataPixel.Pixel^.G := 0;
     517          DataPixel.Pixel^.B := 0;
     518        end else begin
     519          MaskPixel.Pixel^.R := $00;
     520          MaskPixel.Pixel^.G := $00;
     521          MaskPixel.Pixel^.B := $00;
    520522        end;
    521523        DataPixel.NextPixel;
     
    527529    Result.Data.EndUpdate;
    528530    Result.Mask.EndUpdate;
     531
     532    if Gamma <> 100 then
     533      ApplyGammaToBitmap(Result.Data);
     534  end;
     535end;
     536
     537function LoadGraphicSet2(const Name: string): TGraphicSet;
     538var
     539  FileName: string;
     540begin
     541  Result := GrExt.SearchByName(Name);
     542  if not Assigned(Result) then begin
     543    Result := GrExt.AddNew(Name);
     544    FileName := GetGraphicsDir + DirectorySeparator + Name;
     545    if not LoadGraphicFile(Result.Data, FileName, [gfNoGamma]) then begin
     546      Result := nil;
     547      Exit;
     548    end;
     549
     550    FileName := ExtractFileNameWithoutExt(FileName) + GraphicSetFileExt;
     551    if FileExists(FileName) then
     552      Result.LoadFromFile(FileName);
     553
     554    Result.ResetPixUsed;
    529555  end;
    530556end;
     
    11141140procedure Corner(ca: TCanvas; x, y, Kind: Integer; const T: TTexture);
    11151141begin
    1116   { BitBltCanvas(ca,x,y,8,8,GrExt[T.HGr].Mask.Canvas,
     1142  { BitBltCanvas(ca,x,y,8,8,T.HGr.Mask.Canvas,
    11171143    T.xGr+29+Kind*9,T.yGr+89,SRCAND);
    1118     BitBltCanvas(ca,x,y,8,8,GrExt[T.HGr].Data.Canvas,
     1144    BitBltCanvas(ca,x,y,8,8,T.HGr.Data.Canvas,
    11191145    T.xGr+29+Kind*9,T.yGr+89,SRCPAINT); }
    11201146end;
     
    11341160  sp: string;
    11351161  shadow: Boolean;
     1162  Text: string;
    11361163begin
    11371164  Inc(x);
     
    11571184          else
    11581185          begin
    1159             Textout(xp, y, copy(sp, 1, p - 1));
    1160             Inc(xp, ca.TextWidth(copy(sp, 1, p - 1)));
     1186            Text := Copy(sp, 1, p - 1);
     1187            Textout(xp, y, Text);
     1188            Inc(xp, ca.TextWidth(Text));
    11611189            if not shadow then
    11621190              case sp[p + 1] of
     
    14711499  LogoBuffer.Canvas.FillRect(0, 0, LogoBuffer.Width, LogoBuffer.Height);
    14721500  BitBltCanvas(LogoBuffer.Canvas, 0, 0, wLogo, hLogo, ca, x, y);
    1473   ImageOp_BCC(LogoBuffer, Templates, 0, 0, 1, 1, wLogo, hLogo,
     1501  ImageOp_BCC(LogoBuffer, Templates.Data, 0, 0, 1, 1, wLogo, hLogo,
    14741502    clLight, clShade);
    14751503  BitBltCanvas(ca, x, y, wLogo, hLogo, LogoBuffer.Canvas, 0, 0);
     
    16531681  LoadPhrases;
    16541682  LoadFonts;
    1655   LoadGraphicFile(Templates, GetGraphicsDir + DirectorySeparator +
    1656     'Templates.png', [gfNoGamma]);
     1683  Templates := LoadGraphicSet2('Templates.png');
    16571684  LoadGraphicFile(Colors, GetGraphicsDir + DirectorySeparator + 'Colors.png');
    16581685  LoadGraphicFile(Paper, GetGraphicsDir + DirectorySeparator + 'Paper.jpg');
     
    16881715  Ornament := HGrSystem2.GetItem('Ornament');
    16891716
    1690   Templates := TBitmap.Create;
    1691   Templates.PixelFormat := pf24bit;
    16921717  Colors := TBitmap.Create;
    16931718  Colors.PixelFormat := pf24bit;
     
    17061731
    17071732procedure UnitDone;
    1708 var
    1709   I: Integer;
    17101733begin
    17111734  RestoreResolution;
     
    17171740  FreeAndNil(BigImp);
    17181741  FreeAndNil(Paper);
    1719   FreeAndNil(Templates);
    17201742  FreeAndNil(Colors);
    17211743  FreeAndNil(MainTexture.Image);
  • trunk/Packages/CevoComponents/UGraphicSet.pas

    r314 r315  
    6060    function SearchByName(Name: string): TGraphicSet;
    6161    function AddNew(Name: string): TGraphicSet;
     62    procedure ResetPixUsed;
    6263  end;
    6364
     
    259260end;
    260261
     262procedure TGraphicSets.ResetPixUsed;
     263var
     264  I: Integer;
     265begin
     266  for I := 0 to Count - 1 do
     267    Items[I].ResetPixUsed;
     268end;
     269
    261270end.
    262271
Note: See TracChangeset for help on using the changeset viewer.