summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-07-02 23:09:26 +0200
committermanuel <manuel@mausz.at>2020-07-02 23:09:26 +0200
commit5f8335c1e49ce108ef3481863833c98efa00411b (patch)
treef02b5c1c9765bb6a14c8eb42bb4f81b9face0b55 /xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
parente317daf081a1048904fdf0b548946fa3ba6593a7 (diff)
downloadkodi-pvr-build-master.tar.gz
kodi-pvr-build-master.tar.bz2
kodi-pvr-build-master.zip
sync with upstreamHEADmaster
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h417
1 files changed, 290 insertions, 127 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
index 09ac6c9..e41e5ef 100644
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
@@ -9,144 +9,307 @@
9#pragma once 9#pragma once
10 10
11#include "../AddonBase.h" 11#include "../AddonBase.h"
12#include "../c-api/addon-instance/image_decoder.h"
12 13
13namespace kodi { namespace addon { class CInstanceImageDecoder; }} 14#ifdef __cplusplus
14 15namespace kodi
15extern "C" 16{
17namespace addon
16{ 18{
17 19
18 typedef struct AddonProps_ImageDecoder 20//##############################################################################
19 { 21/// @defgroup cpp_kodi_addon_imagedecoder_Defs Definitions, structures and enumerators
20 const char* mimetype; 22/// @ingroup cpp_kodi_addon_imagedecoder
21 } AddonProps_ImageDecoder; 23/// @brief **Image decoder add-on general variables**
24///
25/// Used to exchange the available options between Kodi and addon.
26///
27///
22 28
23 typedef struct AddonToKodiFuncTable_ImageDecoder 29//==============================================================================
30///
31/// @addtogroup cpp_kodi_addon_imagedecoder
32/// @brief @cpp_class{ kodi::addon::CInstanceImageDecoder }
33/// **Image decoder add-on instance**\n
34/// This instance type is used to allow Kodi various additional image format
35/// types.
36///
37/// This usage can be requested under various conditions, by a Mimetype protocol
38/// defined in <b>`addon.xml`</b> or supported file extensions.
39///
40/// Include the header @ref ImageDecoder.h "#include <kodi/addon-instance/ImageDecoder.h>"
41/// to use this class.
42///
43/// ----------------------------------------------------------------------------
44///
45/// Here is an example of what the <b>`addon.xml.in`</b> would look like for an
46/// image decoder addon:
47///
48/// ~~~~~~~~~~~~~{.xml}
49/// <?xml version="1.0" encoding="UTF-8"?>
50/// <addon
51/// id="imagedecoder.myspecialnamefor"
52/// version="1.0.0"
53/// name="My image decoder addon"
54/// provider-name="Your Name">
55/// <requires>@ADDON_DEPENDS@</requires>
56/// <extension
57/// point="kodi.imagedecoder"
58/// extension=".imga|.imgb"
59/// mimetype="image/mymimea|image/mymimea"
60/// library_@PLATFORM@="@LIBRARY_FILENAME@"/>
61/// <extension point="xbmc.addon.metadata">
62/// <summary lang="en_GB">My image decoder addon summary</summary>
63/// <description lang="en_GB">My image decoder description</description>
64/// <platform>@PLATFORM@</platform>
65/// </extension>
66/// </addon>
67/// ~~~~~~~~~~~~~
68///
69/// ### Standard values that can be declared for processing in `addon.xml`.
70///
71/// These values are used by Kodi to identify associated images and file
72/// extensions and then to select the associated addon.
73///
74/// \table_start
75/// \table_h3{ Labels, Type, Description }
76/// \table_row3{ <b>`point`</b>,
77/// @anchor cpp_kodi_addon_imagedecoder_point
78/// string,
79/// The identification of the addon instance to image decoder is mandatory
80/// <b>`kodi.imagedecoder`</b>. In addition\, the instance declared in the
81/// first <b>`<extension ... />`</b> is also the main type of addon.
82/// }
83/// \table_row3{ <b>`extension`</b>,
84/// @anchor cpp_kodi_addon_imagedecoder_defaultPort
85/// string,
86/// The from addon operated and supported image file endings.\n
87/// Use a <b>`|`</b> to separate between different ones.
88/// }
89/// \table_row3{ <b>`defaultPort`</b>,
90/// @anchor cpp_kodi_addon_imagedecoder_defaultPort
91/// string,
92/// The from addon operated image [mimetypes](https://en.wikipedia.org/wiki/Media_type).\n
93/// Use a <b>`|`</b> to separate between different ones.
94/// }
95/// \table_row3{ <b>`library_@PLATFORM@`</b>,
96/// @anchor cpp_kodi_addon_imagedecoder_library
97/// string,
98/// The runtime library used for the addon. This is usually declared by `cmake` and correctly displayed in the translated <b>`addon.xml`</b>.
99/// }
100/// \table_end
101///
102/// @remark For more detailed description of the <b>`addon.xml`</b>, see also https://kodi.wiki/view/Addon.xml.
103///
104///
105/// --------------------------------------------------------------------------
106///
107///
108/// **Example:**
109///
110/// ~~~~~~~~~~~~~{.cpp}
111/// #include <kodi/addon-instance/ImageDecoder.h>
112///
113/// class ATTRIBUTE_HIDDEN CMyImageDecoder : public kodi::addon::CInstanceImageDecoder
114/// {
115/// public:
116/// CMyImageDecoder(KODI_HANDLE instance, const std::string& kodiVersion);
117///
118/// bool LoadImageFromMemory(unsigned char* buffer,
119/// unsigned int bufSize,
120/// unsigned int& width,
121/// unsigned int& height) override;
122///
123/// bool Decode(unsigned char* pixels,
124/// unsigned int width,
125/// unsigned int height,
126/// unsigned int pitch,
127/// ImageFormat format) override;
128///
129/// ...
130/// };
131///
132/// CMyImageDecoder::CMyImageDecoder(KODI_HANDLE instance, const std::string& kodiVersion)
133/// : CInstanceImageDecoder(instance, kodiVersion)
134/// {
135/// ...
136/// }
137///
138/// bool CMyImageDecoder::LoadImageFromMemory(unsigned char* buffer,
139/// unsigned int bufSize,
140/// unsigned int& width,
141/// unsigned int& height)
142/// {
143/// ...
144/// return true;
145/// }
146///
147/// bool CMyImageDecoder::Decode(unsigned char* pixels,
148/// unsigned int width,
149/// unsigned int height,
150/// unsigned int pitch,
151/// ImageFormat format) override;
152/// {
153/// ...
154/// return true;
155/// }
156///
157/// //----------------------------------------------------------------------
158///
159/// class ATTRIBUTE_HIDDEN CMyAddon : public kodi::addon::CAddonBase
160/// {
161/// public:
162/// CMyAddon() = default;
163/// ADDON_STATUS CreateInstance(int instanceType,
164/// const std::string& instanceID,
165/// KODI_HANDLE instance,
166/// const std::string& version,
167/// KODI_HANDLE& addonInstance) override;
168/// };
169///
170/// // If you use only one instance in your add-on, can be instanceType and
171/// // instanceID ignored
172/// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
173/// const std::string& instanceID,
174/// KODI_HANDLE instance,
175/// const std::string& version,
176/// KODI_HANDLE& addonInstance)
177/// {
178/// if (instanceType == ADDON_INSTANCE_IMAGEDECODER)
179/// {
180/// kodi::Log(ADDON_LOG_NOTICE, "Creating my image decoder instance");
181/// addonInstance = new CMyImageDecoder(instance, version);
182/// return ADDON_STATUS_OK;
183/// }
184/// else if (...)
185/// {
186/// ...
187/// }
188/// return ADDON_STATUS_UNKNOWN;
189/// }
190///
191/// ADDONCREATOR(CMyAddon)
192/// ~~~~~~~~~~~~~
193///
194/// The destruction of the example class `CMyImageDecoder` is called from
195/// Kodi's header. Manually deleting the add-on instance is not required.
196///
197//------------------------------------------------------------------------------
198class ATTRIBUTE_HIDDEN CInstanceImageDecoder : public IAddonInstance
199{
200public:
201 //============================================================================
202 /// @ingroup cpp_kodi_addon_imagedecoder
203 /// @brief Class constructor.
204 ///
205 /// @param[in] instance The from Kodi given instance given be add-on
206 /// CreateInstance call with instance id
207 /// @ref ADDON_INSTANCE_IMAGEDECODER.
208 /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to
209 /// allow compatibility to older Kodi versions.
210 ///
211 /// @note Recommended to set <b>`kodiVersion`</b>.
212 ///
213 explicit CInstanceImageDecoder(KODI_HANDLE instance, const std::string& kodiVersion = "")
214 : IAddonInstance(ADDON_INSTANCE_IMAGEDECODER,
215 !kodiVersion.empty() ? kodiVersion
216 : GetKodiTypeVersion(ADDON_INSTANCE_IMAGEDECODER))
24 { 217 {
25 KODI_HANDLE kodi_instance; 218 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
26 } AddonToKodiFuncTable_ImageDecoder; 219 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation of multiple together "
220 "with single instance way is not allowed!");
27 221
28 struct AddonInstance_ImageDecoder; 222 SetAddonStruct(instance);
29 typedef struct KodiToAddonFuncTable_ImageDecoder 223 }
30 { 224 //----------------------------------------------------------------------------
31 kodi::addon::CInstanceImageDecoder* addonInstance;
32 bool (__cdecl* load_image_from_memory) (const AddonInstance_ImageDecoder* instance,
33 unsigned char* buffer, unsigned int buf_size,
34 unsigned int* width, unsigned int* height);
35
36 bool (__cdecl* decode) (const AddonInstance_ImageDecoder* instance,
37 unsigned char* pixels,
38 unsigned int width, unsigned int height,
39 unsigned int pitch, unsigned int format);
40 } KodiToAddonFuncTable_ImageDecoder;
41
42 typedef struct AddonInstance_ImageDecoder
43 {
44 AddonProps_ImageDecoder props;
45 AddonToKodiFuncTable_ImageDecoder toKodi;
46 KodiToAddonFuncTable_ImageDecoder toAddon;
47 } AddonInstance_ImageDecoder;
48 225
49} /* extern "C" */ 226 ~CInstanceImageDecoder() override = default;
50 227
51typedef enum ImageFormat : unsigned int 228 //============================================================================
52{ 229 /// @ingroup cpp_kodi_addon_imagedecoder
53 ADDON_IMG_FMT_A8R8G8B8 = 1, 230 /// @brief Initialize an encoder.
54 ADDON_IMG_FMT_A8 = 2, 231 ///
55 ADDON_IMG_FMT_RGBA8 = 3, 232 /// @param[in] buffer The data to read from memory
56 ADDON_IMG_FMT_RGB8 = 4 233 /// @param[in] bufSize The buffer size
57} ImageFormat; 234 /// @param[in,out] width The optimal width of image on entry, obtained width
235 /// on return
236 /// @param[in,out] height The optimal height of image, actual obtained height
237 /// on return
238 /// @return true if successful done, false on error
239 ///
240 virtual bool LoadImageFromMemory(unsigned char* buffer,
241 unsigned int bufSize,
242 unsigned int& width,
243 unsigned int& height) = 0;
244 //----------------------------------------------------------------------------
58 245
59namespace kodi 246 //============================================================================
60{ 247 /// @ingroup cpp_kodi_addon_imagedecoder
61namespace addon 248 /// @brief Decode previously loaded image.
62{ 249 ///
250 /// @param[in] pixels Output buffer
251 /// @param[in] width Width of output image
252 /// @param[in] height Height of output image
253 /// @param[in] pitch Pitch of output image
254 /// @param[in] format Format of output image
255 /// @return true if successful done, false on error
256 ///
257 virtual bool Decode(unsigned char* pixels,
258 unsigned int width,
259 unsigned int height,
260 unsigned int pitch,
261 ImageFormat format) = 0;
262 //----------------------------------------------------------------------------
263
264 //============================================================================
265 /// @ingroup cpp_kodi_addon_imagedecoder
266 /// @brief **Callback to Kodi Function**\n
267 /// Get the wanted mime type from Kodi.
268 ///
269 /// @return the mimetype wanted from Kodi
270 ///
271 /// @remarks Only called from addon itself.
272 ///
273 inline std::string MimeType() { return m_instanceData->props->mimetype; }
274 //----------------------------------------------------------------------------
275
276private:
277 void SetAddonStruct(KODI_HANDLE instance)
278 {
279 if (instance == nullptr)
280 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation with empty addon "
281 "structure not allowed, table must be given from Kodi!");
282
283 m_instanceData = static_cast<AddonInstance_ImageDecoder*>(instance);
284 m_instanceData->toAddon->addonInstance = this;
285 m_instanceData->toAddon->load_image_from_memory = ADDON_LoadImageFromMemory;
286 m_instanceData->toAddon->decode = ADDON_Decode;
287 }
63 288
64 class CInstanceImageDecoder : public IAddonInstance 289 inline static bool ADDON_LoadImageFromMemory(const AddonInstance_ImageDecoder* instance,
290 unsigned char* buffer,
291 unsigned int bufSize,
292 unsigned int* width,
293 unsigned int* height)
65 { 294 {
66 public: 295 return static_cast<CInstanceImageDecoder*>(instance->toAddon->addonInstance)
67 //========================================================================== 296 ->LoadImageFromMemory(buffer, bufSize, *width, *height);
68 /// @brief Class constructor 297 }
69 /// 298
70 /// @param[in] instance The from Kodi given instance given be 299 inline static bool ADDON_Decode(const AddonInstance_ImageDecoder* instance,
71 /// add-on CreateInstance call with instance 300 unsigned char* pixels,
72 /// id ADDON_INSTANCE_IMAGEDECODER. 301 unsigned int width,
73 explicit CInstanceImageDecoder(KODI_HANDLE instance) 302 unsigned int height,
74 : IAddonInstance(ADDON_INSTANCE_IMAGEDECODER) 303 unsigned int pitch,
75 { 304 enum ImageFormat format)
76 if (CAddonBase::m_interface->globalSingleInstance != nullptr) 305 {
77 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation of multiple together with single instance way is not allowed!"); 306 return static_cast<CInstanceImageDecoder*>(instance->toAddon->addonInstance)
78 307 ->Decode(pixels, width, height, pitch, format);
79 SetAddonStruct(instance); 308 }
80 } 309
81 //-------------------------------------------------------------------------- 310 AddonInstance_ImageDecoder* m_instanceData;
82 311};
83 ~CInstanceImageDecoder() override = default;
84
85 //==========================================================================
86 /// @brief Initialize an encoder
87 ///
88 /// @param[in] buffer The data to read from memory
89 /// @param[in] bufSize The buffer size
90 /// @param[in,out] width The optimal width of image on entry, obtained width on return
91 /// @param[in,out] height The optimal height of image, actual obtained height on return
92 /// @return true if successful done, false on error
93 ///
94 virtual bool LoadImageFromMemory(unsigned char* buffer, unsigned int bufSize,
95 unsigned int& width, unsigned int& height) = 0;
96 //--------------------------------------------------------------------------
97
98 //==========================================================================
99 /// @brief Decode previously loaded image
100 ///
101 /// @param[in] pixels Output buffer
102 /// @param[in] width Width of output image
103 /// @param[in] height Height of output image
104 /// @param[in] pitch Pitch of output image
105 /// @param[in] format Format of output image
106 /// @return true if successful done, false on error
107 ///
108 virtual bool Decode(unsigned char* pixels,
109 unsigned int width, unsigned int height,
110 unsigned int pitch, ImageFormat format) = 0;
111 //--------------------------------------------------------------------------
112
113 //==========================================================================
114 /// @brief Get the wanted mime type from Kodi
115 ///
116 /// @return the mimetype wanted from Kodi
117 ///
118 inline std::string MimeType() { return m_instanceData->props.mimetype; }
119 //--------------------------------------------------------------------------
120
121 private:
122 void SetAddonStruct(KODI_HANDLE instance)
123 {
124 if (instance == nullptr)
125 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation with empty addon structure not allowed, table must be given from Kodi!");
126
127 m_instanceData = static_cast<AddonInstance_ImageDecoder*>(instance);
128 m_instanceData->toAddon.addonInstance = this;
129 m_instanceData->toAddon.load_image_from_memory = ADDON_LoadImageFromMemory;
130 m_instanceData->toAddon.decode = ADDON_Decode;
131 }
132
133 inline static bool ADDON_LoadImageFromMemory(const AddonInstance_ImageDecoder* instance,
134 unsigned char* buffer, unsigned int bufSize,
135 unsigned int* width, unsigned int* height)
136 {
137 return instance->toAddon.addonInstance->LoadImageFromMemory(buffer, bufSize, *width, *height);
138 }
139
140 inline static bool ADDON_Decode(const AddonInstance_ImageDecoder* instance,
141 unsigned char* pixels,
142 unsigned int width, unsigned int height,
143 unsigned int pitch, unsigned int format)
144 {
145 return instance->toAddon.addonInstance->Decode(pixels, width, height, pitch, static_cast<ImageFormat>(format));
146 }
147
148 AddonInstance_ImageDecoder* m_instanceData;
149 };
150 312
151} /* namespace addon */ 313} /* namespace addon */
152} /* namespace kodi */ 314} /* namespace kodi */
315#endif /* __cplusplus */