diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/ImageDecoder.h | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/ImageDecoder.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/ImageDecoder.h | 315 |
1 files changed, 315 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/ImageDecoder.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/ImageDecoder.h new file mode 100644 index 0000000..7aeef7b --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/ImageDecoder.h | |||
| @@ -0,0 +1,315 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-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 "../AddonBase.h" | ||
| 12 | #include "../c-api/addon-instance/image_decoder.h" | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | namespace kodi | ||
| 16 | { | ||
| 17 | namespace addon | ||
| 18 | { | ||
| 19 | |||
| 20 | //############################################################################## | ||
| 21 | /// @defgroup cpp_kodi_addon_imagedecoder_Defs Definitions, structures and enumerators | ||
| 22 | /// @ingroup cpp_kodi_addon_imagedecoder | ||
| 23 | /// @brief **Image decoder add-on general variables** | ||
| 24 | /// | ||
| 25 | /// Used to exchange the available options between Kodi and addon. | ||
| 26 | /// | ||
| 27 | /// | ||
| 28 | |||
| 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_INFO, "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 | //------------------------------------------------------------------------------ | ||
| 198 | class ATTRIBUTE_HIDDEN CInstanceImageDecoder : public IAddonInstance | ||
| 199 | { | ||
| 200 | public: | ||
| 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)) | ||
| 217 | { | ||
| 218 | if (CAddonBase::m_interface->globalSingleInstance != nullptr) | ||
| 219 | throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation of multiple together " | ||
| 220 | "with single instance way is not allowed!"); | ||
| 221 | |||
| 222 | SetAddonStruct(instance); | ||
| 223 | } | ||
| 224 | //---------------------------------------------------------------------------- | ||
| 225 | |||
| 226 | ~CInstanceImageDecoder() override = default; | ||
| 227 | |||
| 228 | //============================================================================ | ||
| 229 | /// @ingroup cpp_kodi_addon_imagedecoder | ||
| 230 | /// @brief Initialize an encoder. | ||
| 231 | /// | ||
| 232 | /// @param[in] buffer The data to read from memory | ||
| 233 | /// @param[in] bufSize The buffer size | ||
| 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 | //---------------------------------------------------------------------------- | ||
| 245 | |||
| 246 | //============================================================================ | ||
| 247 | /// @ingroup cpp_kodi_addon_imagedecoder | ||
| 248 | /// @brief Decode previously loaded image. | ||
| 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 | |||
| 276 | private: | ||
| 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 | } | ||
| 288 | |||
| 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) | ||
| 294 | { | ||
| 295 | return static_cast<CInstanceImageDecoder*>(instance->toAddon->addonInstance) | ||
| 296 | ->LoadImageFromMemory(buffer, bufSize, *width, *height); | ||
| 297 | } | ||
| 298 | |||
| 299 | inline static bool ADDON_Decode(const AddonInstance_ImageDecoder* instance, | ||
| 300 | unsigned char* pixels, | ||
| 301 | unsigned int width, | ||
| 302 | unsigned int height, | ||
| 303 | unsigned int pitch, | ||
| 304 | enum ImageFormat format) | ||
| 305 | { | ||
| 306 | return static_cast<CInstanceImageDecoder*>(instance->toAddon->addonInstance) | ||
| 307 | ->Decode(pixels, width, height, pitch, format); | ||
| 308 | } | ||
| 309 | |||
| 310 | AddonInstance_ImageDecoder* m_instanceData; | ||
| 311 | }; | ||
| 312 | |||
| 313 | } /* namespace addon */ | ||
| 314 | } /* namespace kodi */ | ||
| 315 | #endif /* __cplusplus */ | ||
