Formats.HDRImage.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // The graphics platform GLScene https://github.com/glscene
  3. //
  4. unit Formats.HDRImage;
  5. (*
  6. Good for preview picture in OpenDialog,
  7. so you may include both HDRImage (preview) and GLFileHDR (loading)
  8. *)
  9. interface
  10. {$I GLScene.inc}
  11. uses
  12. Winapi.Windows,
  13. System.Classes,
  14. System.SysUtils,
  15. Vcl.Graphics,
  16. GLS.VectorTypes,
  17. GLS.VectorGeometry,
  18. GLS.Graphics;
  19. type
  20. THDRImage = class(TBitmap)
  21. public
  22. procedure LoadFromStream(stream: TStream); override;
  23. procedure SaveToStream(stream: TStream); override;
  24. end;
  25. //--------------------------------------------------------------------
  26. implementation
  27. //--------------------------------------------------------------------
  28. uses
  29. GLS.FileHDR,
  30. GLS.TextureFormat;
  31. // ------------------
  32. // ------------------ THDRImage ------------------
  33. // ------------------
  34. procedure THDRImage.LoadFromStream(stream: TStream);
  35. var
  36. FullHDR: TGLHDRImage;
  37. src, dst: PGLubyte;
  38. y: integer;
  39. begin
  40. FullHDR := TGLHDRImage.Create;
  41. try
  42. FullHDR.LoadFromStream(stream);
  43. except
  44. FullHDR.Free;
  45. raise;
  46. end;
  47. FullHDR.Narrow;
  48. Width := FullHDR.LevelWidth[0];
  49. Height := FullHDR.LevelHeight[0];
  50. Transparent := false;
  51. PixelFormat := pf32bit;
  52. src := PGLubyte(FullHDR.Data);
  53. for y := 0 to Height - 1 do
  54. begin
  55. dst := ScanLine[Height - 1 - y];
  56. Move(src^, dst^, Width * 4);
  57. Inc(src, Width * 4);
  58. end;
  59. FullHDR.Free;
  60. end;
  61. procedure THDRImage.SaveToStream(stream: TStream);
  62. begin
  63. Assert(False, 'Not supported');
  64. end;
  65. // ------------------------------------------------------------------
  66. initialization
  67. // ------------------------------------------------------------------
  68. TPicture.RegisterFileFormat('HDR', 'High Dynamic Range Image', THDRImage);
  69. // ------------------------------------------------------------------
  70. finalization
  71. // ------------------------------------------------------------------
  72. TPicture.UnregisterGraphicClass(THDRImage);
  73. end.