Skip to content

Commit

Permalink
support for image (en|de)coder add-ons
Browse files Browse the repository at this point in the history
  • Loading branch information
notspiff committed Dec 7, 2016
1 parent 5e57a75 commit 89ff2af
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 14 deletions.
5 changes: 5 additions & 0 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -20392,3 +20392,8 @@ msgstr ""
msgctxt "#39010"
msgid "Select sort method"
msgstr ""

#: /xbmc/addons/Addon.cpp
msgctxt "#39011"
msgid "Image encoder"
msgstr ""
3 changes: 3 additions & 0 deletions project/cmake/scripts/linux/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ install(FILES ${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/kod
${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_addon_dll.h
${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_addon_types.h
${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_codec_types.h
${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_imageenc_types.h
${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_imageenc_dll.h
${CORE_SOURCE_DIR}/xbmc/guilib/TextureFormats.h
${CORE_SOURCE_DIR}/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h
${CORE_SOURCE_DIR}/xbmc/filesystem/IFileTypes.h
${CORE_SOURCE_DIR}/xbmc/input/XBMC_vkeys.h
Expand Down
1 change: 1 addition & 0 deletions xbmc/addons/Addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static const TypeMapping types[] =
{"kodi.resource.games", ADDON_RESOURCE_GAMES, 35209, "DefaultAddonGame.png" },
{"kodi.adsp", ADDON_ADSPDLL, 24135, "DefaultAddonAudioDSP.png" },
{"kodi.inputstream", ADDON_INPUTSTREAM, 24048, "DefaultAddonInputstream.png" },
{"kodi.imageencoder", ADDON_IMAGEENCODER, 39011, "DefaultAddonImageEncoder.png" },
};

std::string TranslateType(ADDON::TYPE type, bool pretty/*=false*/)
Expand Down
4 changes: 4 additions & 0 deletions xbmc/addons/AddonBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "addons/AudioEncoder.h"
#include "addons/ContextMenuAddon.h"
#include "addons/GameResource.h"
#include "addons/ImageEncoder.h"
#include "addons/ImageResource.h"
#include "addons/InputStream.h"
#include "addons/LanguageResource.h"
Expand Down Expand Up @@ -89,6 +90,7 @@ std::shared_ptr<IAddon> CAddonBuilder::Build()
type == ADDON_ADSPDLL ||
type == ADDON_AUDIOENCODER ||
type == ADDON_AUDIODECODER ||
type == ADDON_IMAGEENCODER ||
type == ADDON_INPUTSTREAM ||
type == ADDON_PERIPHERALDLL ||
type == ADDON_GAMEDLL)
Expand Down Expand Up @@ -136,6 +138,8 @@ std::shared_ptr<IAddon> CAddonBuilder::Build()
return CAudioEncoder::FromExtension(std::move(m_props), m_extPoint);
case ADDON_AUDIODECODER:
return CAudioDecoder::FromExtension(std::move(m_props), m_extPoint);
case ADDON_IMAGEENCODER:
return CImageEncoder::FromExtension(std::move(m_props), m_extPoint);
case ADDON_INPUTSTREAM:
return CInputStream::FromExtension(std::move(m_props), m_extPoint);
case ADDON_PERIPHERALDLL:
Expand Down
3 changes: 2 additions & 1 deletion xbmc/addons/BinaryAddonCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void CBinaryAddonCache::Init()
{
m_addonsToCache = {
ADDON_AUDIODECODER,
ADDON_IMAGEENCODER,
ADDON_INPUTSTREAM,
ADDON_PVRDLL,
ADDON_GAMEDLL,
Expand Down Expand Up @@ -111,4 +112,4 @@ void CBinaryAddonCache::Update()
}
}

}
}
2 changes: 2 additions & 0 deletions xbmc/addons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(SOURCES Addon.cpp
GUIDialogAddonSettings.cpp
GUIViewStateAddonBrowser.cpp
GUIWindowAddonBrowser.cpp
ImageEncoder.cpp
ImageResource.cpp
InputStream.cpp
LanguageResource.cpp
Expand Down Expand Up @@ -58,6 +59,7 @@ set(HEADERS Addon.h
GUIViewStateAddonBrowser.h
GUIWindowAddonBrowser.h
IAddon.h
ImageEncoder.h
ImageResource.h
InputStream.h
LanguageResource.h
Expand Down
1 change: 1 addition & 0 deletions xbmc/addons/IAddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace ADDON
ADDON_RESOURCE_LANGUAGE,
ADDON_RESOURCE_UISOUNDS,
ADDON_RESOURCE_GAMES,
ADDON_IMAGEENCODER,
ADDON_VIDEO, // virtual addon types
ADDON_AUDIO,
ADDON_IMAGE,
Expand Down
91 changes: 91 additions & 0 deletions xbmc/addons/ImageEncoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2013 Arne Morten Kvarving
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "ImageEncoder.h"

namespace ADDON
{

std::unique_ptr<CImageEncoder>
CImageEncoder::FromExtension(AddonProps props, const cp_extension_t* ext)
{
std::string mime = CAddonMgr::GetInstance().GetExtValue(ext->configuration, "@mimetype");
return std::unique_ptr<CImageEncoder>(new CImageEncoder(std::move(props),
std::move(mime)));
}

CImageEncoder::CImageEncoder(AddonProps props, std::string mime) :
ImageEncoderDll(std::move(props)),
m_mimetype(std::move(mime))
{
}

CImageEncoder::~CImageEncoder()
{
if (m_image && Initialized())
m_pStruct->Close(m_image);
}

bool CImageEncoder::LoadImageFromMemory(unsigned char* buffer, unsigned int bufSize,
unsigned int width, unsigned int height)
{
if (!Initialized())
return false;

m_width = width;
m_height = height;
m_image = m_pStruct->LoadImage(buffer, bufSize, &m_width, &m_height);

return m_image != nullptr;
}

bool CImageEncoder::Decode(unsigned char* const pixels, unsigned int width,
unsigned int height, unsigned int pitch,
unsigned int format)
{
if (!Initialized())
return false;

bool result = m_pStruct->Decode(m_image, pixels, width, height, pitch, format);
m_width = width;
m_height = height;

return result;
}

bool CImageEncoder::CreateThumbnailFromSurface(unsigned char* bufferin, unsigned int width,
unsigned int height, unsigned int format,
unsigned int pitch, const std::string& destFile,
unsigned char*& bufferout, unsigned int& bufferoutSize)
{
if (!Initialized())
return false;

return m_pStruct->CreateThumbnail(bufferin, width, height, pitch, format, destFile.c_str());
}

bool CImageEncoder::Create(const std::string& mimetype)
{
m_pInfo = new IMAGEENC_PROPS;
m_pInfo->mimetype = mimetype.c_str();

return ImageEncoderDll::Create();
}

} /*namespace ADDON*/

62 changes: 62 additions & 0 deletions xbmc/addons/ImageEncoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2013 Arne Morten Kvarving
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "AddonDll.h"
#include "addons/kodi-addon-dev-kit/include/kodi/kodi_imageenc_types.h"
#include "guilib/iimage.h"

typedef DllAddon<ImageEncoder, IMAGEENC_PROPS> DllImageEncoder;
namespace ADDON
{
typedef CAddonDll<DllImageEncoder,
ImageEncoder, IMAGEENC_PROPS> ImageEncoderDll;

class CImageEncoder : public ImageEncoderDll,
public IImage
{
public:
static std::unique_ptr<CImageEncoder> FromExtension(AddonProps,
const cp_extension_t* ext);
explicit CImageEncoder(AddonProps props) :
ImageEncoderDll(std::move(props))
{}

CImageEncoder(AddonProps props, std::string mimetypes);
virtual ~CImageEncoder();

bool Create(const std::string& mimetype);

bool LoadImageFromMemory(unsigned char* buffer, unsigned int bufSize,
unsigned int width, unsigned int height);
bool Decode(unsigned char* const pixels, unsigned int width,
unsigned int height, unsigned int pitch,
unsigned int format);
bool CreateThumbnailFromSurface(unsigned char* bufferin, unsigned int width,
unsigned int height, unsigned int format,
unsigned int pitch, const std::string& destFile,
unsigned char*& bufferout, unsigned int& bufferoutSize);

const std::string& GetMimetypes() const { return m_mimetype; }
protected:
void* m_image = nullptr;
std::string m_mimetype;
};

} /*namespace ADDON*/
1 change: 1 addition & 0 deletions xbmc/addons/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SRCS=Addon.cpp \
GUIDialogAddonSettings.cpp \
GUIViewStateAddonBrowser.cpp \
GUIWindowAddonBrowser.cpp \
ImageEncoder.cpp \
ImageResource.cpp \
InputStream.cpp \
LanguageResource.cpp \
Expand Down
3 changes: 3 additions & 0 deletions xbmc/addons/addon-bindings.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_epg_types.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_game_callbacks.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_game_dll.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_game_types.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_imageenc_types.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_imageenc_dll.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_inputstream_dll.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_inputstream_types.h
BINDINGS+=xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_callbacks.h
Expand Down Expand Up @@ -43,3 +45,4 @@ BINDINGS+=xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h
BINDINGS+=xbmc/cores/AudioEngine/Utils/AEChannelData.h
BINDINGS+=xbmc/filesystem/IFileTypes.h
BINDINGS+=xbmc/input/XBMC_vkeys.h
BINDINGS+=xbmc/guilib/TextureFormats.h
53 changes: 53 additions & 0 deletions xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_imageenc_dll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include <stdint.h>
#include "xbmc_addon_dll.h"
#include "kodi_imageenc_types.h"

extern "C"
{
void* LoadImage(unsigned char* buffer, unsigned int bufSize,
unsigned int* width, unsigned int* height);

bool Decode(void* image, unsigned char* pixels,
unsigned int width, unsigned int height,
unsigned int pitch, unsigned int format);

bool CreateThumbnail(unsigned char* bufferin,
unsigned int width,
unsigned int height,
unsigned int pitch,
unsigned int format,
const char* destFile);

void Close(void* image);

// function to export the above structure to Kodi
void __declspec(dllexport) get_addon(struct ImageEncoder* pEnc)
{
pEnc->LoadImage = LoadImage;
pEnc->Decode = Decode;
pEnc->CreateThumbnail = CreateThumbnail;
pEnc->Close = Close;
};
};
Loading

0 comments on commit 89ff2af

Please sign in to comment.