mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
Revert "loaders: Consider colorspaces (#838)"
This reverts commit cd5116b053
.
Ah this breaks the Stress example due to Picture::duplicate() is not available...
Need to consider and come back again.
This commit is contained in:
parent
cd5116b053
commit
3b2e1f4291
22 changed files with 25 additions and 86 deletions
|
@ -1099,6 +1099,7 @@ public:
|
|||
* @retval Result::Success When succeed.
|
||||
* @retval Result::InvalidArguments In case the @p path is invalid.
|
||||
* @retval Result::NonSupport When trying to load a file with an unknown extension.
|
||||
* @retval Result::Unknown If an error occurs at a later stage.
|
||||
*
|
||||
* @note The Load behavior can be asynchronous if the assigned thread number is greater than zero.
|
||||
* @see Initializer::init()
|
||||
|
@ -1115,6 +1116,7 @@ public:
|
|||
* @retval Result::Success When succeed.
|
||||
* @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
|
||||
* @retval Result::NonSupport When trying to load a file with an unknown extension.
|
||||
* @retval Result::Unknown If an error occurs at a later stage.
|
||||
*
|
||||
* @warning: you have responsibility to release the @p data memory if the @p copy is true
|
||||
* @deprecated Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead.
|
||||
|
@ -1133,6 +1135,7 @@ public:
|
|||
* @retval Result::Success When succeed.
|
||||
* @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
|
||||
* @retval Result::NonSupport When trying to load a file with an unknown extension.
|
||||
* @retval Result::Unknown If an error occurs at a later stage.
|
||||
*
|
||||
* @warning: It's the user responsibility to release the @p data memory if the @p copy is @c true.
|
||||
*
|
||||
|
|
|
@ -246,13 +246,6 @@ bool GlRenderer::viewport(TVG_UNUSED const RenderRegion& vp)
|
|||
}
|
||||
|
||||
|
||||
uint32_t GlRenderer::colorSpace()
|
||||
{
|
||||
//TODO:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int GlRenderer::init(uint32_t threads)
|
||||
{
|
||||
if ((initEngineCnt++) > 0) return true;
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
RenderRegion region(RenderData data) override;
|
||||
RenderRegion viewport() override;
|
||||
bool viewport(const RenderRegion& vp) override;
|
||||
uint32_t colorSpace() override;
|
||||
|
||||
bool target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h);
|
||||
bool sync() override;
|
||||
|
|
|
@ -299,12 +299,6 @@ bool SwRenderer::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
|
|||
}
|
||||
|
||||
|
||||
uint32_t SwRenderer::colorSpace()
|
||||
{
|
||||
return surface->cs;
|
||||
}
|
||||
|
||||
|
||||
bool SwRenderer::preRender()
|
||||
{
|
||||
return rasterClear(surface);
|
||||
|
|
|
@ -45,7 +45,6 @@ public:
|
|||
RenderRegion region(RenderData data) override;
|
||||
RenderRegion viewport() override;
|
||||
bool viewport(const RenderRegion& vp) override;
|
||||
uint32_t colorSpace() override;
|
||||
|
||||
bool clear() override;
|
||||
bool sync() override;
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
//Override this if the vector-format has own resizing policy.
|
||||
virtual bool resize(Paint* paint, float w, float h) { return false; };
|
||||
|
||||
virtual bool read(uint32_t colorspace) = 0;
|
||||
virtual bool read() = 0;
|
||||
virtual bool close() = 0;
|
||||
virtual const uint32_t* pixels() { return nullptr; };
|
||||
virtual unique_ptr<Paint> paint() { return nullptr; };
|
||||
|
|
|
@ -66,7 +66,6 @@ struct Picture::Impl
|
|||
void* rdata = nullptr; //engine data
|
||||
float w = 0, h = 0;
|
||||
bool resizing = false;
|
||||
bool justloaded = false;
|
||||
|
||||
Impl(Picture* p) : picture(p)
|
||||
{
|
||||
|
@ -91,7 +90,7 @@ struct Picture::Impl
|
|||
|
||||
uint32_t reload()
|
||||
{
|
||||
if (loader && !justloaded) {
|
||||
if (loader) {
|
||||
if (!paint) {
|
||||
if (auto p = loader->paint()) {
|
||||
paint = p.release();
|
||||
|
@ -128,14 +127,6 @@ struct Picture::Impl
|
|||
|
||||
void* update(RenderMethod &renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag)
|
||||
{
|
||||
if (loader && justloaded) {
|
||||
justloaded = false;
|
||||
if (!loader->read(renderer.colorSpace())) {
|
||||
TVGERR("Picture", "Loader read failure!");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto flag = reload();
|
||||
|
||||
if (pixels) {
|
||||
|
@ -203,9 +194,9 @@ struct Picture::Impl
|
|||
if (invalid) return Result::InvalidArguments;
|
||||
return Result::NonSupport;
|
||||
}
|
||||
if (!loader->read()) return Result::Unknown;
|
||||
w = loader->w;
|
||||
h = loader->h;
|
||||
justloaded = true;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
|
@ -215,9 +206,9 @@ struct Picture::Impl
|
|||
if (loader) loader->close();
|
||||
loader = LoaderMgr::loader(data, size, mimeType, copy);
|
||||
if (!loader) return Result::NonSupport;
|
||||
if (!loader->read()) return Result::Unknown;
|
||||
w = loader->w;
|
||||
h = loader->h;
|
||||
justloaded = true;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
|
@ -229,7 +220,6 @@ struct Picture::Impl
|
|||
if (!loader) return Result::NonSupport;
|
||||
this->w = loader->w;
|
||||
this->h = loader->h;
|
||||
justloaded = true;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,8 +100,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 uint32_t colorSpace() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -124,15 +124,14 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
|||
}
|
||||
|
||||
|
||||
bool JpgLoader::read(uint32_t colorspace)
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
if (image) tjFree(image);
|
||||
image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[TJPF_BGRX]);
|
||||
if (!image) return false;
|
||||
|
||||
//decompress jpg image
|
||||
auto pixelFormat = (colorspace == tvg::SwCanvas::ABGR8888) ? TJPF_RGBX : TJPF_BGRX;
|
||||
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), pixelFormat, 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;
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
|
|
@ -20,27 +20,9 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void PngLoader::clear()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
data = nullptr;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
PngLoader::PngLoader()
|
||||
{
|
||||
image = static_cast<png_imagep>(calloc(1, sizeof(png_image)));
|
||||
|
@ -50,9 +32,6 @@ PngLoader::PngLoader()
|
|||
|
||||
PngLoader::~PngLoader()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
data = nullptr;
|
||||
|
||||
if (content) {
|
||||
free((void*)content);
|
||||
content = nullptr;
|
||||
|
@ -62,7 +41,6 @@ PngLoader::~PngLoader()
|
|||
|
||||
bool PngLoader::open(const string& path)
|
||||
{
|
||||
clear();
|
||||
image->opaque = NULL;
|
||||
|
||||
if (!png_image_begin_read_from_file(image, path.c_str())) return false;
|
||||
|
@ -75,19 +53,9 @@ bool PngLoader::open(const string& path)
|
|||
|
||||
bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
||||
{
|
||||
clear();
|
||||
image->opaque = NULL;
|
||||
|
||||
if (copy) {
|
||||
this->data = (char *) malloc(size);
|
||||
if (!this->data) return false;
|
||||
memcpy(this->data, data, size);
|
||||
freeData = true;
|
||||
} else {
|
||||
this->data = (char *) data;
|
||||
}
|
||||
|
||||
if (!png_image_begin_read_from_memory(image, this->data, size)) return false;
|
||||
if (!png_image_begin_read_from_memory(image, data, size)) return false;
|
||||
|
||||
w = (float)image->width;
|
||||
h = (float)image->height;
|
||||
|
@ -95,10 +63,10 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PngLoader::read(uint32_t colorspace)
|
||||
bool PngLoader::read()
|
||||
{
|
||||
png_bytep buffer;
|
||||
image->format = (colorspace == tvg::SwCanvas::ABGR8888) ? PNG_FORMAT_RGBA : PNG_FORMAT_BGRA;
|
||||
image->format = PNG_FORMAT_BGRA;
|
||||
buffer = static_cast<png_bytep>(malloc(PNG_IMAGE_SIZE((*image))));
|
||||
if (!buffer) {
|
||||
//out of memory, only time when libpng doesnt free its data
|
||||
|
|
|
@ -33,16 +33,12 @@ public:
|
|||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
char* data = nullptr;
|
||||
bool freeData = false;
|
||||
png_imagep image = nullptr;
|
||||
const uint32_t* content = nullptr;
|
||||
};
|
||||
|
|
|
@ -90,7 +90,8 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
|||
}
|
||||
|
||||
|
||||
bool JpgLoader::read(uint32_t colorspace)
|
||||
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
if (!decoder || w <= 0 || h <= 0) return false;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
|
|
@ -123,7 +123,7 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
|||
}
|
||||
|
||||
|
||||
bool PngLoader::read(uint32_t colorspace)
|
||||
bool PngLoader::read()
|
||||
{
|
||||
if (!data || w <= 0 || h <= 0) return false;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
|
|
@ -60,9 +60,8 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy)
|
|||
}
|
||||
|
||||
|
||||
bool RawLoader::read(uint32_t colorspace)
|
||||
bool RawLoader::read()
|
||||
{
|
||||
//NOTE: raw data is used "as it is"- developer must take care of it so the same color space used
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
|
||||
using LoadModule::open;
|
||||
bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
|
|
@ -2927,7 +2927,7 @@ bool SvgLoader::resize(Paint* paint, float w, float h)
|
|||
}
|
||||
|
||||
|
||||
bool SvgLoader::read(uint32_t colorspace)
|
||||
bool SvgLoader::read()
|
||||
{
|
||||
if (!content || size == 0) return false;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool resize(Paint* paint, float w, float h) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
unique_ptr<Paint> paint() override;
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ bool TvgLoader::resize(Paint* paint, float w, float h)
|
|||
}
|
||||
|
||||
|
||||
bool TvgLoader::read(uint32_t colorspace)
|
||||
bool TvgLoader::read()
|
||||
{
|
||||
if (!ptr || size == 0) return false;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
using LoadModule::open;
|
||||
bool open(const string &path) override;
|
||||
bool open(const char *data, uint32_t size, bool copy) override;
|
||||
bool read(uint32_t colorspace) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
bool resize(Paint* paint, float w, float h) override;
|
||||
unique_ptr<Paint> paint() override;
|
||||
|
|
Loading…
Add table
Reference in a new issue