mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
loaders: Remove the color space conversion on the loader side.
Now, the job is completely delegated to the backend engine.
This commit is contained in:
parent
b733030357
commit
c710af2560
17 changed files with 37 additions and 167 deletions
|
@ -123,13 +123,6 @@ bool GlRenderer::endComposite(TVG_UNUSED Compositor* cmp)
|
|||
}
|
||||
|
||||
|
||||
ColorSpace GlRenderer::colorSpace()
|
||||
{
|
||||
//TODO: return a proper color space value.
|
||||
return ColorSpace::Unsupported;
|
||||
}
|
||||
|
||||
|
||||
bool GlRenderer::renderImage(TVG_UNUSED void* data)
|
||||
{
|
||||
//TODO: render requested images
|
||||
|
|
|
@ -50,8 +50,6 @@ public:
|
|||
bool beginComposite(Compositor* cmp, CompositeMethod method, uint32_t opacity) override;
|
||||
bool endComposite(Compositor* cmp) override;
|
||||
|
||||
ColorSpace colorSpace() override;
|
||||
|
||||
static GlRenderer* gen();
|
||||
static int init(TVG_UNUSED uint32_t threads);
|
||||
static int32_t init();
|
||||
|
|
|
@ -761,13 +761,6 @@ SwRenderer::SwRenderer():mpool(globalMpool)
|
|||
}
|
||||
|
||||
|
||||
ColorSpace SwRenderer::colorSpace()
|
||||
{
|
||||
if (surface) return surface->cs;
|
||||
return ColorSpace::Unsupported;
|
||||
}
|
||||
|
||||
|
||||
bool SwRenderer::init(uint32_t threads)
|
||||
{
|
||||
if ((initEngineCnt++) > 0) return true;
|
||||
|
|
|
@ -58,8 +58,6 @@ public:
|
|||
bool endComposite(Compositor* cmp) override;
|
||||
void clearCompositors();
|
||||
|
||||
ColorSpace colorSpace() override;
|
||||
|
||||
static SwRenderer* gen();
|
||||
static bool init(uint32_t threads);
|
||||
static int32_t init();
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
float vw = 0;
|
||||
float vh = 0;
|
||||
float w = 0, h = 0; //default image size
|
||||
ColorSpace cs = ColorSpace::ARGB8888;
|
||||
ColorSpace cs = ColorSpace::Unsupported; //must be clarified at open()
|
||||
|
||||
virtual ~LoadModule() {}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
virtual bool read() = 0;
|
||||
virtual bool close() = 0;
|
||||
virtual unique_ptr<Surface> bitmap(ColorSpace cs) { return nullptr; }
|
||||
virtual unique_ptr<Surface> bitmap() { return nullptr; }
|
||||
virtual unique_ptr<Paint> paint() { return nullptr; }
|
||||
};
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ struct Picture::Impl
|
|||
Surface* surface = nullptr; //bitmap picture uses
|
||||
RenderData rd = nullptr; //engine data
|
||||
float w = 0, h = 0;
|
||||
ColorSpace rendererColorSpace = ColorSpace::Unsupported;
|
||||
RenderMesh rm; //mesh data
|
||||
bool resizing = false;
|
||||
|
||||
|
@ -105,7 +104,7 @@ struct Picture::Impl
|
|||
}
|
||||
}
|
||||
free(surface);
|
||||
if ((surface = loader->bitmap(rendererColorSpace).release())) {
|
||||
if ((surface = loader->bitmap().release())) {
|
||||
loader->close();
|
||||
return RenderUpdateFlag::Image;
|
||||
}
|
||||
|
@ -129,7 +128,6 @@ struct Picture::Impl
|
|||
|
||||
RenderData update(RenderMethod &renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag, bool clipper)
|
||||
{
|
||||
rendererColorSpace = renderer.colorSpace();
|
||||
auto flag = reload();
|
||||
|
||||
if (surface) {
|
||||
|
|
|
@ -226,8 +226,6 @@ public:
|
|||
virtual Compositor* target(const RenderRegion& region) = 0;
|
||||
virtual bool beginComposite(Compositor* cmp, CompositeMethod method, uint32_t opacity) = 0;
|
||||
virtual bool endComposite(Compositor* cmp) = 0;
|
||||
|
||||
virtual ColorSpace colorSpace() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,43 +29,6 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static uint32_t convertColorSpaceType(ColorSpace cs)
|
||||
{
|
||||
uint32_t tjpfColorSpace = TJPF_RGBX;
|
||||
|
||||
switch (cs) {
|
||||
case ColorSpace::ARGB8888:
|
||||
case ColorSpace::ARGB8888S:
|
||||
default:
|
||||
tjpfColorSpace = TJPF_BGRX;
|
||||
break;
|
||||
case ColorSpace::ABGR8888:
|
||||
case ColorSpace::ABGR8888S:
|
||||
tjpfColorSpace = TJPF_RGBX;
|
||||
break;
|
||||
}
|
||||
|
||||
return tjpfColorSpace;
|
||||
}
|
||||
|
||||
|
||||
static inline uint32_t CHANGE_COLORSPACE(uint32_t c)
|
||||
{
|
||||
return (c & 0xff000000) + ((c & 0x00ff0000)>>16) + (c & 0x0000ff00) + ((c & 0x000000ff)<<16);
|
||||
}
|
||||
|
||||
|
||||
static void _changeColorSpace(uint32_t* data, uint32_t w, uint32_t h)
|
||||
{
|
||||
auto buffer = data;
|
||||
for (uint32_t y = 0; y < h; ++y, buffer += w) {
|
||||
auto src = buffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++src) {
|
||||
*src = CHANGE_COLORSPACE(*src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JpgLoader::clear()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
|
@ -124,6 +87,7 @@ bool JpgLoader::open(const string& path)
|
|||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
cs = ColorSpace::ARGB8888;
|
||||
ret = true;
|
||||
|
||||
goto finalize;
|
||||
|
@ -156,6 +120,7 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
|||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
cs = ColorSpace::ARGB8888;
|
||||
this->size = size;
|
||||
|
||||
return true;
|
||||
|
@ -164,12 +129,14 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
|||
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
/* OPTIMIZE: We assume the desired colorspace is ColorSpace::ARGB
|
||||
How could we notice the renderer colorspace at this time? */
|
||||
if (image) tjFree(image);
|
||||
image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[convertColorSpaceType(cs)]);
|
||||
image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[TJPF_BGRX]);
|
||||
if (!image) return false;
|
||||
|
||||
//decompress jpg image
|
||||
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), convertColorSpaceType(cs), 0) < 0) {
|
||||
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), TJPF_BGRX, 0) < 0) {
|
||||
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
|
||||
tjFree(image);
|
||||
image = nullptr;
|
||||
|
@ -187,13 +154,9 @@ bool JpgLoader::close()
|
|||
}
|
||||
|
||||
|
||||
unique_ptr<Surface> JpgLoader::bitmap(ColorSpace cs)
|
||||
unique_ptr<Surface> JpgLoader::bitmap()
|
||||
{
|
||||
if (!image) return nullptr;
|
||||
if (this->cs != cs) {
|
||||
this->cs = cs;
|
||||
_changeColorSpace(reinterpret_cast<uint32_t*>(image), w, h);
|
||||
}
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = (uint32_t*)(image);
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
unique_ptr<Surface> bitmap(ColorSpace cs) override;
|
||||
unique_ptr<Surface> bitmap() override;
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#include "tvgLoader.h"
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static inline uint32_t PREMULTIPLY(uint32_t c)
|
||||
{
|
||||
auto a = (c >> 24);
|
||||
|
@ -42,23 +46,9 @@ static void _premultiply(uint32_t* data, uint32_t w, uint32_t h)
|
|||
}
|
||||
|
||||
|
||||
static inline uint32_t CHANGE_COLORSPACE(uint32_t c)
|
||||
{
|
||||
return (c & 0xff000000) + ((c & 0x00ff0000)>>16) + (c & 0x0000ff00) + ((c & 0x000000ff)<<16);
|
||||
}
|
||||
|
||||
|
||||
static void _changeColorSpace(uint32_t* data, uint32_t w, uint32_t h)
|
||||
{
|
||||
auto buffer = data;
|
||||
for (uint32_t y = 0; y < h; ++y, buffer += w) {
|
||||
auto src = buffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++src) {
|
||||
*src = CHANGE_COLORSPACE(*src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
PngLoader::PngLoader()
|
||||
{
|
||||
|
@ -84,6 +74,7 @@ bool PngLoader::open(const string& path)
|
|||
|
||||
w = (float)image->width;
|
||||
h = (float)image->height;
|
||||
cs = ColorSpace::ARGB8888;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -96,6 +87,7 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
|||
|
||||
w = (float)image->width;
|
||||
h = (float)image->height;
|
||||
cs = ColorSpace::ARGB8888;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -128,13 +120,9 @@ bool PngLoader::close()
|
|||
return true;
|
||||
}
|
||||
|
||||
unique_ptr<Surface> PngLoader::bitmap(ColorSpace cs)
|
||||
unique_ptr<Surface> PngLoader::bitmap()
|
||||
{
|
||||
if (!content) return nullptr;
|
||||
if (this->cs != cs) {
|
||||
this->cs = cs;
|
||||
_changeColorSpace(content, w, h);
|
||||
}
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = content;
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
unique_ptr<Surface> bitmap(ColorSpace cs) override;
|
||||
unique_ptr<Surface> bitmap() override;
|
||||
|
||||
private:
|
||||
png_imagep image = nullptr;
|
||||
|
|
|
@ -28,24 +28,6 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static inline uint32_t CHANGE_COLORSPACE(uint32_t c)
|
||||
{
|
||||
return (c & 0xff000000) + ((c & 0x00ff0000)>>16) + (c & 0x0000ff00) + ((c & 0x000000ff)<<16);
|
||||
}
|
||||
|
||||
|
||||
static void _changeColorSpace(uint32_t* data, uint32_t w, uint32_t h)
|
||||
{
|
||||
auto buffer = data;
|
||||
for (uint32_t y = 0; y < h; ++y, buffer += w) {
|
||||
auto src = buffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++src) {
|
||||
*src = CHANGE_COLORSPACE(*src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JpgLoader::clear()
|
||||
{
|
||||
jpgdDelete(decoder);
|
||||
|
@ -79,6 +61,7 @@ bool JpgLoader::open(const string& path)
|
|||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
cs = ColorSpace::ARGB8888;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -104,6 +87,7 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
|||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
cs = ColorSpace::ARGB8888;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -128,15 +112,11 @@ bool JpgLoader::close()
|
|||
}
|
||||
|
||||
|
||||
unique_ptr<Surface> JpgLoader::bitmap(ColorSpace cs)
|
||||
unique_ptr<Surface> JpgLoader::bitmap()
|
||||
{
|
||||
this->done();
|
||||
|
||||
if (!image) return nullptr;
|
||||
if (this->cs != cs) {
|
||||
this->cs = cs;
|
||||
_changeColorSpace(reinterpret_cast<uint32_t*>(image), static_cast<uint32_t>(w), static_cast<uint32_t>(h));
|
||||
}
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = reinterpret_cast<uint32_t*>(image);
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
unique_ptr<Surface> bitmap(ColorSpace cs) override;
|
||||
unique_ptr<Surface> bitmap() override;
|
||||
void run(unsigned tid) override;
|
||||
};
|
||||
|
||||
|
|
|
@ -49,24 +49,6 @@ static void _premultiply(uint32_t* data, uint32_t w, uint32_t h)
|
|||
}
|
||||
|
||||
|
||||
static inline uint32_t CHANGE_COLORSPACE(uint32_t c)
|
||||
{
|
||||
return (c & 0xff000000) + ((c & 0x00ff0000)>>16) + (c & 0x0000ff00) + ((c & 0x000000ff)<<16);
|
||||
}
|
||||
|
||||
|
||||
static void _changeColorSpace(uint32_t* data, uint32_t w, uint32_t h)
|
||||
{
|
||||
auto buffer = data;
|
||||
for (uint32_t y = 0; y < h; ++y, buffer += w) {
|
||||
auto src = buffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++src) {
|
||||
*src = CHANGE_COLORSPACE(*src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PngLoader::clear()
|
||||
{
|
||||
lodepng_state_cleanup(&state);
|
||||
|
@ -123,9 +105,11 @@ bool PngLoader::open(const string& path)
|
|||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
ret = true;
|
||||
|
||||
if (state.info_png.color.colortype == LCT_RGBA) cs = ColorSpace::ABGR8888;
|
||||
else cs = ColorSpace::ARGB8888;
|
||||
|
||||
ret = true;
|
||||
|
||||
goto finalize;
|
||||
|
||||
|
@ -162,6 +146,7 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
|||
this->size = size;
|
||||
|
||||
if (state.info_png.color.colortype == LCT_RGBA) cs = ColorSpace::ABGR8888;
|
||||
else cs = ColorSpace::ARGB8888;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -185,16 +170,10 @@ bool PngLoader::close()
|
|||
}
|
||||
|
||||
|
||||
unique_ptr<Surface> PngLoader::bitmap(ColorSpace cs)
|
||||
unique_ptr<Surface> PngLoader::bitmap()
|
||||
{
|
||||
this->done();
|
||||
|
||||
if (!image) return nullptr;
|
||||
if (this->cs != cs) {
|
||||
this->cs = cs;
|
||||
_changeColorSpace(reinterpret_cast<uint32_t*>(image), static_cast<uint32_t>(w), static_cast<uint32_t>(h));
|
||||
}
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = reinterpret_cast<uint32_t*>(image);
|
||||
surface->stride = static_cast<uint32_t>(w);
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
unique_ptr<Surface> bitmap(ColorSpace cs) override;
|
||||
unique_ptr<Surface> bitmap() override;
|
||||
void run(unsigned tid) override;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,22 +29,6 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static inline uint32_t CHANGE_COLORSPACE(uint32_t c)
|
||||
{
|
||||
return (c & 0xff000000) + ((c & 0x00ff0000)>>16) + (c & 0x0000ff00) + ((c & 0x000000ff)<<16);
|
||||
}
|
||||
|
||||
|
||||
static void _changeColorSpace(uint32_t* data, uint32_t w, uint32_t h)
|
||||
{
|
||||
auto buffer = data;
|
||||
for (uint32_t y = 0; y < h; ++y, buffer += w) {
|
||||
auto src = buffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++src) {
|
||||
*src = CHANGE_COLORSPACE(*src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
|
@ -74,6 +58,8 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy)
|
|||
}
|
||||
else content = const_cast<uint32_t*>(data);
|
||||
|
||||
cs = ColorSpace::ARGB8888;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -90,13 +76,9 @@ bool RawLoader::close()
|
|||
}
|
||||
|
||||
|
||||
unique_ptr<Surface> RawLoader::bitmap(ColorSpace cs)
|
||||
unique_ptr<Surface> RawLoader::bitmap()
|
||||
{
|
||||
if (!content) return nullptr;
|
||||
if (this->cs != cs) {
|
||||
this->cs = cs;
|
||||
_changeColorSpace(content, static_cast<uint32_t>(w), static_cast<uint32_t>(h));
|
||||
}
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = content;
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
unique_ptr<Surface> bitmap(ColorSpace cs) override;
|
||||
unique_ptr<Surface> bitmap() override;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue