1 // Author: Kirill Gavrilov
2 // Copyright (c) 2015-2019 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Image_Texture_HeaderFile
16 #define _Image_Texture_HeaderFile
18 #include <NCollection_Buffer.hxx>
19 #include <TCollection_AsciiString.hxx>
21 class Image_CompressedPixMap;
22 class Image_SupportedFormats;
25 //! Texture image definition.
26 //! The image can be stored as path to image file, as file path with the given offset and as a data buffer of encoded image.
27 class Image_Texture : public Standard_Transient
29 DEFINE_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
32 //! Constructor pointing to file location.
33 Standard_EXPORT explicit Image_Texture (const TCollection_AsciiString& theFileName);
35 //! Constructor pointing to file part.
36 Standard_EXPORT explicit Image_Texture (const TCollection_AsciiString& theFileName,
40 //! Constructor pointing to buffer.
41 Standard_EXPORT explicit Image_Texture (const Handle(NCollection_Buffer)& theBuffer,
42 const TCollection_AsciiString& theId);
44 //! Return generated texture id.
45 const TCollection_AsciiString& TextureId() const { return myTextureId; }
47 //! Return image file path.
48 const TCollection_AsciiString& FilePath() const { return myImagePath; }
50 //! Return offset within file.
51 int64_t FileOffset() const { return myOffset; }
53 //! Return length of image data within the file after offset.
54 int64_t FileLength() const { return myLength; }
56 //! Return buffer holding encoded image content.
57 const Handle(NCollection_Buffer)& DataBuffer() const { return myBuffer; }
59 //! Return image file format.
60 Standard_EXPORT TCollection_AsciiString ProbeImageFileFormat() const;
62 //! Image reader without decoding data for formats supported natively by GPUs.
63 Standard_EXPORT virtual Handle(Image_CompressedPixMap) ReadCompressedImage (const Handle(Image_SupportedFormats)& theSupported) const;
66 Standard_EXPORT virtual Handle(Image_PixMap) ReadImage (const Handle(Image_SupportedFormats)& theSupported) const;
68 //! Write image to specified file without decoding data.
69 Standard_EXPORT virtual Standard_Boolean WriteImage (const TCollection_AsciiString& theFile);
71 public: //! @name hasher interface
73 //! Hash value, for Map interface.
74 static int HashCode (const Handle(Image_Texture)& theTexture, const int theUpper)
76 return !theTexture.IsNull()
77 ? TCollection_AsciiString::HashCode (theTexture->myTextureId, theUpper)
81 //! Matching two instances, for Map interface.
82 static Standard_Boolean IsEqual (const Handle(Image_Texture)& theTex1,
83 const Handle(Image_Texture)& theTex2)
85 if (theTex1.IsNull() != theTex2.IsNull())
87 return Standard_False;
89 else if (theTex1.IsNull())
93 return theTex1->myTextureId.IsEqual (theTex2->myTextureId);
96 //! Dumps the content of me into the stream
97 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
101 //! Read image from normal image file.
102 Standard_EXPORT virtual Handle(Image_PixMap) loadImageFile (const TCollection_AsciiString& thePath) const;
104 //! Read image from file with some offset.
105 Standard_EXPORT virtual Handle(Image_PixMap) loadImageOffset (const TCollection_AsciiString& thePath,
107 int64_t theLength) const;
109 //! Read image from buffer.
110 Standard_EXPORT virtual Handle(Image_PixMap) loadImageBuffer (const Handle(NCollection_Buffer)& theBuffer,
111 const TCollection_AsciiString& theId) const;
115 TCollection_AsciiString myTextureId; //!< generated texture id
116 TCollection_AsciiString myImagePath; //!< image file path
117 Handle(NCollection_Buffer) myBuffer; //!< image buffer
118 int64_t myOffset; //!< offset within file
119 int64_t myLength; //!< length within file
123 #endif // _Image_Texture_HeaderFile