Kodi Development  20.0
for Binary and Script based Add-Ons

Detailed Description

Class: kodi::addon::CInstanceImageDecoder

Image decoder add-on instance
This instance type is used to allow Kodi various additional image format types.

This usage can be requested under various conditions, by a Mimetype protocol defined in addon.xml or supported file extensions.

Include the header #include <kodi/addon-instance/ImageDecoder.h> to use this class.


Here is an example of what the addon.xml.in would look like for an image decoder addon:

<?xml version="1.0" encoding="UTF-8"?>
<addon
id="imagedecoder.myspecialnamefor"
version="1.0.0"
name="My image decoder addon"
provider-name="Your Name">
<requires>@ADDON_DEPENDS@</requires>
<extension
point="kodi.imagedecoder"
extension=".imga|.imgb"
mimetype="image/mymimea|image/mymimea"
library_@PLATFORM@="@LIBRARY_FILENAME@"/>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">My image decoder addon summary</summary>
<description lang="en_GB">My image decoder description</description>
<platform>@PLATFORM@</platform>
</extension>
</addon>

Standard values that can be declared for processing in addon.xml.

These values are used by Kodi to identify associated images and file extensions and then to select the associated addon.

Labels Type Description
point string The identification of the addon instance to image decoder is mandatory kodi.imagedecoder. In addition, the instance declared in the first <extension ... /> is also the main type of addon.
extension string The from addon operated and supported image file endings.
Use a | to separate between different ones.
defaultPort string The from addon operated image mimetypes.
Use a | to separate between different ones.
library_@PLATFORM@ string The runtime library used for the addon. This is usually declared by cmake and correctly displayed in the translated addon.xml.
Remarks
For more detailed description of the addon.xml, see also https://kodi.wiki/view/Addon.xml.

Example:

#include <kodi/addon-instance/ImageDecoder.h>
class ATTRIBUTE_HIDDEN CMyImageDecoder : public kodi::addon::CInstanceImageDecoder
{
public:
CMyImageDecoder(KODI_HANDLE instance, const std::string& kodiVersion);
bool LoadImageFromMemory(unsigned char* buffer,
unsigned int bufSize,
unsigned int& width,
unsigned int& height) override;
bool Decode(unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int pitch,
ImageFormat format) override;
...
};
CMyImageDecoder::CMyImageDecoder(KODI_HANDLE instance, const std::string& kodiVersion)
: CInstanceImageDecoder(instance, kodiVersion)
{
...
}
bool CMyImageDecoder::LoadImageFromMemory(unsigned char* buffer,
unsigned int bufSize,
unsigned int& width,
unsigned int& height)
{
...
return true;
}
bool CMyImageDecoder::Decode(unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int pitch,
ImageFormat format) override;
{
...
return true;
}
//----------------------------------------------------------------------
class ATTRIBUTE_HIDDEN CMyAddon : public kodi::addon::CAddonBase
{
public:
CMyAddon() = default;
ADDON_STATUS CreateInstance(int instanceType,
const std::string& instanceID,
KODI_HANDLE instance,
const std::string& version,
KODI_HANDLE& addonInstance) override;
};
// If you use only one instance in your add-on, can be instanceType and
// instanceID ignored
ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
const std::string& instanceID,
KODI_HANDLE instance,
const std::string& version,
KODI_HANDLE& addonInstance)
{
if (instanceType == ADDON_INSTANCE_IMAGEDECODER)
{
kodi::Log(ADDON_LOG_INFO, "Creating my image decoder instance");
addonInstance = new CMyImageDecoder(instance, version);
}
else if (...)
{
...
}
}
ADDONCREATOR(CMyAddon)
Definition: AddonBase.h:322
Definition: ImageDecoder.h:199
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition: addon_base.h:177
ADDON_STATUS
Definition: addon_base.h:128
@ ADDON_STATUS_OK
For everything OK and no error.
Definition: addon_base.h:130
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition: addon_base.h:142
@ ADDON_INSTANCE_IMAGEDECODER
Image Decoder instance, see kodi::addon::CInstanceImageDecoder.
Definition: versions.h:244
ImageFormat
Image format types Used to define wanted target format where image decoder should give to Kodi.
Definition: image_decoder.h:26
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749

The destruction of the example class CMyImageDecoder is called from Kodi's header. Manually deleting the add-on instance is not required.

Modules

 Definitions, structures and enumerators
 Image decoder add-on general variables
 

Function Documentation

◆ CInstanceImageDecoder()

CInstanceImageDecoder ( KODI_HANDLE  instance,
const std::string &  kodiVersion = "" 
)
inlineexplicit

Class constructor.

Parameters
[in]instanceThe from Kodi given instance given be add-on CreateInstance call with instance id ADDON_INSTANCE_IMAGEDECODER.
[in]kodiVersion[opt] Version used in Kodi for this instance, to allow compatibility to older Kodi versions.
Note
Recommended to set kodiVersion.

◆ LoadImageFromMemory()

virtual bool LoadImageFromMemory ( unsigned char *  buffer,
unsigned int  bufSize,
unsigned int &  width,
unsigned int &  height 
)
pure virtual

Initialize an encoder.

Parameters
[in]bufferThe data to read from memory
[in]bufSizeThe buffer size
[in,out]widthThe optimal width of image on entry, obtained width on return
[in,out]heightThe optimal height of image, actual obtained height on return
Returns
true if successful done, false on error

◆ Decode()

virtual bool Decode ( unsigned char *  pixels,
unsigned int  width,
unsigned int  height,
unsigned int  pitch,
ImageFormat  format 
)
pure virtual

Decode previously loaded image.

Parameters
[in]pixelsOutput buffer
[in]widthWidth of output image
[in]heightHeight of output image
[in]pitchPitch of output image
[in]formatFormat of output image
Returns
true if successful done, false on error

◆ MimeType()

std::string MimeType ( )
inline

Callback to Kodi Function
Get the wanted mime type from Kodi.

Returns
the mimetype wanted from Kodi
Remarks
Only called from addon itself.