mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
loaders: prepare for static jpg/png loaders.
This patch has 2 purposes, 1. revise the loaders infrastructure to support both static/external linking loaders. 2. add a template for static jpg/png loaders after external jpg/png. Our default loaders prefer static linking, external loaders are only available when dependent libraries on the build system are found. You might wonder why we have the external loaders together, they might be faster than static loaders since the popular libraries are likely to be well maintained, fine-grained optimized. Thus in this patch, meson tries to apply the external loaders first then see if the dependencies were found or not, if it's failed, it turns to the default static loaders. Next this patch, we need the contribution for actual static jpg/png loaders implementation. @Issue: https://github.com/Samsung/thorvg/issues/594
This commit is contained in:
parent
875e5bd058
commit
ff20974632
13 changed files with 437 additions and 160 deletions
18
src/loaders/external_jpg/meson.build
Normal file
18
src/loaders/external_jpg/meson.build
Normal file
|
@ -0,0 +1,18 @@
|
|||
source_file = [
|
||||
'tvgJpgLoader.h',
|
||||
'tvgJpgLoader.cpp',
|
||||
]
|
||||
|
||||
jpg_dep = dependency('libturbojpeg', required: false)
|
||||
|
||||
if not jpg_dep.found()
|
||||
jpg_dep = cc.find_library('turbojpeg', required: false)
|
||||
endif
|
||||
|
||||
if jpg_dep.found()
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : jpg_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
endif
|
153
src/loaders/external_jpg/tvgJpgLoader.cpp
Normal file
153
src/loaders/external_jpg/tvgJpgLoader.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
#include <turbojpeg.h>
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgJpgLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void JpgLoader::clear()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
JpgLoader::JpgLoader()
|
||||
{
|
||||
jpegDecompressor = tjInitDecompress();
|
||||
}
|
||||
|
||||
|
||||
JpgLoader::~JpgLoader()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
tjDestroy(jpegDecompressor);
|
||||
|
||||
//This image is shared with raster engine.
|
||||
tjFree(image);
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const string& path)
|
||||
{
|
||||
clear();
|
||||
|
||||
auto jpegFile = fopen(path.c_str(), "rb");
|
||||
if (!jpegFile) return false;
|
||||
|
||||
auto ret = false;
|
||||
|
||||
//determine size
|
||||
if (fseek(jpegFile, 0, SEEK_END) < 0) goto finalize;
|
||||
if (((size = ftell(jpegFile)) < 1)) goto finalize;
|
||||
if (fseek(jpegFile, 0, SEEK_SET)) goto finalize;
|
||||
|
||||
data = (unsigned char *) malloc(size);
|
||||
if (!data) goto finalize;
|
||||
|
||||
if (fread(data, size, 1, jpegFile) < 1) goto failure;
|
||||
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &subSample, &colorSpace) < 0) {
|
||||
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
|
||||
goto failure;
|
||||
}
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
ret = true;
|
||||
freeData = true;
|
||||
|
||||
goto finalize;
|
||||
|
||||
failure:
|
||||
clear();
|
||||
|
||||
finalize:
|
||||
fclose(jpegFile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
||||
{
|
||||
clear();
|
||||
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
||||
|
||||
if (copy) {
|
||||
this->data = (unsigned char *) malloc(size);
|
||||
if (!this->data) return false;
|
||||
memcpy((unsigned char *)this->data, data, size);
|
||||
freeData = true;
|
||||
} else {
|
||||
this->data = (unsigned char *) data;
|
||||
}
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
this->size = size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
if (image) tjFree(image);
|
||||
image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[TJPF_BGRX]);
|
||||
if (!image) return false;
|
||||
|
||||
//decompress jpg image
|
||||
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), TJPF_BGRX, 0) < 0) {
|
||||
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
|
||||
tjFree(image);
|
||||
image = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::close()
|
||||
{
|
||||
clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const uint32_t* JpgLoader::pixels()
|
||||
{
|
||||
return (const uint32_t*) image;
|
||||
}
|
52
src/loaders/external_jpg/tvgJpgLoader.h
Normal file
52
src/loaders/external_jpg/tvgJpgLoader.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef _TVG_JPG_LOADER_H_
|
||||
#define _TVG_JPG_LOADER_H_
|
||||
|
||||
using tjhandle = void*;
|
||||
|
||||
//TODO: Use Task?
|
||||
class JpgLoader : public LoadModule
|
||||
{
|
||||
public:
|
||||
JpgLoader();
|
||||
~JpgLoader();
|
||||
|
||||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
tjhandle jpegDecompressor;
|
||||
unsigned char* data = nullptr;
|
||||
unsigned char *image = nullptr;
|
||||
unsigned long size = 0;
|
||||
bool freeData = false;
|
||||
};
|
||||
|
||||
#endif //_TVG_JPG_LOADER_H_
|
14
src/loaders/external_png/meson.build
Normal file
14
src/loaders/external_png/meson.build
Normal file
|
@ -0,0 +1,14 @@
|
|||
source_file = [
|
||||
'tvgPngLoader.h',
|
||||
'tvgPngLoader.cpp',
|
||||
]
|
||||
|
||||
png_dep = meson.get_compiler('cpp').find_library('libpng')
|
||||
|
||||
if png_dep.found()
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : png_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
endif
|
91
src/loaders/external_png/tvgPngLoader.cpp
Normal file
91
src/loaders/external_png/tvgPngLoader.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
PngLoader::PngLoader()
|
||||
{
|
||||
image = static_cast<png_imagep>(calloc(1, sizeof(png_image)));
|
||||
image->version = PNG_IMAGE_VERSION;
|
||||
image->opaque = NULL;
|
||||
}
|
||||
|
||||
PngLoader::~PngLoader()
|
||||
{
|
||||
if (content) {
|
||||
free((void*)content);
|
||||
content = nullptr;
|
||||
}
|
||||
free(image);
|
||||
}
|
||||
|
||||
bool PngLoader::open(const string& path)
|
||||
{
|
||||
image->opaque = NULL;
|
||||
|
||||
if (!png_image_begin_read_from_file(image, path.c_str())) return false;
|
||||
|
||||
w = image->width;
|
||||
h = image->height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
||||
{
|
||||
image->opaque = NULL;
|
||||
|
||||
if (!png_image_begin_read_from_memory(image, data, size)) return false;
|
||||
|
||||
w = image->width;
|
||||
h = image->height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PngLoader::read()
|
||||
{
|
||||
png_bytep buffer;
|
||||
image->format = PNG_FORMAT_BGRA;
|
||||
buffer = static_cast<png_bytep>(malloc(PNG_IMAGE_SIZE((*image))));
|
||||
if (!buffer) {
|
||||
//out of memory, only time when libpng doesnt free its data
|
||||
png_image_free(image);
|
||||
return false;
|
||||
}
|
||||
if (!png_image_finish_read(image, NULL, buffer, 0, NULL)) return false;
|
||||
content = reinterpret_cast<uint32_t*>(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PngLoader::close()
|
||||
{
|
||||
png_image_free(image);
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint32_t* PngLoader::pixels()
|
||||
{
|
||||
return this->content;
|
||||
}
|
46
src/loaders/external_png/tvgPngLoader.h
Normal file
46
src/loaders/external_png/tvgPngLoader.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef _TVG_PNG_LOADER_H_
|
||||
#define _TVG_PNG_LOADER_H_
|
||||
|
||||
#include <png.h>
|
||||
|
||||
class PngLoader : public LoadModule
|
||||
{
|
||||
public:
|
||||
PngLoader();
|
||||
~PngLoader();
|
||||
|
||||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
||||
private:
|
||||
png_imagep image = nullptr;
|
||||
const uint32_t* content = nullptr;
|
||||
};
|
||||
|
||||
#endif //_TVG_PNG_LOADER_H_
|
|
@ -3,16 +3,7 @@ source_file = [
|
|||
'tvgJpgLoader.cpp',
|
||||
]
|
||||
|
||||
jpg_dep = dependency('libturbojpeg', required: false)
|
||||
if not jpg_dep.found()
|
||||
jpg_dep = cc.find_library('turbojpeg', required: false)
|
||||
endif
|
||||
if not jpg_dep.found()
|
||||
error('JPEG image loading requires libturbojpeg or turbojpeg, neither was found.')
|
||||
endif
|
||||
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : jpg_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
#include <turbojpeg.h>
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgJpgLoader.h"
|
||||
|
||||
|
@ -29,13 +27,6 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
void JpgLoader::clear()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
|
@ -43,111 +34,51 @@ void JpgLoader::clear()
|
|||
|
||||
JpgLoader::JpgLoader()
|
||||
{
|
||||
jpegDecompressor = tjInitDecompress();
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
||||
JpgLoader::~JpgLoader()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
tjDestroy(jpegDecompressor);
|
||||
|
||||
//This image is shared with raster engine.
|
||||
tjFree(image);
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const string& path)
|
||||
{
|
||||
clear();
|
||||
//TODO:
|
||||
|
||||
auto jpegFile = fopen(path.c_str(), "rb");
|
||||
if (!jpegFile) return false;
|
||||
|
||||
auto ret = false;
|
||||
|
||||
//determine size
|
||||
if (fseek(jpegFile, 0, SEEK_END) < 0) goto finalize;
|
||||
if (((size = ftell(jpegFile)) < 1)) goto finalize;
|
||||
if (fseek(jpegFile, 0, SEEK_SET)) goto finalize;
|
||||
|
||||
data = (unsigned char *) malloc(size);
|
||||
if (!data) goto finalize;
|
||||
|
||||
if (fread(data, size, 1, jpegFile) < 1) goto failure;
|
||||
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &subSample, &colorSpace) < 0) {
|
||||
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
|
||||
goto failure;
|
||||
}
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
ret = true;
|
||||
freeData = true;
|
||||
|
||||
goto finalize;
|
||||
|
||||
failure:
|
||||
clear();
|
||||
|
||||
finalize:
|
||||
fclose(jpegFile);
|
||||
return ret;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
||||
{
|
||||
clear();
|
||||
//TODO:
|
||||
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
||||
|
||||
if (copy) {
|
||||
this->data = (unsigned char *) malloc(size);
|
||||
if (!this->data) return false;
|
||||
memcpy((unsigned char *)this->data, data, size);
|
||||
freeData = true;
|
||||
} else {
|
||||
this->data = (unsigned char *) data;
|
||||
}
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
this->size = size;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::read()
|
||||
{
|
||||
if (image) tjFree(image);
|
||||
image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[TJPF_BGRX]);
|
||||
if (!image) return false;
|
||||
//TODO:
|
||||
|
||||
//decompress jpg image
|
||||
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), TJPF_BGRX, 0) < 0) {
|
||||
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
|
||||
tjFree(image);
|
||||
image = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool JpgLoader::close()
|
||||
{
|
||||
clear();
|
||||
return true;
|
||||
//TODO:
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const uint32_t* JpgLoader::pixels()
|
||||
{
|
||||
return (const uint32_t*) image;
|
||||
}
|
||||
//TODO:
|
||||
|
||||
return nullptr;
|
||||
}
|
|
@ -22,8 +22,6 @@
|
|||
#ifndef _TVG_JPG_LOADER_H_
|
||||
#define _TVG_JPG_LOADER_H_
|
||||
|
||||
using tjhandle = void*;
|
||||
|
||||
//TODO: Use Task?
|
||||
class JpgLoader : public LoadModule
|
||||
{
|
||||
|
@ -38,15 +36,6 @@ public:
|
|||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
tjhandle jpegDecompressor;
|
||||
unsigned char* data = nullptr;
|
||||
unsigned char *image = nullptr;
|
||||
unsigned long size = 0;
|
||||
bool freeData = false;
|
||||
};
|
||||
|
||||
#endif //_TVG_JPG_LOADER_H_
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
subloader_dep = []
|
||||
|
||||
if get_option('loaders').contains('tvg') == true
|
||||
subdir('tvg')
|
||||
endif
|
||||
|
||||
if get_option('loaders').contains('svg') == true
|
||||
subdir('svg')
|
||||
endif
|
||||
|
||||
if get_option('loaders').contains('png') == true
|
||||
subdir('png')
|
||||
endif
|
||||
|
||||
if get_option('loaders').contains('tvg') == true
|
||||
subdir('tvg')
|
||||
subdir('external_png')
|
||||
if not png_dep.found()
|
||||
subdir('png')
|
||||
endif
|
||||
endif
|
||||
|
||||
if get_option('loaders').contains('jpg') == true
|
||||
subdir('jpg')
|
||||
subdir('external_jpg')
|
||||
if not jpg_dep.found()
|
||||
subdir('jpg')
|
||||
endif
|
||||
endif
|
||||
|
||||
subdir('raw')
|
||||
|
||||
loader_dep = declare_dependency(
|
||||
dependencies: subloader_dep,
|
||||
include_directories : include_directories('.'),
|
||||
dependencies: subloader_dep,
|
||||
include_directories : include_directories('.'),
|
||||
)
|
||||
|
|
3
src/loaders/png/meson.build
Executable file → Normal file
3
src/loaders/png/meson.build
Executable file → Normal file
|
@ -3,10 +3,7 @@ source_file = [
|
|||
'tvgPngLoader.cpp',
|
||||
]
|
||||
|
||||
png_dep = meson.get_compiler('cpp').find_library('libpng')
|
||||
|
||||
subloader_dep += [declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
dependencies : png_dep,
|
||||
sources : source_file
|
||||
)]
|
||||
|
|
70
src/loaders/png/tvgPngLoader.cpp
Executable file → Normal file
70
src/loaders/png/tvgPngLoader.cpp
Executable file → Normal file
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -23,69 +23,63 @@
|
|||
#include "tvgLoader.h"
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
PngLoader::PngLoader()
|
||||
{
|
||||
image = static_cast<png_imagep>(calloc(1, sizeof(png_image)));
|
||||
image->version = PNG_IMAGE_VERSION;
|
||||
image->opaque = NULL;
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
||||
PngLoader::~PngLoader()
|
||||
{
|
||||
if (content) {
|
||||
free((void*)content);
|
||||
content = nullptr;
|
||||
}
|
||||
free(image);
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const string& path)
|
||||
{
|
||||
image->opaque = NULL;
|
||||
//TODO:
|
||||
|
||||
if (!png_image_begin_read_from_file(image, path.c_str())) return false;
|
||||
|
||||
w = image->width;
|
||||
h = image->height;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
||||
{
|
||||
image->opaque = NULL;
|
||||
//TODO:
|
||||
|
||||
if (!png_image_begin_read_from_memory(image, data, size)) return false;
|
||||
|
||||
w = image->width;
|
||||
h = image->height;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::read()
|
||||
{
|
||||
png_bytep buffer;
|
||||
image->format = PNG_FORMAT_BGRA;
|
||||
buffer = static_cast<png_bytep>(malloc(PNG_IMAGE_SIZE((*image))));
|
||||
if (!buffer) {
|
||||
//out of memory, only time when libpng doesnt free its data
|
||||
png_image_free(image);
|
||||
return false;
|
||||
}
|
||||
if (!png_image_finish_read(image, NULL, buffer, 0, NULL)) return false;
|
||||
content = reinterpret_cast<uint32_t*>(buffer);
|
||||
//TODO:
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::close()
|
||||
{
|
||||
png_image_free(image);
|
||||
return true;
|
||||
//TODO:
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const uint32_t* PngLoader::pixels()
|
||||
{
|
||||
return this->content;
|
||||
}
|
||||
//TODO:
|
||||
|
||||
return nullptr;
|
||||
}
|
9
src/loaders/png/tvgPngLoader.h
Executable file → Normal file
9
src/loaders/png/tvgPngLoader.h
Executable file → Normal file
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -22,8 +22,7 @@
|
|||
#ifndef _TVG_PNG_LOADER_H_
|
||||
#define _TVG_PNG_LOADER_H_
|
||||
|
||||
#include <png.h>
|
||||
|
||||
//TODO: Use Task?
|
||||
class PngLoader : public LoadModule
|
||||
{
|
||||
public:
|
||||
|
@ -37,10 +36,6 @@ public:
|
|||
bool close() override;
|
||||
|
||||
const uint32_t* pixels() override;
|
||||
|
||||
private:
|
||||
png_imagep image = nullptr;
|
||||
const uint32_t* content = nullptr;
|
||||
};
|
||||
|
||||
#endif //_TVG_PNG_LOADER_H_
|
||||
|
|
Loading…
Add table
Reference in a new issue