* @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()
* @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.
* @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.
*
}
-uint32_t GlRenderer::colorSpace()
-{
- //TODO:
- return 0;
-}
-
-
int GlRenderer::init(uint32_t threads)
{
if ((initEngineCnt++) > 0) return true;
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;
}
-uint32_t SwRenderer::colorSpace()
-{
- return surface->cs;
-}
-
-
bool SwRenderer::preRender()
{
return rasterClear(surface);
RenderRegion region(RenderData data) override;
RenderRegion viewport() override;
bool viewport(const RenderRegion& vp) override;
- uint32_t colorSpace() override;
bool clear() override;
bool sync() override;
//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; };
void* rdata = nullptr; //engine data
float w = 0, h = 0;
bool resizing = false;
- bool justloaded = false;
Impl(Picture* p) : picture(p)
{
uint32_t reload()
{
- if (loader && !justloaded) {
+ if (loader) {
if (!paint) {
if (auto p = loader->paint()) {
paint = p.release();
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) {
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;
}
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;
}
if (!loader) return Result::NonSupport;
this->w = loader->w;
this->h = loader->h;
- justloaded = true;
return Result::Success;
}
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;
};
}
}
-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;
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;
* 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)));
PngLoader::~PngLoader()
{
- if (freeData) free(data);
- data = nullptr;
-
if (content) {
free((void*)content);
content = nullptr;
bool PngLoader::open(const string& path)
{
- clear();
image->opaque = NULL;
if (!png_image_begin_read_from_file(image, path.c_str())) return false;
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;
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
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;
};
}
-bool JpgLoader::read(uint32_t colorspace)
+
+bool JpgLoader::read()
{
if (!decoder || w <= 0 || h <= 0) return false;
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;
}
-bool PngLoader::read(uint32_t colorspace)
+bool PngLoader::read()
{
if (!data || w <= 0 || h <= 0) return false;
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;
}
-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;
}
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;
}
-bool SvgLoader::read(uint32_t colorspace)
+bool SvgLoader::read()
{
if (!content || size == 0) return false;
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;
}
-bool TvgLoader::read(uint32_t colorspace)
+bool TvgLoader::read()
{
if (!ptr || size == 0) return false;
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;