FileO3TCImage.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // This unit is part of the GLScene Engine, http://glscene.org
  3. //
  4. (*
  5. Good to preview pictures in OpenDialog,
  6. so you may include both O3TCImage (preview) and GLFileO3TC (loading)
  7. *)
  8. unit FileO3TCImage;
  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. TO3TCImage = 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. GLFileO3TC,
  30. GLTextureFormat;
  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.