Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:05

0001 // Author: Kirill Gavrilov
0002 // Copyright (c) 2015-2019 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _Image_Texture_HeaderFile
0016 #define _Image_Texture_HeaderFile
0017 
0018 #include <NCollection_Buffer.hxx>
0019 #include <TCollection_AsciiString.hxx>
0020 
0021 class Image_CompressedPixMap;
0022 class Image_SupportedFormats;
0023 class Image_PixMap;
0024 
0025 //! Texture image definition.
0026 //! 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.
0027 class Image_Texture : public Standard_Transient
0028 {
0029   DEFINE_STANDARD_RTTIEXT(Image_Texture, Standard_Transient)
0030 public:
0031 
0032   //! Constructor pointing to file location.
0033   Standard_EXPORT explicit Image_Texture (const TCollection_AsciiString& theFileName);
0034 
0035   //! Constructor pointing to file part.
0036   Standard_EXPORT explicit Image_Texture (const TCollection_AsciiString& theFileName,
0037                                           int64_t theOffset,
0038                                           int64_t theLength);
0039 
0040   //! Constructor pointing to buffer.
0041   Standard_EXPORT explicit Image_Texture (const Handle(NCollection_Buffer)& theBuffer,
0042                                           const TCollection_AsciiString& theId);
0043 
0044   //! Return generated texture id.
0045   const TCollection_AsciiString& TextureId() const { return myTextureId; }
0046 
0047   //! Return image file path.
0048   const TCollection_AsciiString& FilePath() const { return myImagePath; }
0049 
0050   //! Return offset within file.
0051   int64_t FileOffset() const { return myOffset; }
0052 
0053   //! Return length of image data within the file after offset.
0054   int64_t FileLength() const { return myLength; }
0055 
0056   //! Return buffer holding encoded image content.
0057   const Handle(NCollection_Buffer)& DataBuffer() const { return myBuffer; }
0058 
0059   //! Return mime-type of image file based on ProbeImageFileFormat().
0060   Standard_EXPORT TCollection_AsciiString MimeType() const;
0061 
0062   //! Return image file format.
0063   Standard_EXPORT TCollection_AsciiString ProbeImageFileFormat() const;
0064 
0065   //! Image reader without decoding data for formats supported natively by GPUs.
0066   Standard_EXPORT virtual Handle(Image_CompressedPixMap) ReadCompressedImage (const Handle(Image_SupportedFormats)& theSupported) const;
0067 
0068   //! Image reader.
0069   Standard_EXPORT virtual Handle(Image_PixMap) ReadImage (const Handle(Image_SupportedFormats)& theSupported) const;
0070 
0071   //! Write image to specified file without decoding data.
0072   Standard_EXPORT virtual Standard_Boolean WriteImage (const TCollection_AsciiString& theFile);
0073 
0074   //! Write image to specified stream without decoding data.
0075   Standard_EXPORT virtual Standard_Boolean WriteImage (std::ostream& theStream,
0076                                                        const TCollection_AsciiString& theFile);
0077 
0078 public: //! @name hasher interface
0079   
0080   //! Dumps the content of me into the stream
0081   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0082 
0083 protected:
0084 
0085   //! Read image from normal image file.
0086   Standard_EXPORT virtual Handle(Image_PixMap) loadImageFile (const TCollection_AsciiString& thePath) const;
0087 
0088   //! Read image from file with some offset.
0089   Standard_EXPORT virtual Handle(Image_PixMap) loadImageOffset (const TCollection_AsciiString& thePath,
0090                                                                 int64_t theOffset,
0091                                                                 int64_t theLength) const;
0092 
0093   //! Read image from buffer.
0094   Standard_EXPORT virtual Handle(Image_PixMap) loadImageBuffer (const Handle(NCollection_Buffer)& theBuffer,
0095                                                                 const TCollection_AsciiString& theId) const;
0096 
0097 protected:
0098 
0099   TCollection_AsciiString myTextureId; //!< generated texture id
0100   TCollection_AsciiString myImagePath; //!< image file path
0101   Handle(NCollection_Buffer) myBuffer; //!< image buffer
0102   int64_t                    myOffset; //!< offset within file
0103   int64_t                    myLength; //!< length within file
0104 
0105 };
0106 
0107 namespace std
0108 {
0109   template<>
0110   struct equal_to<Handle(Image_Texture)>
0111   {
0112     bool operator()(const Handle(Image_Texture)& theTex1,
0113                     const Handle(Image_Texture)& theTex2) const
0114     {
0115       if (theTex1.IsNull() != theTex2.IsNull())
0116       {
0117         return Standard_False;
0118       }
0119       else if (theTex1.IsNull())
0120       {
0121         return Standard_True;
0122       }
0123       return theTex1->TextureId().IsEqual(theTex2->TextureId());
0124     }
0125   };
0126 
0127   template<>
0128   struct hash<Handle(Image_Texture)>
0129   {
0130     size_t operator()(const Handle(Image_Texture)& theTexture) const noexcept
0131     {
0132       return !theTexture.IsNull()
0133         ? std::hash<TCollection_AsciiString>{}(theTexture->TextureId())
0134         : 0;
0135     }
0136   };
0137 }
0138 
0139 #endif // _Image_Texture_HeaderFile