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>
23 //! Texture image definition.
24 //! 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.
25 class Image_Texture : public Standard_Transient
27 DEFINE_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
30 //! Constructor pointing to file location.
31 Standard_EXPORT explicit Image_Texture (const TCollection_AsciiString& theFileName);
33 //! Constructor pointing to file part.
34 Standard_EXPORT explicit Image_Texture (const TCollection_AsciiString& theFileName,
38 //! Constructor pointing to buffer.
39 Standard_EXPORT explicit Image_Texture (const Handle(NCollection_Buffer)& theBuffer,
40 const TCollection_AsciiString& theId);
42 //! Return generated texture id.
43 const TCollection_AsciiString& TextureId() const { return myTextureId; }
45 //! Return image file path.
46 const TCollection_AsciiString& FilePath() const { return myImagePath; }
48 //! Return offset within file.
49 int64_t FileOffset() const { return myOffset; }
51 //! Return length of image data within the file after offset.
52 int64_t FileLength() const { return myLength; }
54 //! Return buffer holding encoded image content.
55 const Handle(NCollection_Buffer)& DataBuffer() const { return myBuffer; }
57 //! Return image file format.
58 Standard_EXPORT TCollection_AsciiString ProbeImageFileFormat() const;
61 Standard_EXPORT virtual Handle(Image_PixMap) ReadImage() const;
63 //! Write image to specified file without decoding data.
64 Standard_EXPORT virtual Standard_Boolean WriteImage (const TCollection_AsciiString& theFile);
66 public: //! @name hasher interface
68 //! Hash value, for Map interface.
69 static int HashCode (const Handle(Image_Texture)& theTexture, const int theUpper)
71 return !theTexture.IsNull()
72 ? TCollection_AsciiString::HashCode (theTexture->myTextureId, theUpper)
76 //! Matching two instances, for Map interface.
77 static Standard_Boolean IsEqual (const Handle(Image_Texture)& theTex1,
78 const Handle(Image_Texture)& theTex2)
80 if (theTex1.IsNull() != theTex2.IsNull())
82 return Standard_False;
84 else if (theTex1.IsNull())
88 return theTex1->myTextureId.IsEqual (theTex2->myTextureId);
91 //! Dumps the content of me into the stream
92 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
96 //! Read image from normal image file.
97 Standard_EXPORT virtual Handle(Image_PixMap) loadImageFile (const TCollection_AsciiString& thePath) const;
99 //! Read image from file with some offset.
100 Standard_EXPORT virtual Handle(Image_PixMap) loadImageOffset (const TCollection_AsciiString& thePath,
102 int64_t theLength) const;
104 //! Read image from buffer.
105 Standard_EXPORT virtual Handle(Image_PixMap) loadImageBuffer (const Handle(NCollection_Buffer)& theBuffer,
106 const TCollection_AsciiString& theId) const;
110 TCollection_AsciiString myTextureId; //!< generated texture id
111 TCollection_AsciiString myImagePath; //!< image file path
112 Handle(NCollection_Buffer) myBuffer; //!< image buffer
113 int64_t myOffset; //!< offset within file
114 int64_t myLength; //!< length within file
118 #endif // _Image_Texture_HeaderFile