GLS.FileO3TCImage.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // The multimedia graphics platform GLScene https://github.com/glscene
  3. //
  4. unit GLS.FileO3TCImage;
  5. (*
  6. Good to preview pictures in OpenDialog,
  7. so you may include both O3TCImage (preview) and GLFileO3TC (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. GLS.FileO3TC;
  20. type
  21. TO3TCImage = class(TBitmap)
  22. public
  23. procedure LoadFromStream(stream: TStream); override;
  24. procedure SaveToStream(stream: TStream); override;
  25. end;
  26. //--------------------------------------------------
  27. implementation
  28. //--------------------------------------------------
  29. uses
  30. GLS.TextureFormat;
  31. // ------------------
  32. // ------------------ TO3TCImage ------------------
  33. // ------------------
  34. procedure TO3TCImage.LoadFromStream(stream: TStream);
  35. var
  36. FullO3TC: TGLO3TCImage;
  37. src, dst: PGLubyte;
  38. y: Integer;
  39. begin
  40. FullO3TC := TGLO3TCImage.Create;
  41. try
  42. FullO3TC.LoadFromStream(stream);
  43. except
  44. FullO3TC.Free;
  45. raise;
  46. end;
  47. FullO3TC.Narrow;
  48. Width := FullO3TC.LevelWidth[0];
  49. Height := FullO3TC.LevelHeight[0];
  50. Transparent := true;
  51. PixelFormat := pf32bit;
  52. src := PGLubyte(FullO3TC.Data);
  53. for y := 0 to Height - 1 do
  54. begin
  55. dst := ScanLine[Height - 1 - y];
  56. BGRA32ToRGBA32(src, dst, Width);
  57. Inc(src, Width * 4);
  58. end;
  59. FullO3TC.Free;
  60. end;
  61. procedure TO3TCImage.SaveToStream(stream: TStream);
  62. begin
  63. Assert(False, 'Not supported');
  64. end;
  65. // ------------------------------------------------------------------
  66. initialization
  67. // ------------------------------------------------------------------
  68. TPicture.RegisterFileFormat(
  69. 'o3tc', 'oZone3D Texture Compression', TO3TCImage);
  70. // ------------------------------------------------------------------
  71. finalization
  72. // ------------------------------------------------------------------
  73. TPicture.UnregisterGraphicClass(TO3TCImage);
  74. end.