Formats.HDRImage.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // The graphics engine 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.Defines.inc}
  11. uses
  12. Winapi.Windows,
  13. System.Classes,
  14. System.SysUtils,
  15. Vcl.Graphics,
  16. GLScene.VectorTypes,
  17. GLScene.OpenGLTokens,
  18. GLScene.VectorGeometry,
  19. GLS.TextureFormat,
  20. GLS.Graphics;
  21. type
  22. THDRImage = class(TBitmap)
  23. public
  24. procedure LoadFromStream(stream: TStream); override;
  25. procedure SaveToStream(stream: TStream); override;
  26. end;
  27. //--------------------------------------------------------------------
  28. implementation
  29. //--------------------------------------------------------------------
  30. uses
  31. GLS.FileHDR;
  32. // ------------------
  33. // ------------------ THDRImage ------------------
  34. // ------------------
  35. procedure THDRImage.LoadFromStream(stream: TStream);
  36. var
  37. FullHDR: TGLHDRImage;
  38. src, dst: PGLubyte;
  39. y: integer;
  40. begin
  41. FullHDR := TGLHDRImage.Create;
  42. try
  43. FullHDR.LoadFromStream(stream);
  44. except
  45. FullHDR.Free;
  46. raise;
  47. end;
  48. FullHDR.Narrow;
  49. Width := FullHDR.LevelWidth[0];
  50. Height := FullHDR.LevelHeight[0];
  51. Transparent := false;
  52. PixelFormat := pf32bit;
  53. src := PGLubyte(FullHDR.Data);
  54. for y := 0 to Height - 1 do
  55. begin
  56. dst := ScanLine[Height - 1 - y];
  57. Move(src^, dst^, Width * 4);
  58. Inc(src, Width * 4);
  59. end;
  60. FullHDR.Free;
  61. end;
  62. procedure THDRImage.SaveToStream(stream: TStream);
  63. begin
  64. Assert(False, 'Not supported');
  65. end;
  66. // ------------------------------------------------------------------
  67. initialization
  68. // ------------------------------------------------------------------
  69. TPicture.RegisterFileFormat('HDR', 'High Dynamic Range Image', THDRImage);
  70. // ------------------------------------------------------------------
  71. finalization
  72. // ------------------------------------------------------------------
  73. TPicture.UnregisterGraphicClass(THDRImage);
  74. end.