Kodi Development 19.0
for Binary and Script based Add-Ons
ImageDecoder.h
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
15namespace kodi
16{
17namespace addon
18{
19
20//##############################################################################
28
29//==============================================================================
197//------------------------------------------------------------------------------
198class ATTRIBUTE_HIDDEN CInstanceImageDecoder : public IAddonInstance
199{
200public:
201 //============================================================================
213 explicit CInstanceImageDecoder(KODI_HANDLE instance, const std::string& kodiVersion = "")
215 !kodiVersion.empty() ? kodiVersion
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 //============================================================================
240 virtual bool LoadImageFromMemory(unsigned char* buffer,
241 unsigned int bufSize,
242 unsigned int& width,
243 unsigned int& height) = 0;
244 //----------------------------------------------------------------------------
245
246 //============================================================================
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 //============================================================================
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 }
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 */
Definition: ImageDecoder.h:199
Definition: AddonBase.h:186
@ ADDON_INSTANCE_IMAGEDECODER
Image Decoder instance, see kodi::addon::CInstanceImageDecoder.
Definition: versions.h:243
ImageFormat
Image format types Used to define wanted target format where image decoder should give to Kodi.
Definition: image_decoder.h:26
virtual bool Decode(unsigned char *pixels, unsigned int width, unsigned int height, unsigned int pitch, ImageFormat format)=0
Decode previously loaded image.
CInstanceImageDecoder(KODI_HANDLE instance, const std::string &kodiVersion="")
Class constructor.
Definition: ImageDecoder.h:213
virtual bool LoadImageFromMemory(unsigned char *buffer, unsigned int bufSize, unsigned int &width, unsigned int &height)=0
Initialize an encoder.
std::string MimeType()
Callback to Kodi Function Get the wanted mime type from Kodi.
Definition: ImageDecoder.h:273
std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
To get used version inside Kodi itself about asked type.
Definition: AddonBase.h:630
Definition: image_decoder.h:71