mirror of
https://github.com/Relintai/pandemonium_engine_minimal.git
synced 2024-12-21 16:56:50 +01:00
Removed the svg module.
This commit is contained in:
parent
b31bf4eaaa
commit
fb171e569c
@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_svg = env_modules.Clone()
|
||||
|
||||
# Thirdparty source files
|
||||
|
||||
thirdparty_obj = []
|
||||
|
||||
thirdparty_dir = "#thirdparty/nanosvg/"
|
||||
thirdparty_sources = ["nanosvg.cc"]
|
||||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
||||
|
||||
env_svg.Prepend(CPPPATH=[thirdparty_dir])
|
||||
|
||||
env_thirdparty = env_svg.Clone()
|
||||
env_thirdparty.disable_warnings()
|
||||
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
||||
env.modules_sources += thirdparty_obj
|
||||
|
||||
# Pandemonium source files
|
||||
|
||||
module_obj = []
|
||||
|
||||
env_svg.add_source_files(module_obj, "*.cpp")
|
||||
env.modules_sources += module_obj
|
||||
|
||||
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
||||
env.Depends(module_obj, thirdparty_obj)
|
@ -1,6 +0,0 @@
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
@ -1,160 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* image_loader_svg.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "image_loader_svg.h"
|
||||
|
||||
#include <nanosvg.h>
|
||||
#include <nanosvgrast.h>
|
||||
|
||||
void SVGRasterizer::rasterize(NSVGimage *p_image, float p_tx, float p_ty, float p_scale, unsigned char *p_dst, int p_w, int p_h, int p_stride) {
|
||||
nsvgRasterize(rasterizer, p_image, p_tx, p_ty, p_scale, p_dst, p_w, p_h, p_stride);
|
||||
}
|
||||
|
||||
SVGRasterizer::SVGRasterizer() {
|
||||
rasterizer = nsvgCreateRasterizer();
|
||||
}
|
||||
SVGRasterizer::~SVGRasterizer() {
|
||||
nsvgDeleteRasterizer(rasterizer);
|
||||
}
|
||||
|
||||
SVGRasterizer ImageLoaderSVG::rasterizer;
|
||||
|
||||
inline void change_nsvg_paint_color(NSVGpaint *p_paint, const uint32_t p_old, const uint32_t p_new) {
|
||||
if (p_paint->type == NSVG_PAINT_COLOR) {
|
||||
if (p_paint->color << 8 == p_old << 8) {
|
||||
p_paint->color = (p_paint->color & 0xFF000000) | (p_new & 0x00FFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_paint->type == NSVG_PAINT_LINEAR_GRADIENT || p_paint->type == NSVG_PAINT_RADIAL_GRADIENT) {
|
||||
for (int stop_index = 0; stop_index < p_paint->gradient->nstops; stop_index++) {
|
||||
if (p_paint->gradient->stops[stop_index].color << 8 == p_old << 8) {
|
||||
p_paint->gradient->stops[stop_index].color = p_new;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageLoaderSVG::_convert_colors(NSVGimage *p_svg_image) {
|
||||
for (NSVGshape *shape = p_svg_image->shapes; shape != nullptr; shape = shape->next) {
|
||||
for (int i = 0; i < replace_colors.old_colors.size(); i++) {
|
||||
change_nsvg_paint_color(&(shape->stroke), replace_colors.old_colors[i], replace_colors.new_colors[i]);
|
||||
change_nsvg_paint_color(&(shape->fill), replace_colors.old_colors[i], replace_colors.new_colors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageLoaderSVG::set_convert_colors(Dictionary *p_replace_color) {
|
||||
if (p_replace_color) {
|
||||
Dictionary replace_color = *p_replace_color;
|
||||
for (int i = 0; i < replace_color.keys().size(); i++) {
|
||||
Variant o_c = replace_color.keys()[i];
|
||||
Variant n_c = replace_color[replace_color.keys()[i]];
|
||||
if (o_c.get_type() == Variant::COLOR && n_c.get_type() == Variant::COLOR) {
|
||||
Color old_color = o_c;
|
||||
Color new_color = n_c;
|
||||
replace_colors.old_colors.push_back(old_color.to_abgr32());
|
||||
replace_colors.new_colors.push_back(new_color.to_abgr32());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
replace_colors.old_colors.clear();
|
||||
replace_colors.new_colors.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t> *p_data, float p_scale, bool upsample, bool convert_colors) {
|
||||
NSVGimage *svg_image;
|
||||
PoolVector<uint8_t>::Read src_r = p_data->read();
|
||||
svg_image = nsvgParse((char *)src_r.ptr(), "px", 96);
|
||||
if (svg_image == nullptr) {
|
||||
ERR_PRINT("SVG Corrupted");
|
||||
return ERR_FILE_CORRUPT;
|
||||
}
|
||||
|
||||
if (convert_colors) {
|
||||
_convert_colors(svg_image);
|
||||
}
|
||||
|
||||
const float upscale = upsample ? 2.0 : 1.0;
|
||||
|
||||
const int w = (int)(svg_image->width * p_scale * upscale);
|
||||
ERR_FAIL_COND_V_MSG(w > Image::MAX_WIDTH, ERR_PARAMETER_RANGE_ERROR, vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max width.", rtos(p_scale)));
|
||||
|
||||
const int h = (int)(svg_image->height * p_scale * upscale);
|
||||
ERR_FAIL_COND_V_MSG(h > Image::MAX_HEIGHT, ERR_PARAMETER_RANGE_ERROR, vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max height.", rtos(p_scale)));
|
||||
|
||||
PoolVector<uint8_t> dst_image;
|
||||
dst_image.resize(w * h * 4);
|
||||
|
||||
PoolVector<uint8_t>::Write dw = dst_image.write();
|
||||
|
||||
rasterizer.rasterize(svg_image, 0, 0, p_scale * upscale, (unsigned char *)dw.ptr(), w, h, w * 4);
|
||||
|
||||
dw.release();
|
||||
p_image->create(w, h, false, Image::FORMAT_RGBA8, dst_image);
|
||||
if (upsample) {
|
||||
p_image->shrink_x2();
|
||||
}
|
||||
|
||||
nsvgDelete(svg_image);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *p_svg_str, float p_scale, bool upsample, bool convert_colors) {
|
||||
size_t str_len = strlen(p_svg_str);
|
||||
PoolVector<uint8_t> src_data;
|
||||
src_data.resize(str_len + 1);
|
||||
PoolVector<uint8_t>::Write src_w = src_data.write();
|
||||
memcpy(src_w.ptr(), p_svg_str, str_len + 1);
|
||||
|
||||
return _create_image(p_image, &src_data, p_scale, upsample, convert_colors);
|
||||
}
|
||||
|
||||
Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
|
||||
uint64_t size = f->get_len();
|
||||
PoolVector<uint8_t> src_image;
|
||||
src_image.resize(size + 1);
|
||||
PoolVector<uint8_t>::Write src_w = src_image.write();
|
||||
f->get_buffer(src_w.ptr(), size);
|
||||
src_w.ptr()[size] = '\0';
|
||||
|
||||
return _create_image(p_image, &src_image, p_scale, 1.0);
|
||||
}
|
||||
|
||||
void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
p_extensions->push_back("svg");
|
||||
}
|
||||
|
||||
ImageLoaderSVG::ImageLoaderSVG() {
|
||||
}
|
||||
|
||||
ImageLoaderSVG::ReplaceColors ImageLoaderSVG::replace_colors;
|
@ -1,72 +0,0 @@
|
||||
#ifndef IMAGE_LOADER_SVG_H
|
||||
#define IMAGE_LOADER_SVG_H
|
||||
/*************************************************************************/
|
||||
/* image_loader_svg.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/io/image_loader.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
/**
|
||||
@author Daniel Ramirez <djrmuv@gmail.com>
|
||||
*/
|
||||
|
||||
// Forward declare and include thirdparty headers in .cpp.
|
||||
struct NSVGrasterizer;
|
||||
struct NSVGimage;
|
||||
|
||||
class SVGRasterizer {
|
||||
NSVGrasterizer *rasterizer;
|
||||
|
||||
public:
|
||||
void rasterize(NSVGimage *p_image, float p_tx, float p_ty, float p_scale, unsigned char *p_dst, int p_w, int p_h, int p_stride);
|
||||
|
||||
SVGRasterizer();
|
||||
~SVGRasterizer();
|
||||
};
|
||||
|
||||
class ImageLoaderSVG : public ImageFormatLoader {
|
||||
static struct ReplaceColors {
|
||||
List<uint32_t> old_colors;
|
||||
List<uint32_t> new_colors;
|
||||
} replace_colors;
|
||||
static SVGRasterizer rasterizer;
|
||||
static void _convert_colors(NSVGimage *p_svg_image);
|
||||
static Error _create_image(Ref<Image> p_image, const PoolVector<uint8_t> *p_data, float p_scale, bool upsample, bool convert_colors = false);
|
||||
|
||||
public:
|
||||
static void set_convert_colors(Dictionary *p_replace_color = nullptr);
|
||||
static Error create_image_from_string(Ref<Image> p_image, const char *p_svg_str, float p_scale, bool upsample, bool convert_colors = false);
|
||||
|
||||
virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale);
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
ImageLoaderSVG();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,48 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "register_types.h"
|
||||
|
||||
#include "image_loader_svg.h"
|
||||
|
||||
static ImageLoaderSVG *image_loader_svg = nullptr;
|
||||
|
||||
void register_svg_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
image_loader_svg = memnew(ImageLoaderSVG);
|
||||
ImageLoader::add_image_format_loader(image_loader_svg);
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_svg_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
memdelete(image_loader_svg);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#ifndef SVG_REGISTER_TYPES_H
|
||||
#define SVG_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "modules/register_module_types.h"
|
||||
|
||||
void register_svg_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_svg_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif // SVG_REGISTER_TYPES_H
|
18
thirdparty/nanosvg/LICENSE.txt
vendored
18
thirdparty/nanosvg/LICENSE.txt
vendored
@ -1,18 +0,0 @@
|
||||
Copyright (c) 2013-14 Mikko Mononen memon@inside.org
|
||||
|
||||
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.
|
||||
|
5
thirdparty/nanosvg/nanosvg.cc
vendored
5
thirdparty/nanosvg/nanosvg.cc
vendored
@ -1,5 +0,0 @@
|
||||
#define NANOSVG_ALL_COLOR_KEYWORDS
|
||||
#define NANOSVG_IMPLEMENTATION
|
||||
#include "nanosvg.h"
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
#include "nanosvgrast.h"
|
3072
thirdparty/nanosvg/nanosvg.h
vendored
3072
thirdparty/nanosvg/nanosvg.h
vendored
File diff suppressed because it is too large
Load Diff
1460
thirdparty/nanosvg/nanosvgrast.h
vendored
1460
thirdparty/nanosvg/nanosvgrast.h
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user