Changeset 52 for trunk/ScreenTools.pas


Ignore:
Timestamp:
Jan 11, 2017, 10:14:11 PM (7 years ago)
Author:
chronos
Message:
  • Fixed: More Bitmap.ScanLine replaced by direct access to RAWImage data.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ScreenTools.pas

    r48 r52  
    2929  end;
    3030  PPixel32 = ^TPixel32;
     31
     32  { TPixelPointer }
     33
     34  TPixelPointer = record
     35    Base: PPixel32;
     36    Pixel: PPixel32;
     37    Line: PPixel32;
     38    BytesPerPixel: Integer;
     39    BytesPerLine: Integer;
     40    procedure NextLine;
     41    procedure NextPixel;
     42    procedure SetXY(X, Y: Integer);
     43    procedure SetX(X: Integer);
     44    procedure Init(Bitmap: TBitmap; X: Integer = 0; Y: Integer = 0);
     45  end;
    3146
    3247{$IFDEF WINDOWS}
     
    14881503      Reg: TRegistry;
    14891504
     1505{ TPixelPointer }
     1506
     1507procedure TPixelPointer.NextLine; inline;
     1508begin
     1509  Line := Pointer(Line) + BytesPerLine;
     1510  Pixel := Line;
     1511end;
     1512
     1513procedure TPixelPointer.NextPixel; inline;
     1514begin
     1515  Pixel := Pointer(Pixel) + BytesPerPixel;
     1516end;
     1517
     1518procedure TPixelPointer.SetXY(X, Y: Integer); inline;
     1519begin
     1520  Line := Pointer(Base) + Y * BytesPerLine;
     1521  SetX(X);
     1522end;
     1523
     1524procedure TPixelPointer.SetX(X: Integer); inline;
     1525begin
     1526  Pixel := Pointer(Line) + X * BytesPerPixel;
     1527end;
     1528
     1529procedure TPixelPointer.Init(Bitmap: TBitmap; X: Integer = 0; Y: Integer = 0); inline;
     1530begin
     1531  Base := PPixel32(Bitmap.RawImage.Data);
     1532  BytesPerLine := Bitmap.RawImage.Description.BytesPerLine;
     1533  BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3;
     1534  SetXY(X, Y);
     1535end;
     1536
     1537procedure UnitInit;
     1538begin
     1539  Reg := TRegistry.create;
     1540  try
     1541    Reg.OpenKey('SOFTWARE\cevo\RegVer9', true);
     1542    if Reg.ValueExists('Gamma') then
     1543      Gamma := Reg.ReadInteger('Gamma')
     1544      else begin
     1545        Gamma := 100;
     1546        Reg.WriteInteger('Gamma', Gamma);
     1547      end;
     1548  finally
     1549    Reg.Free;
     1550  end;
     1551
     1552  if Gamma <> 100 then
     1553  begin
     1554    GammaLUT[0] := 0;
     1555    for i := 1 to 255 do
     1556    begin
     1557      p := round(255.0 * exp(ln(i / 255.0) * 100.0 / Gamma));
     1558      assert((p >= 0) and (p < 256));
     1559      GammaLUT[i] := p;
     1560    end;
     1561  end;
     1562
     1563  {$IFDEF WINDOWS}
     1564  EnumDisplaySettings(nil, $FFFFFFFF, StartResolution);
     1565  {$ENDIF}
     1566  ResolutionChanged := false;
     1567
     1568  Phrases := TStringTable.create;
     1569  Phrases2 := TStringTable.create;
     1570  Phrases2FallenBackToEnglish := false;
     1571  if FileExists(DataDir + 'Localization' + DirectorySeparator + 'Language.txt') then
     1572  begin
     1573    Phrases.loadfromfile(DataDir + 'Localization' + DirectorySeparator + ' + Language.txt');
     1574    if FileExists(DataDir + 'Localization' + DirectorySeparator + 'Language2.txt') then
     1575      Phrases2.loadfromfile(DataDir + 'Localization' + DirectorySeparator + 'Language2.txt')
     1576    else
     1577    begin
     1578      Phrases2.loadfromfile(HomeDir + 'Language2.txt');
     1579      Phrases2FallenBackToEnglish := true;
     1580    end
     1581  end
     1582  else
     1583  begin
     1584    Phrases.loadfromfile(HomeDir + 'Language.txt');
     1585    Phrases2.loadfromfile(HomeDir + 'Language2.txt');
     1586  end;
     1587
     1588  Sounds := TStringTable.create;
     1589  if not Sounds.loadfromfile(HomeDir + 'Sounds' + DirectorySeparator + 'sound.txt') then
     1590  begin
     1591    Sounds.Free;
     1592    Sounds := nil
     1593  end;
     1594
     1595  for section := Low(TFontType) to High(TFontType) do
     1596    UniFont[section] := TFont.create;
     1597
     1598  LogoBuffer := TBitmap.create;
     1599  LogoBuffer.PixelFormat := pf24bit;
     1600  LogoBuffer.SetSize(wBBook, hBBook);
     1601
     1602  section := ftNormal;
     1603  AssignFile(fontscript, LocalizedFilePath('Fonts.txt'));
     1604  try
     1605    Reset(fontscript);
     1606    while not eof(fontscript) do
     1607    begin
     1608      ReadLn(fontscript, s);
     1609      if s <> '' then
     1610        if s[1] = '#' then
     1611        begin
     1612          s := TrimRight(s);
     1613          if s = '#SMALL' then
     1614            section := ftSmall
     1615          else if s = '#TINY' then
     1616            section := ftTiny
     1617          else if s = '#CAPTION' then
     1618            section := ftCaption
     1619          else if s = '#BUTTON' then
     1620            section := ftButton
     1621          else
     1622            section := ftNormal;
     1623        end
     1624        else
     1625        begin
     1626          p := pos(',', s);
     1627          if p > 0 then
     1628          begin
     1629            UniFont[section].Name := Trim(copy(s, 1, p - 1));
     1630            size := 0;
     1631            for i := p + 1 to Length(s) do
     1632              case s[i] of
     1633                '0' .. '9':
     1634                  size := size * 10 + Byte(s[i]) - 48;
     1635                'B', 'b':
     1636                  UniFont[section].Style := UniFont[section].Style + [fsBold];
     1637                'I', 'i':
     1638                  UniFont[section].Style := UniFont[section].Style + [fsItalic];
     1639              end;
     1640            // 0.8 constant is compensation for Lazarus as size of fonts against Delphi differs
     1641            UniFont[section].size :=
     1642              round(size * 72 / UniFont[section].PixelsPerInch * 0.8);
     1643          end;
     1644        end;
     1645    end;
     1646    CloseFile(fontscript);
     1647  except
     1648  end;
     1649
     1650  nGrExt := 0;
     1651  HGrSystem := LoadGraphicSet('System');
     1652  HGrSystem2 := LoadGraphicSet('System2');
     1653  Templates := TBitmap.create;
     1654  LoadGraphicFile(Templates, HomeDir + 'Graphics' + DirectorySeparator + 'Templates', gfNoGamma);
     1655  Templates.PixelFormat := pf24bit;
     1656  Colors := TBitmap.create;
     1657  LoadGraphicFile(Colors, HomeDir + 'Graphics' + DirectorySeparator + 'Colors');
     1658  Paper := TBitmap.create;
     1659  LoadGraphicFile(Paper, HomeDir + 'Graphics' + DirectorySeparator + 'Paper', gfJPG);
     1660  BigImp := TBitmap.create;
     1661  LoadGraphicFile(BigImp, HomeDir + 'Graphics' + DirectorySeparator + 'Icons');
     1662  MainTexture.Image := TBitmap.create;
     1663  MainTextureAge := -2;
     1664  ClickFrameColor := GrExt[HGrSystem].Data.Canvas.Pixels[187, 175];
     1665  InitOrnamentDone := false;
     1666  GenerateNames := true;
     1667end;
     1668
     1669procedure UnitDone;
     1670begin
     1671  RestoreResolution;
     1672  for i := 0 to nGrExt - 1 do
     1673  begin
     1674    GrExt[i].Data.Free;
     1675    GrExt[i].Mask.Free;
     1676    FreeMem(GrExt[i]);
     1677  end;
     1678  for section := Low(TFontType) to High(TFontType) do
     1679    FreeAndNil(UniFont[section]);
     1680  FreeAndNil(Phrases);
     1681  FreeAndNil(Phrases2);
     1682  if Sounds <> nil then
     1683    FreeAndNil(Sounds);
     1684  FreeAndNil(LogoBuffer);
     1685  FreeAndNil(BigImp);
     1686  FreeAndNil(Paper);
     1687  FreeAndNil(Templates);
     1688  FreeAndNil(Colors);
     1689  FreeAndNil(MainTexture.Image);
     1690end;
     1691
    14901692initialization
    14911693
    1492 Reg := TRegistry.create;
    1493 try
    1494   Reg.OpenKey('SOFTWARE\cevo\RegVer9', true);
    1495   if Reg.ValueExists('Gamma') then
    1496     Gamma := Reg.ReadInteger('Gamma')
    1497     else begin
    1498       Gamma := 100;
    1499       Reg.WriteInteger('Gamma', Gamma);
    1500     end;
    1501 finally
    1502   Reg.Free;
    1503 end;
    1504 
    1505 if Gamma <> 100 then
    1506 begin
    1507   GammaLUT[0] := 0;
    1508   for i := 1 to 255 do
    1509   begin
    1510     p := round(255.0 * exp(ln(i / 255.0) * 100.0 / Gamma));
    1511     assert((p >= 0) and (p < 256));
    1512     GammaLUT[i] := p;
    1513   end;
    1514 end;
    1515 
    1516 {$IFDEF WINDOWS}
    1517 EnumDisplaySettings(nil, $FFFFFFFF, StartResolution);
    1518 {$ENDIF}
    1519 ResolutionChanged := false;
    1520 
    1521 Phrases := TStringTable.create;
    1522 Phrases2 := TStringTable.create;
    1523 Phrases2FallenBackToEnglish := false;
    1524 if FileExists(DataDir + 'Localization' + DirectorySeparator + 'Language.txt') then
    1525 begin
    1526   Phrases.loadfromfile(DataDir + 'Localization' + DirectorySeparator + ' + Language.txt');
    1527   if FileExists(DataDir + 'Localization' + DirectorySeparator + 'Language2.txt') then
    1528     Phrases2.loadfromfile(DataDir + 'Localization' + DirectorySeparator + 'Language2.txt')
    1529   else
    1530   begin
    1531     Phrases2.loadfromfile(HomeDir + 'Language2.txt');
    1532     Phrases2FallenBackToEnglish := true;
    1533   end
    1534 end
    1535 else
    1536 begin
    1537   Phrases.loadfromfile(HomeDir + 'Language.txt');
    1538   Phrases2.loadfromfile(HomeDir + 'Language2.txt');
    1539 end;
    1540 
    1541 Sounds := TStringTable.create;
    1542 if not Sounds.loadfromfile(HomeDir + 'Sounds' + DirectorySeparator + 'sound.txt') then
    1543 begin
    1544   Sounds.Free;
    1545   Sounds := nil
    1546 end;
    1547 
    1548 for section := Low(TFontType) to High(TFontType) do
    1549   UniFont[section] := TFont.create;
    1550 
    1551 LogoBuffer := TBitmap.create;
    1552 LogoBuffer.PixelFormat := pf24bit;
    1553 LogoBuffer.SetSize(wBBook, hBBook);
    1554 
    1555 section := ftNormal;
    1556 AssignFile(fontscript, LocalizedFilePath('Fonts.txt'));
    1557 try
    1558   Reset(fontscript);
    1559   while not eof(fontscript) do
    1560   begin
    1561     ReadLn(fontscript, s);
    1562     if s <> '' then
    1563       if s[1] = '#' then
    1564       begin
    1565         s := TrimRight(s);
    1566         if s = '#SMALL' then
    1567           section := ftSmall
    1568         else if s = '#TINY' then
    1569           section := ftTiny
    1570         else if s = '#CAPTION' then
    1571           section := ftCaption
    1572         else if s = '#BUTTON' then
    1573           section := ftButton
    1574         else
    1575           section := ftNormal;
    1576       end
    1577       else
    1578       begin
    1579         p := pos(',', s);
    1580         if p > 0 then
    1581         begin
    1582           UniFont[section].Name := Trim(copy(s, 1, p - 1));
    1583           size := 0;
    1584           for i := p + 1 to Length(s) do
    1585             case s[i] of
    1586               '0' .. '9':
    1587                 size := size * 10 + Byte(s[i]) - 48;
    1588               'B', 'b':
    1589                 UniFont[section].Style := UniFont[section].Style + [fsBold];
    1590               'I', 'i':
    1591                 UniFont[section].Style := UniFont[section].Style + [fsItalic];
    1592             end;
    1593           // 0.8 constant is compensation for Lazarus as size of fonts against Delphi differs
    1594           UniFont[section].size :=
    1595             round(size * 72 / UniFont[section].PixelsPerInch * 0.8);
    1596         end;
    1597       end;
    1598   end;
    1599   CloseFile(fontscript);
    1600 except
    1601 end;
    1602 
    1603 nGrExt := 0;
    1604 HGrSystem := LoadGraphicSet('System');
    1605 HGrSystem2 := LoadGraphicSet('System2');
    1606 Templates := TBitmap.create;
    1607 LoadGraphicFile(Templates, HomeDir + 'Graphics' + DirectorySeparator + 'Templates', gfNoGamma);
    1608 Templates.PixelFormat := pf24bit;
    1609 Colors := TBitmap.create;
    1610 LoadGraphicFile(Colors, HomeDir + 'Graphics' + DirectorySeparator + 'Colors');
    1611 Paper := TBitmap.create;
    1612 LoadGraphicFile(Paper, HomeDir + 'Graphics' + DirectorySeparator + 'Paper', gfJPG);
    1613 BigImp := TBitmap.create;
    1614 LoadGraphicFile(BigImp, HomeDir + 'Graphics' + DirectorySeparator + 'Icons');
    1615 MainTexture.Image := TBitmap.create;
    1616 MainTextureAge := -2;
    1617 ClickFrameColor := GrExt[HGrSystem].Data.Canvas.Pixels[187, 175];
    1618 InitOrnamentDone := false;
    1619 GenerateNames := true;
     1694UnitInit;
    16201695
    16211696finalization
    16221697
    1623 RestoreResolution;
    1624 for i := 0 to nGrExt - 1 do
    1625 begin
    1626   GrExt[i].Data.Free;
    1627   GrExt[i].Mask.Free;
    1628   FreeMem(GrExt[i]);
    1629 end;
    1630 for section := Low(TFontType) to High(TFontType) do
    1631   UniFont[section].Free;
    1632 Phrases.Free;
    1633 FreeAndNil(Phrases2);
    1634 if Sounds <> nil then
    1635   Sounds.Free;
    1636 LogoBuffer.Free;
    1637 BigImp.Free;
    1638 Paper.Free;
    1639 Templates.Free;
    1640 Colors.Free;
    1641 MainTexture.Image.Free;
     1698UnitDone;
    16421699
    16431700end.
Note: See TracChangeset for help on using the changeset viewer.