Merge pull request #67351 from akien-mga/thorvg-0.8.2-cleanup-includes
thorvg: Sync with 0.8.2, cleanup SCsub and fix includes
This commit is contained in:
commit
01ae26d31b
|
@ -11,6 +11,16 @@ thirdparty_obj = []
|
|||
|
||||
thirdparty_dir = "#thirdparty/thorvg/"
|
||||
thirdparty_sources = [
|
||||
"src/lib/sw_engine/tvgSwFill.cpp",
|
||||
"src/lib/sw_engine/tvgSwImage.cpp",
|
||||
"src/lib/sw_engine/tvgSwMath.cpp",
|
||||
"src/lib/sw_engine/tvgSwMemPool.cpp",
|
||||
"src/lib/sw_engine/tvgSwRaster.cpp",
|
||||
"src/lib/sw_engine/tvgSwRenderer.cpp",
|
||||
"src/lib/sw_engine/tvgSwRle.cpp",
|
||||
"src/lib/sw_engine/tvgSwShape.cpp",
|
||||
"src/lib/sw_engine/tvgSwStroke.cpp",
|
||||
"src/lib/tvgAccessor.cpp",
|
||||
"src/lib/tvgBezier.cpp",
|
||||
"src/lib/tvgCanvas.cpp",
|
||||
"src/lib/tvgFill.cpp",
|
||||
|
@ -28,27 +38,18 @@ thirdparty_sources = [
|
|||
"src/lib/tvgShape.cpp",
|
||||
"src/lib/tvgSwCanvas.cpp",
|
||||
"src/lib/tvgTaskScheduler.cpp",
|
||||
"src/loaders/external_png/tvgPngLoader.cpp",
|
||||
"src/loaders/jpg/tvgJpgd.cpp",
|
||||
"src/loaders/jpg/tvgJpgLoader.cpp",
|
||||
"src/loaders/raw/tvgRawLoader.cpp",
|
||||
"src/loaders/svg/tvgXmlParser.cpp",
|
||||
"src/loaders/svg/tvgSvgUtil.cpp",
|
||||
"src/loaders/svg/tvgSvgSceneBuilder.cpp",
|
||||
"src/loaders/svg/tvgSvgPath.cpp",
|
||||
"src/loaders/svg/tvgSvgLoader.cpp",
|
||||
"src/loaders/svg/tvgSvgCssStyle.cpp",
|
||||
"src/loaders/svg/tvgSvgLoader.cpp",
|
||||
"src/loaders/svg/tvgSvgPath.cpp",
|
||||
"src/loaders/svg/tvgSvgSceneBuilder.cpp",
|
||||
"src/loaders/svg/tvgSvgUtil.cpp",
|
||||
"src/loaders/svg/tvgXmlParser.cpp",
|
||||
"src/loaders/tvg/tvgTvgBinInterpreter.cpp",
|
||||
"src/loaders/tvg/tvgTvgLoader.cpp",
|
||||
"src/loaders/jpg/tvgJpgLoader.cpp",
|
||||
"src/loaders/jpg/tvgJpgd.cpp",
|
||||
"src/loaders/external_png/tvgPngLoader.cpp",
|
||||
"src/lib/sw_engine/tvgSwFill.cpp",
|
||||
"src/lib/sw_engine/tvgSwImage.cpp",
|
||||
"src/lib/sw_engine/tvgSwMath.cpp",
|
||||
"src/lib/sw_engine/tvgSwMemPool.cpp",
|
||||
"src/lib/sw_engine/tvgSwRaster.cpp",
|
||||
"src/lib/sw_engine/tvgSwRenderer.cpp",
|
||||
"src/lib/sw_engine/tvgSwRle.cpp",
|
||||
"src/lib/sw_engine/tvgSwShape.cpp",
|
||||
"src/lib/sw_engine/tvgSwStroke.cpp",
|
||||
"src/savers/tvg/tvgTvgSaver.cpp",
|
||||
]
|
||||
|
||||
|
@ -62,14 +63,18 @@ env_thirdparty.Prepend(
|
|||
CPPPATH=[
|
||||
thirdparty_dir + "src/lib",
|
||||
thirdparty_dir + "src/lib/sw_engine",
|
||||
thirdparty_dir + "src/loaders/external_png",
|
||||
thirdparty_dir + "src/loaders/jpg",
|
||||
thirdparty_dir + "src/loaders/raw",
|
||||
thirdparty_dir + "src/loaders/svg",
|
||||
thirdparty_dir + "src/loaders/jpg",
|
||||
thirdparty_dir + "src/loaders/png",
|
||||
thirdparty_dir + "src/loaders/tvg",
|
||||
thirdparty_dir + "src/savers/tvg",
|
||||
]
|
||||
)
|
||||
# Also requires libpng headers
|
||||
if env["builtin_libpng"]:
|
||||
env_thirdparty.Prepend(CPPPATH=["#thirdparty/libpng"])
|
||||
|
||||
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
||||
env.modules_sources += thirdparty_obj
|
||||
|
||||
|
|
|
@ -656,7 +656,7 @@ instead of `miniz.h` as an external dependency.
|
|||
## thorvg
|
||||
|
||||
- Upstream: https://github.com/Samsung/thorvg
|
||||
- Version: 0.8.1 (c4ccb1078f4390ec749ab8e05ba7e9e35f81285f, 2022)
|
||||
- Version: 0.8.2 (496796f1e5e85bd5fbba36dae987edb1b3945592, 2022)
|
||||
- License: MIT
|
||||
|
||||
Files extracted from upstream source:
|
||||
|
|
|
@ -13,5 +13,5 @@
|
|||
|
||||
#define THORVG_JPG_LOADER_SUPPORT 1
|
||||
|
||||
#define THORVG_VERSION_STRING "0.8.1"
|
||||
#define THORVG_VERSION_STRING "0.8.2"
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -22,8 +22,8 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <stdlib.h>
|
||||
#elif __FreeBSD__
|
||||
#include<stdlib.h>
|
||||
#else
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 - 2022 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;
|
||||
|
||||
freeData = true;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
unique_ptr<Surface> JpgLoader::bitmap()
|
||||
{
|
||||
if (!image) return nullptr;
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = (uint32_t*)(image);
|
||||
surface->stride = w;
|
||||
surface->w = w;
|
||||
surface->h = h;
|
||||
surface->cs = SwCanvas::ARGB8888;
|
||||
|
||||
return unique_ptr<Surface>(surface);
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 - 2022 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;
|
||||
|
||||
unique_ptr<Surface> bitmap() 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_
|
File diff suppressed because it is too large
Load Diff
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 - 2022 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
LodePNG version 20200306
|
||||
|
||||
Copyright (c) 2005-2020 Lode Vandevenne
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#ifndef _TVG_LODEPNG_H_
|
||||
#define _TVG_LODEPNG_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/*The PNG color types (also used for raw image).*/
|
||||
enum LodePNGColorType
|
||||
{
|
||||
LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/
|
||||
LCT_RGB = 2, /*RGB: 8,16 bit*/
|
||||
LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/
|
||||
LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/
|
||||
LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/
|
||||
/*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid
|
||||
byte value from 0 to 255 that could be present in an invalid PNG file header. Do
|
||||
not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use
|
||||
the valid color type names above, or numeric values like 1 or 7 when checking for
|
||||
particular disallowed color type byte values, or cast to integer to print it.*/
|
||||
LCT_MAX_OCTET_VALUE = 255
|
||||
};
|
||||
|
||||
/*Settings for zlib decompression*/
|
||||
struct LodePNGDecompressSettings
|
||||
{
|
||||
/* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */
|
||||
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
|
||||
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
|
||||
|
||||
/*use custom zlib decoder instead of built in one (default: null)*/
|
||||
unsigned (*custom_zlib)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings*);
|
||||
/*use custom deflate decoder instead of built in one (default: null) if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
|
||||
unsigned (*custom_inflate)(unsigned char**, size_t*, const unsigned char*, size_t, const LodePNGDecompressSettings*);
|
||||
|
||||
const void* custom_context; /*optional custom settings for custom functions*/
|
||||
};
|
||||
|
||||
/*
|
||||
Color mode of an image. Contains all information required to decode the pixel
|
||||
bits to RGBA colors. This information is the same as used in the PNG file
|
||||
format, and is used both for PNG and raw image data in LodePNG.
|
||||
*/
|
||||
struct LodePNGColorMode
|
||||
{
|
||||
/*header (IHDR)*/
|
||||
LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/
|
||||
unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/
|
||||
|
||||
/*
|
||||
palette (PLTE and tRNS)
|
||||
|
||||
Dynamically allocated with the colors of the palette, including alpha.
|
||||
This field may not be allocated directly, use lodepng_color_mode_init first,
|
||||
then lodepng_palette_add per color to correctly initialize it (to ensure size
|
||||
of exactly 1024 bytes).
|
||||
|
||||
The alpha channels must be set as well, set them to 255 for opaque images.
|
||||
|
||||
When decoding, by default you can ignore this palette, since LodePNG already
|
||||
fills the palette colors in the pixels of the raw RGBA output.
|
||||
|
||||
The palette is only supported for color type 3.
|
||||
*/
|
||||
unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/
|
||||
size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/
|
||||
|
||||
/*
|
||||
transparent color key (tRNS)
|
||||
|
||||
This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit.
|
||||
For grayscale PNGs, r, g and b will all 3 be set to the same.
|
||||
|
||||
When decoding, by default you can ignore this information, since LodePNG sets
|
||||
pixels with this key to transparent already in the raw RGBA output.
|
||||
|
||||
The color key is only supported for color types 0 and 2.
|
||||
*/
|
||||
unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/
|
||||
unsigned key_r; /*red/grayscale component of color key*/
|
||||
unsigned key_g; /*green component of color key*/
|
||||
unsigned key_b; /*blue component of color key*/
|
||||
};
|
||||
|
||||
/*Information about the PNG image, except pixels, width and height.*/
|
||||
struct LodePNGInfo
|
||||
{
|
||||
/*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/
|
||||
unsigned compression_method;/*compression method of the original file. Always 0.*/
|
||||
unsigned filter_method; /*filter method of the original file*/
|
||||
unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/
|
||||
LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/
|
||||
};
|
||||
|
||||
/*
|
||||
Settings for the decoder. This contains settings for the PNG and the Zlib
|
||||
decoder, but not the Info settings from the Info structs.
|
||||
*/
|
||||
struct LodePNGDecoderSettings
|
||||
{
|
||||
LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/
|
||||
|
||||
/* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */
|
||||
unsigned ignore_crc; /*ignore CRC checksums*/
|
||||
unsigned ignore_critical; /*ignore unknown critical chunks*/
|
||||
unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/
|
||||
/* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable
|
||||
errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some
|
||||
strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters
|
||||
in string keys, etc... */
|
||||
|
||||
unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/
|
||||
};
|
||||
|
||||
/*The settings, state and information for extended encoding and decoding.*/
|
||||
struct LodePNGState
|
||||
{
|
||||
LodePNGDecoderSettings decoder; /*the decoding settings*/
|
||||
LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/
|
||||
LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/
|
||||
unsigned error;
|
||||
};
|
||||
|
||||
void lodepng_state_init(LodePNGState* state);
|
||||
void lodepng_state_cleanup(LodePNGState* state);
|
||||
unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize);
|
||||
unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state, const unsigned char* in, size_t insize);
|
||||
|
||||
#endif //_TVG_LODEPNG_H_
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 - 2022 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 "tvgLoader.h"
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
|
||||
static inline uint32_t PREMULTIPLY(uint32_t c)
|
||||
{
|
||||
auto a = (c >> 24);
|
||||
return (c & 0xff000000) + ((((c >> 8) & 0xff) * a) & 0xff00) + ((((c & 0x00ff00ff) * a) >> 8) & 0x00ff00ff);
|
||||
}
|
||||
|
||||
|
||||
static void _premultiply(uint32_t* data, uint32_t w, uint32_t h)
|
||||
{
|
||||
auto buffer = data;
|
||||
for (uint32_t y = 0; y < h; ++y, buffer += w) {
|
||||
auto src = buffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++src) {
|
||||
*src = PREMULTIPLY(*src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PngLoader::clear()
|
||||
{
|
||||
lodepng_state_cleanup(&state);
|
||||
|
||||
if (freeData) free(data);
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
PngLoader::PngLoader()
|
||||
{
|
||||
lodepng_state_init(&state);
|
||||
}
|
||||
|
||||
|
||||
PngLoader::~PngLoader()
|
||||
{
|
||||
if (freeData) free(data);
|
||||
free(image);
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const string& path)
|
||||
{
|
||||
clear();
|
||||
|
||||
auto pngFile = fopen(path.c_str(), "rb");
|
||||
if (!pngFile) return false;
|
||||
|
||||
auto ret = false;
|
||||
|
||||
//determine size
|
||||
if (fseek(pngFile, 0, SEEK_END) < 0) goto finalize;
|
||||
if (((size = ftell(pngFile)) < 1)) goto finalize;
|
||||
if (fseek(pngFile, 0, SEEK_SET)) goto finalize;
|
||||
|
||||
data = (unsigned char *) malloc(size);
|
||||
if (!data) goto finalize;
|
||||
|
||||
freeData = true;
|
||||
|
||||
if (fread(data, size, 1, pngFile) < 1) goto failure;
|
||||
|
||||
lodepng_state_init(&state);
|
||||
|
||||
unsigned int width, height;
|
||||
if (lodepng_inspect(&width, &height, &state, data, size) > 0) goto failure;
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
ret = true;
|
||||
|
||||
goto finalize;
|
||||
|
||||
failure:
|
||||
clear();
|
||||
|
||||
finalize:
|
||||
fclose(pngFile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
||||
{
|
||||
clear();
|
||||
|
||||
lodepng_state_init(&state);
|
||||
|
||||
unsigned int width, height;
|
||||
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 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;
|
||||
freeData = false;
|
||||
}
|
||||
|
||||
w = static_cast<float>(width);
|
||||
h = static_cast<float>(height);
|
||||
this->size = size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::read()
|
||||
{
|
||||
if (!data || w <= 0 || h <= 0) return false;
|
||||
|
||||
TaskScheduler::request(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PngLoader::close()
|
||||
{
|
||||
this->done();
|
||||
clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
unique_ptr<Surface> PngLoader::bitmap()
|
||||
{
|
||||
this->done();
|
||||
|
||||
if (!image) return nullptr;
|
||||
|
||||
auto surface = static_cast<Surface*>(malloc(sizeof(Surface)));
|
||||
surface->buffer = (uint32_t*)(image);
|
||||
surface->stride = w;
|
||||
surface->w = w;
|
||||
surface->h = h;
|
||||
surface->cs = SwCanvas::ARGB8888;
|
||||
|
||||
return unique_ptr<Surface>(surface);
|
||||
}
|
||||
|
||||
|
||||
void PngLoader::run(unsigned tid)
|
||||
{
|
||||
if (image) {
|
||||
free(image);
|
||||
image = nullptr;
|
||||
}
|
||||
auto width = static_cast<unsigned>(w);
|
||||
auto height = static_cast<unsigned>(h);
|
||||
|
||||
lodepng_decode(&image, &width, &height, &state, data, size);
|
||||
|
||||
_premultiply((uint32_t*)(image), width, height);
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 - 2022 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 "tvgLodePng.h"
|
||||
#include "tvgTaskScheduler.h"
|
||||
|
||||
|
||||
class PngLoader : public LoadModule, public Task
|
||||
{
|
||||
private:
|
||||
LodePNGState state;
|
||||
unsigned char* data = nullptr;
|
||||
unsigned char *image = nullptr;
|
||||
unsigned long size = 0;
|
||||
bool freeData = false;
|
||||
|
||||
void clear();
|
||||
|
||||
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;
|
||||
|
||||
unique_ptr<Surface> bitmap() override;
|
||||
void run(unsigned tid) override;
|
||||
};
|
||||
|
||||
#endif //_TVG_PNG_LOADER_H_
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <stdlib.h>
|
||||
#elif __FreeBSD__
|
||||
#include<stdlib.h>
|
||||
#else
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
@ -390,7 +390,7 @@ bool simpleXmlParse(const char* buf, unsigned bufLength, bool strip, simpleXMLCb
|
|||
|
||||
if (p) {
|
||||
//Invalid case: '<' nested
|
||||
if (*p == '<') return false;
|
||||
if (*p == '<' && type != SimpleXMLType::Doctype) return false;
|
||||
const char *start, *end;
|
||||
|
||||
start = itr + 1 + toff;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <stdlib.h>
|
||||
#elif __FreeBSD__
|
||||
#include<stdlib.h>
|
||||
#else
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <stdlib.h>
|
||||
#elif __FreeBSD__
|
||||
#include<stdlib.h>
|
||||
#else
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
VERSION=0.8.1
|
||||
VERSION=0.8.2
|
||||
rm -rf AUTHORS inc LICENSE src *.zip
|
||||
curl -L -O https://github.com/Samsung/thorvg/archive/$VERSION.zip
|
||||
curl -L -O https://github.com/Samsung/thorvg/archive/v$VERSION.zip
|
||||
bsdtar --strip-components=1 -xvf *.zip
|
||||
rm *.zip
|
||||
rm -rf .github docs pc res test tools .git* *.md *.txt wasm_build.sh
|
||||
rm -rf .github docs pc res test tools tvgcompat .git* *.md *.txt wasm_build.sh
|
||||
find . -type f -name 'meson.build' -delete
|
||||
rm -rf src/bin src/bindings src/examples src/wasm
|
||||
rm -rf src/lib/gl_engine tvgcompat
|
||||
rm -rf src/lib/gl_engine src/loaders/external_jpg src/loaders/png
|
||||
cat << EOF > inc/config.h
|
||||
#ifndef THORVG_CONFIG_H
|
||||
#define THORVG_CONFIG_H
|
||||
|
|
Loading…
Reference in New Issue