2
0

FileHDRImage.pas 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // This unit is part of the GLScene Engine, http://glscene.org
  3. //
  4. (*
  5. Good for preview picture in OpenDialog,
  6. so you may include both HDRImage (preview) and GLFileHDR (loading)
  7. *)
  8. unit FileHDRImage;
  9. interface
  10. {$I GLScene.inc}
  11. uses
  12. Winapi.Windows,
  13. System.Classes,
  14. System.SysUtils,
  15. Vcl.Graphics,
  16. OpenGLTokens,
  17. GLVectorGeometry,
  18. GLGraphics;
  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. GLFileHDR,
  30. GLTextureFormat;
  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.