summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
diff options
context:
space:
mode:
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.h163
1 files changed, 163 insertions, 0 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
new file mode 100644
index 0000000..a854711
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/ImageDecoder.h
@@ -0,0 +1,163 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2017 Team Kodi
4 * http://kodi.tv
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Kodi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "../AddonBase.h"
23
24namespace kodi { namespace addon { class CInstanceImageDecoder; }}
25
26extern "C"
27{
28
29 typedef struct AddonProps_ImageDecoder
30 {
31 const char* mimetype;
32 } AddonProps_ImageDecoder;
33
34 typedef struct AddonToKodiFuncTable_ImageDecoder
35 {
36 KODI_HANDLE kodi_instance;
37 } AddonToKodiFuncTable_ImageDecoder;
38
39 struct AddonInstance_ImageDecoder;
40 typedef struct KodiToAddonFuncTable_ImageDecoder
41 {
42 kodi::addon::CInstanceImageDecoder* addonInstance;
43 bool (__cdecl* load_image_from_memory) (const AddonInstance_ImageDecoder* instance,
44 unsigned char* buffer, unsigned int buf_size,
45 unsigned int* width, unsigned int* height);
46
47 bool (__cdecl* decode) (const AddonInstance_ImageDecoder* instance,
48 unsigned char* pixels,
49 unsigned int width, unsigned int height,
50 unsigned int pitch, unsigned int format);
51 } KodiToAddonFuncTable_ImageDecoder;
52
53 typedef struct AddonInstance_ImageDecoder
54 {
55 AddonProps_ImageDecoder props;
56 AddonToKodiFuncTable_ImageDecoder toKodi;
57 KodiToAddonFuncTable_ImageDecoder toAddon;
58 } AddonInstance_ImageDecoder;
59
60} /* extern "C" */
61
62typedef enum ImageFormat : unsigned int
63{
64 ADDON_IMG_FMT_A8R8G8B8 = 1,
65 ADDON_IMG_FMT_A8 = 2,
66 ADDON_IMG_FMT_RGBA8 = 3,
67 ADDON_IMG_FMT_RGB8 = 4
68} ImageFormat;
69
70namespace kodi
71{
72namespace addon
73{
74
75 class CInstanceImageDecoder : public IAddonInstance
76 {
77 public:
78 //==========================================================================
79 /// @brief Class constructor
80 ///
81 /// @param[in] instance The from Kodi given instance given be
82 /// add-on CreateInstance call with instance
83 /// id ADDON_INSTANCE_IMAGEDECODER.
84 CInstanceImageDecoder(KODI_HANDLE instance)
85 : IAddonInstance(ADDON_INSTANCE_IMAGEDECODER)
86 {
87 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
88 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation of multiple together with single instance way is not allowed!");
89
90 SetAddonStruct(instance);
91 }
92 //--------------------------------------------------------------------------
93
94 ~CInstanceImageDecoder() override = default;
95
96 //==========================================================================
97 /// @brief Initialize an encoder
98 ///
99 /// @param[in] buffer The data to read from memory
100 /// @param[in] bufSize The buffer size
101 /// @param[in,out] width The optimal width of image on entry, obtained width on return
102 /// @param[in,out] height The optimal height of image, actual obtained height on return
103 /// @return true if successful done, false on error
104 ///
105 virtual bool LoadImageFromMemory(unsigned char* buffer, unsigned int bufSize,
106 unsigned int& width, unsigned int& height) = 0;
107 //--------------------------------------------------------------------------
108
109 //==========================================================================
110 /// @brief Decode previously loaded image
111 ///
112 /// @param[in] pixels Output buffer
113 /// @param[in] width Width of output image
114 /// @param[in] height Height of output image
115 /// @param[in] pitch Pitch of output image
116 /// @param[in] format Format of output image
117 /// @return true if successful done, false on error
118 ///
119 virtual bool Decode(unsigned char* pixels,
120 unsigned int width, unsigned int height,
121 unsigned int pitch, ImageFormat format) = 0;
122 //--------------------------------------------------------------------------
123
124 //==========================================================================
125 /// @brief Get the wanted mime type from Kodi
126 ///
127 /// @return the mimetype wanted from Kodi
128 ///
129 inline std::string MimeType() { return m_instanceData->props.mimetype; }
130 //--------------------------------------------------------------------------
131
132 private:
133 void SetAddonStruct(KODI_HANDLE instance)
134 {
135 if (instance == nullptr)
136 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation with empty addon structure not allowed, table must be given from Kodi!");
137
138 m_instanceData = static_cast<AddonInstance_ImageDecoder*>(instance);
139 m_instanceData->toAddon.addonInstance = this;
140 m_instanceData->toAddon.load_image_from_memory = ADDON_LoadImageFromMemory;
141 m_instanceData->toAddon.decode = ADDON_Decode;
142 }
143
144 inline static bool ADDON_LoadImageFromMemory(const AddonInstance_ImageDecoder* instance,
145 unsigned char* buffer, unsigned int bufSize,
146 unsigned int* width, unsigned int* height)
147 {
148 return instance->toAddon.addonInstance->LoadImageFromMemory(buffer, bufSize, *width, *height);
149 }
150
151 inline static bool ADDON_Decode(const AddonInstance_ImageDecoder* instance,
152 unsigned char* pixels,
153 unsigned int width, unsigned int height,
154 unsigned int pitch, unsigned int format)
155 {
156 return instance->toAddon.addonInstance->Decode(pixels, width, height, pitch, static_cast<ImageFormat>(format));
157 }
158
159 AddonInstance_ImageDecoder* m_instanceData;
160 };
161
162} /* namespace addon */
163} /* namespace kodi */