Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
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/imagedecoder.h"
13
14#ifdef __cplusplus
15
16#include <stdexcept>
17
18namespace kodi
19{
20namespace addon
21{
22
23//##############################################################################
31
32//==============================================================================
46class ATTR_DLL_LOCAL ImageDecoderInfoTag
47{
48public:
50 ImageDecoderInfoTag() = default;
83
86
88 void SetWidth(int width) { m_width = width; }
89
91 int GetWidth() const { return m_width; }
92
94 void SetHeight(int height) { m_height = height; }
95
97 int GetHeight() const { return m_height; }
98
100 void SetDistance(int distance) { m_distance = distance; }
101
103 int GetDistance() const { return m_distance; }
104
108 void SetColor(ADDON_IMG_COLOR color) { m_color = color; }
109
111 ADDON_IMG_COLOR GetColor() const { return m_color; }
112
116 void SetMeteringMode(ADDON_IMG_METERING_MODE metering_mode) { m_metering_mode = metering_mode; }
117
119 ADDON_IMG_METERING_MODE GetMeteringMode() const { return m_metering_mode; }
120
122 void SetExposureTime(float exposure_time) { m_exposure_time = exposure_time; }
123
125 float GetExposureTime() const { return m_exposure_time; }
126
128 void SetExposureBias(float exposure_bias) { m_exposure_bias = exposure_bias; }
129
131 float GetExposureBias() const { return m_exposure_bias; }
132
137 {
138 m_exposure_program = exposure_program;
139 }
140
142 ADDON_IMG_EXPOSURE_PROGRAM GetExposureProgram() const { return m_exposure_program; }
143
147 void SetExposureMode(ADDON_IMG_EXPOSURE_MODE exposure_mode) { m_exposure_mode = exposure_mode; }
148
150 ADDON_IMG_EXPOSURE_MODE GetExposureMode() const { return m_exposure_mode; }
151
155 void SetOrientation(ADDON_IMG_ORIENTATION orientation) { m_orientation = orientation; }
156
158 ADDON_IMG_ORIENTATION GetOrientation() const { return m_orientation; }
159
161 void SetTimeCreated(time_t time_created) { m_time_created = time_created; }
162
164 time_t GetTimeCreated() const { return m_time_created; }
165
167 void SetApertureFNumber(float aperture_f_number) { m_aperture_f_number = aperture_f_number; }
168
170 float GetApertureFNumber() const { return m_aperture_f_number; }
171
173 void SetFlashUsed(ADDON_IMG_FLASH_TYPE flash_used) { m_flash_used = flash_used; }
174
176 ADDON_IMG_FLASH_TYPE GetFlashUsed() const { return m_flash_used; }
177
179 void SetFocalLength(int focal_length) { m_focal_length = focal_length; }
180
182 int GetFocalLength() const { return m_focal_length; }
183
185 void SetLightSource(ADDON_IMG_LIGHT_SOURCE light_source) { m_light_source = light_source; }
186
188 ADDON_IMG_LIGHT_SOURCE GetLightSource() const { return m_light_source; }
189
193 void SetFocalLengthIn35mmFormat(int focal_length_in_35mm_format)
194 {
195 m_focal_length_in_35mm_format = focal_length_in_35mm_format;
196 }
197
199 int GetFocalLengthIn35mmFormat() const { return m_focal_length_in_35mm_format; }
200
202 void SetDigitalZoomRatio(float digital_zoom_ratio) { m_digital_zoom_ratio = digital_zoom_ratio; }
203
205 float GetDigitalZoomRatio() const { return m_digital_zoom_ratio; }
206
208 void SetISOSpeed(float iso_speed) { m_iso_speed = iso_speed; }
209
211 float GetISOSpeed() const { return m_iso_speed; }
212
214 void SetGPSInfo(bool gps_info_present,
215 char latitude_ref,
216 float latitude[3],
217 char longitude_ref,
218 float longitude[3],
219 int altitude_ref,
220 float altitude)
221 {
222 if (!latitude || !longitude)
223 return;
224
225 m_gps_info_present = gps_info_present;
226 if (gps_info_present)
227 {
228 m_latitude_ref = latitude_ref;
229 m_longitude_ref = longitude_ref;
230 for (int i = 0; i < 3; i++)
231 {
232 m_latitude[i] = latitude[i];
233 m_longitude[i] = longitude[i];
234 }
235 m_altitude_ref = altitude_ref;
236 m_altitude = altitude;
237 }
238 else
239 {
240 m_latitude_ref = 0.0f;
241 m_longitude_ref = 0.0f;
242 for (int i = 0; i < 3; i++)
243 latitude[i] = longitude[i] = 0.0f;
244 m_altitude_ref = 0;
245 m_altitude = 0.0f;
246 }
247 }
248
250 void GetGPSInfo(bool& gps_info_present,
251 char& latitude_ref,
252 float latitude[3],
253 char& longitude_ref,
254 float longitude[3],
255 int& altitude_ref,
256 float& altitude)
257 {
258 if (!latitude || !longitude)
259 return;
260
261 gps_info_present = m_gps_info_present;
262 if (m_gps_info_present)
263 {
264 latitude_ref = m_latitude_ref;
265 longitude_ref = m_longitude_ref;
266 for (int i = 0; i < 3; i++)
267 {
268 latitude[i] = m_latitude[i];
269 longitude[i] = m_longitude[i];
270 }
271 altitude_ref = m_altitude_ref;
272 altitude = m_altitude;
273 }
274 else
275 {
276 latitude_ref = ' ';
277 longitude_ref = ' ';
278 for (int i = 0; i < 3; i++)
279 latitude[i] = longitude[i] = 0.0f;
280 altitude_ref = 0;
281 altitude = 0.0f;
282 }
283 }
284
286 void SetCameraManufacturer(const std::string& camera_manufacturer)
287 {
288 m_camera_manufacturer = camera_manufacturer;
289 }
290
292 const std::string& GetCameraManufacturer() const { return m_camera_manufacturer; }
293
295 void SetCameraModel(const std::string& camera_model) { m_camera_model = camera_model; }
296
298 const std::string& GetCameraModel() const { return m_camera_model; }
299
301 void SetAuthor(const std::string& author) { m_author = author; }
302
304 const std::string& GetAuthor() const { return m_author; }
305
307 void SetDescription(const std::string& description) { m_description = description; }
308
310 const std::string& GetDescription() const { return m_description; }
311
313 void SetCopyright(const std::string& copyright) { m_copyright = copyright; }
314
316 const std::string& GetCopyright() const { return m_copyright; }
317
319
320private:
321 int m_width{};
322 int m_height{};
323 float m_distance{};
327 float m_exposure_time{};
328 float m_exposure_bias{};
331 time_t m_time_created{};
332 float m_aperture_f_number{};
334 ADDON_IMG_LIGHT_SOURCE m_light_source{};
335 int m_focal_length{};
336 int m_focal_length_in_35mm_format{};
337 float m_digital_zoom_ratio{};
338 float m_iso_speed{};
339
340 bool m_gps_info_present{false};
341 char m_latitude_ref{' '};
342 float m_latitude[3]{}; /* Deg,min,sec */
343 char m_longitude_ref{' '};
344 float m_longitude[3]{}; /* Deg,min,sec */
345 int m_altitude_ref{};
346 float m_altitude{};
347
348 std::string m_camera_manufacturer;
349 std::string m_camera_model;
350 std::string m_author;
351 std::string m_description;
352 std::string m_copyright;
353};
355//------------------------------------------------------------------------------
356
357//==============================================================================
535//------------------------------------------------------------------------------
536class ATTR_DLL_LOCAL CInstanceImageDecoder : public IAddonInstance
537{
538public:
539 //============================================================================
547 explicit CInstanceImageDecoder(const IInstanceInfo& instance) : IAddonInstance(instance)
548 {
549 if (CPrivateBase::m_interface->globalSingleInstance != nullptr)
550 throw std::logic_error("kodi::addon::CInstanceImageDecoder: Creation of multiple together "
551 "with single instance way is not allowed!");
552
553 SetAddonStruct(instance);
554 }
555 //----------------------------------------------------------------------------
556
557 ~CInstanceImageDecoder() override = default;
558
559 //==========================================================================
568 virtual bool SupportsFile(const std::string& filename) { return true; }
569 //--------------------------------------------------------------------------
570
571 //==========================================================================
583 virtual bool ReadTag(const std::string& file, kodi::addon::ImageDecoderInfoTag& tag)
584 {
585 return false;
586 }
587 //--------------------------------------------------------------------------
588
589 //============================================================================
602 virtual bool LoadImageFromMemory(const std::string& mimetype,
603 const uint8_t* buffer,
604 size_t bufSize,
605 unsigned int& width,
606 unsigned int& height) = 0;
607 //----------------------------------------------------------------------------
608
609 //============================================================================
620 virtual bool Decode(uint8_t* pixels,
621 unsigned int width,
622 unsigned int height,
623 unsigned int pitch,
624 ADDON_IMG_FMT format) = 0;
625 //----------------------------------------------------------------------------
626
627private:
628 void SetAddonStruct(KODI_ADDON_INSTANCE_STRUCT* instance)
629 {
630 instance->hdl = this;
631 instance->imagedecoder->toAddon->supports_file = ADDON_supports_file;
632 instance->imagedecoder->toAddon->read_tag = ADDON_read_tag;
633 instance->imagedecoder->toAddon->load_image_from_memory = ADDON_load_image_from_memory;
634 instance->imagedecoder->toAddon->decode = ADDON_decode;
635 }
636
637 inline static bool ADDON_supports_file(const KODI_ADDON_IMAGEDECODER_HDL hdl, const char* file)
638 {
639 return static_cast<CInstanceImageDecoder*>(hdl)->SupportsFile(file);
640 }
641
642 inline static bool ADDON_read_tag(const KODI_ADDON_IMAGEDECODER_HDL hdl,
643 const char* file,
645 {
646#ifdef _WIN32
647#pragma warning(push)
648#pragma warning(disable : 4996)
649#endif // _WIN32
651 bool ret = static_cast<CInstanceImageDecoder*>(hdl)->ReadTag(file, cppTag);
652 if (ret)
653 {
654 tag->width = cppTag.GetWidth();
655 tag->height = cppTag.GetHeight();
656 tag->distance = cppTag.GetDistance();
657 tag->color = cppTag.GetColor();
658 tag->orientation = cppTag.GetOrientation();
659 tag->metering_mode = cppTag.GetMeteringMode();
660 tag->exposure_time = cppTag.GetExposureTime();
661 tag->exposure_bias = cppTag.GetExposureBias();
662 tag->exposure_mode = cppTag.GetExposureMode();
663 tag->exposure_program = cppTag.GetExposureProgram();
664 tag->time_created = cppTag.GetTimeCreated();
665 tag->aperture_f_number = cppTag.GetApertureFNumber();
666 tag->flash_used = cppTag.GetFlashUsed();
667 tag->light_source = cppTag.GetLightSource();
668 tag->focal_length = cppTag.GetFocalLength();
669 tag->focal_length_in_35mm_format = cppTag.GetFocalLengthIn35mmFormat();
670 tag->iso_speed = cppTag.GetISOSpeed();
671 tag->digital_zoom_ratio = cppTag.GetDigitalZoomRatio();
672 cppTag.GetGPSInfo(tag->gps_info_present, tag->latitude_ref, tag->latitude, tag->longitude_ref,
673 tag->longitude, tag->altitude_ref, tag->altitude);
674 tag->camera_manufacturer = strdup(cppTag.GetCameraManufacturer().c_str());
675 tag->camera_model = strdup(cppTag.GetCameraModel().c_str());
676 tag->author = strdup(cppTag.GetAuthor().c_str());
677 tag->description = strdup(cppTag.GetDescription().c_str());
678 tag->copyright = strdup(cppTag.GetCopyright().c_str());
679 }
680 return ret;
681#ifdef _WIN32
682#pragma warning(pop)
683#endif // _WIN32
684 }
685
686 inline static bool ADDON_load_image_from_memory(const KODI_ADDON_IMAGEDECODER_HDL hdl,
687 const char* mimetype,
688 const uint8_t* buffer,
689 size_t bufSize,
690 unsigned int* width,
691 unsigned int* height)
692 {
693 return static_cast<CInstanceImageDecoder*>(hdl)->LoadImageFromMemory(mimetype, buffer, bufSize,
694 *width, *height);
695 }
696
697 inline static bool ADDON_decode(const KODI_ADDON_IMAGEDECODER_HDL hdl,
698 uint8_t* pixels,
699 size_t pixels_size,
700 unsigned int width,
701 unsigned int height,
702 unsigned int pitch,
703 enum ADDON_IMG_FMT format)
704 {
705 return static_cast<CInstanceImageDecoder*>(hdl)->Decode(pixels, width, height, pitch, format);
706 }
707};
708
709} /* namespace addon */
710} /* namespace kodi */
711#endif /* __cplusplus */
Definition ImageDecoder.h:537
Definition AddonBase.h:565
Definition AddonBase.h:498
Definition ImageDecoder.h:47
ADDON_IMG_COLOR
Definition imagedecoder.h:91
@ ADDON_IMG_COLOR_COLORED
Colored image.
Definition imagedecoder.h:93
ADDON_IMG_EXPOSURE_MODE
Definition imagedecoder.h:190
@ ADDON_IMG_EXPOSURE_MODE_AUTO
0 = Auto exposure
Definition imagedecoder.h:192
ADDON_IMG_EXPOSURE_PROGRAM
Definition imagedecoder.h:144
@ ADDON_IMG_EXPOSURE_PROGRAM_UNDEFINED
0 = Not Defined
Definition imagedecoder.h:146
ADDON_IMG_FLASH_TYPE
Definition imagedecoder.h:284
@ ADDON_IMG_FLASH_TYPE_NO_FLASH
0x0 = No Flash
Definition imagedecoder.h:286
ADDON_IMG_FMT
Definition imagedecoder.h:30
ADDON_IMG_LIGHT_SOURCE
Definition imagedecoder.h:210
ADDON_IMG_METERING_MODE
Definition imagedecoder.h:108
@ ADDON_IMG_METERING_MODE_UNKNOWN
0 = Unknown
Definition imagedecoder.h:110
ADDON_IMG_ORIENTATION
Definition imagedecoder.h:55
@ ADDON_IMG_ORIENTATION_NONE
If not available.
Definition imagedecoder.h:57
ADDON_IMG_FLASH_TYPE GetFlashUsed() const
Get info about image was created with flash.
Definition ImageDecoder.h:176
void SetFlashUsed(ADDON_IMG_FLASH_TYPE flash_used)
Set to true if image was created with flash.
Definition ImageDecoder.h:173
void SetOrientation(ADDON_IMG_ORIENTATION orientation)
Set the orientation.
Definition ImageDecoder.h:155
const std::string & GetDescription() const
Get description.
Definition ImageDecoder.h:310
void SetHeight(int height)
Set the image height as pixels.
Definition ImageDecoder.h:94
void SetFocalLength(int focal_length)
Set focal length.
Definition ImageDecoder.h:179
void SetDistance(int distance)
Set the image distance in meters.
Definition ImageDecoder.h:100
int GetDistance() const
Get mage distance in meters.
Definition ImageDecoder.h:103
float GetExposureTime() const
Get exposure time.
Definition ImageDecoder.h:125
int GetWidth() const
Get image width as pixels.
Definition ImageDecoder.h:91
void SetExposureBias(float exposure_bias)
Set exposure bias.
Definition ImageDecoder.h:128
int GetHeight() const
Get image height as pixels.
Definition ImageDecoder.h:97
void SetDescription(const std::string &description)
Set description.
Definition ImageDecoder.h:307
ADDON_IMG_COLOR GetColor() const
Get image image color type.
Definition ImageDecoder.h:111
float GetExposureBias() const
Get exposure bias.
Definition ImageDecoder.h:131
void SetExposureTime(float exposure_time)
Set exposure time.
Definition ImageDecoder.h:122
int GetFocalLength() const
Get focal length.
Definition ImageDecoder.h:182
const std::string & GetAuthor() const
Get author.
Definition ImageDecoder.h:304
void SetFocalLengthIn35mmFormat(int focal_length_in_35mm_format)
Set focal length in 35 mm format.
Definition ImageDecoder.h:193
const std::string & GetCameraModel() const
Get camera model.
Definition ImageDecoder.h:298
void SetApertureFNumber(float aperture_f_number)
Set Aperture F number.
Definition ImageDecoder.h:167
void SetColor(ADDON_IMG_COLOR color)
Set the image color type.
Definition ImageDecoder.h:108
void GetGPSInfo(bool &gps_info_present, char &latitude_ref, float latitude[3], char &longitude_ref, float longitude[3], int &altitude_ref, float &altitude)
Get GPS position information.
Definition ImageDecoder.h:250
void SetCameraModel(const std::string &camera_model)
Set camera model.
Definition ImageDecoder.h:295
time_t GetTimeCreated() const
Get image creation time.
Definition ImageDecoder.h:164
void SetISOSpeed(float iso_speed)
Set ISO sensitivity.
Definition ImageDecoder.h:208
void SetCameraManufacturer(const std::string &camera_manufacturer)
Set the camera manufacturer as string on info tag.
Definition ImageDecoder.h:286
float GetApertureFNumber() const
Get Aperture F number.
Definition ImageDecoder.h:170
ADDON_IMG_EXPOSURE_MODE GetExposureMode() const
Get Exposure mode.
Definition ImageDecoder.h:150
ADDON_IMG_ORIENTATION GetOrientation() const
Get image orientation.
Definition ImageDecoder.h:158
float GetISOSpeed() const
Get ISO sensitivity.
Definition ImageDecoder.h:211
void SetDigitalZoomRatio(float digital_zoom_ratio)
Set digital zoom ratio.
Definition ImageDecoder.h:202
void SetTimeCreated(time_t time_created)
Set the image creation time in time_t format (number of seconds elapsed since 00:00 hours,...
Definition ImageDecoder.h:161
float GetDigitalZoomRatio() const
Get digital zoom ratio.
Definition ImageDecoder.h:205
void SetWidth(int width)
Set the camera manufacturer as string on info tag.
Definition ImageDecoder.h:88
ADDON_IMG_LIGHT_SOURCE GetLightSource() const
Get light source.
Definition ImageDecoder.h:188
const std::string & GetCameraManufacturer() const
Get camera manufacturer.
Definition ImageDecoder.h:292
void SetAuthor(const std::string &author)
Set author.
Definition ImageDecoder.h:301
ADDON_IMG_EXPOSURE_PROGRAM GetExposureProgram() const
Get Exposure program.
Definition ImageDecoder.h:142
void SetCopyright(const std::string &copyright)
Set copyright.
Definition ImageDecoder.h:313
void SetExposureProgram(ADDON_IMG_EXPOSURE_PROGRAM exposure_program)
Set Exposure program.
Definition ImageDecoder.h:136
ADDON_IMG_METERING_MODE GetMeteringMode() const
Get metering mode.
Definition ImageDecoder.h:119
void SetExposureMode(ADDON_IMG_EXPOSURE_MODE exposure_mode)
Set Exposure mode.
Definition ImageDecoder.h:147
const std::string & GetCopyright() const
Get copyright.
Definition ImageDecoder.h:316
void SetMeteringMode(ADDON_IMG_METERING_MODE metering_mode)
Set metering mode.
Definition ImageDecoder.h:116
void SetGPSInfo(bool gps_info_present, char latitude_ref, float latitude[3], char longitude_ref, float longitude[3], int altitude_ref, float altitude)
Set GPS position information.
Definition ImageDecoder.h:214
void SetLightSource(ADDON_IMG_LIGHT_SOURCE light_source)
Set light source.
Definition ImageDecoder.h:185
int GetFocalLengthIn35mmFormat() const
Get focal length in 35 mm format.
Definition ImageDecoder.h:199
virtual bool ReadTag(const std::string &file, kodi::addon::ImageDecoderInfoTag &tag)
Read tag of a file.
Definition ImageDecoder.h:583
virtual bool Decode(uint8_t *pixels, unsigned int width, unsigned int height, unsigned int pitch, ADDON_IMG_FMT format)=0
Decode previously loaded image.
virtual bool SupportsFile(const std::string &filename)
Checks addon support given file path.
Definition ImageDecoder.h:568
virtual bool LoadImageFromMemory(const std::string &mimetype, const uint8_t *buffer, size_t bufSize, unsigned int &width, unsigned int &height)=0
Initialize an encoder.
CInstanceImageDecoder(const IInstanceInfo &instance)
Class constructor.
Definition ImageDecoder.h:547
Definition imagedecoder.h:370
Definition addon_base.h:268