Formats.HDRImage.pas 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. GLScene.TextureFormat,
  20. GLS.FileHDR;
  21. type
  22. THDRImage = class(TBitmap)
  23. public
  24. procedure LoadFromStream(stream: TStream); override;
  25. procedure SaveToStream(stream: TStream); override;
  26. end;
  27. implementation //------------------------------------------------------------
  28. // ------------------
  29. // ------------------ THDRImage ------------------
  30. // ------------------
  31. procedure THDRImage.LoadFromStream(stream: TStream);
  32. var
  33. FullHDR: TGLHDRImage;
  34. src, dst: PGLubyte;
  35. y: integer;
  36. begin
  37. FullHDR := TGLHDRImage.Create;
  38. try
  39. FullHDR.LoadFromStream(stream);
  40. except
  41. FullHDR.Free;
  42. raise;
  43. end;
  44. FullHDR.Narrow;
  45. Width := FullHDR.LevelWidth[0];
  46. Height := FullHDR.LevelHeight[0];
  47. Transparent := false;
  48. PixelFormat := pf32bit;
  49. src := PGLubyte(FullHDR.Data);
  50. for y := 0 to Height - 1 do
  51. begin
  52. dst := ScanLine[Height - 1 - y];
  53. Move(src^, dst^, Width * 4);
  54. Inc(src, Width * 4);
  55. end;
  56. FullHDR.Free;
  57. end;
  58. procedure THDRImage.SaveToStream(stream: TStream);
  59. begin
  60. Assert(False, 'Not supported');
  61. end;
  62. initialization // ------------------------------------------------------------
  63. TPicture.RegisterFileFormat('HDR', 'High Dynamic Range Image', THDRImage);
  64. finalization // --------------------------------------------------------------
  65. TPicture.UnregisterGraphicClass(THDRImage);
  66. end.