From 6a9c990da72a737fa95d9e97d53f835706aea7c3 Mon Sep 17 00:00:00 2001 From: Ferenc Arn Date: Wed, 26 Apr 2017 10:49:08 -0500 Subject: Add ETC1/ETC2 compression support though etc2comp. Remove rg-etc1 code. Also updated travis to use ubuntu 14.04. Fixes #8457. --- modules/etc/SCsub | 37 ++++++++ modules/etc/config.py | 7 ++ modules/etc/image_etc.cpp | 181 +++++++++++++++++++++++++++++++++++ modules/etc/image_etc.h | 35 +++++++ modules/etc/register_types.cpp | 48 ++++++++++ modules/etc/register_types.h | 31 ++++++ modules/etc/texture_loader_pkm.cpp | 114 ++++++++++++++++++++++ modules/etc/texture_loader_pkm.h | 46 +++++++++ modules/etc1/SCsub | 20 ---- modules/etc1/config.py | 7 -- modules/etc1/image_etc.cpp | 183 ------------------------------------ modules/etc1/image_etc.h | 35 ------- modules/etc1/register_types.cpp | 48 ---------- modules/etc1/register_types.h | 31 ------ modules/etc1/texture_loader_pkm.cpp | 114 ---------------------- modules/etc1/texture_loader_pkm.h | 46 --------- 16 files changed, 499 insertions(+), 484 deletions(-) create mode 100644 modules/etc/SCsub create mode 100644 modules/etc/config.py create mode 100644 modules/etc/image_etc.cpp create mode 100644 modules/etc/image_etc.h create mode 100644 modules/etc/register_types.cpp create mode 100644 modules/etc/register_types.h create mode 100644 modules/etc/texture_loader_pkm.cpp create mode 100644 modules/etc/texture_loader_pkm.h delete mode 100644 modules/etc1/SCsub delete mode 100644 modules/etc1/config.py delete mode 100644 modules/etc1/image_etc.cpp delete mode 100644 modules/etc1/image_etc.h delete mode 100644 modules/etc1/register_types.cpp delete mode 100644 modules/etc1/register_types.h delete mode 100644 modules/etc1/texture_loader_pkm.cpp delete mode 100644 modules/etc1/texture_loader_pkm.h (limited to 'modules') diff --git a/modules/etc/SCsub b/modules/etc/SCsub new file mode 100644 index 0000000000..8f5937017e --- /dev/null +++ b/modules/etc/SCsub @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_etc = env_modules.Clone() + +# Thirdparty source files +# Not unbundled so far since not widespread as shared library +thirdparty_dir = "#thirdparty/etc2comp/" +thirdparty_sources = [ + "EtcBlock4x4.cpp", + "EtcBlock4x4Encoding.cpp", + "EtcBlock4x4Encoding_ETC1.cpp", + "EtcBlock4x4Encoding_R11.cpp", + "EtcBlock4x4Encoding_RG11.cpp", + "EtcBlock4x4Encoding_RGB8A1.cpp", + "EtcBlock4x4Encoding_RGB8.cpp", + "EtcBlock4x4Encoding_RGBA8.cpp", + "Etc.cpp", + "EtcDifferentialTrys.cpp", + "EtcFilter.cpp", + "EtcImage.cpp", + "EtcIndividualTrys.cpp", + "EtcMath.cpp", + "EtcSortedBlockList.cpp", +] +thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + +env_etc.add_source_files(env.modules_sources, thirdparty_sources) +env_etc.Append(CPPPATH=[thirdparty_dir]) + +# Godot source files +env_etc.add_source_files(env.modules_sources, "*.cpp") + +# upstream uses c++11 +env_etc.Append(CXXFLAGS="-std=gnu++11") diff --git a/modules/etc/config.py b/modules/etc/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/etc/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp new file mode 100644 index 0000000000..4ccd5c8d89 --- /dev/null +++ b/modules/etc/image_etc.cpp @@ -0,0 +1,181 @@ +/*************************************************************************/ +/* image_etc.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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_etc.h" +#include "Etc.h" +#include "EtcFilter.h" +#include "image.h" +#include "os/copymem.h" +#include "os/os.h" +#include "print_string.h" + +static Image::Format _get_etc2_mode(Image::DetectChannels format) { + switch (format) { + case Image::DETECTED_L: + case Image::DETECTED_R: + return Image::FORMAT_ETC2_R11; + + case Image::DETECTED_RG: + return Image::FORMAT_ETC2_RG11; + + case Image::DETECTED_RGB: + return Image::FORMAT_ETC2_RGB8; + + case Image::DETECTED_RGBA: + return Image::FORMAT_ETC2_RGBA8; + + // TODO: would be nice if we could use FORMAT_ETC2_RGB8A1 for FORMAT_RGBA5551 + } + + ERR_FAIL_COND_V(true, Image::FORMAT_MAX); +} + +static Etc::Image::Format _image_format_to_etc2comp_format(Image::Format format) { + switch (format) { + case Image::FORMAT_ETC: + return Etc::Image::Format::ETC1; + + case Image::FORMAT_ETC2_R11: + return Etc::Image::Format::R11; + + case Image::FORMAT_ETC2_R11S: + return Etc::Image::Format::SIGNED_R11; + + case Image::FORMAT_ETC2_RG11: + return Etc::Image::Format::RG11; + + case Image::FORMAT_ETC2_RG11S: + return Etc::Image::Format::SIGNED_RG11; + + case Image::FORMAT_ETC2_RGB8: + return Etc::Image::Format::RGB8; + + case Image::FORMAT_ETC2_RGBA8: + return Etc::Image::Format::RGBA8; + + case Image::FORMAT_ETC2_RGB8A1: + return Etc::Image::Format::RGB8A1; + } + + ERR_FAIL_COND_V(true, Etc::Image::Format::UNKNOWN); +} + +static void _decompress_etc1(Image *p_img) { + // not implemented, to be removed +} + +static void _decompress_etc2(Image *p_img) { + // not implemented, to be removed +} + +static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_format) { + Image::Format img_format = p_img->get_format(); + Image::DetectChannels detected_channels = p_img->get_detected_channels(); + + if (img_format >= Image::FORMAT_DXT1) { + return; //do not compress, already compressed + } + + if (img_format > Image::FORMAT_RGBA8) { + // TODO: we should be able to handle FORMAT_RGBA4444 and FORMAT_RGBA5551 eventually + return; + } + + int imgw = p_img->get_width(), imgh = p_img->get_height(); + ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh); + + Image::Format etc_format = force_etc1_format ? Image::FORMAT_ETC : _get_etc2_mode(detected_channels); + + Ref img = p_img->duplicate(); + + if (img->get_format() != Image::FORMAT_RGBA8) + img->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + + PoolVector::Read r = img->get_data().read(); + + int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps() ? -1 : 0); + int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0; + + PoolVector dst_data; + dst_data.resize(target_size); + + PoolVector::Write w = dst_data.write(); + + // prepare parameters to be passed to etc2comp + int num_cpus = OS::get_singleton()->get_processor_count(); + int encoding_time = 0; + float effort = CLAMP(p_lossy_quality * 100, 0, 100); + Etc::ErrorMetric error_metric = Etc::ErrorMetric::BT709; // NOTE: we can experiment with other error metrics + Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format); + + int wofs = 0; + for (int i = 0; i < mmc + 1; i++) { + // convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF) + // NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion. + int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; + img->get_mipmap_offset_size_and_dimensions(i, mipmap_ofs, mipmap_size, mipmap_w, mipmap_h); + const uint8_t *src = &r[mipmap_ofs]; + + Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h]; + for (int i = 0; i < mipmap_w * mipmap_h; i++) { + int si = i * 4; // RGBA8 + src_rgba_f[i] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); + } + + unsigned char *etc_data = NULL; + unsigned int etc_data_len = 0; + unsigned int extended_width = 0, extended_height = 0; + Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time); + + memcpy(&w[wofs], etc_data, etc_data_len); + wofs += etc_data_len; + + delete[] etc_data; + delete[] src_rgba_f; + } + + p_img->create(imgw, imgh, mmc > 1 ? true : false, etc_format, dst_data); +} + +static void _compress_etc1(Image *p_img, float p_lossy_quality) { + _compress_etc(p_img, p_lossy_quality, true); +} + +static void _compress_etc2(Image *p_img, float p_lossy_quality) { + _compress_etc(p_img, p_lossy_quality, false); +} + +void _register_etc_compress_func() { + + Image::_image_compress_etc1_func = _compress_etc1; + //Image::_image_decompress_etc1 = _decompress_etc1; + + Image::_image_compress_etc2_func = _compress_etc2; + //Image::_image_decompress_etc2 = _decompress_etc2; +} diff --git a/modules/etc/image_etc.h b/modules/etc/image_etc.h new file mode 100644 index 0000000000..3cbadef6fa --- /dev/null +++ b/modules/etc/image_etc.h @@ -0,0 +1,35 @@ +/*************************************************************************/ +/* image_etc.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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. */ +/*************************************************************************/ +#ifndef IMAGE_ETC1_H +#define IMAGE_ETC1_H + +void _register_etc_compress_func(); + +#endif // IMAGE_ETC_H diff --git a/modules/etc/register_types.cpp b/modules/etc/register_types.cpp new file mode 100644 index 0000000000..e777859a8f --- /dev/null +++ b/modules/etc/register_types.cpp @@ -0,0 +1,48 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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_etc.h" +#include "texture_loader_pkm.h" + +static ResourceFormatPKM *resource_loader_pkm = NULL; + +void register_etc_types() { + + resource_loader_pkm = memnew(ResourceFormatPKM); + ResourceLoader::add_resource_format_loader(resource_loader_pkm); + + _register_etc_compress_func(); +} + +void unregister_etc_types() { + + memdelete(resource_loader_pkm); +} diff --git a/modules/etc/register_types.h b/modules/etc/register_types.h new file mode 100644 index 0000000000..44399376f3 --- /dev/null +++ b/modules/etc/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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. */ +/*************************************************************************/ +void register_etc_types(); +void unregister_etc_types(); diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp new file mode 100644 index 0000000000..c04528d2a0 --- /dev/null +++ b/modules/etc/texture_loader_pkm.cpp @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* texture_loader_pkm.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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 "texture_loader_pkm.h" + +#include "os/file_access.h" +#include + +struct ETC1Header { + char tag[6]; // "PKM 10" + uint16_t format; // Format == number of mips (== zero) + uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian) + uint16_t texHeight; + uint16_t origWidth; // Original dimensions (big-endian) + uint16_t origHeight; +}; + +RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error) { + + if (r_error) + *r_error = ERR_CANT_OPEN; + + Error err; + FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); + if (!f) + return RES(); + + FileAccessRef fref(f); + if (r_error) + *r_error = ERR_FILE_CORRUPT; + + ERR_EXPLAIN("Unable to open PKM texture file: " + p_path); + ERR_FAIL_COND_V(err != OK, RES()); + + // big endian + f->set_endian_swap(true); + + ETC1Header h; + ERR_EXPLAIN("Invalid or Unsupported PKM texture file: " + p_path); + f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag)); + if (strncmp(h.tag, "PKM 10", sizeof(h.tag))) + ERR_FAIL_V(RES()); + + h.format = f->get_16(); + h.texWidth = f->get_16(); + h.texHeight = f->get_16(); + h.origWidth = f->get_16(); + h.origHeight = f->get_16(); + + PoolVector src_data; + + uint32_t size = h.texWidth * h.texHeight / 2; + src_data.resize(size); + PoolVector::Write wb = src_data.write(); + f->get_buffer(wb.ptr(), size); + wb = PoolVector::Write(); + + int mipmaps = h.format; + int width = h.origWidth; + int height = h.origHeight; + + Ref img = memnew(Image(width, height, mipmaps, Image::FORMAT_ETC, src_data)); + + Ref texture = memnew(ImageTexture); + texture->create_from_image(img); + + if (r_error) + *r_error = OK; + + return texture; +} + +void ResourceFormatPKM::get_recognized_extensions(List *p_extensions) const { + + p_extensions->push_back("pkm"); +} + +bool ResourceFormatPKM::handles_type(const String &p_type) const { + + return ClassDB::is_parent_class(p_type, "Texture"); +} + +String ResourceFormatPKM::get_resource_type(const String &p_path) const { + + if (p_path.get_extension().to_lower() == "pkm") + return "ImageTexture"; + return ""; +} diff --git a/modules/etc/texture_loader_pkm.h b/modules/etc/texture_loader_pkm.h new file mode 100644 index 0000000000..8a0f06a51a --- /dev/null +++ b/modules/etc/texture_loader_pkm.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* texture_loader_pkm.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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. */ +/*************************************************************************/ +#ifndef TEXTURE_LOADER_PKM_H +#define TEXTURE_LOADER_PKM_H + +#include "io/resource_loader.h" +#include "scene/resources/texture.h" + +class ResourceFormatPKM : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); + virtual void get_recognized_extensions(List *p_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; + + virtual ~ResourceFormatPKM() {} +}; + +#endif // TEXTURE_LOADER_PKM_H diff --git a/modules/etc1/SCsub b/modules/etc1/SCsub deleted file mode 100644 index 0c5dc66d2e..0000000000 --- a/modules/etc1/SCsub +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -Import('env') -Import('env_modules') - -env_etc1 = env_modules.Clone() - -# Thirdparty source files -# Not unbundled so far since not widespread as shared library -thirdparty_dir = "#thirdparty/rg-etc1/" -thirdparty_sources = [ - "rg_etc1.cpp", -] -thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - -env_etc1.add_source_files(env.modules_sources, thirdparty_sources) -env_etc1.Append(CPPPATH=[thirdparty_dir]) - -# Godot source files -env_etc1.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/etc1/config.py b/modules/etc1/config.py deleted file mode 100644 index fb920482f5..0000000000 --- a/modules/etc1/config.py +++ /dev/null @@ -1,7 +0,0 @@ - -def can_build(platform): - return True - - -def configure(env): - pass diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp deleted file mode 100644 index 121f50684d..0000000000 --- a/modules/etc1/image_etc.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*************************************************************************/ -/* image_etc.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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_etc.h" -#include "image.h" -#include "os/copymem.h" -#include "print_string.h" -#include "rg_etc1.h" -static void _decompress_etc(Image *p_img) { - - ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_ETC); - - int imgw = p_img->get_width(); - int imgh = p_img->get_height(); - PoolVector src = p_img->get_data(); - PoolVector dst; - - PoolVector::Read r = src.read(); - - int mmc = p_img->get_mipmap_count(); - - for (int i = 0; i <= mmc; i++) { - - dst.resize(dst.size() + imgw * imgh * 3); - const uint8_t *srcbr = &r[p_img->get_mipmap_offset(i)]; - PoolVector::Write w = dst.write(); - - uint8_t *wptr = &w[dst.size() - imgw * imgh * 3]; - - int bw = MAX(imgw / 4, 1); - int bh = MAX(imgh / 4, 1); - - for (int y = 0; y < bh; y++) { - - for (int x = 0; x < bw; x++) { - - uint8_t block[4 * 4 * 4]; - - rg_etc1::unpack_etc1_block(srcbr, (unsigned int *)block); - srcbr += 8; - - int maxx = MIN(imgw, 4); - int maxy = MIN(imgh, 4); - - for (int yy = 0; yy < maxy; yy++) { - - for (int xx = 0; xx < maxx; xx++) { - - uint32_t src_ofs = (yy * 4 + xx) * 4; - uint32_t dst_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3; - wptr[dst_ofs + 0] = block[src_ofs + 0]; - wptr[dst_ofs + 1] = block[src_ofs + 1]; - wptr[dst_ofs + 2] = block[src_ofs + 2]; - } - } - } - } - - imgw = MAX(1, imgw / 2); - imgh = MAX(1, imgh / 2); - } - - r = PoolVector::Read(); - //print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps())); - bool needs_mipmaps = p_img->has_mipmaps(); - p_img->create(p_img->get_width(), p_img->get_height(), p_img->has_mipmaps(), Image::FORMAT_RGB8, dst); - if (needs_mipmaps) - p_img->generate_mipmaps(); -} - -static void _compress_etc(Image *p_img) { - - Ref img = p_img->duplicate(); - - int imgw = img->get_width(), imgh = img->get_height(); - - ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh); - - if (img->get_format() != Image::FORMAT_RGB8) - img->convert(Image::FORMAT_RGB8); - - PoolVector res_data; - PoolVector dst_data; - PoolVector::Read r = img->get_data().read(); - - int target_size = Image::get_image_data_size(p_img->get_width(), p_img->get_height(), Image::FORMAT_ETC, p_img->has_mipmaps() ? -1 : 0); - int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(), p_img->get_height(), Image::FORMAT_ETC) : 0; - - dst_data.resize(target_size); - int mc = 0; - int ofs = 0; - PoolVector::Write w = dst_data.write(); - - rg_etc1::etc1_pack_params pp; - pp.m_quality = rg_etc1::cLowQuality; - for (int i = 0; i <= mmc; i++) { - - int bw = MAX(imgw / 4, 1); - int bh = MAX(imgh / 4, 1); - const uint8_t *src = &r[img->get_mipmap_offset(i)]; - int mmsize = MAX(bw, 1) * MAX(bh, 1) * 8; - - uint8_t *dst = &w[ofs]; - ofs += mmsize; - - //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); - - for (int y = 0; y < bh; y++) { - - for (int x = 0; x < bw; x++) { - - //print_line("x: "+itos(x)+" y: "+itos(y)); - - uint8_t block[4 * 4 * 4]; - zeromem(block, 4 * 4 * 4); - uint8_t cblock[8]; - - int maxy = MIN(imgh, 4); - int maxx = MIN(imgw, 4); - - for (int yy = 0; yy < maxy; yy++) { - - for (int xx = 0; xx < maxx; xx++) { - - uint32_t dst_ofs = (yy * 4 + xx) * 4; - uint32_t src_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3; - block[dst_ofs + 0] = src[src_ofs + 0]; - block[dst_ofs + 1] = src[src_ofs + 1]; - block[dst_ofs + 2] = src[src_ofs + 2]; - block[dst_ofs + 3] = 255; - } - } - - rg_etc1::pack_etc1_block(cblock, (const unsigned int *)block, pp); - for (int j = 0; j < 8; j++) { - - dst[j] = cblock[j]; - } - - dst += 8; - } - } - - imgw = MAX(1, imgw / 2); - imgh = MAX(1, imgh / 2); - mc++; - } - - p_img->create(p_img->get_width(), p_img->get_height(), (mc - 1) ? true : false, Image::FORMAT_ETC, dst_data); -} - -void _register_etc1_compress_func() { - - rg_etc1::pack_etc1_block_init(); - Image::_image_compress_etc_func = _compress_etc; - Image::_image_decompress_etc = _decompress_etc; -} diff --git a/modules/etc1/image_etc.h b/modules/etc1/image_etc.h deleted file mode 100644 index 69e082bb87..0000000000 --- a/modules/etc1/image_etc.h +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************/ -/* image_etc.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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. */ -/*************************************************************************/ -#ifndef IMAGE_ETC1_H -#define IMAGE_ETC1_H - -void _register_etc1_compress_func(); - -#endif // IMAGE_ETC_H diff --git a/modules/etc1/register_types.cpp b/modules/etc1/register_types.cpp deleted file mode 100644 index 859486222f..0000000000 --- a/modules/etc1/register_types.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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_etc.h" -#include "texture_loader_pkm.h" - -static ResourceFormatPKM *resource_loader_pkm = NULL; - -void register_etc1_types() { - - resource_loader_pkm = memnew(ResourceFormatPKM); - ResourceLoader::add_resource_format_loader(resource_loader_pkm); - - _register_etc1_compress_func(); -} - -void unregister_etc1_types() { - - memdelete(resource_loader_pkm); -} diff --git a/modules/etc1/register_types.h b/modules/etc1/register_types.h deleted file mode 100644 index 0552b87d65..0000000000 --- a/modules/etc1/register_types.h +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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. */ -/*************************************************************************/ -void register_etc1_types(); -void unregister_etc1_types(); diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc1/texture_loader_pkm.cpp deleted file mode 100644 index c04528d2a0..0000000000 --- a/modules/etc1/texture_loader_pkm.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************/ -/* texture_loader_pkm.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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 "texture_loader_pkm.h" - -#include "os/file_access.h" -#include - -struct ETC1Header { - char tag[6]; // "PKM 10" - uint16_t format; // Format == number of mips (== zero) - uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian) - uint16_t texHeight; - uint16_t origWidth; // Original dimensions (big-endian) - uint16_t origHeight; -}; - -RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error) { - - if (r_error) - *r_error = ERR_CANT_OPEN; - - Error err; - FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) - return RES(); - - FileAccessRef fref(f); - if (r_error) - *r_error = ERR_FILE_CORRUPT; - - ERR_EXPLAIN("Unable to open PKM texture file: " + p_path); - ERR_FAIL_COND_V(err != OK, RES()); - - // big endian - f->set_endian_swap(true); - - ETC1Header h; - ERR_EXPLAIN("Invalid or Unsupported PKM texture file: " + p_path); - f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag)); - if (strncmp(h.tag, "PKM 10", sizeof(h.tag))) - ERR_FAIL_V(RES()); - - h.format = f->get_16(); - h.texWidth = f->get_16(); - h.texHeight = f->get_16(); - h.origWidth = f->get_16(); - h.origHeight = f->get_16(); - - PoolVector src_data; - - uint32_t size = h.texWidth * h.texHeight / 2; - src_data.resize(size); - PoolVector::Write wb = src_data.write(); - f->get_buffer(wb.ptr(), size); - wb = PoolVector::Write(); - - int mipmaps = h.format; - int width = h.origWidth; - int height = h.origHeight; - - Ref img = memnew(Image(width, height, mipmaps, Image::FORMAT_ETC, src_data)); - - Ref texture = memnew(ImageTexture); - texture->create_from_image(img); - - if (r_error) - *r_error = OK; - - return texture; -} - -void ResourceFormatPKM::get_recognized_extensions(List *p_extensions) const { - - p_extensions->push_back("pkm"); -} - -bool ResourceFormatPKM::handles_type(const String &p_type) const { - - return ClassDB::is_parent_class(p_type, "Texture"); -} - -String ResourceFormatPKM::get_resource_type(const String &p_path) const { - - if (p_path.get_extension().to_lower() == "pkm") - return "ImageTexture"; - return ""; -} diff --git a/modules/etc1/texture_loader_pkm.h b/modules/etc1/texture_loader_pkm.h deleted file mode 100644 index 8a0f06a51a..0000000000 --- a/modules/etc1/texture_loader_pkm.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************/ -/* texture_loader_pkm.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 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. */ -/*************************************************************************/ -#ifndef TEXTURE_LOADER_PKM_H -#define TEXTURE_LOADER_PKM_H - -#include "io/resource_loader.h" -#include "scene/resources/texture.h" - -class ResourceFormatPKM : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); - virtual void get_recognized_extensions(List *p_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; - - virtual ~ResourceFormatPKM() {} -}; - -#endif // TEXTURE_LOADER_PKM_H -- cgit v1.2.3