createresource.pas 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-License-Identifier: GPL-3.0-only
  2. program createresource;
  3. {$mode objfpc}{$H+}
  4. uses
  5. {$IFDEF UNIX}{$IFDEF UseCThreads}
  6. cthreads,
  7. {$ENDIF}{$ENDIF}
  8. Interfaces, // this includes the LCL widgetset
  9. BGRABitmap, BGRALazPaint, BGRABitmapTypes,
  10. BGRALazResource, BGRAMultiFileType,
  11. LazFileUtils, LazUTF8Classes, SysUtils,
  12. LCVectorOriginal, LCVectorShapes, LCVectorPolyShapes;
  13. {$R *.res}
  14. const
  15. imgWidth = 24;
  16. imgHeight = 24;
  17. procedure MakeResource(AVectorImagesPath: string; AListFile: string; AResourceFile: string; ACombinedImage: string);
  18. var
  19. search: TSearchRec;
  20. res: TMultiFileContainer;
  21. fs: TFileStreamUTF8;
  22. lzp: TBGRALazPaintImage;
  23. bigImg: TBGRABitmap;
  24. i, idxEntry: Integer;
  25. mem: TMemoryStreamUTF8;
  26. combineList: TStringListUTF8;
  27. begin
  28. AVectorImagesPath := StringReplace(AVectorImagesPath,'/',PathDelim,[rfReplaceAll]);
  29. AListFile := StringReplace(AListFile,'/',PathDelim,[rfReplaceAll]);
  30. AResourceFile := StringReplace(AResourceFile,'/',PathDelim,[rfReplaceAll]);
  31. ACombinedImage := StringReplace(ACombinedImage,'/',PathDelim,[rfReplaceAll]);
  32. if FindFirstUTF8(AVectorImagesPath+'*.lzp', faAnyFile, search)=0 then
  33. begin
  34. res := TLazResourceContainer.Create;
  35. writeln('Adding files to resource...');
  36. repeat
  37. fs := TFileStreamUTF8.Create(AVectorImagesPath+search.name, fmOpenRead);
  38. res.Add(EntryFilename(search.name), fs, false, false);
  39. fs.Free;
  40. writeln(search.Name);
  41. until FindNextUTF8(search)<>0;
  42. FindClose(search);
  43. combineList:= TStringListUTF8.Create;
  44. if FileExists(AListFile) then
  45. combineList.LoadFromFile(AListFile)
  46. else
  47. begin
  48. for i := 0 to res.Count-1 do
  49. combineList.Add(res.Entry[i].Name+'.'+res.Entry[i].Extension);
  50. combineList.SaveToFile(AListFile);
  51. end;
  52. for i := combineList.Count-1 downto 0 do
  53. if combineList[i]='' then combineList.Delete(i);
  54. res.RawStringByFilename[ExtractFilename(AListFile)] := combineList.CommaText;
  55. res.SaveToFile(AResourceFile);
  56. writeln('Done Resource');
  57. lzp := TBGRALazPaintImage.Create;
  58. bigImg := TBGRABitmap.Create(imgWidth, imgHeight*combineList.Count);
  59. for i := 0 to combineList.Count-1 do
  60. begin
  61. idxEntry := res.IndexOf(EntryFilename(combineList[i]));
  62. if idxEntry = -1 then
  63. begin
  64. writeln('Cannot find "'+combineList[i]+'"');
  65. continue;
  66. end;
  67. mem := TMemoryStreamUTF8.Create;
  68. res.Entry[idxEntry].CopyTo(mem);
  69. mem.Position:= 0;
  70. lzp.LoadFromStream(mem);
  71. mem.Free;
  72. lzp.Resample(imgWidth,imgHeight,rmFineResample);
  73. lzp.Draw(bigImg,0,i*imgHeight);
  74. end;
  75. combineList.Free;
  76. res.Free;
  77. bigImg.SaveToFileUTF8(ACombinedImage);
  78. writeln('Done PNG');
  79. bigImg.Free;
  80. end;
  81. end;
  82. begin
  83. MakeResource('../vector/', '../vectorimages.lst', '../vectorimages.lrs', '../vectorimages'+inttostr(imgHeight)+'.png');
  84. MakeResource('../vector/fill/', '../fillimages.lst', '../fillimages.lrs', '../fillimages'+inttostr(imgHeight)+'.png');
  85. end.