| 1 | /* |
| 2 | * Copyright (C) 2012-2018 Team Kodi |
| 3 | * This file is part of Kodi - https://kodi.tv |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | * See LICENSES/README.md for more information. |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include <string> |
| 12 | |
| 13 | class IImage |
| 14 | { |
| 15 | public: |
| 16 | |
| 17 | virtual ~IImage() = default; |
| 18 | |
| 19 | /*! |
| 20 | \brief Load an image from memory with the format m_strMimeType to determine it's size and orientation |
| 21 | \param buffer The memory location where the image data can be found |
| 22 | \param bufSize The size of the buffer |
| 23 | \param width The ideal width of the texture |
| 24 | \param height The ideal height of the texture |
| 25 | \return true if the image could be loaded |
| 26 | */ |
| 27 | virtual bool LoadImageFromMemory(unsigned char* buffer, unsigned int bufSize, unsigned int width, unsigned int height)=0; |
| 28 | /*! |
| 29 | \brief Decodes the previously loaded image data to the output buffer in 32 bit raw bits |
| 30 | \param pixels The output buffer |
| 31 | \param width The width of the image |
| 32 | \param height The height of the image |
| 33 | \param pitch The pitch of the output buffer |
| 34 | \param format The format of the output buffer (JpegIO only) |
| 35 | \return true if the image data could be decoded to the output buffer |
| 36 | */ |
| 37 | virtual bool Decode(unsigned char* const pixels, unsigned int width, unsigned int height, unsigned int pitch, unsigned int format)=0; |
| 38 | /*! |
| 39 | \brief Encodes an thumbnail from raw bits of given memory location |
| 40 | \remarks Caller need to call ReleaseThumbnailBuffer() afterwards to free the output buffer |
| 41 | \param bufferin The memory location where the image data can be found |
| 42 | \param width The width of the thumbnail |
| 43 | \param height The height of the thumbnail |
| 44 | \param format The format of the input buffer (JpegIO only) |
| 45 | \param pitch The pitch of the input texture stored in bufferin |
| 46 | \param destFile The destination path of the thumbnail to determine the image format from the extension |
| 47 | \param bufferout The output buffer (will be allocated inside the method) |
| 48 | \param bufferoutSize The output buffer size |
| 49 | \return true if the thumbnail was successfully created |
| 50 | */ |
| 51 | virtual bool CreateThumbnailFromSurface(unsigned char* bufferin, unsigned int width, unsigned int height, unsigned int format, unsigned int pitch, const std::string& destFile, |
| 52 | unsigned char* &bufferout, unsigned int &bufferoutSize)=0; |
| 53 | /*! |
| 54 | \brief Frees the output buffer allocated by CreateThumbnailFromSurface |
| 55 | */ |
| 56 | virtual void ReleaseThumbnailBuffer() {} |
| 57 | |
| 58 | unsigned int Width() const { return m_width; } |
| 59 | unsigned int Height() const { return m_height; } |
| 60 | unsigned int originalWidth() const { return m_originalWidth; } |
| 61 | unsigned int originalHeight() const { return m_originalHeight; } |
| 62 | unsigned int Orientation() const { return m_orientation; } |
| 63 | bool hasAlpha() const { return m_hasAlpha; } |
| 64 | |
| 65 | protected: |
| 66 | |
| 67 | unsigned int m_width = 0; |
| 68 | unsigned int m_height = 0; |
| 69 | unsigned int m_originalWidth = 0; ///< original image width before scaling or cropping |
| 70 | unsigned int m_originalHeight = 0; ///< original image height before scaling or cropping |
| 71 | unsigned int m_orientation = 0; |
| 72 | bool m_hasAlpha = false; |
| 73 | |
| 74 | }; |