mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
common: introduced designated memory allocators
Support the bindings to be more integrable with a system's coherent memory management. Pleaes note that thorvg now only allow the desinated memory allocators here: malloc -> tvg::malloc calloc -> tvg::calloc realloc -> tvg::realloc free -> tvg::free issue: https://github.com/thorvg/thorvg/issues/2652
This commit is contained in:
parent
424953ad7b
commit
b77f3ca024
62 changed files with 466 additions and 487 deletions
|
@ -23,9 +23,7 @@
|
||||||
#ifndef _TVG_ARRAY_H_
|
#ifndef _TVG_ARRAY_H_
|
||||||
#define _TVG_ARRAY_H_
|
#define _TVG_ARRAY_H_
|
||||||
|
|
||||||
#include <memory.h>
|
#include "tvgCommon.h"
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#define ARRAY_FOREACH(A, B) \
|
#define ARRAY_FOREACH(A, B) \
|
||||||
for (auto A = (B).begin(); A < (B).end(); ++A)
|
for (auto A = (B).begin(); A < (B).end(); ++A)
|
||||||
|
@ -60,7 +58,7 @@ struct Array
|
||||||
{
|
{
|
||||||
if (count + 1 > reserved) {
|
if (count + 1 > reserved) {
|
||||||
reserved = count + (count + 2) / 2;
|
reserved = count + (count + 2) / 2;
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
data = tvg::realloc<T*>(data, sizeof(T) * reserved);
|
||||||
}
|
}
|
||||||
data[count++] = element;
|
data[count++] = element;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +75,7 @@ struct Array
|
||||||
{
|
{
|
||||||
if (size > reserved) {
|
if (size > reserved) {
|
||||||
reserved = size;
|
reserved = size;
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
data = tvg::realloc<T*>(data, sizeof(T) * reserved);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +142,7 @@ struct Array
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
free(data);
|
tvg::free(data);
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
count = reserved = 0;
|
count = reserved = 0;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +172,7 @@ struct Array
|
||||||
|
|
||||||
~Array()
|
~Array()
|
||||||
{
|
{
|
||||||
free(data);
|
tvg::free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -54,9 +54,7 @@
|
||||||
* http://marknelson.us/1989/10/01/lzw-data-compression/
|
* http://marknelson.us/1989/10/01/lzw-data-compression/
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "tvgCommon.h"
|
||||||
#include <string>
|
|
||||||
#include <memory.h>
|
|
||||||
#include "tvgCompressor.h"
|
#include "tvgCompressor.h"
|
||||||
|
|
||||||
namespace tvg {
|
namespace tvg {
|
||||||
|
@ -209,7 +207,7 @@ uint8_t* lzwDecode(const uint8_t* compressed, uint32_t compressedSizeBytes, uint
|
||||||
int firstByte = 0;
|
int firstByte = 0;
|
||||||
int bytesDecoded = 0;
|
int bytesDecoded = 0;
|
||||||
int codeBitsWidth = StartBits;
|
int codeBitsWidth = StartBits;
|
||||||
auto uncompressed = (uint8_t*) malloc(sizeof(uint8_t) * uncompressedSizeBytes);
|
auto uncompressed = tvg::malloc<uint8_t*>(sizeof(uint8_t) * uncompressedSizeBytes);
|
||||||
auto ptr = uncompressed;
|
auto ptr = uncompressed;
|
||||||
|
|
||||||
/* We'll reconstruct the dictionary based on the bit stream codes.
|
/* We'll reconstruct the dictionary based on the bit stream codes.
|
||||||
|
@ -263,7 +261,7 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded)
|
||||||
if (!decoded || !encoded || len == 0) return 0;
|
if (!decoded || !encoded || len == 0) return 0;
|
||||||
|
|
||||||
auto reserved = 3 * (1 + (len >> 2)) + 1;
|
auto reserved = 3 * (1 + (len >> 2)) + 1;
|
||||||
auto output = static_cast<char*>(malloc(reserved * sizeof(char)));
|
auto output = tvg::malloc<char*>(reserved * sizeof(char));
|
||||||
if (!output) return 0;
|
if (!output) return 0;
|
||||||
output[reserved - 1] = '\0';
|
output[reserved - 1] = '\0';
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include "tvgCommon.h"
|
||||||
#include <memory.h>
|
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
#include "tvgStr.h"
|
#include "tvgStr.h"
|
||||||
|
|
||||||
|
@ -212,7 +211,7 @@ char* strDuplicate(const char *str, size_t n)
|
||||||
auto len = strlen(str);
|
auto len = strlen(str);
|
||||||
if (len < n) n = len;
|
if (len < n) n = len;
|
||||||
|
|
||||||
auto ret = (char *) malloc(n + 1);
|
auto ret = tvg::malloc<char*>(n + 1);
|
||||||
if (!ret) return nullptr;
|
if (!ret) return nullptr;
|
||||||
ret[n] = '\0';
|
ret[n] = '\0';
|
||||||
|
|
||||||
|
@ -223,7 +222,7 @@ char* strAppend(char* lhs, const char* rhs, size_t n)
|
||||||
{
|
{
|
||||||
if (!rhs) return lhs;
|
if (!rhs) return lhs;
|
||||||
if (!lhs) return strDuplicate(rhs, n);
|
if (!lhs) return strDuplicate(rhs, n);
|
||||||
lhs = (char*)realloc(lhs, strlen(lhs) + n + 1);
|
lhs = tvg::realloc<char*>(lhs, strlen(lhs) + n + 1);
|
||||||
return strncat(lhs, rhs, n);
|
return strncat(lhs, rhs, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory.h>
|
|
||||||
#include <turbojpeg.h>
|
#include <turbojpeg.h>
|
||||||
#include "tvgJpgLoader.h"
|
#include "tvgJpgLoader.h"
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
|
|
||||||
void JpgLoader::clear()
|
void JpgLoader::clear()
|
||||||
{
|
{
|
||||||
if (freeData) free(data);
|
if (freeData) tvg::free(data);
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
size = 0;
|
size = 0;
|
||||||
freeData = false;
|
freeData = false;
|
||||||
|
@ -69,7 +68,7 @@ bool JpgLoader::open(const char* path)
|
||||||
if (((size = ftell(jpegFile)) < 1)) goto finalize;
|
if (((size = ftell(jpegFile)) < 1)) goto finalize;
|
||||||
if (fseek(jpegFile, 0, SEEK_SET)) goto finalize;
|
if (fseek(jpegFile, 0, SEEK_SET)) goto finalize;
|
||||||
|
|
||||||
data = (unsigned char *) malloc(size);
|
data = tvg::malloc<unsigned char*>(size);
|
||||||
if (!data) goto finalize;
|
if (!data) goto finalize;
|
||||||
|
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
@ -106,7 +105,7 @@ bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpa
|
||||||
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
this->data = (unsigned char *) malloc(size);
|
this->data = tvg::malloc<unsigned char*>(size);
|
||||||
if (!this->data) return false;
|
if (!this->data) return false;
|
||||||
memcpy((unsigned char *)this->data, data, size);
|
memcpy((unsigned char *)this->data, data, size);
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
void PngLoader::clear()
|
void PngLoader::clear()
|
||||||
{
|
{
|
||||||
png_image_free(image);
|
png_image_free(image);
|
||||||
free(image);
|
tvg::free(image);
|
||||||
image = nullptr;
|
image = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ void PngLoader::clear()
|
||||||
|
|
||||||
PngLoader::PngLoader() : ImageLoader(FileType::Png)
|
PngLoader::PngLoader() : ImageLoader(FileType::Png)
|
||||||
{
|
{
|
||||||
image = static_cast<png_imagep>(calloc(1, sizeof(png_image)));
|
image = tvg::calloc<png_imagep>(1, sizeof(png_image));
|
||||||
image->version = PNG_IMAGE_VERSION;
|
image->version = PNG_IMAGE_VERSION;
|
||||||
image->opaque = NULL;
|
image->opaque = NULL;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ PngLoader::PngLoader() : ImageLoader(FileType::Png)
|
||||||
PngLoader::~PngLoader()
|
PngLoader::~PngLoader()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
free((void*)surface.buf32);
|
tvg::free(surface.buf32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ bool PngLoader::read()
|
||||||
surface.cs = ColorSpace::ABGR8888S;
|
surface.cs = ColorSpace::ABGR8888S;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto buffer = static_cast<png_bytep>(malloc(PNG_IMAGE_SIZE((*image))));
|
auto buffer = tvg::malloc<png_bytep>(PNG_IMAGE_SIZE((*image)));
|
||||||
if (!png_image_finish_read(image, NULL, buffer, 0, NULL)) {
|
if (!png_image_finish_read(image, NULL, buffer, 0, NULL)) {
|
||||||
free(buffer);
|
tvg::free(buffer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ WebpLoader::~WebpLoader()
|
||||||
{
|
{
|
||||||
this->done();
|
this->done();
|
||||||
|
|
||||||
if (freeData) free(data);
|
if (freeData) tvg::free(data);
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
size = 0;
|
size = 0;
|
||||||
freeData = false;
|
freeData = false;
|
||||||
|
@ -78,7 +78,7 @@ bool WebpLoader::open(const char* path)
|
||||||
if (((size = ftell(webpFile)) < 1)) goto finalize;
|
if (((size = ftell(webpFile)) < 1)) goto finalize;
|
||||||
if (fseek(webpFile, 0, SEEK_SET)) goto finalize;
|
if (fseek(webpFile, 0, SEEK_SET)) goto finalize;
|
||||||
|
|
||||||
data = (unsigned char *) malloc(size);
|
data = tvg::malloc<unsigned char*>(size);
|
||||||
if (!data) goto finalize;
|
if (!data) goto finalize;
|
||||||
|
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
@ -105,7 +105,7 @@ finalize:
|
||||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||||
{
|
{
|
||||||
if (copy) {
|
if (copy) {
|
||||||
this->data = (unsigned char *) malloc(size);
|
this->data = tvg::malloc<unsigned char*>(size);
|
||||||
if (!this->data) return false;
|
if (!this->data) return false;
|
||||||
memcpy((unsigned char *)this->data, data, size);
|
memcpy((unsigned char *)this->data, data, size);
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory.h>
|
|
||||||
#include "tvgJpgLoader.h"
|
#include "tvgJpgLoader.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
void JpgLoader::clear()
|
void JpgLoader::clear()
|
||||||
{
|
{
|
||||||
jpgdDelete(decoder);
|
jpgdDelete(decoder);
|
||||||
if (freeData) free(data);
|
if (freeData) tvg::free(data);
|
||||||
decoder = nullptr;
|
decoder = nullptr;
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
freeData = false;
|
freeData = false;
|
||||||
|
@ -64,7 +63,7 @@ JpgLoader::JpgLoader() : ImageLoader(FileType::Jpg)
|
||||||
JpgLoader::~JpgLoader()
|
JpgLoader::~JpgLoader()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
free(surface.buf8);
|
tvg::free(surface.buf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +87,7 @@ bool JpgLoader::open(const char* path)
|
||||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||||
{
|
{
|
||||||
if (copy) {
|
if (copy) {
|
||||||
this->data = (char *) malloc(size);
|
this->data = tvg::malloc<char*>(size);
|
||||||
if (!this->data) return false;
|
if (!this->data) return false;
|
||||||
memcpy((char *)this->data, data, size);
|
memcpy((char *)this->data, data, size);
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
// Chroma upsampling reference: "Fast Scheme for Image Size Change in the Compressed Domain"
|
// Chroma upsampling reference: "Fast Scheme for Image Size Change in the Compressed Domain"
|
||||||
// http://vision.ai.uiuc.edu/~dugad/research/dct/index.html
|
// http://vision.ai.uiuc.edu/~dugad/research/dct/index.html
|
||||||
|
|
||||||
#include <memory.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
@ -1087,7 +1086,7 @@ void jpeg_decoder::free_all_blocks()
|
||||||
|
|
||||||
for (mem_block *b = m_pMem_blocks; b; ) {
|
for (mem_block *b = m_pMem_blocks; b; ) {
|
||||||
mem_block *n = b->m_pNext;
|
mem_block *n = b->m_pNext;
|
||||||
free(b);
|
tvg::free(b);
|
||||||
b = n;
|
b = n;
|
||||||
}
|
}
|
||||||
m_pMem_blocks = nullptr;
|
m_pMem_blocks = nullptr;
|
||||||
|
@ -1117,7 +1116,7 @@ void *jpeg_decoder::alloc(size_t nSize, bool zero)
|
||||||
}
|
}
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
int capacity = JPGD_MAX(32768 - 256, (nSize + 2047) & ~2047);
|
int capacity = JPGD_MAX(32768 - 256, (nSize + 2047) & ~2047);
|
||||||
mem_block *b = (mem_block*)malloc(sizeof(mem_block) + capacity);
|
mem_block *b = tvg::malloc<mem_block*>(sizeof(mem_block) + capacity);
|
||||||
if (!b) stop_decoding(JPGD_NOTENOUGHMEM);
|
if (!b) stop_decoding(JPGD_NOTENOUGHMEM);
|
||||||
b->m_pNext = m_pMem_blocks; m_pMem_blocks = b;
|
b->m_pNext = m_pMem_blocks; m_pMem_blocks = b;
|
||||||
b->m_used_count = nSize;
|
b->m_used_count = nSize;
|
||||||
|
@ -2967,14 +2966,14 @@ unsigned char* jpgdDecompress(jpeg_decoder* decoder)
|
||||||
if (decoder->begin_decoding() != JPGD_SUCCESS) return nullptr;
|
if (decoder->begin_decoding() != JPGD_SUCCESS) return nullptr;
|
||||||
|
|
||||||
const int dst_bpl = image_width * req_comps;
|
const int dst_bpl = image_width * req_comps;
|
||||||
uint8_t *pImage_data = (uint8_t*)malloc(dst_bpl * image_height);
|
uint8_t *pImage_data = tvg::malloc<uint8_t*>(dst_bpl * image_height);
|
||||||
if (!pImage_data) return nullptr;
|
if (!pImage_data) return nullptr;
|
||||||
|
|
||||||
for (int y = 0; y < image_height; y++) {
|
for (int y = 0; y < image_height; y++) {
|
||||||
const uint8_t* pScan_line;
|
const uint8_t* pScan_line;
|
||||||
uint32_t scan_line_len;
|
uint32_t scan_line_len;
|
||||||
if (decoder->decode((const void**)&pScan_line, &scan_line_len) != JPGD_SUCCESS) {
|
if (decoder->decode((const void**)&pScan_line, &scan_line_len) != JPGD_SUCCESS) {
|
||||||
free(pImage_data);
|
tvg::free(pImage_data);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,7 @@
|
||||||
different translation units of a single application.
|
different translation units of a single application.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdlib> // malloc(), realloc(), free(), size_t
|
#include "tvgCommon.h"
|
||||||
#include <cstring> // memset(), memcpy(), memmove(), memcmp()
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// RAPIDJSON_VERSION_STRING
|
// RAPIDJSON_VERSION_STRING
|
||||||
|
@ -694,15 +693,15 @@ RAPIDJSON_NAMESPACE_END
|
||||||
|
|
||||||
#ifndef RAPIDJSON_MALLOC
|
#ifndef RAPIDJSON_MALLOC
|
||||||
///! customization point for global \c malloc
|
///! customization point for global \c malloc
|
||||||
#define RAPIDJSON_MALLOC(size) std::malloc(size)
|
#define RAPIDJSON_MALLOC(size) tvg::malloc(size)
|
||||||
#endif
|
#endif
|
||||||
#ifndef RAPIDJSON_REALLOC
|
#ifndef RAPIDJSON_REALLOC
|
||||||
///! customization point for global \c realloc
|
///! customization point for global \c realloc
|
||||||
#define RAPIDJSON_REALLOC(ptr, new_size) std::realloc(ptr, new_size)
|
#define RAPIDJSON_REALLOC(ptr, new_size) tvg::realloc(ptr, new_size)
|
||||||
#endif
|
#endif
|
||||||
#ifndef RAPIDJSON_FREE
|
#ifndef RAPIDJSON_FREE
|
||||||
///! customization point for global \c free
|
///! customization point for global \c free
|
||||||
#define RAPIDJSON_FREE(ptr) std::free(ptr)
|
#define RAPIDJSON_FREE(ptr) tvg::free(ptr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -20,16 +20,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#ifdef _WIN32
|
|
||||||
#include <malloc.h>
|
|
||||||
#elif defined(__linux__) || defined(__ZEPHYR__)
|
|
||||||
#include <alloca.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
#include "tvgLottieModel.h"
|
#include "tvgLottieModel.h"
|
||||||
|
@ -177,7 +168,7 @@ void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, f
|
||||||
uint8_t opacity;
|
uint8_t opacity;
|
||||||
|
|
||||||
if (parent->mergeable()) {
|
if (parent->mergeable()) {
|
||||||
if (!ctx->transform) ctx->transform = (Matrix*)malloc(sizeof(Matrix));
|
if (!ctx->transform) ctx->transform = tvg::malloc<Matrix*>(sizeof(Matrix));
|
||||||
_updateTransform(transform, frameNo, *ctx->transform, opacity, false, tween, exps);
|
_updateTransform(transform, frameNo, *ctx->transform, opacity, false, tween, exps);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ struct RenderContext
|
||||||
~RenderContext()
|
~RenderContext()
|
||||||
{
|
{
|
||||||
propagator->unref(false);
|
propagator->unref(false);
|
||||||
free(transform);
|
tvg::free(transform);
|
||||||
delete(roundness);
|
delete(roundness);
|
||||||
delete(offset);
|
delete(offset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ static LottieExpressions* exps = nullptr; //singleton instance engine
|
||||||
|
|
||||||
static ExpContent* _expcontent(LottieExpression* exp, float frameNo, LottieObject* obj)
|
static ExpContent* _expcontent(LottieExpression* exp, float frameNo, LottieObject* obj)
|
||||||
{
|
{
|
||||||
auto data = (ExpContent*)malloc(sizeof(ExpContent));
|
auto data = tvg::malloc<ExpContent*>(sizeof(ExpContent));
|
||||||
data->exp = exp;
|
data->exp = exp;
|
||||||
data->frameNo = frameNo;
|
data->frameNo = frameNo;
|
||||||
data->obj = obj;
|
data->obj = obj;
|
||||||
|
@ -70,7 +70,7 @@ static ExpContent* _expcontent(LottieExpression* exp, float frameNo, LottieObjec
|
||||||
|
|
||||||
static void contentFree(void *native_p, struct jerry_object_native_info_t *info_p)
|
static void contentFree(void *native_p, struct jerry_object_native_info_t *info_p)
|
||||||
{
|
{
|
||||||
free(native_p);
|
tvg::free(native_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jerry_object_native_info_t freeCb {contentFree, 0, 0};
|
static jerry_object_native_info_t freeCb {contentFree, 0, 0};
|
||||||
|
@ -81,7 +81,7 @@ static char* _name(jerry_value_t args)
|
||||||
{
|
{
|
||||||
auto arg0 = jerry_value_to_string(args);
|
auto arg0 = jerry_value_to_string(args);
|
||||||
auto len = jerry_string_length(arg0);
|
auto len = jerry_string_length(arg0);
|
||||||
auto name = (jerry_char_t*)malloc(len * sizeof(jerry_char_t) + 1);
|
auto name = tvg::malloc<jerry_char_t*>(len * sizeof(jerry_char_t) + 1);
|
||||||
jerry_string_to_buffer(arg0, JERRY_ENCODING_UTF8, name, len);
|
jerry_string_to_buffer(arg0, JERRY_ENCODING_UTF8, name, len);
|
||||||
name[len] = '\0';
|
name[len] = '\0';
|
||||||
jerry_value_free(arg0);
|
jerry_value_free(arg0);
|
||||||
|
@ -93,7 +93,7 @@ static unsigned long _idByName(jerry_value_t args)
|
||||||
{
|
{
|
||||||
auto name = _name(args);
|
auto name = _name(args);
|
||||||
auto id = djb2Encode(name);
|
auto id = djb2Encode(name);
|
||||||
free(name);
|
tvg::free(name);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,7 +831,7 @@ static bool _loopOutCommon(LottieExpression* exp, const jerry_value_t args[], co
|
||||||
else if (!strcmp(name, EXP_PINGPONG)) exp->loop.mode = LottieExpression::LoopMode::OutPingPong;
|
else if (!strcmp(name, EXP_PINGPONG)) exp->loop.mode = LottieExpression::LoopMode::OutPingPong;
|
||||||
else if (!strcmp(name, EXP_OFFSET)) exp->loop.mode = LottieExpression::LoopMode::OutOffset;
|
else if (!strcmp(name, EXP_OFFSET)) exp->loop.mode = LottieExpression::LoopMode::OutOffset;
|
||||||
else if (!strcmp(name, EXP_CONTINUE)) exp->loop.mode = LottieExpression::LoopMode::OutContinue;
|
else if (!strcmp(name, EXP_CONTINUE)) exp->loop.mode = LottieExpression::LoopMode::OutContinue;
|
||||||
free(name);
|
tvg::free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp->loop.mode != LottieExpression::LoopMode::OutCycle && exp->loop.mode != LottieExpression::LoopMode::OutPingPong) {
|
if (exp->loop.mode != LottieExpression::LoopMode::OutCycle && exp->loop.mode != LottieExpression::LoopMode::OutPingPong) {
|
||||||
|
@ -883,7 +883,7 @@ static bool _loopInCommon(LottieExpression* exp, const jerry_value_t args[], con
|
||||||
else if (!strcmp(name, EXP_PINGPONG)) exp->loop.mode = LottieExpression::LoopMode::InPingPong;
|
else if (!strcmp(name, EXP_PINGPONG)) exp->loop.mode = LottieExpression::LoopMode::InPingPong;
|
||||||
else if (!strcmp(name, EXP_OFFSET)) exp->loop.mode = LottieExpression::LoopMode::InOffset;
|
else if (!strcmp(name, EXP_OFFSET)) exp->loop.mode = LottieExpression::LoopMode::InOffset;
|
||||||
else if (!strcmp(name, EXP_CONTINUE)) exp->loop.mode = LottieExpression::LoopMode::InContinue;
|
else if (!strcmp(name, EXP_CONTINUE)) exp->loop.mode = LottieExpression::LoopMode::InContinue;
|
||||||
free(name);
|
tvg::free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp->loop.mode != LottieExpression::LoopMode::InCycle && exp->loop.mode != LottieExpression::LoopMode::InPingPong) {
|
if (exp->loop.mode != LottieExpression::LoopMode::InCycle && exp->loop.mode != LottieExpression::LoopMode::InPingPong) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ void LottieLoader::run(unsigned tid)
|
||||||
void LottieLoader::release()
|
void LottieLoader::release()
|
||||||
{
|
{
|
||||||
if (copy) {
|
if (copy) {
|
||||||
free((char*)content);
|
tvg::free((char*)content);
|
||||||
content = nullptr;
|
content = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ LottieLoader::~LottieLoader()
|
||||||
delete(comp);
|
delete(comp);
|
||||||
delete(builder);
|
delete(builder);
|
||||||
|
|
||||||
free(dirName);
|
tvg::free(dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ bool LottieLoader::header()
|
||||||
bool LottieLoader::open(const char* data, uint32_t size, const char* rpath, bool copy)
|
bool LottieLoader::open(const char* data, uint32_t size, const char* rpath, bool copy)
|
||||||
{
|
{
|
||||||
if (copy) {
|
if (copy) {
|
||||||
content = (char*)malloc(size + 1);
|
content = tvg::malloc<char*>(size + 1);
|
||||||
if (!content) return false;
|
if (!content) return false;
|
||||||
memcpy((char*)content, data, size);
|
memcpy((char*)content, data, size);
|
||||||
const_cast<char*>(content)[size] = '\0';
|
const_cast<char*>(content)[size] = '\0';
|
||||||
|
@ -230,7 +230,7 @@ bool LottieLoader::open(const char* path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto content = (char*)(malloc(sizeof(char) * size + 1));
|
auto content = tvg::malloc<char*>(sizeof(char) * size + 1);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
size = fread(content, sizeof(char), size, f);
|
size = fread(content, sizeof(char), size, f);
|
||||||
content[size] = '\0';
|
content[size] = '\0';
|
||||||
|
@ -313,7 +313,7 @@ bool LottieLoader::override(const char* slots, bool byDefault)
|
||||||
if (!applied) parser.skip();
|
if (!applied) parser.skip();
|
||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
free((char*)temp);
|
tvg::free((char*)temp);
|
||||||
rebuild = succeed;
|
rebuild = succeed;
|
||||||
overridden |= succeed;
|
overridden |= succeed;
|
||||||
return rebuild;
|
return rebuild;
|
||||||
|
|
|
@ -493,7 +493,7 @@ LottieLayer::~LottieLayer()
|
||||||
ARRAY_FOREACH(p, effects) delete(*p);
|
ARRAY_FOREACH(p, effects) delete(*p);
|
||||||
|
|
||||||
delete(transform);
|
delete(transform);
|
||||||
free(name);
|
tvg::free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -543,12 +543,12 @@ LottieComposition::~LottieComposition()
|
||||||
if (!initiated && root) delete(root->scene);
|
if (!initiated && root) delete(root->scene);
|
||||||
|
|
||||||
delete(root);
|
delete(root);
|
||||||
free(version);
|
tvg::free(version);
|
||||||
free(name);
|
tvg::free(name);
|
||||||
|
|
||||||
ARRAY_FOREACH(p, interpolators) {
|
ARRAY_FOREACH(p, interpolators) {
|
||||||
free((*p)->key);
|
tvg::free((*p)->key);
|
||||||
free(*p);
|
tvg::free(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
ARRAY_FOREACH(p, assets) delete(*p);
|
ARRAY_FOREACH(p, assets) delete(*p);
|
||||||
|
|
|
@ -245,7 +245,7 @@ struct LottieGlyph
|
||||||
~LottieGlyph()
|
~LottieGlyph()
|
||||||
{
|
{
|
||||||
ARRAY_FOREACH(p, children) delete(*p);
|
ARRAY_FOREACH(p, children) delete(*p);
|
||||||
free(code);
|
tvg::free(code);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ struct LottieTextRange
|
||||||
|
|
||||||
~LottieTextRange()
|
~LottieTextRange()
|
||||||
{
|
{
|
||||||
free(interpolator);
|
tvg::free(interpolator);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -300,10 +300,10 @@ struct LottieFont
|
||||||
~LottieFont()
|
~LottieFont()
|
||||||
{
|
{
|
||||||
ARRAY_FOREACH(p, chars) delete(*p);
|
ARRAY_FOREACH(p, chars) delete(*p);
|
||||||
free(style);
|
tvg::free(style);
|
||||||
free(family);
|
tvg::free(family);
|
||||||
free(name);
|
tvg::free(name);
|
||||||
free(data.b64src);
|
tvg::free(data.b64src);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -330,7 +330,7 @@ struct LottieMarker
|
||||||
|
|
||||||
~LottieMarker()
|
~LottieMarker()
|
||||||
{
|
{
|
||||||
free(name);
|
tvg::free(name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -925,7 +925,7 @@ struct LottieSlot
|
||||||
|
|
||||||
~LottieSlot()
|
~LottieSlot()
|
||||||
{
|
{
|
||||||
free(sid);
|
tvg::free(sid);
|
||||||
if (!overridden) return;
|
if (!overridden) return;
|
||||||
ARRAY_FOREACH(pair, pairs) delete(pair->prop);
|
ARRAY_FOREACH(pair, pairs) delete(pair->prop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ LottieInterpolator* LottieParser::getInterpolator(const char* key, Point& in, Po
|
||||||
|
|
||||||
//new interpolator
|
//new interpolator
|
||||||
if (!interpolator) {
|
if (!interpolator) {
|
||||||
interpolator = static_cast<LottieInterpolator*>(malloc(sizeof(LottieInterpolator)));
|
interpolator = tvg::malloc<LottieInterpolator*>(sizeof(LottieInterpolator));
|
||||||
interpolator->set(key, in, out);
|
interpolator->set(key, in, out);
|
||||||
comp->interpolators.push(interpolator);
|
comp->interpolators.push(interpolator);
|
||||||
}
|
}
|
||||||
|
@ -901,7 +901,7 @@ void LottieParser::parseImage(LottieImage* image, const char* data, const char*
|
||||||
//external image resource
|
//external image resource
|
||||||
} else {
|
} else {
|
||||||
auto len = strlen(dirName) + strlen(subPath) + strlen(data) + 2;
|
auto len = strlen(dirName) + strlen(subPath) + strlen(data) + 2;
|
||||||
image->data.path = static_cast<char*>(malloc(len));
|
image->data.path = tvg::malloc<char*>(len);
|
||||||
snprintf(image->data.path, len, "%s/%s%s", dirName, subPath, data);
|
snprintf(image->data.path, len, "%s/%s%s", dirName, subPath, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,7 +1135,7 @@ void LottieParser::parseTextRange(LottieText* text)
|
||||||
if (KEY_AS("t")) selector->expressible = (bool) getInt();
|
if (KEY_AS("t")) selector->expressible = (bool) getInt();
|
||||||
else if (KEY_AS("xe")) {
|
else if (KEY_AS("xe")) {
|
||||||
parseProperty<LottieProperty::Type::Float>(selector->maxEase);
|
parseProperty<LottieProperty::Type::Float>(selector->maxEase);
|
||||||
selector->interpolator = static_cast<LottieInterpolator*>(malloc(sizeof(LottieInterpolator)));
|
selector->interpolator = tvg::malloc<LottieInterpolator*>(sizeof(LottieInterpolator));
|
||||||
}
|
}
|
||||||
else if (KEY_AS("ne")) parseProperty<LottieProperty::Type::Float>(selector->minEase);
|
else if (KEY_AS("ne")) parseProperty<LottieProperty::Type::Float>(selector->minEase);
|
||||||
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Float>(selector->maxAmount);
|
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Float>(selector->maxAmount);
|
||||||
|
@ -1467,8 +1467,8 @@ void LottieParser::postProcess(Array<LottieGlyph*>& glyphs)
|
||||||
auto& font = comp->fonts[i];
|
auto& font = comp->fonts[i];
|
||||||
if (!strcmp(font->family, glyph->family) && !strcmp(font->style, glyph->style)) {
|
if (!strcmp(font->family, glyph->family) && !strcmp(font->style, glyph->style)) {
|
||||||
font->chars.push(glyph);
|
font->chars.push(glyph);
|
||||||
free(glyph->family);
|
tvg::free(glyph->family);
|
||||||
free(glyph->style);
|
tvg::free(glyph->style);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1570,7 +1570,7 @@ bool LottieParser::apply(LottieSlot* slot, bool byDefault)
|
||||||
|
|
||||||
void LottieParser::captureSlots(const char* key)
|
void LottieParser::captureSlots(const char* key)
|
||||||
{
|
{
|
||||||
free(slots);
|
tvg::free(slots);
|
||||||
|
|
||||||
// TODO: Replace with immediate parsing, once the slot spec is confirmed by the LAC
|
// TODO: Replace with immediate parsing, once the slot spec is confirmed by the LAC
|
||||||
|
|
||||||
|
@ -1600,7 +1600,7 @@ void LottieParser::captureSlots(const char* key)
|
||||||
|
|
||||||
//composite '{' + slots + '}'
|
//composite '{' + slots + '}'
|
||||||
auto len = (end - begin + 2);
|
auto len = (end - begin + 2);
|
||||||
slots = (char*)malloc(sizeof(char) * len + 1);
|
slots = tvg::malloc<char*>(sizeof(char) * len + 1);
|
||||||
slots[0] = '{';
|
slots[0] = '{';
|
||||||
memcpy(slots + 1, begin, len);
|
memcpy(slots + 1, begin, len);
|
||||||
slots[len] = '\0';
|
slots[len] = '\0';
|
||||||
|
|
|
@ -158,7 +158,7 @@ struct LottieExpression
|
||||||
|
|
||||||
~LottieExpression()
|
~LottieExpression()
|
||||||
{
|
{
|
||||||
free(code);
|
tvg::free(code);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -415,17 +415,17 @@ struct LottiePathSet : LottieProperty
|
||||||
exp = nullptr;
|
exp = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(value.cmds);
|
tvg::free(value.cmds);
|
||||||
free(value.pts);
|
tvg::free(value.pts);
|
||||||
|
|
||||||
if (!frames) return;
|
if (!frames) return;
|
||||||
|
|
||||||
ARRAY_FOREACH(p, *frames) {
|
ARRAY_FOREACH(p, *frames) {
|
||||||
free((*p).value.cmds);
|
tvg::free((*p).value.cmds);
|
||||||
free((*p).value.pts);
|
tvg::free((*p).value.pts);
|
||||||
}
|
}
|
||||||
free(frames->data);
|
tvg::free(frames->data);
|
||||||
free(frames);
|
tvg::free(frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t nearest(float frameNo) override
|
uint32_t nearest(float frameNo) override
|
||||||
|
@ -446,7 +446,7 @@ struct LottiePathSet : LottieProperty
|
||||||
LottieScalarFrame<PathSet>& newFrame()
|
LottieScalarFrame<PathSet>& newFrame()
|
||||||
{
|
{
|
||||||
if (!frames) {
|
if (!frames) {
|
||||||
frames = static_cast<Array<LottieScalarFrame<PathSet>>*>(calloc(1, sizeof(Array<LottieScalarFrame<PathSet>>)));
|
frames = tvg::calloc<Array<LottieScalarFrame<PathSet>>*>(1, sizeof(Array<LottieScalarFrame<PathSet>>));
|
||||||
}
|
}
|
||||||
if (frames->count + 1 >= frames->reserved) {
|
if (frames->count + 1 >= frames->reserved) {
|
||||||
auto old = frames->reserved;
|
auto old = frames->reserved;
|
||||||
|
@ -500,7 +500,7 @@ struct LottiePathSet : LottieProperty
|
||||||
//interpolate 2 frames
|
//interpolate 2 frames
|
||||||
auto s = frame->value.pts;
|
auto s = frame->value.pts;
|
||||||
auto e = (frame + 1)->value.pts;
|
auto e = (frame + 1)->value.pts;
|
||||||
auto interpPts = (Point*)malloc(frame->value.ptsCnt * sizeof(Point));
|
auto interpPts = tvg::malloc<Point*>(frame->value.ptsCnt * sizeof(Point));
|
||||||
auto p = interpPts;
|
auto p = interpPts;
|
||||||
|
|
||||||
for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e, ++p) {
|
for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e, ++p) {
|
||||||
|
@ -510,7 +510,7 @@ struct LottiePathSet : LottieProperty
|
||||||
|
|
||||||
if (modifier) modifier->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, nullptr, out);
|
if (modifier) modifier->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, nullptr, out);
|
||||||
|
|
||||||
free(interpPts);
|
tvg::free(interpPts);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -610,17 +610,17 @@ struct LottieColorStop : LottieProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.data) {
|
if (value.data) {
|
||||||
free(value.data);
|
tvg::free(value.data);
|
||||||
value.data = nullptr;
|
value.data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!frames) return;
|
if (!frames) return;
|
||||||
|
|
||||||
ARRAY_FOREACH(p, *frames) {
|
ARRAY_FOREACH(p, *frames) {
|
||||||
free((*p).value.data);
|
tvg::free((*p).value.data);
|
||||||
}
|
}
|
||||||
free(frames->data);
|
tvg::free(frames->data);
|
||||||
free(frames);
|
tvg::free(frames);
|
||||||
frames = nullptr;
|
frames = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,7 +642,7 @@ struct LottieColorStop : LottieProperty
|
||||||
LottieScalarFrame<ColorStop>& newFrame()
|
LottieScalarFrame<ColorStop>& newFrame()
|
||||||
{
|
{
|
||||||
if (!frames) {
|
if (!frames) {
|
||||||
frames = static_cast<Array<LottieScalarFrame<ColorStop>>*>(calloc(1, sizeof(Array<LottieScalarFrame<ColorStop>>)));
|
frames = tvg::calloc<Array<LottieScalarFrame<ColorStop>>*>(1, sizeof(Array<LottieScalarFrame<ColorStop>>));
|
||||||
}
|
}
|
||||||
if (frames->count + 1 >= frames->reserved) {
|
if (frames->count + 1 >= frames->reserved) {
|
||||||
auto old = frames->reserved;
|
auto old = frames->reserved;
|
||||||
|
@ -789,19 +789,19 @@ struct LottieTextDoc : LottieProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.text) {
|
if (value.text) {
|
||||||
free(value.text);
|
tvg::free(value.text);
|
||||||
value.text = nullptr;
|
value.text = nullptr;
|
||||||
}
|
}
|
||||||
if (value.name) {
|
if (value.name) {
|
||||||
free(value.name);
|
tvg::free(value.name);
|
||||||
value.name = nullptr;
|
value.name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!frames) return;
|
if (!frames) return;
|
||||||
|
|
||||||
ARRAY_FOREACH(p, *frames) {
|
ARRAY_FOREACH(p, *frames) {
|
||||||
free((*p).value.text);
|
tvg::free((*p).value.text);
|
||||||
free((*p).value.name);
|
tvg::free((*p).value.name);
|
||||||
}
|
}
|
||||||
delete(frames);
|
delete(frames);
|
||||||
frames = nullptr;
|
frames = nullptr;
|
||||||
|
@ -900,8 +900,8 @@ struct LottieBitmap : LottieProperty
|
||||||
|
|
||||||
void release()
|
void release()
|
||||||
{
|
{
|
||||||
free(b64Data);
|
tvg::free(b64Data);
|
||||||
free(mimeType);
|
tvg::free(mimeType);
|
||||||
|
|
||||||
b64Data = nullptr;
|
b64Data = nullptr;
|
||||||
mimeType = nullptr;
|
mimeType = nullptr;
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
3. This notice may not be removed or altered from any sourcedistribution.
|
3. This notice may not be removed or altered from any sourcedistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdlib>
|
#include "tvgCommon.h"
|
||||||
#include "tvgLodePng.h"
|
#include "tvgLodePng.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ static unsigned ucvector_resize(ucvector* p, size_t size)
|
||||||
{
|
{
|
||||||
if (size > p->allocsize) {
|
if (size > p->allocsize) {
|
||||||
size_t newsize = size + (p->allocsize >> 1u);
|
size_t newsize = size + (p->allocsize >> 1u);
|
||||||
void* data = realloc(p->data, newsize);
|
auto data = tvg::realloc(p->data, newsize);
|
||||||
if(data) {
|
if(data) {
|
||||||
p->allocsize = newsize;
|
p->allocsize = newsize;
|
||||||
p->data = (unsigned char*)data;
|
p->data = (unsigned char*)data;
|
||||||
|
@ -456,10 +456,10 @@ static void HuffmanTree_init(HuffmanTree* tree)
|
||||||
|
|
||||||
static void HuffmanTree_cleanup(HuffmanTree* tree)
|
static void HuffmanTree_cleanup(HuffmanTree* tree)
|
||||||
{
|
{
|
||||||
free(tree->codes);
|
tvg::free(tree->codes);
|
||||||
free(tree->lengths);
|
tvg::free(tree->lengths);
|
||||||
free(tree->table_len);
|
tvg::free(tree->table_len);
|
||||||
free(tree->table_value);
|
tvg::free(tree->table_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree)
|
||||||
static const unsigned headsize = 1u << FIRSTBITS; /*size of the first table*/
|
static const unsigned headsize = 1u << FIRSTBITS; /*size of the first table*/
|
||||||
static const unsigned mask = (1u << FIRSTBITS) /*headsize*/ - 1u;
|
static const unsigned mask = (1u << FIRSTBITS) /*headsize*/ - 1u;
|
||||||
size_t i, numpresent, pointer, size; /*total table size*/
|
size_t i, numpresent, pointer, size; /*total table size*/
|
||||||
unsigned* maxlens = (unsigned*)malloc(headsize * sizeof(unsigned));
|
unsigned* maxlens = tvg::malloc<unsigned*>(headsize * sizeof(unsigned));
|
||||||
if (!maxlens) return 83; /*alloc fail*/
|
if (!maxlens) return 83; /*alloc fail*/
|
||||||
|
|
||||||
/* compute maxlens: max total bit length of symbols sharing prefix in the first table*/
|
/* compute maxlens: max total bit length of symbols sharing prefix in the first table*/
|
||||||
|
@ -497,10 +497,10 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree)
|
||||||
unsigned l = maxlens[i];
|
unsigned l = maxlens[i];
|
||||||
if (l > FIRSTBITS) size += (1u << (l - FIRSTBITS));
|
if (l > FIRSTBITS) size += (1u << (l - FIRSTBITS));
|
||||||
}
|
}
|
||||||
tree->table_len = (unsigned char*)malloc(size * sizeof(*tree->table_len));
|
tree->table_len = tvg::malloc<unsigned char*>(size * sizeof(*tree->table_len));
|
||||||
tree->table_value = (unsigned short*)malloc(size * sizeof(*tree->table_value));
|
tree->table_value = tvg::malloc<unsigned short*>(size * sizeof(*tree->table_value));
|
||||||
if (!tree->table_len || !tree->table_value) {
|
if (!tree->table_len || !tree->table_value) {
|
||||||
free(maxlens);
|
tvg::free(maxlens);
|
||||||
/* freeing tree->table values is done at a higher scope */
|
/* freeing tree->table values is done at a higher scope */
|
||||||
return 83; /*alloc fail*/
|
return 83; /*alloc fail*/
|
||||||
}
|
}
|
||||||
|
@ -516,7 +516,7 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree)
|
||||||
tree->table_value[i] = pointer;
|
tree->table_value[i] = pointer;
|
||||||
pointer += (1u << (l - FIRSTBITS));
|
pointer += (1u << (l - FIRSTBITS));
|
||||||
}
|
}
|
||||||
free(maxlens);
|
tvg::free(maxlens);
|
||||||
|
|
||||||
/*fill in the first table for short symbols, or secondary table for long symbols*/
|
/*fill in the first table for short symbols, or secondary table for long symbols*/
|
||||||
numpresent = 0;
|
numpresent = 0;
|
||||||
|
@ -600,9 +600,9 @@ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
|
||||||
unsigned error = 0;
|
unsigned error = 0;
|
||||||
unsigned bits, n;
|
unsigned bits, n;
|
||||||
|
|
||||||
tree->codes = (unsigned*)malloc(tree->numcodes * sizeof(unsigned));
|
tree->codes = tvg::malloc<unsigned*>(tree->numcodes * sizeof(unsigned));
|
||||||
blcount = (unsigned*)malloc((tree->maxbitlen + 1) * sizeof(unsigned));
|
blcount = tvg::malloc<unsigned*>((tree->maxbitlen + 1) * sizeof(unsigned));
|
||||||
nextcode = (unsigned*)malloc((tree->maxbitlen + 1) * sizeof(unsigned));
|
nextcode = tvg::malloc<unsigned*>((tree->maxbitlen + 1) * sizeof(unsigned));
|
||||||
if (!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/
|
if (!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
@ -623,8 +623,8 @@ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(blcount);
|
tvg::free(blcount);
|
||||||
free(nextcode);
|
tvg::free(nextcode);
|
||||||
|
|
||||||
if (!error) error = HuffmanTree_makeTable(tree);
|
if (!error) error = HuffmanTree_makeTable(tree);
|
||||||
return error;
|
return error;
|
||||||
|
@ -639,7 +639,7 @@ static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
|
||||||
static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* bitlen, size_t numcodes, unsigned maxbitlen)
|
static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* bitlen, size_t numcodes, unsigned maxbitlen)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
tree->lengths = (unsigned*)malloc(numcodes * sizeof(unsigned));
|
tree->lengths = tvg::malloc<unsigned*>(numcodes * sizeof(unsigned));
|
||||||
if (!tree->lengths) return 83; /*alloc fail*/
|
if (!tree->lengths) return 83; /*alloc fail*/
|
||||||
for (i = 0; i != numcodes; ++i) tree->lengths[i] = bitlen[i];
|
for (i = 0; i != numcodes; ++i) tree->lengths[i] = bitlen[i];
|
||||||
tree->numcodes = (unsigned)numcodes; /*number of symbols*/
|
tree->numcodes = (unsigned)numcodes; /*number of symbols*/
|
||||||
|
@ -652,7 +652,7 @@ static unsigned HuffmanTree_makeFromLengths(HuffmanTree* tree, const unsigned* b
|
||||||
static unsigned generateFixedLitLenTree(HuffmanTree* tree)
|
static unsigned generateFixedLitLenTree(HuffmanTree* tree)
|
||||||
{
|
{
|
||||||
unsigned i, error = 0;
|
unsigned i, error = 0;
|
||||||
unsigned* bitlen = (unsigned*)malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned));
|
unsigned* bitlen = tvg::malloc<unsigned*>(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned));
|
||||||
if (!bitlen) return 83; /*alloc fail*/
|
if (!bitlen) return 83; /*alloc fail*/
|
||||||
|
|
||||||
/*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/
|
/*288 possible codes: 0-255=literals, 256=endcode, 257-285=lengthcodes, 286-287=unused*/
|
||||||
|
@ -663,7 +663,7 @@ static unsigned generateFixedLitLenTree(HuffmanTree* tree)
|
||||||
|
|
||||||
error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DEFLATE_CODE_SYMBOLS, 15);
|
error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DEFLATE_CODE_SYMBOLS, 15);
|
||||||
|
|
||||||
free(bitlen);
|
tvg::free(bitlen);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,14 +672,14 @@ static unsigned generateFixedLitLenTree(HuffmanTree* tree)
|
||||||
static unsigned generateFixedDistanceTree(HuffmanTree* tree)
|
static unsigned generateFixedDistanceTree(HuffmanTree* tree)
|
||||||
{
|
{
|
||||||
unsigned i, error = 0;
|
unsigned i, error = 0;
|
||||||
unsigned* bitlen = (unsigned*)malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned));
|
unsigned* bitlen = tvg::malloc<unsigned*>(NUM_DISTANCE_SYMBOLS * sizeof(unsigned));
|
||||||
if (!bitlen) return 83; /*alloc fail*/
|
if (!bitlen) return 83; /*alloc fail*/
|
||||||
|
|
||||||
/*there are 32 distance codes, but 30-31 are unused*/
|
/*there are 32 distance codes, but 30-31 are unused*/
|
||||||
for (i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen[i] = 5;
|
for (i = 0; i != NUM_DISTANCE_SYMBOLS; ++i) bitlen[i] = 5;
|
||||||
error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DISTANCE_SYMBOLS, 15);
|
error = HuffmanTree_makeFromLengths(tree, bitlen, NUM_DISTANCE_SYMBOLS, 15);
|
||||||
|
|
||||||
free(bitlen);
|
tvg::free(bitlen);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,7 +742,7 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
|
||||||
/*number of code length codes. Unlike the spec, the value 4 is added to it here already*/
|
/*number of code length codes. Unlike the spec, the value 4 is added to it here already*/
|
||||||
HCLEN = readBits(reader, 4) + 4;
|
HCLEN = readBits(reader, 4) + 4;
|
||||||
|
|
||||||
bitlen_cl = (unsigned*)malloc(NUM_CODE_LENGTH_CODES * sizeof(unsigned));
|
bitlen_cl = tvg::malloc<unsigned*>(NUM_CODE_LENGTH_CODES * sizeof(unsigned));
|
||||||
if(!bitlen_cl) return 83 /*alloc fail*/;
|
if(!bitlen_cl) return 83 /*alloc fail*/;
|
||||||
|
|
||||||
HuffmanTree_init(&tree_cl);
|
HuffmanTree_init(&tree_cl);
|
||||||
|
@ -764,8 +764,8 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
|
||||||
if(error) break;
|
if(error) break;
|
||||||
|
|
||||||
/*now we can use this tree to read the lengths for the tree that this function will return*/
|
/*now we can use this tree to read the lengths for the tree that this function will return*/
|
||||||
bitlen_ll = (unsigned*)malloc(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned));
|
bitlen_ll = tvg::malloc<unsigned*>(NUM_DEFLATE_CODE_SYMBOLS * sizeof(unsigned));
|
||||||
bitlen_d = (unsigned*)malloc(NUM_DISTANCE_SYMBOLS * sizeof(unsigned));
|
bitlen_d = tvg::malloc<unsigned*>(NUM_DISTANCE_SYMBOLS * sizeof(unsigned));
|
||||||
if (!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/);
|
if (!bitlen_ll || !bitlen_d) ERROR_BREAK(83 /*alloc fail*/);
|
||||||
lodepng_memset(bitlen_ll, 0, NUM_DEFLATE_CODE_SYMBOLS * sizeof(*bitlen_ll));
|
lodepng_memset(bitlen_ll, 0, NUM_DEFLATE_CODE_SYMBOLS * sizeof(*bitlen_ll));
|
||||||
lodepng_memset(bitlen_d, 0, NUM_DISTANCE_SYMBOLS * sizeof(*bitlen_d));
|
lodepng_memset(bitlen_d, 0, NUM_DISTANCE_SYMBOLS * sizeof(*bitlen_d));
|
||||||
|
@ -844,9 +844,9 @@ static unsigned getTreeInflateDynamic(HuffmanTree* tree_ll, HuffmanTree* tree_d,
|
||||||
break; /*end of error-while*/
|
break; /*end of error-while*/
|
||||||
}
|
}
|
||||||
|
|
||||||
free(bitlen_cl);
|
tvg::free(bitlen_cl);
|
||||||
free(bitlen_ll);
|
tvg::free(bitlen_ll);
|
||||||
free(bitlen_d);
|
tvg::free(bitlen_d);
|
||||||
HuffmanTree_cleanup(&tree_cl);
|
HuffmanTree_cleanup(&tree_cl);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
@ -1366,7 +1366,7 @@ static void lodepng_color_mode_alloc_palette(LodePNGColorMode* info)
|
||||||
size_t i;
|
size_t i;
|
||||||
/*if the palette is already allocated, it will have size 1024 so no reallocation needed in that case*/
|
/*if the palette is already allocated, it will have size 1024 so no reallocation needed in that case*/
|
||||||
/*the palette must have room for up to 256 colors with 4 bytes each.*/
|
/*the palette must have room for up to 256 colors with 4 bytes each.*/
|
||||||
if (!info->palette) info->palette = (unsigned char*)malloc(1024);
|
if (!info->palette) info->palette = tvg::malloc<unsigned char*>(1024);
|
||||||
if (!info->palette) return; /*alloc fail*/
|
if (!info->palette) return; /*alloc fail*/
|
||||||
for (i = 0; i != 256; ++i) {
|
for (i = 0; i != 256; ++i) {
|
||||||
/*Initialize all unused colors with black, the value used for invalid palette indices.
|
/*Initialize all unused colors with black, the value used for invalid palette indices.
|
||||||
|
@ -1381,7 +1381,7 @@ static void lodepng_color_mode_alloc_palette(LodePNGColorMode* info)
|
||||||
|
|
||||||
static void lodepng_palette_clear(LodePNGColorMode* info)
|
static void lodepng_palette_clear(LodePNGColorMode* info)
|
||||||
{
|
{
|
||||||
if (info->palette) free(info->palette);
|
if (info->palette) tvg::free(info->palette);
|
||||||
info->palette = 0;
|
info->palette = 0;
|
||||||
info->palettesize = 0;
|
info->palettesize = 0;
|
||||||
}
|
}
|
||||||
|
@ -1399,7 +1399,7 @@ static unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGCol
|
||||||
lodepng_color_mode_cleanup(dest);
|
lodepng_color_mode_cleanup(dest);
|
||||||
lodepng_memcpy(dest, source, sizeof(LodePNGColorMode));
|
lodepng_memcpy(dest, source, sizeof(LodePNGColorMode));
|
||||||
if (source->palette) {
|
if (source->palette) {
|
||||||
dest->palette = (unsigned char*)malloc(1024);
|
dest->palette = tvg::malloc<unsigned char*>(1024);
|
||||||
if (!dest->palette && source->palettesize) return 83; /*alloc fail*/
|
if (!dest->palette && source->palettesize) return 83; /*alloc fail*/
|
||||||
lodepng_memcpy(dest->palette, source->palette, source->palettesize * 4);
|
lodepng_memcpy(dest->palette, source->palette, source->palettesize * 4);
|
||||||
}
|
}
|
||||||
|
@ -1531,7 +1531,7 @@ static void color_tree_cleanup(ColorTree* tree)
|
||||||
for (i = 0; i != 16; ++i) {
|
for (i = 0; i != 16; ++i) {
|
||||||
if(tree->children[i]) {
|
if(tree->children[i]) {
|
||||||
color_tree_cleanup(tree->children[i]);
|
color_tree_cleanup(tree->children[i]);
|
||||||
free(tree->children[i]);
|
tvg::free(tree->children[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1559,7 +1559,7 @@ static unsigned color_tree_add(ColorTree* tree, unsigned char r, unsigned char g
|
||||||
for (bit = 0; bit < 8; ++bit) {
|
for (bit = 0; bit < 8; ++bit) {
|
||||||
int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1);
|
int i = 8 * ((r >> bit) & 1) + 4 * ((g >> bit) & 1) + 2 * ((b >> bit) & 1) + 1 * ((a >> bit) & 1);
|
||||||
if (!tree->children[i]) {
|
if (!tree->children[i]) {
|
||||||
tree->children[i] = (ColorTree*)malloc(sizeof(ColorTree));
|
tree->children[i] = tvg::malloc<ColorTree*>(sizeof(ColorTree));
|
||||||
if (!tree->children[i]) return 83; /*alloc fail*/
|
if (!tree->children[i]) return 83; /*alloc fail*/
|
||||||
color_tree_init(tree->children[i]);
|
color_tree_init(tree->children[i]);
|
||||||
}
|
}
|
||||||
|
@ -2386,7 +2386,7 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, LodePNG
|
||||||
}
|
}
|
||||||
|
|
||||||
/*the input filesize is a safe upper bound for the sum of idat chunks size*/
|
/*the input filesize is a safe upper bound for the sum of idat chunks size*/
|
||||||
idat = (unsigned char*)malloc(insize);
|
idat = tvg::malloc<unsigned char*>(insize);
|
||||||
if (!idat) CERROR_RETURN(state->error, 83); /*alloc fail*/
|
if (!idat) CERROR_RETURN(state->error, 83); /*alloc fail*/
|
||||||
|
|
||||||
chunk = &in[33]; /*first byte of the first chunk after the header*/
|
chunk = &in[33]; /*first byte of the first chunk after the header*/
|
||||||
|
@ -2482,18 +2482,18 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h, LodePNG
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state->error && scanlines_size != expected_size) state->error = 91; /*decompressed size doesn't match prediction*/
|
if (!state->error && scanlines_size != expected_size) state->error = 91; /*decompressed size doesn't match prediction*/
|
||||||
free(idat);
|
tvg::free(idat);
|
||||||
|
|
||||||
if (!state->error) {
|
if (!state->error) {
|
||||||
outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color);
|
outsize = lodepng_get_raw_size(*w, *h, &state->info_png.color);
|
||||||
*out = (unsigned char*)malloc(outsize);
|
*out = tvg::malloc<unsigned char*>(outsize);
|
||||||
if (!*out) state->error = 83; /*alloc fail*/
|
if (!*out) state->error = 83; /*alloc fail*/
|
||||||
}
|
}
|
||||||
if (!state->error) {
|
if (!state->error) {
|
||||||
lodepng_memset(*out, 0, outsize);
|
lodepng_memset(*out, 0, outsize);
|
||||||
state->error = postProcessScanlines(*out, scanlines, *w, *h, &state->info_png);
|
state->error = postProcessScanlines(*out, scanlines, *w, *h, &state->info_png);
|
||||||
}
|
}
|
||||||
free(scanlines);
|
tvg::free(scanlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2601,12 +2601,12 @@ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, LodePNGSt
|
||||||
}
|
}
|
||||||
|
|
||||||
outsize = lodepng_get_raw_size(*w, *h, &state->info_raw);
|
outsize = lodepng_get_raw_size(*w, *h, &state->info_raw);
|
||||||
*out = (unsigned char*)malloc(outsize);
|
*out = tvg::malloc<unsigned char*>(outsize);
|
||||||
if (!(*out)) {
|
if (!(*out)) {
|
||||||
state->error = 83; /*alloc fail*/
|
state->error = 83; /*alloc fail*/
|
||||||
}
|
}
|
||||||
else state->error = lodepng_convert(*out, data, &state->info_raw, &state->info_png.color, *w, *h);
|
else state->error = lodepng_convert(*out, data, &state->info_raw, &state->info_png.color, *w, *h);
|
||||||
free(data);
|
tvg::free(data);
|
||||||
}
|
}
|
||||||
return state->error;
|
return state->error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,8 @@ PngLoader::PngLoader() : ImageLoader(FileType::Png)
|
||||||
|
|
||||||
PngLoader::~PngLoader()
|
PngLoader::~PngLoader()
|
||||||
{
|
{
|
||||||
if (freeData) free(data);
|
if (freeData) tvg::free(data);
|
||||||
free(surface.buf8);
|
tvg::free(surface.buf8);
|
||||||
lodepng_state_cleanup(&state);
|
lodepng_state_cleanup(&state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ bool PngLoader::open(const char* path)
|
||||||
if (((size = ftell(pngFile)) < 1)) goto finalize;
|
if (((size = ftell(pngFile)) < 1)) goto finalize;
|
||||||
if (fseek(pngFile, 0, SEEK_SET)) goto finalize;
|
if (fseek(pngFile, 0, SEEK_SET)) goto finalize;
|
||||||
|
|
||||||
data = (unsigned char *) malloc(size);
|
data = tvg::malloc<unsigned char*>(size);
|
||||||
if (!data) goto finalize;
|
if (!data) goto finalize;
|
||||||
|
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
@ -114,7 +114,7 @@ bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpa
|
||||||
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false;
|
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false;
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
this->data = (unsigned char *) malloc(size);
|
this->data = tvg::malloc<unsigned char*>(size);
|
||||||
if (!this->data) return false;
|
if (!this->data) return false;
|
||||||
memcpy((unsigned char *)this->data, data, size);
|
memcpy((unsigned char *)this->data, data, size);
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string.h>
|
|
||||||
#include "tvgLoader.h"
|
#include "tvgLoader.h"
|
||||||
#include "tvgRawLoader.h"
|
#include "tvgRawLoader.h"
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ RawLoader::RawLoader() : ImageLoader(FileType::Raw)
|
||||||
|
|
||||||
RawLoader::~RawLoader()
|
RawLoader::~RawLoader()
|
||||||
{
|
{
|
||||||
if (copy) free(surface.buf32);
|
if (copy) tvg::free(surface.buf32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs
|
||||||
this->copy = copy;
|
this->copy = copy;
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
surface.buf32 = (uint32_t*)malloc(sizeof(uint32_t) * w * h);
|
surface.buf32 = tvg::malloc<uint32_t*>(sizeof(uint32_t) * w * h);
|
||||||
if (!surface.buf32) return false;
|
if (!surface.buf32) return false;
|
||||||
memcpy((void*)surface.buf32, data, sizeof(uint32_t) * w * h);
|
memcpy((void*)surface.buf32, data, sizeof(uint32_t) * w * h);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#include "tvgSvgCssStyle.h"
|
#include "tvgSvgCssStyle.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -72,7 +70,7 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->fill.paint.none = from->fill.paint.none;
|
to->fill.paint.none = from->fill.paint.none;
|
||||||
to->fill.paint.curColor = from->fill.paint.curColor;
|
to->fill.paint.curColor = from->fill.paint.curColor;
|
||||||
if (from->fill.paint.url) {
|
if (from->fill.paint.url) {
|
||||||
if (to->fill.paint.url) free(to->fill.paint.url);
|
if (to->fill.paint.url) tvg::free(to->fill.paint.url);
|
||||||
to->fill.paint.url = strdup(from->fill.paint.url);
|
to->fill.paint.url = strdup(from->fill.paint.url);
|
||||||
}
|
}
|
||||||
to->fill.flags = (to->fill.flags | SvgFillFlags::Paint);
|
to->fill.flags = (to->fill.flags | SvgFillFlags::Paint);
|
||||||
|
@ -106,7 +104,7 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->stroke.paint.none = from->stroke.paint.none;
|
to->stroke.paint.none = from->stroke.paint.none;
|
||||||
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
||||||
if (from->stroke.paint.url) {
|
if (from->stroke.paint.url) {
|
||||||
if (to->stroke.paint.url) free(to->stroke.paint.url);
|
if (to->stroke.paint.url) tvg::free(to->stroke.paint.url);
|
||||||
to->stroke.paint.url = strdup(from->stroke.paint.url);
|
to->stroke.paint.url = strdup(from->stroke.paint.url);
|
||||||
}
|
}
|
||||||
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Paint);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Paint);
|
||||||
|
@ -187,7 +185,7 @@ void cssCopyStyleAttr(SvgNode* to, const SvgNode* from)
|
||||||
{
|
{
|
||||||
//Copy matrix attribute
|
//Copy matrix attribute
|
||||||
if (from->transform && !(to->style->flags & SvgStyleFlags::Transform)) {
|
if (from->transform && !(to->style->flags & SvgStyleFlags::Transform)) {
|
||||||
to->transform = (Matrix*)malloc(sizeof(Matrix));
|
to->transform = tvg::malloc<Matrix*>(sizeof(Matrix));
|
||||||
if (to->transform) {
|
if (to->transform) {
|
||||||
*to->transform = *from->transform;
|
*to->transform = *from->transform;
|
||||||
to->style->flags = (to->style->flags | SvgStyleFlags::Transform);
|
to->style->flags = (to->style->flags | SvgStyleFlags::Transform);
|
||||||
|
@ -197,11 +195,11 @@ void cssCopyStyleAttr(SvgNode* to, const SvgNode* from)
|
||||||
_copyStyle(to->style, from->style);
|
_copyStyle(to->style, from->style);
|
||||||
|
|
||||||
if (from->style->clipPath.url) {
|
if (from->style->clipPath.url) {
|
||||||
if (to->style->clipPath.url) free(to->style->clipPath.url);
|
if (to->style->clipPath.url) tvg::free(to->style->clipPath.url);
|
||||||
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
||||||
}
|
}
|
||||||
if (from->style->mask.url) {
|
if (from->style->mask.url) {
|
||||||
if (to->style->mask.url) free(to->style->mask.url);
|
if (to->style->mask.url) tvg::free(to->style->mask.url);
|
||||||
to->style->mask.url = strdup(from->style->mask.url);
|
to->style->mask.url = strdup(from->style->mask.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -683,7 +683,7 @@ static bool _toColor(const char* str, uint8_t* r, uint8_t* g, uint8_t* b, char**
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (ref && len >= 3 && !strncmp(str, "url", 3)) {
|
} else if (ref && len >= 3 && !strncmp(str, "url", 3)) {
|
||||||
free(*ref);
|
tvg::free(*ref);
|
||||||
*ref = _idFromUrl((const char*)(str + 3));
|
*ref = _idFromUrl((const char*)(str + 3));
|
||||||
return true;
|
return true;
|
||||||
} else if (len >= 10 && (str[0] == 'h' || str[0] == 'H') && (str[1] == 's' || str[1] == 'S') && (str[2] == 'l' || str[2] == 'L') && str[3] == '(' && str[len - 1] == ')') {
|
} else if (len >= 10 && (str[0] == 'h' || str[0] == 'H') && (str[1] == 's' || str[1] == 'S') && (str[2] == 'l' || str[2] == 'L') && str[3] == '(' && str[len - 1] == ')') {
|
||||||
|
@ -783,7 +783,7 @@ static Matrix* _parseTransformationMatrix(const char* value)
|
||||||
{
|
{
|
||||||
const int POINT_CNT = 8;
|
const int POINT_CNT = 8;
|
||||||
|
|
||||||
auto matrix = (Matrix*)malloc(sizeof(Matrix));
|
auto matrix = tvg::malloc<Matrix*>(sizeof(Matrix));
|
||||||
identity(matrix);
|
identity(matrix);
|
||||||
|
|
||||||
float points[POINT_CNT];
|
float points[POINT_CNT];
|
||||||
|
@ -866,7 +866,7 @@ static Matrix* _parseTransformationMatrix(const char* value)
|
||||||
}
|
}
|
||||||
return matrix;
|
return matrix;
|
||||||
error:
|
error:
|
||||||
free(matrix);
|
tvg::free(matrix);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1073,7 +1073,7 @@ static void _handleClipPathAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node,
|
||||||
SvgStyleProperty* style = node->style;
|
SvgStyleProperty* style = node->style;
|
||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
if (len >= 3 && !strncmp(value, "url", 3)) {
|
if (len >= 3 && !strncmp(value, "url", 3)) {
|
||||||
free(style->clipPath.url);
|
tvg::free(style->clipPath.url);
|
||||||
style->clipPath.url = _idFromUrl((const char*)(value + 3));
|
style->clipPath.url = _idFromUrl((const char*)(value + 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1084,7 +1084,7 @@ static void _handleMaskAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, con
|
||||||
SvgStyleProperty* style = node->style;
|
SvgStyleProperty* style = node->style;
|
||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
if (len >= 3 && !strncmp(value, "url", 3)) {
|
if (len >= 3 && !strncmp(value, "url", 3)) {
|
||||||
free(style->mask.url);
|
tvg::free(style->mask.url);
|
||||||
style->mask.url = _idFromUrl((const char*)(value + 3));
|
style->mask.url = _idFromUrl((const char*)(value + 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1095,7 +1095,7 @@ static void _handleFilterAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, c
|
||||||
SvgStyleProperty* style = node->style;
|
SvgStyleProperty* style = node->style;
|
||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
if (len >= 3 && !strncmp(value, "url", 3)) {
|
if (len >= 3 && !strncmp(value, "url", 3)) {
|
||||||
if (style->filter.url) free(style->filter.url);
|
if (style->filter.url) tvg::free(style->filter.url);
|
||||||
style->filter.url = _idFromUrl((const char*)(value + 3));
|
style->filter.url = _idFromUrl((const char*)(value + 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1130,7 +1130,7 @@ static void _handleCssClassAttr(SvgLoaderData* loader, SvgNode* node, const char
|
||||||
{
|
{
|
||||||
auto cssClass = &node->style->cssClass;
|
auto cssClass = &node->style->cssClass;
|
||||||
|
|
||||||
if (value) free(*cssClass);
|
if (value) tvg::free(*cssClass);
|
||||||
*cssClass = _copyId(value);
|
*cssClass = _copyId(value);
|
||||||
|
|
||||||
bool cssClassFound = false;
|
bool cssClassFound = false;
|
||||||
|
@ -1217,7 +1217,7 @@ static bool _parseStyleAttr(void* data, const char* key, const char* value, bool
|
||||||
}
|
}
|
||||||
if (importance) {
|
if (importance) {
|
||||||
node->style->flagsImportance = (node->style->flags | styleTags[i].flag);
|
node->style->flagsImportance = (node->style->flags | styleTags[i].flag);
|
||||||
free(const_cast<char*>(value));
|
tvg::free(const_cast<char*>(value));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1246,7 +1246,7 @@ static bool _attrParseGNode(void* data, const char* key, const char* value)
|
||||||
} else if (STR_AS(key, "transform")) {
|
} else if (STR_AS(key, "transform")) {
|
||||||
node->transform = _parseTransformationMatrix(value);
|
node->transform = _parseTransformationMatrix(value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1277,7 +1277,7 @@ static bool _attrParseClipPathNode(void* data, const char* key, const char* valu
|
||||||
} else if (STR_AS(key, "transform")) {
|
} else if (STR_AS(key, "transform")) {
|
||||||
node->transform = _parseTransformationMatrix(value);
|
node->transform = _parseTransformationMatrix(value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1301,7 +1301,7 @@ static bool _attrParseMaskNode(void* data, const char* key, const char* value)
|
||||||
} else if (STR_AS(key, "transform")) {
|
} else if (STR_AS(key, "transform")) {
|
||||||
node->transform = _parseTransformationMatrix(value);
|
node->transform = _parseTransformationMatrix(value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1322,7 +1322,7 @@ static bool _attrParseCssStyleNode(void* data, const char* key, const char* valu
|
||||||
SvgNode* node = loader->svgParse->node;
|
SvgNode* node = loader->svgParse->node;
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else {
|
} else {
|
||||||
return _parseStyleAttr(loader, key, value, false);
|
return _parseStyleAttr(loader, key, value, false);
|
||||||
|
@ -1407,7 +1407,7 @@ static bool _attrParseFilterNode(void* data, const char* key, const char* value)
|
||||||
_parseBox(key, value, &filter->box, filter->isPercentage);
|
_parseBox(key, value, &filter->box, filter->isPercentage);
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (node->id && value) free(node->id);
|
if (node->id && value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "primitiveUnits")) {
|
} else if (STR_AS(key, "primitiveUnits")) {
|
||||||
if (STR_AS(value, "objectBoundingBox")) filter->primitiveUserSpace = false;
|
if (STR_AS(value, "objectBoundingBox")) filter->primitiveUserSpace = false;
|
||||||
|
@ -1448,7 +1448,7 @@ static bool _attrParseGaussianBlurNode(void* data, const char* key, const char*
|
||||||
if (_parseBox(key, value, &gaussianBlur->box, gaussianBlur->isPercentage)) gaussianBlur->hasBox = true;
|
if (_parseBox(key, value, &gaussianBlur->box, gaussianBlur->isPercentage)) gaussianBlur->hasBox = true;
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (node->id && value) free(node->id);
|
if (node->id && value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "stdDeviation")) {
|
} else if (STR_AS(key, "stdDeviation")) {
|
||||||
_parseGaussianBlurStdDeviation(&value, &gaussianBlur->stdDevX, &gaussianBlur->stdDevY);
|
_parseGaussianBlurStdDeviation(&value, &gaussianBlur->stdDevX, &gaussianBlur->stdDevY);
|
||||||
|
@ -1463,15 +1463,15 @@ static bool _attrParseGaussianBlurNode(void* data, const char* key, const char*
|
||||||
|
|
||||||
static SvgNode* _createNode(SvgNode* parent, SvgNodeType type)
|
static SvgNode* _createNode(SvgNode* parent, SvgNodeType type)
|
||||||
{
|
{
|
||||||
SvgNode* node = (SvgNode*)calloc(1, sizeof(SvgNode));
|
SvgNode* node = tvg::calloc<SvgNode*>(1, sizeof(SvgNode));
|
||||||
|
|
||||||
if (!node) return nullptr;
|
if (!node) return nullptr;
|
||||||
|
|
||||||
//Default fill property
|
//Default fill property
|
||||||
node->style = (SvgStyleProperty*)calloc(1, sizeof(SvgStyleProperty));
|
node->style = tvg::calloc<SvgStyleProperty*>(1, sizeof(SvgStyleProperty));
|
||||||
|
|
||||||
if (!node->style) {
|
if (!node->style) {
|
||||||
free(node);
|
tvg::free(node);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1640,7 +1640,7 @@ static bool _attrParsePathNode(void* data, const char* key, const char* value)
|
||||||
SvgPathNode* path = &(node->node.path);
|
SvgPathNode* path = &(node->node.path);
|
||||||
|
|
||||||
if (STR_AS(key, "d")) {
|
if (STR_AS(key, "d")) {
|
||||||
free(path->path);
|
tvg::free(path->path);
|
||||||
//Temporary: need to copy
|
//Temporary: need to copy
|
||||||
path->path = _copyId(value);
|
path->path = _copyId(value);
|
||||||
} else if (STR_AS(key, "style")) {
|
} else if (STR_AS(key, "style")) {
|
||||||
|
@ -1652,7 +1652,7 @@ static bool _attrParsePathNode(void* data, const char* key, const char* value)
|
||||||
} else if (STR_AS(key, "filter")) {
|
} else if (STR_AS(key, "filter")) {
|
||||||
_handleFilterAttr(loader, node, value);
|
_handleFilterAttr(loader, node, value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1716,7 +1716,7 @@ static bool _attrParseCircleNode(void* data, const char* key, const char* value)
|
||||||
} else if (STR_AS(key, "filter")) {
|
} else if (STR_AS(key, "filter")) {
|
||||||
_handleFilterAttr(loader, node, value);
|
_handleFilterAttr(loader, node, value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1772,7 +1772,7 @@ static bool _attrParseEllipseNode(void* data, const char* key, const char* value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1836,7 +1836,7 @@ static bool _attrParsePolygonNode(void* data, const char* key, const char* value
|
||||||
} else if (STR_AS(key, "filter")) {
|
} else if (STR_AS(key, "filter")) {
|
||||||
_handleFilterAttr(loader, node, value);
|
_handleFilterAttr(loader, node, value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1912,7 +1912,7 @@ static bool _attrParseRectNode(void* data, const char* key, const char* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -1977,7 +1977,7 @@ static bool _attrParseLineNode(void* data, const char* key, const char* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -2049,10 +2049,10 @@ static bool _attrParseImageNode(void* data, const char* key, const char* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) {
|
if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) {
|
||||||
if (value) free(image->href);
|
if (value) tvg::free(image->href);
|
||||||
image->href = _idFromHref(value);
|
image->href = _idFromHref(value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -2175,7 +2175,7 @@ static bool _attrParseUseNode(void* data, const char* key, const char* value)
|
||||||
} else {
|
} else {
|
||||||
TVGLOG("SVG", "%s is ancestor element. This reference is invalid.", id);
|
TVGLOG("SVG", "%s is ancestor element. This reference is invalid.", id);
|
||||||
}
|
}
|
||||||
free(id);
|
tvg::free(id);
|
||||||
} else {
|
} else {
|
||||||
//some svg export software include <defs> element at the end of the file
|
//some svg export software include <defs> element at the end of the file
|
||||||
//if so the 'from' element won't be found now and we have to repeat finding
|
//if so the 'from' element won't be found now and we have to repeat finding
|
||||||
|
@ -2232,7 +2232,7 @@ static bool _attrParseTextNode(void* data, const char* key, const char* value)
|
||||||
|
|
||||||
if (STR_AS(key, "font-family")) {
|
if (STR_AS(key, "font-family")) {
|
||||||
if (value) {
|
if (value) {
|
||||||
free(text->fontFamily);
|
tvg::free(text->fontFamily);
|
||||||
text->fontFamily = strdup(value);
|
text->fontFamily = strdup(value);
|
||||||
}
|
}
|
||||||
} else if (STR_AS(key, "style")) {
|
} else if (STR_AS(key, "style")) {
|
||||||
|
@ -2244,7 +2244,7 @@ static bool _attrParseTextNode(void* data, const char* key, const char* value)
|
||||||
} else if (STR_AS(key, "filter")) {
|
} else if (STR_AS(key, "filter")) {
|
||||||
_handleFilterAttr(loader, node, value);
|
_handleFilterAttr(loader, node, value);
|
||||||
} else if (STR_AS(key, "id")) {
|
} else if (STR_AS(key, "id")) {
|
||||||
if (value) free(node->id);
|
if (value) tvg::free(node->id);
|
||||||
node->id = _copyId(value);
|
node->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "class")) {
|
} else if (STR_AS(key, "class")) {
|
||||||
_handleCssClassAttr(loader, node, value);
|
_handleCssClassAttr(loader, node, value);
|
||||||
|
@ -2571,13 +2571,13 @@ static bool _attrParseRadialGradientNode(void* data, const char* key, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (value) free(grad->id);
|
if (value) tvg::free(grad->id);
|
||||||
grad->id = _copyId(value);
|
grad->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "spreadMethod")) {
|
} else if (STR_AS(key, "spreadMethod")) {
|
||||||
grad->spread = _parseSpreadValue(value);
|
grad->spread = _parseSpreadValue(value);
|
||||||
grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod);
|
grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod);
|
||||||
} else if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) {
|
} else if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) {
|
||||||
if (value) free(grad->ref);
|
if (value) tvg::free(grad->ref);
|
||||||
grad->ref = _idFromHref(value);
|
grad->ref = _idFromHref(value);
|
||||||
} else if (STR_AS(key, "gradientUnits")) {
|
} else if (STR_AS(key, "gradientUnits")) {
|
||||||
if (STR_AS(value, "userSpaceOnUse")) grad->userSpace = true;
|
if (STR_AS(value, "userSpaceOnUse")) grad->userSpace = true;
|
||||||
|
@ -2594,15 +2594,15 @@ static bool _attrParseRadialGradientNode(void* data, const char* key, const char
|
||||||
|
|
||||||
static SvgStyleGradient* _createRadialGradient(SvgLoaderData* loader, const char* buf, unsigned bufLength)
|
static SvgStyleGradient* _createRadialGradient(SvgLoaderData* loader, const char* buf, unsigned bufLength)
|
||||||
{
|
{
|
||||||
auto grad = (SvgStyleGradient*)(calloc(1, sizeof(SvgStyleGradient)));
|
auto grad = tvg::calloc<SvgStyleGradient*>(1, sizeof(SvgStyleGradient));
|
||||||
loader->svgParse->styleGrad = grad;
|
loader->svgParse->styleGrad = grad;
|
||||||
|
|
||||||
grad->flags = SvgGradientFlags::None;
|
grad->flags = SvgGradientFlags::None;
|
||||||
grad->type = SvgGradientType::Radial;
|
grad->type = SvgGradientType::Radial;
|
||||||
grad->radial = (SvgRadialGradient*)calloc(1, sizeof(SvgRadialGradient));
|
grad->radial = tvg::calloc<SvgRadialGradient*>(1, sizeof(SvgRadialGradient));
|
||||||
if (!grad->radial) {
|
if (!grad->radial) {
|
||||||
grad->clear();
|
grad->clear();
|
||||||
free(grad);
|
tvg::free(grad);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -2862,13 +2862,13 @@ static bool _attrParseLinearGradientNode(void* data, const char* key, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_AS(key, "id")) {
|
if (STR_AS(key, "id")) {
|
||||||
if (value) free(grad->id);
|
if (value) tvg::free(grad->id);
|
||||||
grad->id = _copyId(value);
|
grad->id = _copyId(value);
|
||||||
} else if (STR_AS(key, "spreadMethod")) {
|
} else if (STR_AS(key, "spreadMethod")) {
|
||||||
grad->spread = _parseSpreadValue(value);
|
grad->spread = _parseSpreadValue(value);
|
||||||
grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod);
|
grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod);
|
||||||
} else if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) {
|
} else if (STR_AS(key, "href") || STR_AS(key, "xlink:href")) {
|
||||||
if (value) free(grad->ref);
|
if (value) tvg::free(grad->ref);
|
||||||
grad->ref = _idFromHref(value);
|
grad->ref = _idFromHref(value);
|
||||||
} else if (STR_AS(key, "gradientUnits")) {
|
} else if (STR_AS(key, "gradientUnits")) {
|
||||||
if (STR_AS(value, "userSpaceOnUse")) grad->userSpace = true;
|
if (STR_AS(value, "userSpaceOnUse")) grad->userSpace = true;
|
||||||
|
@ -2885,15 +2885,15 @@ static bool _attrParseLinearGradientNode(void* data, const char* key, const char
|
||||||
|
|
||||||
static SvgStyleGradient* _createLinearGradient(SvgLoaderData* loader, const char* buf, unsigned bufLength)
|
static SvgStyleGradient* _createLinearGradient(SvgLoaderData* loader, const char* buf, unsigned bufLength)
|
||||||
{
|
{
|
||||||
auto grad = (SvgStyleGradient*)(calloc(1, sizeof(SvgStyleGradient)));
|
auto grad = tvg::calloc<SvgStyleGradient*>(1, sizeof(SvgStyleGradient));
|
||||||
loader->svgParse->styleGrad = grad;
|
loader->svgParse->styleGrad = grad;
|
||||||
|
|
||||||
grad->flags = SvgGradientFlags::None;
|
grad->flags = SvgGradientFlags::None;
|
||||||
grad->type = SvgGradientType::Linear;
|
grad->type = SvgGradientType::Linear;
|
||||||
grad->linear = (SvgLinearGradient*)calloc(1, sizeof(SvgLinearGradient));
|
grad->linear = tvg::calloc<SvgLinearGradient*>(1, sizeof(SvgLinearGradient));
|
||||||
if (!grad->linear) {
|
if (!grad->linear) {
|
||||||
grad->clear();
|
grad->clear();
|
||||||
free(grad);
|
tvg::free(grad);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -2970,7 +2970,7 @@ static void _inheritGradient(SvgLoaderData* loader, SvgStyleGradient* to, SvgSty
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!to->transform && from->transform) {
|
if (!to->transform && from->transform) {
|
||||||
to->transform = (Matrix*)malloc(sizeof(Matrix));
|
to->transform = tvg::malloc<Matrix*>(sizeof(Matrix));
|
||||||
if (to->transform) memcpy(to->transform, from->transform, sizeof(Matrix));
|
if (to->transform) memcpy(to->transform, from->transform, sizeof(Matrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3024,7 +3024,7 @@ static SvgStyleGradient* _cloneGradient(SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
if (!from) return nullptr;
|
if (!from) return nullptr;
|
||||||
|
|
||||||
auto grad = (SvgStyleGradient*)(calloc(1, sizeof(SvgStyleGradient)));
|
auto grad = tvg::calloc<SvgStyleGradient*>(1, sizeof(SvgStyleGradient));
|
||||||
if (!grad) return nullptr;
|
if (!grad) return nullptr;
|
||||||
|
|
||||||
grad->type = from->type;
|
grad->type = from->type;
|
||||||
|
@ -3035,16 +3035,16 @@ static SvgStyleGradient* _cloneGradient(SvgStyleGradient* from)
|
||||||
grad->flags = from->flags;
|
grad->flags = from->flags;
|
||||||
|
|
||||||
if (from->transform) {
|
if (from->transform) {
|
||||||
grad->transform = (Matrix*)calloc(1, sizeof(Matrix));
|
grad->transform = tvg::calloc<Matrix*>(1, sizeof(Matrix));
|
||||||
if (grad->transform) memcpy(grad->transform, from->transform, sizeof(Matrix));
|
if (grad->transform) memcpy(grad->transform, from->transform, sizeof(Matrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grad->type == SvgGradientType::Linear) {
|
if (grad->type == SvgGradientType::Linear) {
|
||||||
grad->linear = (SvgLinearGradient*)calloc(1, sizeof(SvgLinearGradient));
|
grad->linear = tvg::calloc<SvgLinearGradient*>(1, sizeof(SvgLinearGradient));
|
||||||
if (!grad->linear) goto error_grad_alloc;
|
if (!grad->linear) goto error_grad_alloc;
|
||||||
memcpy(grad->linear, from->linear, sizeof(SvgLinearGradient));
|
memcpy(grad->linear, from->linear, sizeof(SvgLinearGradient));
|
||||||
} else if (grad->type == SvgGradientType::Radial) {
|
} else if (grad->type == SvgGradientType::Radial) {
|
||||||
grad->radial = (SvgRadialGradient*)calloc(1, sizeof(SvgRadialGradient));
|
grad->radial = tvg::calloc<SvgRadialGradient*>(1, sizeof(SvgRadialGradient));
|
||||||
if (!grad->radial) goto error_grad_alloc;
|
if (!grad->radial) goto error_grad_alloc;
|
||||||
memcpy(grad->radial, from->radial, sizeof(SvgRadialGradient));
|
memcpy(grad->radial, from->radial, sizeof(SvgRadialGradient));
|
||||||
}
|
}
|
||||||
|
@ -3056,7 +3056,7 @@ static SvgStyleGradient* _cloneGradient(SvgStyleGradient* from)
|
||||||
error_grad_alloc:
|
error_grad_alloc:
|
||||||
if (grad) {
|
if (grad) {
|
||||||
grad->clear();
|
grad->clear();
|
||||||
free(grad);
|
tvg::free(grad);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -3079,7 +3079,7 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
child->fill.paint.none = parent->fill.paint.none;
|
child->fill.paint.none = parent->fill.paint.none;
|
||||||
child->fill.paint.curColor = parent->fill.paint.curColor;
|
child->fill.paint.curColor = parent->fill.paint.curColor;
|
||||||
if (parent->fill.paint.url) {
|
if (parent->fill.paint.url) {
|
||||||
free(child->fill.paint.url);
|
tvg::free(child->fill.paint.url);
|
||||||
child->fill.paint.url = _copyId(parent->fill.paint.url);
|
child->fill.paint.url = _copyId(parent->fill.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3095,7 +3095,7 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
child->stroke.paint.none = parent->stroke.paint.none;
|
child->stroke.paint.none = parent->stroke.paint.none;
|
||||||
child->stroke.paint.curColor = parent->stroke.paint.curColor;
|
child->stroke.paint.curColor = parent->stroke.paint.curColor;
|
||||||
if (parent->stroke.paint.url) {
|
if (parent->stroke.paint.url) {
|
||||||
free(child->stroke.paint.url);
|
tvg::free(child->stroke.paint.url);
|
||||||
child->stroke.paint.url = _copyId(parent->stroke.paint.url);
|
child->stroke.paint.url = _copyId(parent->stroke.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3153,7 +3153,7 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->fill.paint.none = from->fill.paint.none;
|
to->fill.paint.none = from->fill.paint.none;
|
||||||
to->fill.paint.curColor = from->fill.paint.curColor;
|
to->fill.paint.curColor = from->fill.paint.curColor;
|
||||||
if (from->fill.paint.url) {
|
if (from->fill.paint.url) {
|
||||||
free(to->fill.paint.url);
|
tvg::free(to->fill.paint.url);
|
||||||
to->fill.paint.url = _copyId(from->fill.paint.url);
|
to->fill.paint.url = _copyId(from->fill.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3170,7 +3170,7 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->stroke.paint.none = from->stroke.paint.none;
|
to->stroke.paint.none = from->stroke.paint.none;
|
||||||
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
||||||
if (from->stroke.paint.url) {
|
if (from->stroke.paint.url) {
|
||||||
free(to->stroke.paint.url);
|
tvg::free(to->stroke.paint.url);
|
||||||
to->stroke.paint.url = _copyId(from->stroke.paint.url);
|
to->stroke.paint.url = _copyId(from->stroke.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3208,22 +3208,22 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
{
|
{
|
||||||
//Copy matrix attribute
|
//Copy matrix attribute
|
||||||
if (from->transform) {
|
if (from->transform) {
|
||||||
to->transform = (Matrix*)malloc(sizeof(Matrix));
|
to->transform = tvg::malloc<Matrix*>(sizeof(Matrix));
|
||||||
if (to->transform) *to->transform = *from->transform;
|
if (to->transform) *to->transform = *from->transform;
|
||||||
}
|
}
|
||||||
//Copy style attribute
|
//Copy style attribute
|
||||||
_styleCopy(to->style, from->style);
|
_styleCopy(to->style, from->style);
|
||||||
to->style->flags = (to->style->flags | from->style->flags);
|
to->style->flags = (to->style->flags | from->style->flags);
|
||||||
if (from->style->clipPath.url) {
|
if (from->style->clipPath.url) {
|
||||||
free(to->style->clipPath.url);
|
tvg::free(to->style->clipPath.url);
|
||||||
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
||||||
}
|
}
|
||||||
if (from->style->mask.url) {
|
if (from->style->mask.url) {
|
||||||
free(to->style->mask.url);
|
tvg::free(to->style->mask.url);
|
||||||
to->style->mask.url = strdup(from->style->mask.url);
|
to->style->mask.url = strdup(from->style->mask.url);
|
||||||
}
|
}
|
||||||
if (from->style->filter.url) {
|
if (from->style->filter.url) {
|
||||||
if (to->style->filter.url) free(to->style->filter.url);
|
if (to->style->filter.url) tvg::free(to->style->filter.url);
|
||||||
to->style->filter.url = strdup(from->style->filter.url);
|
to->style->filter.url = strdup(from->style->filter.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3247,7 +3247,7 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
}
|
}
|
||||||
case SvgNodeType::Path: {
|
case SvgNodeType::Path: {
|
||||||
if (from->node.path.path) {
|
if (from->node.path.path) {
|
||||||
free(to->node.path.path);
|
tvg::free(to->node.path.path);
|
||||||
to->node.path.path = strdup(from->node.path.path);
|
to->node.path.path = strdup(from->node.path.path);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3270,7 +3270,7 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
to->node.image.w = from->node.image.w;
|
to->node.image.w = from->node.image.w;
|
||||||
to->node.image.h = from->node.image.h;
|
to->node.image.h = from->node.image.h;
|
||||||
if (from->node.image.href) {
|
if (from->node.image.href) {
|
||||||
free(to->node.image.href);
|
tvg::free(to->node.image.href);
|
||||||
to->node.image.href = strdup(from->node.image.href);
|
to->node.image.href = strdup(from->node.image.href);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3290,11 +3290,11 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
to->node.text.y = from->node.text.y;
|
to->node.text.y = from->node.text.y;
|
||||||
to->node.text.fontSize = from->node.text.fontSize;
|
to->node.text.fontSize = from->node.text.fontSize;
|
||||||
if (from->node.text.text) {
|
if (from->node.text.text) {
|
||||||
free(to->node.text.text);
|
tvg::free(to->node.text.text);
|
||||||
to->node.text.text = strdup(from->node.text.text);
|
to->node.text.text = strdup(from->node.text.text);
|
||||||
}
|
}
|
||||||
if (from->node.text.fontFamily) {
|
if (from->node.text.fontFamily) {
|
||||||
free(to->node.text.fontFamily);
|
tvg::free(to->node.text.fontFamily);
|
||||||
to->node.text.fontFamily = strdup(from->node.text.fontFamily);
|
to->node.text.fontFamily = strdup(from->node.text.fontFamily);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3345,7 +3345,7 @@ static void _clonePostponedNodes(Array<SvgNodeIdPair>* cloneNodes, SvgNode* doc)
|
||||||
} else {
|
} else {
|
||||||
TVGLOG("SVG", "%s is ancestor element. This reference is invalid.", nodeIdPair.id);
|
TVGLOG("SVG", "%s is ancestor element. This reference is invalid.", nodeIdPair.id);
|
||||||
}
|
}
|
||||||
free(nodeIdPair.id);
|
tvg::free(nodeIdPair.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3524,8 +3524,8 @@ static void _svgLoaderParserXmlCssStyle(SvgLoaderData* loader, const char* conte
|
||||||
length -= next - content;
|
length -= next - content;
|
||||||
content = next;
|
content = next;
|
||||||
|
|
||||||
free(tag);
|
tvg::free(tag);
|
||||||
free(name);
|
tvg::free(name);
|
||||||
}
|
}
|
||||||
loader->openedTag = OpenedTagType::Other;
|
loader->openedTag = OpenedTagType::Other;
|
||||||
}
|
}
|
||||||
|
@ -3659,7 +3659,7 @@ static void _updateGradient(SvgLoaderData* loader, SvgNode* node, Array<SvgStyle
|
||||||
if (newGrad) {
|
if (newGrad) {
|
||||||
if (node->style->fill.paint.gradient) {
|
if (node->style->fill.paint.gradient) {
|
||||||
node->style->fill.paint.gradient->clear();
|
node->style->fill.paint.gradient->clear();
|
||||||
free(node->style->fill.paint.gradient);
|
tvg::free(node->style->fill.paint.gradient);
|
||||||
}
|
}
|
||||||
node->style->fill.paint.gradient = newGrad;
|
node->style->fill.paint.gradient = newGrad;
|
||||||
}
|
}
|
||||||
|
@ -3669,7 +3669,7 @@ static void _updateGradient(SvgLoaderData* loader, SvgNode* node, Array<SvgStyle
|
||||||
if (newGrad) {
|
if (newGrad) {
|
||||||
if (node->style->stroke.paint.gradient) {
|
if (node->style->stroke.paint.gradient) {
|
||||||
node->style->stroke.paint.gradient->clear();
|
node->style->stroke.paint.gradient->clear();
|
||||||
free(node->style->stroke.paint.gradient);
|
tvg::free(node->style->stroke.paint.gradient);
|
||||||
}
|
}
|
||||||
node->style->stroke.paint.gradient = newGrad;
|
node->style->stroke.paint.gradient = newGrad;
|
||||||
}
|
}
|
||||||
|
@ -3716,23 +3716,23 @@ static void _freeNodeStyle(SvgStyleProperty* style)
|
||||||
if (!style) return;
|
if (!style) return;
|
||||||
|
|
||||||
//style->clipPath.node/mask.node/filter.node has only the addresses of node. Therefore, node is released from _freeNode.
|
//style->clipPath.node/mask.node/filter.node has only the addresses of node. Therefore, node is released from _freeNode.
|
||||||
free(style->clipPath.url);
|
tvg::free(style->clipPath.url);
|
||||||
free(style->mask.url);
|
tvg::free(style->mask.url);
|
||||||
free(style->filter.url);
|
tvg::free(style->filter.url);
|
||||||
free(style->cssClass);
|
tvg::free(style->cssClass);
|
||||||
|
|
||||||
if (style->fill.paint.gradient) {
|
if (style->fill.paint.gradient) {
|
||||||
style->fill.paint.gradient->clear();
|
style->fill.paint.gradient->clear();
|
||||||
free(style->fill.paint.gradient);
|
tvg::free(style->fill.paint.gradient);
|
||||||
}
|
}
|
||||||
if (style->stroke.paint.gradient) {
|
if (style->stroke.paint.gradient) {
|
||||||
style->stroke.paint.gradient->clear();
|
style->stroke.paint.gradient->clear();
|
||||||
free(style->stroke.paint.gradient);
|
tvg::free(style->stroke.paint.gradient);
|
||||||
}
|
}
|
||||||
free(style->fill.paint.url);
|
tvg::free(style->fill.paint.url);
|
||||||
free(style->stroke.paint.url);
|
tvg::free(style->stroke.paint.url);
|
||||||
style->stroke.dash.array.reset();
|
style->stroke.dash.array.reset();
|
||||||
free(style);
|
tvg::free(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3743,20 +3743,20 @@ static void _freeNode(SvgNode* node)
|
||||||
ARRAY_FOREACH(p, node->child) _freeNode(*p);
|
ARRAY_FOREACH(p, node->child) _freeNode(*p);
|
||||||
node->child.reset();
|
node->child.reset();
|
||||||
|
|
||||||
free(node->id);
|
tvg::free(node->id);
|
||||||
free(node->transform);
|
tvg::free(node->transform);
|
||||||
_freeNodeStyle(node->style);
|
_freeNodeStyle(node->style);
|
||||||
switch (node->type) {
|
switch (node->type) {
|
||||||
case SvgNodeType::Path: {
|
case SvgNodeType::Path: {
|
||||||
free(node->node.path.path);
|
tvg::free(node->node.path.path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Polygon: {
|
case SvgNodeType::Polygon: {
|
||||||
free(node->node.polygon.pts.data);
|
tvg::free(node->node.polygon.pts.data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Polyline: {
|
case SvgNodeType::Polyline: {
|
||||||
free(node->node.polyline.pts.data);
|
tvg::free(node->node.polyline.pts.data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Doc: {
|
case SvgNodeType::Doc: {
|
||||||
|
@ -3767,25 +3767,25 @@ static void _freeNode(SvgNode* node)
|
||||||
case SvgNodeType::Defs: {
|
case SvgNodeType::Defs: {
|
||||||
ARRAY_FOREACH(p, node->node.defs.gradients) {
|
ARRAY_FOREACH(p, node->node.defs.gradients) {
|
||||||
(*p)->clear();
|
(*p)->clear();
|
||||||
free(*p);
|
tvg::free(*p);
|
||||||
}
|
}
|
||||||
node->node.defs.gradients.reset();
|
node->node.defs.gradients.reset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Image: {
|
case SvgNodeType::Image: {
|
||||||
free(node->node.image.href);
|
tvg::free(node->node.image.href);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Text: {
|
case SvgNodeType::Text: {
|
||||||
free(node->node.text.text);
|
tvg::free(node->node.text.text);
|
||||||
free(node->node.text.fontFamily);
|
tvg::free(node->node.text.fontFamily);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(node);
|
tvg::free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3852,12 +3852,12 @@ static bool _svgLoaderParserForValidCheck(void* data, SimpleXMLType type, const
|
||||||
void SvgLoader::clear(bool all)
|
void SvgLoader::clear(bool all)
|
||||||
{
|
{
|
||||||
//flush out the intermediate data
|
//flush out the intermediate data
|
||||||
free(loaderData.svgParse);
|
tvg::free(loaderData.svgParse);
|
||||||
loaderData.svgParse = nullptr;
|
loaderData.svgParse = nullptr;
|
||||||
|
|
||||||
ARRAY_FOREACH(p, loaderData.gradients) {
|
ARRAY_FOREACH(p, loaderData.gradients) {
|
||||||
(*p)->clear();
|
(*p)->clear();
|
||||||
free(*p);
|
tvg::free(*p);
|
||||||
}
|
}
|
||||||
loaderData.gradients.reset();
|
loaderData.gradients.reset();
|
||||||
|
|
||||||
|
@ -3867,10 +3867,10 @@ void SvgLoader::clear(bool all)
|
||||||
|
|
||||||
if (!all) return;
|
if (!all) return;
|
||||||
|
|
||||||
ARRAY_FOREACH(p, loaderData.images) free(*p);
|
ARRAY_FOREACH(p, loaderData.images) tvg::free(*p);
|
||||||
loaderData.images.reset();
|
loaderData.images.reset();
|
||||||
|
|
||||||
if (copy) free((char*)content);
|
if (copy) tvg::free((char*)content);
|
||||||
|
|
||||||
delete(root);
|
delete(root);
|
||||||
root = nullptr;
|
root = nullptr;
|
||||||
|
@ -3948,7 +3948,7 @@ bool SvgLoader::header()
|
||||||
//For valid check, only <svg> tag is parsed first.
|
//For valid check, only <svg> tag is parsed first.
|
||||||
//If the <svg> tag is found, the loaded file is valid and stores viewbox information.
|
//If the <svg> tag is found, the loaded file is valid and stores viewbox information.
|
||||||
//After that, the remaining content data is parsed in order with async.
|
//After that, the remaining content data is parsed in order with async.
|
||||||
loaderData.svgParse = (SvgParser*)malloc(sizeof(SvgParser));
|
loaderData.svgParse = tvg::malloc<SvgParser*>(sizeof(SvgParser));
|
||||||
if (!loaderData.svgParse) return false;
|
if (!loaderData.svgParse) return false;
|
||||||
|
|
||||||
loaderData.svgParse->flags = SvgStopStyleFlags::StopDefault;
|
loaderData.svgParse->flags = SvgStopStyleFlags::StopDefault;
|
||||||
|
@ -4021,7 +4021,7 @@ bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpa
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
content = (char*)malloc(size + 1);
|
content = tvg::malloc<char*>(size + 1);
|
||||||
if (!content) return false;
|
if (!content) return false;
|
||||||
memcpy((char*)content, data, size);
|
memcpy((char*)content, data, size);
|
||||||
content[size] = '\0';
|
content[size] = '\0';
|
||||||
|
|
|
@ -463,11 +463,11 @@ struct SvgStyleGradient
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
stops.reset();
|
stops.reset();
|
||||||
free(transform);
|
tvg::free(transform);
|
||||||
free(radial);
|
tvg::free(radial);
|
||||||
free(linear);
|
tvg::free(linear);
|
||||||
free(ref);
|
tvg::free(ref);
|
||||||
free(id);
|
tvg::free(id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tvgMath.h" /* to include math.h before cstring */
|
#include "tvgMath.h" /* to include math.h before cstring */
|
||||||
#include <cstring>
|
|
||||||
#include "tvgShape.h"
|
#include "tvgShape.h"
|
||||||
#include "tvgCompressor.h"
|
#include "tvgCompressor.h"
|
||||||
#include "tvgFill.h"
|
#include "tvgFill.h"
|
||||||
|
@ -109,7 +108,7 @@ static LinearGradient* _applyLinearGradientProperty(SvgStyleGradient* g, const B
|
||||||
//Update the stops
|
//Update the stops
|
||||||
if (g->stops.count == 0) return fillGrad;
|
if (g->stops.count == 0) return fillGrad;
|
||||||
|
|
||||||
stops = (Fill::ColorStop*)malloc(g->stops.count * sizeof(Fill::ColorStop));
|
stops = tvg::malloc<Fill::ColorStop*>(g->stops.count * sizeof(Fill::ColorStop));
|
||||||
auto prevOffset = 0.0f;
|
auto prevOffset = 0.0f;
|
||||||
for (uint32_t i = 0; i < g->stops.count; ++i) {
|
for (uint32_t i = 0; i < g->stops.count; ++i) {
|
||||||
auto colorStop = &g->stops[i];
|
auto colorStop = &g->stops[i];
|
||||||
|
@ -125,7 +124,7 @@ static LinearGradient* _applyLinearGradientProperty(SvgStyleGradient* g, const B
|
||||||
prevOffset = stops[i].offset;
|
prevOffset = stops[i].offset;
|
||||||
}
|
}
|
||||||
fillGrad->colorStops(stops, g->stops.count);
|
fillGrad->colorStops(stops, g->stops.count);
|
||||||
free(stops);
|
tvg::free(stops);
|
||||||
return fillGrad;
|
return fillGrad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +158,7 @@ static RadialGradient* _applyRadialGradientProperty(SvgStyleGradient* g, const B
|
||||||
//Update the stops
|
//Update the stops
|
||||||
if (g->stops.count == 0) return fillGrad;
|
if (g->stops.count == 0) return fillGrad;
|
||||||
|
|
||||||
stops = (Fill::ColorStop*)malloc(g->stops.count * sizeof(Fill::ColorStop));
|
stops = tvg::malloc<Fill::ColorStop*>(g->stops.count * sizeof(Fill::ColorStop));
|
||||||
auto prevOffset = 0.0f;
|
auto prevOffset = 0.0f;
|
||||||
for (uint32_t i = 0; i < g->stops.count; ++i) {
|
for (uint32_t i = 0; i < g->stops.count; ++i) {
|
||||||
auto colorStop = &g->stops[i];
|
auto colorStop = &g->stops[i];
|
||||||
|
@ -175,7 +174,7 @@ static RadialGradient* _applyRadialGradientProperty(SvgStyleGradient* g, const B
|
||||||
prevOffset = stops[i].offset;
|
prevOffset = stops[i].offset;
|
||||||
}
|
}
|
||||||
fillGrad->colorStops(stops, g->stops.count);
|
fillGrad->colorStops(stops, g->stops.count);
|
||||||
free(stops);
|
tvg::free(stops);
|
||||||
return fillGrad;
|
return fillGrad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,14 +658,14 @@ static Paint* _imageBuildHelper(SvgLoaderData& loaderData, SvgNode* node, const
|
||||||
if (encoding == imageMimeTypeEncoding::base64) {
|
if (encoding == imageMimeTypeEncoding::base64) {
|
||||||
auto size = b64Decode(href, strlen(href), &decoded);
|
auto size = b64Decode(href, strlen(href), &decoded);
|
||||||
if (picture->load(decoded, size, mimetype) != Result::Success) {
|
if (picture->load(decoded, size, mimetype) != Result::Success) {
|
||||||
free(decoded);
|
tvg::free(decoded);
|
||||||
TaskScheduler::async(true);
|
TaskScheduler::async(true);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto size = svgUtilURLDecode(href, &decoded);
|
auto size = svgUtilURLDecode(href, &decoded);
|
||||||
if (picture->load(decoded, size, mimetype) != Result::Success) {
|
if (picture->load(decoded, size, mimetype) != Result::Success) {
|
||||||
free(decoded);
|
tvg::free(decoded);
|
||||||
TaskScheduler::async(true);
|
TaskScheduler::async(true);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include "tvgSvgUtil.h"
|
#include "tvgSvgUtil.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -46,7 +45,7 @@ size_t svgUtilURLDecode(const char *src, char** dst)
|
||||||
auto length = strlen(src);
|
auto length = strlen(src);
|
||||||
if (length == 0) return 0;
|
if (length == 0) return 0;
|
||||||
|
|
||||||
char* decoded = (char*)malloc(sizeof(char) * length + 1);
|
char* decoded = tvg::malloc<char*>(sizeof(char) * length + 1);
|
||||||
|
|
||||||
char a, b;
|
char a, b;
|
||||||
int idx =0;
|
int idx =0;
|
||||||
|
|
|
@ -20,18 +20,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <malloc.h>
|
|
||||||
#elif defined(__linux__) || defined(__ZEPHYR__)
|
|
||||||
#include <alloca.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "tvgXmlParser.h"
|
#include "tvgXmlParser.h"
|
||||||
#include "tvgStr.h"
|
#include "tvgStr.h"
|
||||||
|
|
||||||
|
@ -298,7 +287,7 @@ bool isIgnoreUnsupportedLogElements(TVG_UNUSED const char* tagName)
|
||||||
bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data)
|
bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data)
|
||||||
{
|
{
|
||||||
const char *itr = buf, *itrEnd = buf + bufLength;
|
const char *itr = buf, *itrEnd = buf + bufLength;
|
||||||
char* tmpBuf = (char*)malloc(bufLength + 1);
|
char* tmpBuf = tvg::malloc<char*>(bufLength + 1);
|
||||||
|
|
||||||
if (!buf || !func || !tmpBuf) goto error;
|
if (!buf || !func || !tmpBuf) goto error;
|
||||||
|
|
||||||
|
@ -363,11 +352,11 @@ bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttr
|
||||||
}
|
}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
free(tmpBuf);
|
tvg::free(tmpBuf);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(tmpBuf);
|
tvg::free(tmpBuf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ static bool _map(TtfLoader* loader, const char* path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.data = (uint8_t*)malloc(reader.size);
|
reader.data = tvg::malloc<uint8_t*>(reader.size);
|
||||||
|
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
auto ret = fread(reader.data, sizeof(char), reader.size, f);
|
auto ret = fread(reader.data, sizeof(char), reader.size, f);
|
||||||
|
@ -151,7 +151,7 @@ static bool _map(TtfLoader* loader, const char* path)
|
||||||
static void _unmap(TtfLoader* loader)
|
static void _unmap(TtfLoader* loader)
|
||||||
{
|
{
|
||||||
auto& reader = loader->reader;
|
auto& reader = loader->reader;
|
||||||
free(reader.data);
|
tvg::free(reader.data);
|
||||||
reader.data = nullptr;
|
reader.data = nullptr;
|
||||||
reader.size = 0;
|
reader.size = 0;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ static uint32_t* _codepoints(const char* text, size_t n)
|
||||||
|
|
||||||
auto utf8 = text;
|
auto utf8 = text;
|
||||||
//preserve approximate enough space.
|
//preserve approximate enough space.
|
||||||
auto utf32 = (uint32_t*) malloc(sizeof(uint32_t) * (n + 1));
|
auto utf32 = tvg::malloc<uint32_t*>(sizeof(uint32_t) * (n + 1));
|
||||||
|
|
||||||
while(*utf8) {
|
while(*utf8) {
|
||||||
if (!(*utf8 & 0x80U)) {
|
if (!(*utf8 & 0x80U)) {
|
||||||
|
@ -186,7 +186,7 @@ static uint32_t* _codepoints(const char* text, size_t n)
|
||||||
c += (*utf8++ & 0x3fU);
|
c += (*utf8++ & 0x3fU);
|
||||||
utf32[i++] = c;
|
utf32[i++] = c;
|
||||||
} else {
|
} else {
|
||||||
free(utf32);
|
tvg::free(utf32);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ static uint32_t* _codepoints(const char* text, size_t n)
|
||||||
void TtfLoader::clear()
|
void TtfLoader::clear()
|
||||||
{
|
{
|
||||||
if (nomap) {
|
if (nomap) {
|
||||||
if (freeData) free(reader.data);
|
if (freeData) tvg::free(reader.data);
|
||||||
reader.data = nullptr;
|
reader.data = nullptr;
|
||||||
reader.size = 0;
|
reader.size = 0;
|
||||||
freeData = false;
|
freeData = false;
|
||||||
|
@ -260,7 +260,7 @@ bool TtfLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpa
|
||||||
nomap = true;
|
nomap = true;
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
reader.data = (uint8_t*)malloc(size);
|
reader.data = tvg::malloc<uint8_t*>(size);
|
||||||
if (!reader.data) return false;
|
if (!reader.data) return false;
|
||||||
memcpy((char*)reader.data, data, reader.size);
|
memcpy((char*)reader.data, data, reader.size);
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
@ -313,7 +313,7 @@ bool TtfLoader::read()
|
||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(code);
|
tvg::free(code);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
|
@ -20,18 +20,9 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "tvgTtfReader.h"
|
||||||
#ifdef _WIN32
|
|
||||||
#include <malloc.h>
|
|
||||||
#elif defined(__linux__) || defined(__ZEPHYR__)
|
|
||||||
#include <alloca.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
#include "tvgShape.h"
|
#include "tvgShape.h"
|
||||||
#include "tvgTtfReader.h"
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//
|
//
|
||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
#include "./alphai.h"
|
#include "./alphai.h"
|
||||||
#include "./vp8i.h"
|
#include "./vp8i.h"
|
||||||
#include "./vp8li.h"
|
#include "./vp8li.h"
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
// ALPHDecoder object.
|
// ALPHDecoder object.
|
||||||
|
|
||||||
ALPHDecoder* ALPHNew(void) {
|
ALPHDecoder* ALPHNew(void) {
|
||||||
ALPHDecoder* const dec = (ALPHDecoder*)calloc(1ULL, sizeof(*dec));
|
ALPHDecoder* const dec = tvg::calloc<ALPHDecoder*>(1ULL, sizeof(*dec));
|
||||||
return dec;
|
return dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ void ALPHDelete(ALPHDecoder* const dec) {
|
||||||
if (dec != NULL) {
|
if (dec != NULL) {
|
||||||
VP8LDelete(dec->vp8l_dec_);
|
VP8LDelete(dec->vp8l_dec_);
|
||||||
dec->vp8l_dec_ = NULL;
|
dec->vp8l_dec_ = NULL;
|
||||||
free(dec);
|
tvg::free(dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//
|
//
|
||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
|
|
||||||
#include "./vp8i.h"
|
#include "./vp8i.h"
|
||||||
#include "./webpi.h"
|
#include "./webpi.h"
|
||||||
|
@ -104,7 +104,7 @@ static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) {
|
||||||
total_size = size + 2 * uv_size + a_size;
|
total_size = size + 2 * uv_size + a_size;
|
||||||
|
|
||||||
// Security/sanity checks
|
// Security/sanity checks
|
||||||
output = (uint8_t*)malloc(total_size * sizeof(*output));
|
output = tvg::malloc<uint8_t*>(total_size * sizeof(*output));
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
return VP8_STATUS_OUT_OF_MEMORY;
|
return VP8_STATUS_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ int WebPInitDecBufferInternal(WebPDecBuffer* buffer, int version) {
|
||||||
void WebPFreeDecBuffer(WebPDecBuffer* buffer) {
|
void WebPFreeDecBuffer(WebPDecBuffer* buffer) {
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
if (!buffer->is_external_memory) {
|
if (!buffer->is_external_memory) {
|
||||||
free(buffer->private_memory);
|
tvg::free(buffer->private_memory);
|
||||||
}
|
}
|
||||||
buffer->private_memory = NULL;
|
buffer->private_memory = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//
|
//
|
||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
#include "./vp8i.h"
|
#include "./vp8i.h"
|
||||||
#include "../utils/utils.h"
|
#include "../utils/utils.h"
|
||||||
|
|
||||||
|
@ -626,9 +626,9 @@ static int AllocateMemory(VP8Decoder* const dec) {
|
||||||
|
|
||||||
if (needed != (size_t)needed) return 0; // check for overflow
|
if (needed != (size_t)needed) return 0; // check for overflow
|
||||||
if (needed > dec->mem_size_) {
|
if (needed > dec->mem_size_) {
|
||||||
free(dec->mem_);
|
tvg::free(dec->mem_);
|
||||||
dec->mem_size_ = 0;
|
dec->mem_size_ = 0;
|
||||||
dec->mem_ = malloc(needed * sizeof(uint8_t));
|
dec->mem_ = tvg::malloc(needed * sizeof(uint8_t));
|
||||||
if (dec->mem_ == NULL) {
|
if (dec->mem_ == NULL) {
|
||||||
return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY,
|
return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY,
|
||||||
"no memory during frame initialization.");
|
"no memory during frame initialization.");
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
#include "../dec/vp8i.h"
|
#include "../dec/vp8i.h"
|
||||||
#include "./webpi.h"
|
#include "./webpi.h"
|
||||||
#include "../dsp/dsp.h"
|
#include "../dsp/dsp.h"
|
||||||
|
@ -261,7 +261,7 @@ static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) {
|
||||||
tmp_size2 += out_width;
|
tmp_size2 += out_width;
|
||||||
}
|
}
|
||||||
total_size = tmp_size1 * sizeof(*work) + tmp_size2 * sizeof(*tmp);
|
total_size = tmp_size1 * sizeof(*work) + tmp_size2 * sizeof(*tmp);
|
||||||
p->memory = calloc(1ULL, total_size);
|
p->memory = tvg::calloc(1ULL, total_size);
|
||||||
if (p->memory == NULL) {
|
if (p->memory == NULL) {
|
||||||
return 0; // memory error
|
return 0; // memory error
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ static int CustomPut(const VP8Io* io) {
|
||||||
|
|
||||||
static void CustomTeardown(const VP8Io* io) {
|
static void CustomTeardown(const VP8Io* io) {
|
||||||
WebPDecParams* const p = (WebPDecParams*)io->opaque;
|
WebPDecParams* const p = (WebPDecParams*)io->opaque;
|
||||||
free(p->memory);
|
tvg::free(p->memory);
|
||||||
p->memory = NULL;
|
p->memory = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//
|
//
|
||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
|
|
||||||
#include "./alphai.h"
|
#include "./alphai.h"
|
||||||
#include "./vp8i.h"
|
#include "./vp8i.h"
|
||||||
|
@ -45,7 +45,7 @@ int VP8InitIoInternal(VP8Io* const io, int version) {
|
||||||
}
|
}
|
||||||
|
|
||||||
VP8Decoder* VP8New(void) {
|
VP8Decoder* VP8New(void) {
|
||||||
VP8Decoder* const dec = (VP8Decoder*)calloc(1ULL, sizeof(*dec));
|
VP8Decoder* const dec = tvg::calloc<VP8Decoder*>(1ULL, sizeof(*dec));
|
||||||
if (dec != NULL) {
|
if (dec != NULL) {
|
||||||
SetOk(dec);
|
SetOk(dec);
|
||||||
dec->ready_ = 0;
|
dec->ready_ = 0;
|
||||||
|
@ -68,7 +68,7 @@ const char* VP8StatusMessage(VP8Decoder* const dec) {
|
||||||
void VP8Delete(VP8Decoder* const dec) {
|
void VP8Delete(VP8Decoder* const dec) {
|
||||||
if (dec != NULL) {
|
if (dec != NULL) {
|
||||||
VP8Clear(dec);
|
VP8Clear(dec);
|
||||||
free(dec);
|
tvg::free(dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ void VP8Clear(VP8Decoder* const dec) {
|
||||||
}
|
}
|
||||||
ALPHDelete(dec->alph_dec_);
|
ALPHDelete(dec->alph_dec_);
|
||||||
dec->alph_dec_ = NULL;
|
dec->alph_dec_ = NULL;
|
||||||
free(dec->mem_);
|
tvg::free(dec->mem_);
|
||||||
dec->mem_ = NULL;
|
dec->mem_ = NULL;
|
||||||
dec->mem_size_ = 0;
|
dec->mem_size_ = 0;
|
||||||
memset(&dec->br_, 0, sizeof(dec->br_));
|
memset(&dec->br_, 0, sizeof(dec->br_));
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// Authors: Vikas Arora (vikaas.arora@gmail.com)
|
// Authors: Vikas Arora (vikaas.arora@gmail.com)
|
||||||
// Jyrki Alakuijala (jyrki@google.com)
|
// Jyrki Alakuijala (jyrki@google.com)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
|
|
||||||
#include "./alphai.h"
|
#include "./alphai.h"
|
||||||
#include "./vp8li.h"
|
#include "./vp8li.h"
|
||||||
|
@ -352,9 +352,9 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
huffman_tables = (HuffmanCode*)malloc(num_htree_groups * table_size * sizeof(*huffman_tables));
|
huffman_tables = tvg::malloc<HuffmanCode*>(num_htree_groups * table_size * sizeof(*huffman_tables));
|
||||||
htree_groups = VP8LHtreeGroupsNew(num_htree_groups);
|
htree_groups = VP8LHtreeGroupsNew(num_htree_groups);
|
||||||
code_lengths = (int*)calloc((uint64_t)max_alphabet_size, sizeof(*code_lengths));
|
code_lengths = tvg::calloc<int*>((uint64_t)max_alphabet_size, sizeof(*code_lengths));
|
||||||
|
|
||||||
if (htree_groups == NULL || code_lengths == NULL || huffman_tables == NULL) {
|
if (htree_groups == NULL || code_lengths == NULL || huffman_tables == NULL) {
|
||||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||||
|
@ -391,7 +391,7 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||||
((uint32_t)alpha << 24) | (red << 16) | blue;
|
((uint32_t)alpha << 24) | (red << 16) | blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(code_lengths);
|
tvg::free(code_lengths);
|
||||||
|
|
||||||
// All OK. Finalize pointers and return.
|
// All OK. Finalize pointers and return.
|
||||||
hdr->huffman_image_ = huffman_image;
|
hdr->huffman_image_ = huffman_image;
|
||||||
|
@ -401,9 +401,9 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
Error:
|
Error:
|
||||||
free(code_lengths);
|
tvg::free(code_lengths);
|
||||||
free(huffman_image);
|
tvg::free(huffman_image);
|
||||||
free(huffman_tables);
|
tvg::free(huffman_tables);
|
||||||
VP8LHtreeGroupsFree(htree_groups);
|
VP8LHtreeGroupsFree(htree_groups);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -424,7 +424,7 @@ static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) {
|
||||||
const uint64_t memory_size = sizeof(*dec->rescaler) +
|
const uint64_t memory_size = sizeof(*dec->rescaler) +
|
||||||
work_size * sizeof(*work) +
|
work_size * sizeof(*work) +
|
||||||
scaled_data_size * sizeof(*scaled_data);
|
scaled_data_size * sizeof(*scaled_data);
|
||||||
uint8_t* memory = (uint8_t*)calloc(memory_size, sizeof(*memory));
|
uint8_t* memory = tvg::calloc<uint8_t*>(memory_size, sizeof(*memory));
|
||||||
if (memory == NULL) {
|
if (memory == NULL) {
|
||||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1119,7 +1119,7 @@ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data,
|
||||||
// VP8LTransform
|
// VP8LTransform
|
||||||
|
|
||||||
static void ClearTransform(VP8LTransform* const transform) {
|
static void ClearTransform(VP8LTransform* const transform) {
|
||||||
free(transform->data_);
|
tvg::free(transform->data_);
|
||||||
transform->data_ = NULL;
|
transform->data_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1128,7 +1128,7 @@ static void ClearTransform(VP8LTransform* const transform) {
|
||||||
static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
|
static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
|
||||||
int i;
|
int i;
|
||||||
const int final_num_colors = 1 << (8 >> transform->bits_);
|
const int final_num_colors = 1 << (8 >> transform->bits_);
|
||||||
uint32_t* const new_color_map = (uint32_t*)malloc((uint64_t)final_num_colors * sizeof(*new_color_map));
|
uint32_t* const new_color_map = tvg::malloc<uint32_t*>((uint64_t)final_num_colors * sizeof(*new_color_map));
|
||||||
if (new_color_map == NULL) {
|
if (new_color_map == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1141,7 +1141,7 @@ static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
|
||||||
}
|
}
|
||||||
for (; i < 4 * final_num_colors; ++i)
|
for (; i < 4 * final_num_colors; ++i)
|
||||||
new_data[i] = 0; // black tail.
|
new_data[i] = 0; // black tail.
|
||||||
free(transform->data_);
|
tvg::free(transform->data_);
|
||||||
transform->data_ = new_color_map;
|
transform->data_ = new_color_map;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1211,8 +1211,8 @@ static void InitMetadata(VP8LMetadata* const hdr) {
|
||||||
static void ClearMetadata(VP8LMetadata* const hdr) {
|
static void ClearMetadata(VP8LMetadata* const hdr) {
|
||||||
assert(hdr != NULL);
|
assert(hdr != NULL);
|
||||||
|
|
||||||
free(hdr->huffman_image_);
|
tvg::free(hdr->huffman_image_);
|
||||||
free(hdr->huffman_tables_);
|
tvg::free(hdr->huffman_tables_);
|
||||||
VP8LHtreeGroupsFree(hdr->htree_groups_);
|
VP8LHtreeGroupsFree(hdr->htree_groups_);
|
||||||
VP8LColorCacheClear(&hdr->color_cache_);
|
VP8LColorCacheClear(&hdr->color_cache_);
|
||||||
VP8LColorCacheClear(&hdr->saved_color_cache_);
|
VP8LColorCacheClear(&hdr->saved_color_cache_);
|
||||||
|
@ -1223,7 +1223,7 @@ static void ClearMetadata(VP8LMetadata* const hdr) {
|
||||||
// VP8LDecoder
|
// VP8LDecoder
|
||||||
|
|
||||||
VP8LDecoder* VP8LNew(void) {
|
VP8LDecoder* VP8LNew(void) {
|
||||||
VP8LDecoder* const dec = (VP8LDecoder*)calloc(1ULL, sizeof(*dec));
|
VP8LDecoder* const dec = tvg::calloc<VP8LDecoder*>(1ULL, sizeof(*dec));
|
||||||
if (dec == NULL) return NULL;
|
if (dec == NULL) return NULL;
|
||||||
dec->status_ = VP8_STATUS_OK;
|
dec->status_ = VP8_STATUS_OK;
|
||||||
dec->state_ = READ_DIM;
|
dec->state_ = READ_DIM;
|
||||||
|
@ -1238,7 +1238,7 @@ void VP8LClear(VP8LDecoder* const dec) {
|
||||||
if (dec == NULL) return;
|
if (dec == NULL) return;
|
||||||
ClearMetadata(&dec->hdr_);
|
ClearMetadata(&dec->hdr_);
|
||||||
|
|
||||||
free(dec->pixels_);
|
tvg::free(dec->pixels_);
|
||||||
dec->pixels_ = NULL;
|
dec->pixels_ = NULL;
|
||||||
for (i = 0; i < dec->next_transform_; ++i) {
|
for (i = 0; i < dec->next_transform_; ++i) {
|
||||||
ClearTransform(&dec->transforms_[i]);
|
ClearTransform(&dec->transforms_[i]);
|
||||||
|
@ -1246,7 +1246,7 @@ void VP8LClear(VP8LDecoder* const dec) {
|
||||||
dec->next_transform_ = 0;
|
dec->next_transform_ = 0;
|
||||||
dec->transforms_seen_ = 0;
|
dec->transforms_seen_ = 0;
|
||||||
|
|
||||||
free(dec->rescaler_memory);
|
tvg::free(dec->rescaler_memory);
|
||||||
dec->rescaler_memory = NULL;
|
dec->rescaler_memory = NULL;
|
||||||
|
|
||||||
dec->output_ = NULL; // leave no trace behind
|
dec->output_ = NULL; // leave no trace behind
|
||||||
|
@ -1255,7 +1255,7 @@ void VP8LClear(VP8LDecoder* const dec) {
|
||||||
void VP8LDelete(VP8LDecoder* const dec) {
|
void VP8LDelete(VP8LDecoder* const dec) {
|
||||||
if (dec != NULL) {
|
if (dec != NULL) {
|
||||||
VP8LClear(dec);
|
VP8LClear(dec);
|
||||||
free(dec);
|
tvg::free(dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1326,7 +1326,7 @@ static int DecodeImageStream(int xsize, int ysize,
|
||||||
|
|
||||||
{
|
{
|
||||||
const uint64_t total_size = (uint64_t)transform_xsize * transform_ysize;
|
const uint64_t total_size = (uint64_t)transform_xsize * transform_ysize;
|
||||||
data = (uint32_t*)malloc(total_size * sizeof(*data));
|
data = tvg::malloc<uint32_t*>(total_size * sizeof(*data));
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
|
@ -1341,7 +1341,7 @@ static int DecodeImageStream(int xsize, int ysize,
|
||||||
|
|
||||||
End:
|
End:
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
free(data);
|
tvg::free(data);
|
||||||
ClearMetadata(hdr);
|
ClearMetadata(hdr);
|
||||||
} else {
|
} else {
|
||||||
if (decoded_data != NULL) {
|
if (decoded_data != NULL) {
|
||||||
|
@ -1371,7 +1371,7 @@ static int AllocateInternalBuffers32b(VP8LDecoder* const dec, int final_width) {
|
||||||
num_pixels + cache_top_pixels + cache_pixels;
|
num_pixels + cache_top_pixels + cache_pixels;
|
||||||
|
|
||||||
assert(dec->width_ <= final_width);
|
assert(dec->width_ <= final_width);
|
||||||
dec->pixels_ = (uint32_t*)malloc(total_num_pixels * sizeof(uint32_t));
|
dec->pixels_ = tvg::malloc<uint32_t*>(total_num_pixels * sizeof(uint32_t));
|
||||||
if (dec->pixels_ == NULL) {
|
if (dec->pixels_ == NULL) {
|
||||||
dec->argb_cache_ = NULL; // for sanity check
|
dec->argb_cache_ = NULL; // for sanity check
|
||||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||||
|
@ -1384,7 +1384,7 @@ static int AllocateInternalBuffers32b(VP8LDecoder* const dec, int final_width) {
|
||||||
static int AllocateInternalBuffers8b(VP8LDecoder* const dec) {
|
static int AllocateInternalBuffers8b(VP8LDecoder* const dec) {
|
||||||
const uint64_t total_num_pixels = (uint64_t)dec->width_ * dec->height_;
|
const uint64_t total_num_pixels = (uint64_t)dec->width_ * dec->height_;
|
||||||
dec->argb_cache_ = NULL; // for sanity check
|
dec->argb_cache_ = NULL; // for sanity check
|
||||||
dec->pixels_ = (uint32_t*)malloc(total_num_pixels * sizeof(uint8_t));
|
dec->pixels_ = tvg::malloc<uint32_t*>(total_num_pixels * sizeof(uint8_t));
|
||||||
if (dec->pixels_ == NULL) {
|
if (dec->pixels_ == NULL) {
|
||||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
void WebpLoader::clear()
|
void WebpLoader::clear()
|
||||||
{
|
{
|
||||||
if (freeData) free(data);
|
if (freeData) tvg::free(data);
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
freeData = false;
|
freeData = false;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ WebpLoader::WebpLoader() : ImageLoader(FileType::Webp)
|
||||||
WebpLoader::~WebpLoader()
|
WebpLoader::~WebpLoader()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
free(surface.buf8);
|
tvg::free(surface.buf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ bool WebpLoader::open(const char* path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (uint8_t*)malloc(size);
|
data = tvg::malloc<uint8_t*>(size);
|
||||||
|
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
auto ret = fread(data, sizeof(char), size, f);
|
auto ret = fread(data, sizeof(char), size, f);
|
||||||
|
@ -111,7 +111,7 @@ bool WebpLoader::open(const char* path)
|
||||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||||
{
|
{
|
||||||
if (copy) {
|
if (copy) {
|
||||||
this->data = (uint8_t*) malloc(size);
|
this->data = tvg::malloc<uint8_t*>(size);
|
||||||
if (!this->data) return false;
|
if (!this->data) return false;
|
||||||
memcpy((uint8_t*)this->data, data, size);
|
memcpy((uint8_t*)this->data, data, size);
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
// Author: Jyrki Alakuijala (jyrki@google.com)
|
// Author: Jyrki Alakuijala (jyrki@google.com)
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
#include <string.h>
|
|
||||||
#include "./color_cache.h"
|
#include "./color_cache.h"
|
||||||
#include "../utils/utils.h"
|
#include "../utils/utils.h"
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
|
||||||
const int hash_size = 1 << hash_bits;
|
const int hash_size = 1 << hash_bits;
|
||||||
assert(cc != NULL);
|
assert(cc != NULL);
|
||||||
assert(hash_bits > 0);
|
assert(hash_bits > 0);
|
||||||
cc->colors_ = (uint32_t*)calloc((uint64_t)hash_size, sizeof(*cc->colors_));
|
cc->colors_ = tvg::calloc<uint32_t*>((uint64_t)hash_size, sizeof(*cc->colors_));
|
||||||
if (cc->colors_ == NULL) return 0;
|
if (cc->colors_ == NULL) return 0;
|
||||||
cc->hash_shift_ = 32 - hash_bits;
|
cc->hash_shift_ = 32 - hash_bits;
|
||||||
cc->hash_bits_ = hash_bits;
|
cc->hash_bits_ = hash_bits;
|
||||||
|
@ -33,7 +32,7 @@ int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
|
||||||
|
|
||||||
void VP8LColorCacheClear(VP8LColorCache* const cc) {
|
void VP8LColorCacheClear(VP8LColorCache* const cc) {
|
||||||
if (cc != NULL) {
|
if (cc != NULL) {
|
||||||
free(cc->colors_);
|
tvg::free(cc->colors_);
|
||||||
cc->colors_ = NULL;
|
cc->colors_ = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
// Author: Urvang Joshi (urvang@google.com)
|
// Author: Urvang Joshi (urvang@google.com)
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include "tvgCommon.h"
|
||||||
#include <string.h>
|
|
||||||
#include "./huffman.h"
|
#include "./huffman.h"
|
||||||
#include "../utils/utils.h"
|
#include "../utils/utils.h"
|
||||||
#include "../webp/format_constants.h"
|
#include "../webp/format_constants.h"
|
||||||
|
@ -23,7 +22,7 @@
|
||||||
#define MAX_HTREE_GROUPS 0x10000
|
#define MAX_HTREE_GROUPS 0x10000
|
||||||
|
|
||||||
HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups) {
|
HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups) {
|
||||||
HTreeGroup* const htree_groups = (HTreeGroup*)malloc(num_htree_groups * sizeof(*htree_groups));
|
HTreeGroup* const htree_groups = tvg::malloc<HTreeGroup*>(num_htree_groups * sizeof(*htree_groups));
|
||||||
if (htree_groups == NULL) {
|
if (htree_groups == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +32,7 @@ HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups) {
|
||||||
|
|
||||||
void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups) {
|
void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups) {
|
||||||
if (htree_groups != NULL) {
|
if (htree_groups != NULL) {
|
||||||
free(htree_groups);
|
tvg::free(htree_groups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +112,7 @@ int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
offset[len + 1] = offset[len] + count[len];
|
offset[len + 1] = offset[len] + count[len];
|
||||||
}
|
}
|
||||||
|
|
||||||
sorted = (int*)malloc(code_lengths_size * sizeof(*sorted));
|
sorted = tvg::malloc<int*>(code_lengths_size * sizeof(*sorted));
|
||||||
if (sorted == NULL) {
|
if (sorted == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +131,7 @@ int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
code.bits = 0;
|
code.bits = 0;
|
||||||
code.value = (uint16_t)sorted[0];
|
code.value = (uint16_t)sorted[0];
|
||||||
ReplicateValue(table, 1, total_size, code);
|
ReplicateValue(table, 1, total_size, code);
|
||||||
free(sorted);
|
tvg::free(sorted);
|
||||||
return total_size;
|
return total_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
num_nodes += num_open;
|
num_nodes += num_open;
|
||||||
num_open -= count[len];
|
num_open -= count[len];
|
||||||
if (num_open < 0) {
|
if (num_open < 0) {
|
||||||
free(sorted);
|
tvg::free(sorted);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (; count[len] > 0; --count[len]) {
|
for (; count[len] > 0; --count[len]) {
|
||||||
|
@ -171,7 +170,7 @@ int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
num_nodes += num_open;
|
num_nodes += num_open;
|
||||||
num_open -= count[len];
|
num_open -= count[len];
|
||||||
if (num_open < 0) {
|
if (num_open < 0) {
|
||||||
free(sorted);
|
tvg::free(sorted);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (; count[len] > 0; --count[len]) {
|
for (; count[len] > 0; --count[len]) {
|
||||||
|
@ -194,11 +193,11 @@ int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
|
|
||||||
// Check if tree is full.
|
// Check if tree is full.
|
||||||
if (num_nodes != 2 * offset[MAX_ALLOWED_CODE_LENGTH] - 1) {
|
if (num_nodes != 2 * offset[MAX_ALLOWED_CODE_LENGTH] - 1) {
|
||||||
free(sorted);
|
tvg::free(sorted);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sorted);
|
tvg::free(sorted);
|
||||||
return total_size;
|
return total_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,10 @@
|
||||||
//
|
//
|
||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
|
#include "tvgCommon.h"
|
||||||
#include "./quant_levels_dec.h"
|
#include "./quant_levels_dec.h"
|
||||||
#include "./utils.h"
|
#include "./utils.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h> // for memset
|
|
||||||
|
|
||||||
// #define USE_DITHERING // uncomment to enable ordered dithering (not vital)
|
// #define USE_DITHERING // uncomment to enable ordered dithering (not vital)
|
||||||
|
|
||||||
#define FIX 16 // fix-point precision for averaging
|
#define FIX 16 // fix-point precision for averaging
|
||||||
|
@ -216,7 +214,7 @@ static int InitParams(uint8_t* const data, int width, int height,
|
||||||
const size_t size_m = width * sizeof(*p->average_);
|
const size_t size_m = width * sizeof(*p->average_);
|
||||||
const size_t size_lut = (1 + 2 * LUT_SIZE) * sizeof(*p->correction_);
|
const size_t size_lut = (1 + 2 * LUT_SIZE) * sizeof(*p->correction_);
|
||||||
const size_t total_size = size_scratch_m + size_m + size_lut;
|
const size_t total_size = size_scratch_m + size_m + size_lut;
|
||||||
uint8_t* mem = (uint8_t*)malloc(1U * total_size);
|
uint8_t* mem = tvg::malloc<uint8_t*>(1U * total_size);
|
||||||
|
|
||||||
if (mem == NULL) return 0;
|
if (mem == NULL) return 0;
|
||||||
p->mem_ = (void*)mem;
|
p->mem_ = (void*)mem;
|
||||||
|
@ -250,7 +248,7 @@ static int InitParams(uint8_t* const data, int width, int height,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CleanupParams(SmoothParams* const p) {
|
static void CleanupParams(SmoothParams* const p) {
|
||||||
free(p->mem_);
|
tvg::free(p->mem_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebPDequantizeLevels(uint8_t* const data, int width, int height,
|
int WebPDequantizeLevels(uint8_t* const data, int width, int height,
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#define _TVG_GL_COMMON_H_
|
#define _TVG_GL_COMMON_H_
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <memory>
|
|
||||||
#if defined (THORVG_GL_TARGET_GLES)
|
#if defined (THORVG_GL_TARGET_GLES)
|
||||||
#include <GLES3/gl3.h>
|
#include <GLES3/gl3.h>
|
||||||
#define TVG_REQUIRE_GL_MAJOR_VER 3
|
#define TVG_REQUIRE_GL_MAJOR_VER 3
|
||||||
|
|
|
@ -56,10 +56,10 @@ GlProgram::GlProgram(const char* vertSrc, const char* fragSrc)
|
||||||
glGetProgramiv(progObj, GL_INFO_LOG_LENGTH, &infoLen);
|
glGetProgramiv(progObj, GL_INFO_LOG_LENGTH, &infoLen);
|
||||||
if (infoLen > 0)
|
if (infoLen > 0)
|
||||||
{
|
{
|
||||||
auto infoLog = static_cast<char*>(malloc(sizeof(char) * infoLen));
|
auto infoLog = tvg::malloc<char*>(sizeof(char) * infoLen);
|
||||||
glGetProgramInfoLog(progObj, infoLen, NULL, infoLog);
|
glGetProgramInfoLog(progObj, infoLen, NULL, infoLog);
|
||||||
TVGERR("GL_ENGINE", "Error linking shader: %s", infoLog);
|
TVGERR("GL_ENGINE", "Error linking shader: %s", infoLog);
|
||||||
free(infoLog);
|
tvg::free(infoLog);
|
||||||
|
|
||||||
}
|
}
|
||||||
glDeleteProgram(progObj);
|
glDeleteProgram(progObj);
|
||||||
|
|
|
@ -66,10 +66,10 @@ uint32_t GlShader::compileShader(uint32_t type, char* shaderSrc)
|
||||||
|
|
||||||
if (infoLen > 0)
|
if (infoLen > 0)
|
||||||
{
|
{
|
||||||
auto infoLog = static_cast<char*>(malloc(sizeof(char)*infoLen));
|
auto infoLog = tvg::malloc<char*>(sizeof(char)*infoLen);
|
||||||
glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
|
glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
|
||||||
TVGERR("GL_ENGINE", "Error compiling shader: %s", infoLog);
|
TVGERR("GL_ENGINE", "Error compiling shader: %s", infoLog);
|
||||||
free(infoLog);
|
tvg::free(infoLog);
|
||||||
}
|
}
|
||||||
glDeleteShader(shader);
|
glDeleteShader(shader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1570,8 +1570,8 @@ void Stroker::stroke(const RenderShape *rshape)
|
||||||
if (dashCnt == 0) doStroke(cmds, cmdCnt, pts, ptsCnt);
|
if (dashCnt == 0) doStroke(cmds, cmdCnt, pts, ptsCnt);
|
||||||
else doDashStroke(cmds, cmdCnt, pts, ptsCnt, dashCnt, dash_pattern, dash_offset);
|
else doDashStroke(cmds, cmdCnt, pts, ptsCnt, dashCnt, dash_pattern, dash_offset);
|
||||||
|
|
||||||
free(trimmedCmds);
|
tvg::free(trimmedCmds);
|
||||||
free(trimmedPts);
|
tvg::free(trimmedPts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tvgMath.h"
|
|
||||||
#include "tvgSwCommon.h"
|
#include "tvgSwCommon.h"
|
||||||
#include "tvgFill.h"
|
#include "tvgFill.h"
|
||||||
|
|
||||||
|
@ -130,7 +129,7 @@ static bool _updateColorTable(SwFill* fill, const Fill* fdata, const SwSurface*
|
||||||
if (fill->solid) return true;
|
if (fill->solid) return true;
|
||||||
|
|
||||||
if (!fill->ctable) {
|
if (!fill->ctable) {
|
||||||
fill->ctable = static_cast<uint32_t*>(malloc(GRADIENT_STOP_SIZE * sizeof(uint32_t)));
|
fill->ctable = tvg::malloc<uint32_t*>(GRADIENT_STOP_SIZE * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
const Fill::ColorStop* colors;
|
const Fill::ColorStop* colors;
|
||||||
|
@ -830,7 +829,7 @@ const Fill::ColorStop* fillFetchSolid(const SwFill* fill, const Fill* fdata)
|
||||||
void fillReset(SwFill* fill)
|
void fillReset(SwFill* fill)
|
||||||
{
|
{
|
||||||
if (fill->ctable) {
|
if (fill->ctable) {
|
||||||
free(fill->ctable);
|
tvg::free(fill->ctable);
|
||||||
fill->ctable = nullptr;
|
fill->ctable = nullptr;
|
||||||
}
|
}
|
||||||
fill->translucent = false;
|
fill->translucent = false;
|
||||||
|
@ -842,7 +841,7 @@ void fillFree(SwFill* fill)
|
||||||
{
|
{
|
||||||
if (!fill) return;
|
if (!fill) return;
|
||||||
|
|
||||||
if (fill->ctable) free(fill->ctable);
|
if (fill->ctable) tvg::free(fill->ctable);
|
||||||
|
|
||||||
free(fill);
|
tvg::free(fill);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,10 +81,10 @@ SwMpool* mpoolInit(uint32_t threads)
|
||||||
{
|
{
|
||||||
auto allocSize = threads + 1;
|
auto allocSize = threads + 1;
|
||||||
|
|
||||||
auto mpool = static_cast<SwMpool*>(calloc(1, sizeof(SwMpool)));
|
auto mpool = tvg::calloc<SwMpool*>(1, sizeof(SwMpool));
|
||||||
mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
mpool->outline = tvg::calloc<SwOutline*>(1, sizeof(SwOutline) * allocSize);
|
||||||
mpool->strokeOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
mpool->strokeOutline = tvg::calloc<SwOutline*>(1, sizeof(SwOutline) * allocSize);
|
||||||
mpool->dashOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
|
mpool->dashOutline = tvg::calloc<SwOutline*>(1, sizeof(SwOutline) * allocSize);
|
||||||
mpool->allocSize = allocSize;
|
mpool->allocSize = allocSize;
|
||||||
|
|
||||||
return mpool;
|
return mpool;
|
||||||
|
@ -120,10 +120,10 @@ bool mpoolTerm(SwMpool* mpool)
|
||||||
|
|
||||||
mpoolClear(mpool);
|
mpoolClear(mpool);
|
||||||
|
|
||||||
free(mpool->outline);
|
tvg::free(mpool->outline);
|
||||||
free(mpool->strokeOutline);
|
tvg::free(mpool->strokeOutline);
|
||||||
free(mpool->dashOutline);
|
tvg::free(mpool->dashOutline);
|
||||||
free(mpool);
|
tvg::free(mpool);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ bool effectGaussianBlurRegion(RenderEffectGaussianBlur* params)
|
||||||
|
|
||||||
void effectGaussianBlurUpdate(RenderEffectGaussianBlur* params, const Matrix& transform)
|
void effectGaussianBlurUpdate(RenderEffectGaussianBlur* params, const Matrix& transform)
|
||||||
{
|
{
|
||||||
if (!params->rd) params->rd = (SwGaussianBlur*)malloc(sizeof(SwGaussianBlur));
|
if (!params->rd) params->rd = tvg::malloc<SwGaussianBlur*>(sizeof(SwGaussianBlur));
|
||||||
auto rd = static_cast<SwGaussianBlur*>(params->rd);
|
auto rd = static_cast<SwGaussianBlur*>(params->rd);
|
||||||
|
|
||||||
//compute box kernel sizes
|
//compute box kernel sizes
|
||||||
|
@ -315,7 +315,7 @@ bool effectDropShadowRegion(RenderEffectDropShadow* params)
|
||||||
|
|
||||||
void effectDropShadowUpdate(RenderEffectDropShadow* params, const Matrix& transform)
|
void effectDropShadowUpdate(RenderEffectDropShadow* params, const Matrix& transform)
|
||||||
{
|
{
|
||||||
if (!params->rd) params->rd = (SwDropShadow*)malloc(sizeof(SwDropShadow));
|
if (!params->rd) params->rd = tvg::malloc<SwDropShadow*>(sizeof(SwDropShadow));
|
||||||
auto rd = static_cast<SwDropShadow*>(params->rd);
|
auto rd = static_cast<SwDropShadow*>(params->rd);
|
||||||
|
|
||||||
//compute box kernel sizes
|
//compute box kernel sizes
|
||||||
|
|
|
@ -583,14 +583,14 @@ static AASpans* _AASpans(float ymin, float ymax, const SwImage* image, const SwB
|
||||||
|
|
||||||
if (!_arrange(image, region, yStart, yEnd)) return nullptr;
|
if (!_arrange(image, region, yStart, yEnd)) return nullptr;
|
||||||
|
|
||||||
auto aaSpans = static_cast<AASpans*>(malloc(sizeof(AASpans)));
|
auto aaSpans = tvg::malloc<AASpans*>(sizeof(AASpans));
|
||||||
aaSpans->yStart = yStart;
|
aaSpans->yStart = yStart;
|
||||||
aaSpans->yEnd = yEnd;
|
aaSpans->yEnd = yEnd;
|
||||||
|
|
||||||
//Initialize X range
|
//Initialize X range
|
||||||
auto height = yEnd - yStart;
|
auto height = yEnd - yStart;
|
||||||
|
|
||||||
aaSpans->lines = static_cast<AALine*>(malloc(height * sizeof(AALine)));
|
aaSpans->lines = tvg::malloc<AALine*>(height * sizeof(AALine));
|
||||||
|
|
||||||
for (int32_t i = 0; i < height; i++) {
|
for (int32_t i = 0; i < height; i++) {
|
||||||
aaSpans->lines[i].x[0] = INT32_MAX;
|
aaSpans->lines[i].x[0] = INT32_MAX;
|
||||||
|
@ -846,8 +846,8 @@ static bool _apply(SwSurface* surface, AASpans* aaSpans)
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(aaSpans->lines);
|
tvg::free(aaSpans->lines);
|
||||||
free(aaSpans);
|
tvg::free(aaSpans);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include "tvgMath.h"
|
|
||||||
#include "tvgSwCommon.h"
|
#include "tvgSwCommon.h"
|
||||||
#include "tvgTaskScheduler.h"
|
#include "tvgTaskScheduler.h"
|
||||||
#include "tvgSwRenderer.h"
|
#include "tvgSwRenderer.h"
|
||||||
|
@ -384,7 +383,7 @@ void SwRenderer::clearCompositors()
|
||||||
{
|
{
|
||||||
//Free Composite Caches
|
//Free Composite Caches
|
||||||
ARRAY_FOREACH(p, compositors) {
|
ARRAY_FOREACH(p, compositors) {
|
||||||
free((*p)->compositor->image.data);
|
tvg::free((*p)->compositor->image.data);
|
||||||
delete((*p)->compositor);
|
delete((*p)->compositor);
|
||||||
delete(*p);
|
delete(*p);
|
||||||
}
|
}
|
||||||
|
@ -555,7 +554,7 @@ SwSurface* SwRenderer::request(int channelSize, bool square)
|
||||||
//Inherits attributes from main surface
|
//Inherits attributes from main surface
|
||||||
cmp = new SwSurface(surface);
|
cmp = new SwSurface(surface);
|
||||||
cmp->compositor = new SwCompositor;
|
cmp->compositor = new SwCompositor;
|
||||||
cmp->compositor->image.data = (pixel_t*)malloc(channelSize * w * h);
|
cmp->compositor->image.data = tvg::malloc<pixel_t*>(channelSize * w * h);
|
||||||
cmp->w = cmp->compositor->image.w = w;
|
cmp->w = cmp->compositor->image.w = w;
|
||||||
cmp->h = cmp->compositor->image.h = h;
|
cmp->h = cmp->compositor->image.h = h;
|
||||||
cmp->stride = cmp->compositor->image.stride = w;
|
cmp->stride = cmp->compositor->image.stride = w;
|
||||||
|
@ -700,7 +699,7 @@ bool SwRenderer::render(RenderCompositor* cmp, const RenderEffect* effect, bool
|
||||||
|
|
||||||
void SwRenderer::dispose(RenderEffect* effect)
|
void SwRenderer::dispose(RenderEffect* effect)
|
||||||
{
|
{
|
||||||
free(effect->rd);
|
tvg::free(effect->rd);
|
||||||
effect->rd = nullptr;
|
effect->rd = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <memory.h>
|
|
||||||
#include "tvgSwCommon.h"
|
#include "tvgSwCommon.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -342,7 +341,7 @@ static void _horizLine(RleWorker& rw, SwCoord x, SwCoord y, SwCoord area, SwCoor
|
||||||
auto newSize = (rle->size > 0) ? (rle->size * 2) : 256;
|
auto newSize = (rle->size > 0) ? (rle->size * 2) : 256;
|
||||||
if (rle->alloc < newSize) {
|
if (rle->alloc < newSize) {
|
||||||
rle->alloc = newSize;
|
rle->alloc = newSize;
|
||||||
rle->spans = static_cast<SwSpan*>(realloc(rle->spans, rle->alloc * sizeof(SwSpan)));
|
rle->spans = tvg::realloc<SwSpan*>(rle->spans, rle->alloc * sizeof(SwSpan));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,7 +830,7 @@ static SwSpan* _intersectSpansRect(const SwBBox *bbox, const SwRle *targetRle, S
|
||||||
|
|
||||||
void _replaceClipSpan(SwRle *rle, SwSpan* clippedSpans, uint32_t size)
|
void _replaceClipSpan(SwRle *rle, SwSpan* clippedSpans, uint32_t size)
|
||||||
{
|
{
|
||||||
free(rle->spans);
|
tvg::free(rle->spans);
|
||||||
rle->spans = clippedSpans;
|
rle->spans = clippedSpans;
|
||||||
rle->size = rle->alloc = size;
|
rle->size = rle->alloc = size;
|
||||||
}
|
}
|
||||||
|
@ -869,7 +868,7 @@ SwRle* rleRender(SwRle* rle, const SwOutline* outline, const SwBBox& renderRegio
|
||||||
rw.bandShoot = 0;
|
rw.bandShoot = 0;
|
||||||
rw.antiAlias = antiAlias;
|
rw.antiAlias = antiAlias;
|
||||||
|
|
||||||
if (!rle) rw.rle = reinterpret_cast<SwRle*>(calloc(1, sizeof(SwRle)));
|
if (!rle) rw.rle = tvg::calloc<SwRle*>(1, sizeof(SwRle));
|
||||||
else rw.rle = rle;
|
else rw.rle = rle;
|
||||||
|
|
||||||
//Generate RLE
|
//Generate RLE
|
||||||
|
@ -951,7 +950,7 @@ SwRle* rleRender(SwRle* rle, const SwOutline* outline, const SwBBox& renderRegio
|
||||||
return rw.rle;
|
return rw.rle;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(rw.rle);
|
tvg::free(rw.rle);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,8 +960,8 @@ SwRle* rleRender(const SwBBox* bbox)
|
||||||
auto width = static_cast<uint16_t>(bbox->max.x - bbox->min.x);
|
auto width = static_cast<uint16_t>(bbox->max.x - bbox->min.x);
|
||||||
auto height = static_cast<uint16_t>(bbox->max.y - bbox->min.y);
|
auto height = static_cast<uint16_t>(bbox->max.y - bbox->min.y);
|
||||||
|
|
||||||
auto rle = static_cast<SwRle*>(malloc(sizeof(SwRle)));
|
auto rle = tvg::malloc<SwRle*>(sizeof(SwRle));
|
||||||
rle->spans = static_cast<SwSpan*>(malloc(sizeof(SwSpan) * height));
|
rle->spans = tvg::malloc<SwSpan*>(sizeof(SwSpan) * height);
|
||||||
rle->size = height;
|
rle->size = height;
|
||||||
rle->alloc = height;
|
rle->alloc = height;
|
||||||
|
|
||||||
|
@ -988,8 +987,8 @@ void rleReset(SwRle* rle)
|
||||||
void rleFree(SwRle* rle)
|
void rleFree(SwRle* rle)
|
||||||
{
|
{
|
||||||
if (!rle) return;
|
if (!rle) return;
|
||||||
if (rle->spans) free(rle->spans);
|
if (rle->spans) tvg::free(rle->spans);
|
||||||
free(rle);
|
tvg::free(rle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -997,7 +996,7 @@ bool rleClip(SwRle *rle, const SwRle *clip)
|
||||||
{
|
{
|
||||||
if (rle->size == 0 || clip->size == 0) return false;
|
if (rle->size == 0 || clip->size == 0) return false;
|
||||||
auto spanCnt = rle->size > clip->size ? rle->size : clip->size;
|
auto spanCnt = rle->size > clip->size ? rle->size : clip->size;
|
||||||
auto spans = static_cast<SwSpan*>(malloc(sizeof(SwSpan) * (spanCnt)));
|
auto spans = tvg::malloc<SwSpan*>(sizeof(SwSpan) * (spanCnt));
|
||||||
auto spansEnd = _intersectSpansRegion(clip, rle, spans, spanCnt);
|
auto spansEnd = _intersectSpansRegion(clip, rle, spans, spanCnt);
|
||||||
|
|
||||||
_replaceClipSpan(rle, spans, spansEnd - spans);
|
_replaceClipSpan(rle, spans, spansEnd - spans);
|
||||||
|
@ -1011,7 +1010,7 @@ bool rleClip(SwRle *rle, const SwRle *clip)
|
||||||
bool rleClip(SwRle *rle, const SwBBox* clip)
|
bool rleClip(SwRle *rle, const SwBBox* clip)
|
||||||
{
|
{
|
||||||
if (rle->size == 0) return false;
|
if (rle->size == 0) return false;
|
||||||
auto spans = static_cast<SwSpan*>(malloc(sizeof(SwSpan) * (rle->size)));
|
auto spans = tvg::malloc<SwSpan*>(sizeof(SwSpan) * (rle->size));
|
||||||
auto spansEnd = _intersectSpansRect(clip, rle, spans, rle->size);
|
auto spansEnd = _intersectSpansRect(clip, rle, spans, rle->size);
|
||||||
|
|
||||||
_replaceClipSpan(rle, spans, spansEnd - spans);
|
_replaceClipSpan(rle, spans, spansEnd - spans);
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tvgSwCommon.h"
|
#include "tvgSwCommon.h"
|
||||||
#include "tvgMath.h"
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
|
@ -319,8 +318,8 @@ static SwOutline* _genDashOutline(const RenderShape* rshape, const Matrix& trans
|
||||||
++cmds;
|
++cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(trimmedCmds);
|
tvg::free(trimmedCmds);
|
||||||
free(trimmedPts);
|
tvg::free(trimmedPts);
|
||||||
|
|
||||||
_outlineEnd(*dash.outline);
|
_outlineEnd(*dash.outline);
|
||||||
|
|
||||||
|
@ -410,8 +409,8 @@ static SwOutline* _genOutline(SwShape* shape, const RenderShape* rshape, const M
|
||||||
|
|
||||||
outline->fillRule = rshape->rule;
|
outline->fillRule = rshape->rule;
|
||||||
|
|
||||||
free(trimmedCmds);
|
tvg::free(trimmedCmds);
|
||||||
free(trimmedPts);
|
tvg::free(trimmedPts);
|
||||||
|
|
||||||
if (!trimmed) shape->fastTrack = (!hasComposite && _axisAlignedRect(outline));
|
if (!trimmed) shape->fastTrack = (!hasComposite && _axisAlignedRect(outline));
|
||||||
return outline;
|
return outline;
|
||||||
|
@ -494,7 +493,7 @@ void shapeDelStroke(SwShape* shape)
|
||||||
|
|
||||||
void shapeResetStroke(SwShape* shape, const RenderShape* rshape, const Matrix& transform)
|
void shapeResetStroke(SwShape* shape, const RenderShape* rshape, const Matrix& transform)
|
||||||
{
|
{
|
||||||
if (!shape->stroke) shape->stroke = static_cast<SwStroke*>(calloc(1, sizeof(SwStroke)));
|
if (!shape->stroke) shape->stroke = tvg::calloc<SwStroke*>(1, sizeof(SwStroke));
|
||||||
auto stroke = shape->stroke;
|
auto stroke = shape->stroke;
|
||||||
if (!stroke) return;
|
if (!stroke) return;
|
||||||
|
|
||||||
|
@ -567,7 +566,7 @@ bool shapeGenStrokeFillColors(SwShape* shape, const Fill* fill, const Matrix& tr
|
||||||
void shapeResetFill(SwShape* shape)
|
void shapeResetFill(SwShape* shape)
|
||||||
{
|
{
|
||||||
if (!shape->fill) {
|
if (!shape->fill) {
|
||||||
shape->fill = static_cast<SwFill*>(calloc(1, sizeof(SwFill)));
|
shape->fill = tvg::calloc<SwFill*>(1, sizeof(SwFill));
|
||||||
if (!shape->fill) return;
|
if (!shape->fill) return;
|
||||||
}
|
}
|
||||||
fillReset(shape->fill);
|
fillReset(shape->fill);
|
||||||
|
@ -577,7 +576,7 @@ void shapeResetFill(SwShape* shape)
|
||||||
void shapeResetStrokeFill(SwShape* shape)
|
void shapeResetStrokeFill(SwShape* shape)
|
||||||
{
|
{
|
||||||
if (!shape->stroke->fill) {
|
if (!shape->stroke->fill) {
|
||||||
shape->stroke->fill = static_cast<SwFill*>(calloc(1, sizeof(SwFill)));
|
shape->stroke->fill = tvg::calloc<SwFill*>(1, sizeof(SwFill));
|
||||||
if (!shape->stroke->fill) return;
|
if (!shape->stroke->fill) return;
|
||||||
}
|
}
|
||||||
fillReset(shape->stroke->fill);
|
fillReset(shape->stroke->fill);
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include "tvgSwCommon.h"
|
#include "tvgSwCommon.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -58,8 +56,8 @@ static void _growBorder(SwStrokeBorder* border, uint32_t newPts)
|
||||||
while (maxCur < maxNew)
|
while (maxCur < maxNew)
|
||||||
maxCur += (maxCur >> 1) + 16;
|
maxCur += (maxCur >> 1) + 16;
|
||||||
//OPTIMIZE: use mempool!
|
//OPTIMIZE: use mempool!
|
||||||
border->pts = static_cast<SwPoint*>(realloc(border->pts, maxCur * sizeof(SwPoint)));
|
border->pts = tvg::realloc<SwPoint*>(border->pts, maxCur * sizeof(SwPoint));
|
||||||
border->tags = static_cast<uint8_t*>(realloc(border->tags, maxCur * sizeof(uint8_t)));
|
border->tags = tvg::realloc<uint8_t*>(border->tags, maxCur * sizeof(uint8_t));
|
||||||
border->maxPts = maxCur;
|
border->maxPts = maxCur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,15 +804,15 @@ void strokeFree(SwStroke* stroke)
|
||||||
if (!stroke) return;
|
if (!stroke) return;
|
||||||
|
|
||||||
//free borders
|
//free borders
|
||||||
if (stroke->borders[0].pts) free(stroke->borders[0].pts);
|
if (stroke->borders[0].pts) tvg::free(stroke->borders[0].pts);
|
||||||
if (stroke->borders[0].tags) free(stroke->borders[0].tags);
|
if (stroke->borders[0].tags) tvg::free(stroke->borders[0].tags);
|
||||||
if (stroke->borders[1].pts) free(stroke->borders[1].pts);
|
if (stroke->borders[1].pts) tvg::free(stroke->borders[1].pts);
|
||||||
if (stroke->borders[1].tags) free(stroke->borders[1].tags);
|
if (stroke->borders[1].tags) tvg::free(stroke->borders[1].tags);
|
||||||
|
|
||||||
fillFree(stroke->fill);
|
fillFree(stroke->fill);
|
||||||
stroke->fill = nullptr;
|
stroke->fill = nullptr;
|
||||||
|
|
||||||
free(stroke);
|
tvg::free(stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,17 @@
|
||||||
#ifndef _TVG_COMMON_H_
|
#ifndef _TVG_COMMON_H_
|
||||||
#define _TVG_COMMON_H_
|
#define _TVG_COMMON_H_
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <malloc.h>
|
||||||
|
#elif defined(__linux__) || defined(__ZEPHYR__)
|
||||||
|
#include <alloca.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "thorvg.h"
|
#include "thorvg.h"
|
||||||
|
|
||||||
|
@ -55,40 +65,59 @@ using namespace tvg;
|
||||||
#define strdup _strdup
|
#define strdup _strdup
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum class FileType { Png = 0, Jpg, Webp, Svg, Lottie, Ttf, Raw, Gif, Unknown };
|
void* operator new(std::size_t size);
|
||||||
|
void operator delete(void* ptr) noexcept;
|
||||||
|
|
||||||
using Size = Point;
|
namespace tvg {
|
||||||
|
|
||||||
#ifdef THORVG_LOG_ENABLED
|
enum class FileType { Png = 0, Jpg, Webp, Svg, Lottie, Ttf, Raw, Gif, Unknown };
|
||||||
constexpr auto ErrorColor = "\033[31m"; //red
|
|
||||||
constexpr auto ErrorBgColor = "\033[41m";//bg red
|
|
||||||
constexpr auto LogColor = "\033[32m"; //green
|
|
||||||
constexpr auto LogBgColor = "\033[42m"; //bg green
|
|
||||||
constexpr auto GreyColor = "\033[90m"; //grey
|
|
||||||
constexpr auto ResetColors = "\033[0m"; //default
|
|
||||||
#define TVGERR(tag, fmt, ...) fprintf(stderr, "%s[E]%s %s" tag "%s (%s %d): %s" fmt "\n", ErrorBgColor, ResetColors, ErrorColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__)
|
|
||||||
#define TVGLOG(tag, fmt, ...) fprintf(stdout, "%s[L]%s %s" tag "%s (%s %d): %s" fmt "\n", LogBgColor, ResetColors, LogColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define TVGERR(...) do {} while(0)
|
|
||||||
#define TVGLOG(...) do {} while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint16_t THORVG_VERSION_NUMBER();
|
using Size = Point;
|
||||||
|
|
||||||
#define PIMPL(INST, CLASS) ((CLASS::Impl*)INST->pImpl) //Access to pimpl
|
#ifdef THORVG_LOG_ENABLED
|
||||||
|
constexpr auto ErrorColor = "\033[31m"; //red
|
||||||
|
constexpr auto ErrorBgColor = "\033[41m";//bg red
|
||||||
|
constexpr auto LogColor = "\033[32m"; //green
|
||||||
|
constexpr auto LogBgColor = "\033[42m"; //bg green
|
||||||
|
constexpr auto GreyColor = "\033[90m"; //grey
|
||||||
|
constexpr auto ResetColors = "\033[0m"; //default
|
||||||
|
#define TVGERR(tag, fmt, ...) fprintf(stderr, "%s[E]%s %s" tag "%s (%s %d): %s" fmt "\n", ErrorBgColor, ResetColors, ErrorColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__)
|
||||||
|
#define TVGLOG(tag, fmt, ...) fprintf(stdout, "%s[L]%s %s" tag "%s (%s %d): %s" fmt "\n", LogBgColor, ResetColors, LogColor, GreyColor, __FILE__, __LINE__, ResetColors, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define TVGERR(...) do {} while(0)
|
||||||
|
#define TVGLOG(...) do {} while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TVG_DELETE(PAINT) \
|
uint16_t THORVG_VERSION_NUMBER();
|
||||||
if (PAINT->refCnt() == 0) delete(PAINT)
|
|
||||||
|
|
||||||
//for debugging
|
#define PIMPL(INST, CLASS) ((CLASS::Impl*)INST->pImpl) //Access to pimpl
|
||||||
#if 0
|
|
||||||
#include <sys/time.h>
|
#define TVG_DELETE(PAINT) \
|
||||||
static inline double THORVG_TIMESTAMP()
|
if (PAINT->refCnt() == 0) delete(PAINT)
|
||||||
{
|
|
||||||
struct timeval tv;
|
//custom memory allocators
|
||||||
gettimeofday(&tv, NULL);
|
template<typename T = void*>
|
||||||
return (tv.tv_sec + tv.tv_usec / 1000000.0);
|
static inline T malloc(size_t size)
|
||||||
|
{
|
||||||
|
return static_cast<T>(std::malloc(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T = void*>
|
||||||
|
static inline T calloc(size_t nmem, size_t size)
|
||||||
|
{
|
||||||
|
return static_cast<T>(std::calloc(nmem, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T = void*>
|
||||||
|
static inline T realloc(void* ptr, size_t size)
|
||||||
|
{
|
||||||
|
return static_cast<T>(std::realloc(ptr, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void free(void* ptr)
|
||||||
|
{
|
||||||
|
std::free(ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //_TVG_COMMON_H_
|
#endif //_TVG_COMMON_H_
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
#ifndef _TVG_FILL_H_
|
#ifndef _TVG_FILL_H_
|
||||||
#define _TVG_FILL_H_
|
#define _TVG_FILL_H_
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
|
|
||||||
#define LINEAR(A) PIMPL(A, LinearGradient)
|
#define LINEAR(A) PIMPL(A, LinearGradient)
|
||||||
|
@ -39,14 +37,14 @@ struct Fill::Impl
|
||||||
|
|
||||||
virtual ~Impl()
|
virtual ~Impl()
|
||||||
{
|
{
|
||||||
free(colorStops);
|
tvg::free(colorStops);
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy(Fill::Impl* dup)
|
void copy(Fill::Impl* dup)
|
||||||
{
|
{
|
||||||
cnt = dup->cnt;
|
cnt = dup->cnt;
|
||||||
spread = dup->spread;
|
spread = dup->spread;
|
||||||
colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * dup->cnt));
|
colorStops = tvg::malloc<ColorStop*>(sizeof(ColorStop) * dup->cnt);
|
||||||
if (dup->cnt > 0) memcpy(colorStops, dup->colorStops, sizeof(ColorStop) * dup->cnt);
|
if (dup->cnt > 0) memcpy(colorStops, dup->colorStops, sizeof(ColorStop) * dup->cnt);
|
||||||
transform = dup->transform;
|
transform = dup->transform;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +55,7 @@ struct Fill::Impl
|
||||||
|
|
||||||
if (cnt == 0) {
|
if (cnt == 0) {
|
||||||
if (this->colorStops) {
|
if (this->colorStops) {
|
||||||
free(this->colorStops);
|
tvg::free(this->colorStops);
|
||||||
this->colorStops = nullptr;
|
this->colorStops = nullptr;
|
||||||
this->cnt = 0;
|
this->cnt = 0;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +63,7 @@ struct Fill::Impl
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cnt != this->cnt) {
|
if (cnt != this->cnt) {
|
||||||
this->colorStops = static_cast<ColorStop*>(realloc(this->colorStops, cnt * sizeof(ColorStop)));
|
this->colorStops = tvg::realloc<ColorStop*>(this->colorStops, cnt * sizeof(ColorStop));
|
||||||
}
|
}
|
||||||
|
|
||||||
this->cnt = cnt;
|
this->cnt = cnt;
|
||||||
|
|
|
@ -24,10 +24,6 @@
|
||||||
#include "tvgTaskScheduler.h"
|
#include "tvgTaskScheduler.h"
|
||||||
#include "tvgLoader.h"
|
#include "tvgLoader.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <cstring>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef THORVG_SW_RASTER_SUPPORT
|
#ifdef THORVG_SW_RASTER_SUPPORT
|
||||||
#include "tvgSwRenderer.h"
|
#include "tvgSwRenderer.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -174,4 +170,14 @@ const char* Initializer::version(uint32_t* major, uint32_t* minor, uint32_t* mic
|
||||||
uint16_t THORVG_VERSION_NUMBER()
|
uint16_t THORVG_VERSION_NUMBER()
|
||||||
{
|
{
|
||||||
return _version;
|
return _version;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* operator new(std::size_t size) {
|
||||||
|
return tvg::malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void operator delete(void* ptr) noexcept {
|
||||||
|
tvg::free(ptr);
|
||||||
}
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
#ifndef _TVG_LOAD_MODULE_H_
|
#ifndef _TVG_LOAD_MODULE_H_
|
||||||
#define _TVG_LOAD_MODULE_H_
|
#define _TVG_LOAD_MODULE_H_
|
||||||
|
|
||||||
|
#include "tvgCommon.h"
|
||||||
#include "tvgRender.h"
|
#include "tvgRender.h"
|
||||||
#include "tvgInlist.h"
|
#include "tvgInlist.h"
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ struct LoadModule
|
||||||
LoadModule(FileType type) : type(type) {}
|
LoadModule(FileType type) : type(type) {}
|
||||||
virtual ~LoadModule()
|
virtual ~LoadModule()
|
||||||
{
|
{
|
||||||
if (pathcache) free(hashpath);
|
if (pathcache) tvg::free(hashpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool open(const char* path) { return false; }
|
virtual bool open(const char* path) { return false; }
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#ifndef _TVG_PAINT_H_
|
#ifndef _TVG_PAINT_H_
|
||||||
#define _TVG_PAINT_H_
|
#define _TVG_PAINT_H_
|
||||||
|
|
||||||
|
#include "tvgCommon.h"
|
||||||
#include "tvgRender.h"
|
#include "tvgRender.h"
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ namespace tvg
|
||||||
{
|
{
|
||||||
if (maskData) {
|
if (maskData) {
|
||||||
maskData->target->unref();
|
maskData->target->unref();
|
||||||
free(maskData);
|
tvg::free(maskData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clipper) clipper->unref();
|
if (clipper) clipper->unref();
|
||||||
|
@ -163,13 +164,13 @@ namespace tvg
|
||||||
maskData->target->unref(maskData->target != target);
|
maskData->target->unref(maskData->target != target);
|
||||||
//Reset scenario
|
//Reset scenario
|
||||||
if (!target && method == MaskMethod::None) {
|
if (!target && method == MaskMethod::None) {
|
||||||
free(maskData);
|
tvg::free(maskData);
|
||||||
maskData = nullptr;
|
maskData = nullptr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!target && method == MaskMethod::None) return true;
|
if (!target && method == MaskMethod::None) return true;
|
||||||
maskData = static_cast<Mask*>(malloc(sizeof(Mask)));
|
maskData = tvg::malloc<Mask*>(sizeof(Mask));
|
||||||
}
|
}
|
||||||
target->ref();
|
target->ref();
|
||||||
maskData->target = target;
|
maskData->target = target;
|
||||||
|
@ -198,7 +199,7 @@ namespace tvg
|
||||||
|
|
||||||
if (maskData) {
|
if (maskData) {
|
||||||
maskData->target->unref();
|
maskData->target->unref();
|
||||||
free(maskData);
|
tvg::free(maskData);
|
||||||
maskData = nullptr;
|
maskData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,9 +117,9 @@ struct RenderStroke
|
||||||
if (rhs.fill) fill = rhs.fill->duplicate();
|
if (rhs.fill) fill = rhs.fill->duplicate();
|
||||||
else fill = nullptr;
|
else fill = nullptr;
|
||||||
|
|
||||||
free(dashPattern);
|
tvg::free(dashPattern);
|
||||||
if (rhs.dashCnt > 0) {
|
if (rhs.dashCnt > 0) {
|
||||||
dashPattern = static_cast<float*>(malloc(sizeof(float) * rhs.dashCnt));
|
dashPattern = tvg::malloc<float*>(sizeof(float) * rhs.dashCnt);
|
||||||
memcpy(dashPattern, rhs.dashPattern, sizeof(float) * rhs.dashCnt);
|
memcpy(dashPattern, rhs.dashPattern, sizeof(float) * rhs.dashCnt);
|
||||||
} else {
|
} else {
|
||||||
dashPattern = nullptr;
|
dashPattern = nullptr;
|
||||||
|
@ -135,7 +135,7 @@ struct RenderStroke
|
||||||
|
|
||||||
~RenderStroke()
|
~RenderStroke()
|
||||||
{
|
{
|
||||||
free(dashPattern);
|
tvg::free(dashPattern);
|
||||||
delete(fill);
|
delete(fill);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#ifndef _TVG_SHAPE_H_
|
#ifndef _TVG_SHAPE_H_
|
||||||
#define _TVG_SHAPE_H_
|
#define _TVG_SHAPE_H_
|
||||||
|
|
||||||
#include <memory.h>
|
#include "tvgCommon.h"
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
#include "tvgPaint.h"
|
#include "tvgPaint.h"
|
||||||
|
|
||||||
|
@ -307,16 +307,16 @@ struct Shape::Impl : Paint::Impl
|
||||||
|
|
||||||
//Reset dash
|
//Reset dash
|
||||||
if (!pattern && cnt == 0) {
|
if (!pattern && cnt == 0) {
|
||||||
free(rs.stroke->dashPattern);
|
tvg::free(rs.stroke->dashPattern);
|
||||||
rs.stroke->dashPattern = nullptr;
|
rs.stroke->dashPattern = nullptr;
|
||||||
} else {
|
} else {
|
||||||
if (!rs.stroke) rs.stroke = new RenderStroke();
|
if (!rs.stroke) rs.stroke = new RenderStroke();
|
||||||
if (rs.stroke->dashCnt != cnt) {
|
if (rs.stroke->dashCnt != cnt) {
|
||||||
free(rs.stroke->dashPattern);
|
tvg::free(rs.stroke->dashPattern);
|
||||||
rs.stroke->dashPattern = nullptr;
|
rs.stroke->dashPattern = nullptr;
|
||||||
}
|
}
|
||||||
if (!rs.stroke->dashPattern) {
|
if (!rs.stroke->dashPattern) {
|
||||||
rs.stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
|
rs.stroke->dashPattern = tvg::malloc<float*>(sizeof(float) * cnt);
|
||||||
if (!rs.stroke->dashPattern) return Result::FailedAllocation;
|
if (!rs.stroke->dashPattern) return Result::FailedAllocation;
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < cnt; ++i) {
|
for (uint32_t i = 0; i < cnt; ++i) {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#ifndef _TVG_TEXT_H
|
#ifndef _TVG_TEXT_H
|
||||||
#define _TVG_TEXT_H
|
#define _TVG_TEXT_H
|
||||||
|
|
||||||
#include <cstring>
|
#include "tvgCommon.h"
|
||||||
#include "tvgShape.h"
|
#include "tvgShape.h"
|
||||||
#include "tvgFill.h"
|
#include "tvgFill.h"
|
||||||
#include "tvgLoader.h"
|
#include "tvgLoader.h"
|
||||||
|
@ -45,14 +45,14 @@ struct Text::Impl : Paint::Impl
|
||||||
|
|
||||||
~Impl()
|
~Impl()
|
||||||
{
|
{
|
||||||
free(utf8);
|
tvg::free(utf8);
|
||||||
LoaderMgr::retrieve(loader);
|
LoaderMgr::retrieve(loader);
|
||||||
delete(shape);
|
delete(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result text(const char* utf8)
|
Result text(const char* utf8)
|
||||||
{
|
{
|
||||||
free(this->utf8);
|
tvg::free(this->utf8);
|
||||||
if (utf8) this->utf8 = strdup(utf8);
|
if (utf8) this->utf8 = strdup(utf8);
|
||||||
else this->utf8 = nullptr;
|
else this->utf8 = nullptr;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
|
@ -70,14 +70,14 @@ struct WgVertexBuffer
|
||||||
|
|
||||||
WgVertexBuffer(float scale = 1.0f) : scale(scale)
|
WgVertexBuffer(float scale = 1.0f) : scale(scale)
|
||||||
{
|
{
|
||||||
data = (Point*)malloc(sizeof(Point) * reserved);
|
data = tvg::malloc<Point*>(sizeof(Point) * reserved);
|
||||||
dist = (Distance*)malloc(sizeof(Distance) * reserved);
|
dist = tvg::malloc<Distance*>(sizeof(Distance) * reserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
~WgVertexBuffer()
|
~WgVertexBuffer()
|
||||||
{
|
{
|
||||||
free(data);
|
tvg::free(data);
|
||||||
free(dist);
|
tvg::free(dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset buffer
|
// reset buffer
|
||||||
|
@ -159,8 +159,8 @@ struct WgVertexBuffer
|
||||||
{
|
{
|
||||||
if (count >= reserved) {
|
if (count >= reserved) {
|
||||||
reserved *= 2;
|
reserved *= 2;
|
||||||
data = (Point*) realloc(data, reserved * sizeof(Point));
|
data = tvg::realloc<Point*>(data, reserved * sizeof(Point));
|
||||||
dist = (Distance*) realloc(dist, reserved * sizeof(Distance));
|
dist = tvg::realloc<Distance*>(dist, reserved * sizeof(Distance));
|
||||||
}
|
}
|
||||||
data[count++] = p;
|
data[count++] = p;
|
||||||
}
|
}
|
||||||
|
@ -262,8 +262,8 @@ struct WgVertexBuffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(trimmedCmds);
|
tvg::free(trimmedCmds);
|
||||||
free(trimmedPts);
|
tvg::free(trimmedPts);
|
||||||
|
|
||||||
// after path decoding we need to update distances and total length
|
// after path decoding we need to update distances and total length
|
||||||
if (update_dist) updateDistances();
|
if (update_dist) updateDistances();
|
||||||
|
@ -286,16 +286,16 @@ struct WgIndexedVertexBuffer
|
||||||
|
|
||||||
WgIndexedVertexBuffer(WgGeometryBufferPool* pool, float scale = 1.0f) : pool(pool), scale(scale)
|
WgIndexedVertexBuffer(WgGeometryBufferPool* pool, float scale = 1.0f) : pool(pool), scale(scale)
|
||||||
{
|
{
|
||||||
vbuff = (Point*)malloc(sizeof(Point) * vreserved);
|
vbuff = tvg::malloc<Point*>(sizeof(Point) * vreserved);
|
||||||
ibuff = (uint32_t*)malloc(sizeof(uint32_t) * ireserved);
|
ibuff = tvg::malloc<uint32_t*>(sizeof(uint32_t) * ireserved);
|
||||||
dashed = pool->reqVertexBuffer();
|
dashed = pool->reqVertexBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
~WgIndexedVertexBuffer()
|
~WgIndexedVertexBuffer()
|
||||||
{
|
{
|
||||||
pool->retVertexBuffer(dashed);
|
pool->retVertexBuffer(dashed);
|
||||||
free(vbuff);
|
tvg::free(vbuff);
|
||||||
free(ibuff);
|
tvg::free(ibuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset buffer
|
// reset buffer
|
||||||
|
@ -309,7 +309,7 @@ struct WgIndexedVertexBuffer
|
||||||
{
|
{
|
||||||
if (icount + grow >= ireserved) {
|
if (icount + grow >= ireserved) {
|
||||||
ireserved *= 2;
|
ireserved *= 2;
|
||||||
ibuff = (uint32_t*) realloc(ibuff, ireserved * sizeof(uint32_t));
|
ibuff = tvg::realloc<uint32_t*>(ibuff, ireserved * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ struct WgIndexedVertexBuffer
|
||||||
{
|
{
|
||||||
if (vcount + grow >= vreserved) {
|
if (vcount + grow >= vreserved) {
|
||||||
vreserved *= 2;
|
vreserved *= 2;
|
||||||
vbuff = (Point*) realloc(vbuff, vreserved * sizeof(Point));
|
vbuff = tvg::realloc<Point*>(vbuff, vreserved * sizeof(Point));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
// Finally, call GifEnd() to close the file handle and free memory.
|
// Finally, call GifEnd() to close the file handle and free memory.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <memory.h>
|
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
#include "tvgGifEncoder.h"
|
#include "tvgGifEncoder.h"
|
||||||
|
|
||||||
|
@ -465,7 +464,7 @@ static void _writeLzwImage(GifWriter* writer, uint32_t width, uint32_t height, u
|
||||||
|
|
||||||
fputc(minCodeSize, f); // min code size 8 bits
|
fputc(minCodeSize, f); // min code size 8 bits
|
||||||
|
|
||||||
GifLzwNode* codetree = (GifLzwNode*)malloc(sizeof(GifLzwNode)*4096);
|
GifLzwNode* codetree = tvg::malloc<GifLzwNode*>(sizeof(GifLzwNode)*4096);
|
||||||
|
|
||||||
memset(codetree, 0, sizeof(GifLzwNode)*4096);
|
memset(codetree, 0, sizeof(GifLzwNode)*4096);
|
||||||
int32_t curCode = -1;
|
int32_t curCode = -1;
|
||||||
|
@ -531,7 +530,7 @@ static void _writeLzwImage(GifWriter* writer, uint32_t width, uint32_t height, u
|
||||||
|
|
||||||
fputc(0, f); // image block terminator
|
fputc(0, f); // image block terminator
|
||||||
|
|
||||||
free(codetree);
|
tvg::free(codetree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -553,8 +552,8 @@ bool gifBegin(GifWriter* writer, const char* filename, uint32_t width, uint32_t
|
||||||
writer->firstFrame = true;
|
writer->firstFrame = true;
|
||||||
|
|
||||||
// allocate
|
// allocate
|
||||||
writer->oldImage = (uint8_t*)malloc(width*height*4);
|
writer->oldImage = tvg::malloc<uint8_t*>(width*height*4);
|
||||||
writer->tmpImage = (uint8_t*)malloc(width*height*4);
|
writer->tmpImage = tvg::malloc<uint8_t*>(width*height*4);
|
||||||
|
|
||||||
fputs("GIF89a", writer->f);
|
fputs("GIF89a", writer->f);
|
||||||
|
|
||||||
|
@ -618,8 +617,8 @@ bool gifEnd(GifWriter* writer)
|
||||||
|
|
||||||
fputc(0x3b, writer->f); // end of file
|
fputc(0x3b, writer->f); // end of file
|
||||||
fclose(writer->f);
|
fclose(writer->f);
|
||||||
free(writer->oldImage);
|
tvg::free(writer->oldImage);
|
||||||
free(writer->tmpImage);
|
tvg::free(writer->tmpImage);
|
||||||
|
|
||||||
writer->f = NULL;
|
writer->f = NULL;
|
||||||
writer->oldImage = NULL;
|
writer->oldImage = NULL;
|
||||||
|
|
|
@ -24,9 +24,7 @@
|
||||||
#ifndef TVG_GIF_ENCODER_H
|
#ifndef TVG_GIF_ENCODER_H
|
||||||
#define TVG_GIF_ENCODER_H
|
#define TVG_GIF_ENCODER_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "tvgCommon.h"
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,7 +37,7 @@ void GifSaver::run(unsigned tid)
|
||||||
auto w = static_cast<uint32_t>(vsize[0]);
|
auto w = static_cast<uint32_t>(vsize[0]);
|
||||||
auto h = static_cast<uint32_t>(vsize[1]);
|
auto h = static_cast<uint32_t>(vsize[1]);
|
||||||
|
|
||||||
buffer = (uint32_t*)realloc(buffer, sizeof(uint32_t) * w * h);
|
buffer = tvg::realloc<uint32_t*>(buffer, sizeof(uint32_t) * w * h);
|
||||||
canvas->target(buffer, w, w, h, ColorSpace::ABGR8888S);
|
canvas->target(buffer, w, w, h, ColorSpace::ABGR8888S);
|
||||||
canvas->push(bg);
|
canvas->push(bg);
|
||||||
bg = nullptr;
|
bg = nullptr;
|
||||||
|
@ -99,10 +99,10 @@ bool GifSaver::close()
|
||||||
if (animation && animation->picture()->refCnt() <= 1) delete(animation);
|
if (animation && animation->picture()->refCnt() <= 1) delete(animation);
|
||||||
animation = nullptr;
|
animation = nullptr;
|
||||||
|
|
||||||
free(path);
|
tvg::free(path);
|
||||||
path = nullptr;
|
path = nullptr;
|
||||||
|
|
||||||
free(buffer);
|
tvg::free(buffer);
|
||||||
buffer = nullptr;
|
buffer = nullptr;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue