GXS.FileJPEG.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // The graphics engine GXScene https://github.com/glscene
  3. //
  4. unit GXS.FileJPEG;
  5. interface
  6. {$I Stage.Defines.inc}
  7. uses
  8. System.Classes,
  9. System.SysUtils,
  10. Stage.VectorGeometry,
  11. Stage.Strings,
  12. GXS.Context,
  13. GXS.Graphics,
  14. Stage.TextureFormat,
  15. GXS.ApplicationFileIO;
  16. type
  17. TgxJPEGImage = class(TgxBaseImage)
  18. private
  19. FAbortLoading: boolean;
  20. FDivScale: longword;
  21. FDither: boolean;
  22. FSmoothing: boolean;
  23. FProgressiveEncoding: boolean;
  24. procedure SetSmoothing(const AValue: boolean);
  25. public
  26. constructor Create; override;
  27. class function Capabilities: TDataFileCapabilities; override;
  28. procedure LoadFromFile(const filename: string); override;
  29. procedure SaveToFile(const filename: string); override;
  30. procedure LoadFromStream(stream: TStream); override;
  31. procedure SaveToStream(stream: TStream); override;
  32. // Assigns from any Texture.
  33. procedure AssignFromTexture(textureContext: TgxContext; const textureHandle: Cardinal; textureTarget: TglTextureTarget;
  34. const CurrentFormat: boolean; const intFormat: TglInternalFormat); reintroduce;
  35. property DivScale: longword read FDivScale write FDivScale;
  36. property Dither: boolean read FDither write FDither;
  37. property Smoothing: boolean read FSmoothing write SetSmoothing;
  38. property ProgressiveEncoding: boolean read FProgressiveEncoding;
  39. end;
  40. // ===================================================================
  41. implementation
  42. // ===================================================================
  43. // ------------------
  44. // ------------------ TgxJPEGImage ------------------
  45. // ------------------
  46. constructor TgxJPEGImage.Create;
  47. begin
  48. inherited;
  49. FAbortLoading := False;
  50. FDivScale := 1;
  51. FDither := False;
  52. end;
  53. procedure TgxJPEGImage.LoadFromFile(const filename: string);
  54. var
  55. fs: TStream;
  56. begin
  57. if FileStreamExists(filename) then
  58. begin
  59. fs := TFileStream.Create(filename, fmOpenRead);
  60. try
  61. LoadFromStream(fs);
  62. finally
  63. fs.Free;
  64. ResourceName := filename;
  65. end;
  66. end
  67. else
  68. raise EInvalidRasterFile.CreateFmt('File %s not found', [filename]);
  69. end;
  70. procedure TgxJPEGImage.SaveToFile(const filename: string);
  71. var
  72. fs: TStream;
  73. begin
  74. fs := TFileStream.Create(filename, fmOpenWrite or fmCreate);
  75. try
  76. SaveToStream(fs);
  77. finally
  78. fs.Free;
  79. end;
  80. ResourceName := filename;
  81. end;
  82. procedure TgxJPEGImage.LoadFromStream(stream: TStream);
  83. begin
  84. // Do nothing
  85. end;
  86. procedure TgxJPEGImage.SaveToStream(stream: TStream);
  87. begin
  88. // Do nothing
  89. end;
  90. procedure TgxJPEGImage.AssignFromTexture(textureContext: TgxContext; const textureHandle: Cardinal;
  91. textureTarget: TglTextureTarget; const CurrentFormat: boolean; const intFormat: TglInternalFormat);
  92. begin
  93. //
  94. end;
  95. procedure TgxJPEGImage.SetSmoothing(const AValue: boolean);
  96. begin
  97. if FSmoothing <> AValue then
  98. FSmoothing := AValue;
  99. end;
  100. class function TgxJPEGImage.Capabilities: TDataFileCapabilities;
  101. begin
  102. Result := [dfcRead { , dfcWrite } ];
  103. end;
  104. // ------------------------------------------------------------------
  105. initialization
  106. // ------------------------------------------------------------------
  107. RegisterRasterFormat('jpg', 'Joint Photographic Experts Group Image', TgxJPEGImage);
  108. RegisterRasterFormat('jpeg', 'Joint Photographic Experts Group Image', TgxJPEGImage);
  109. RegisterRasterFormat('jpe', 'Joint Photographic Experts Group Image', TgxJPEGImage);
  110. end.