diff options
Diffstat (limited to 'modules')
33 files changed, 778 insertions, 71 deletions
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 4448c80387..71593ebfa9 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -76,8 +76,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { { "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 }, { "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 }, { "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 }, - { "ATI1", true, false, 4, 8, Image::FORMAT_ATI1 }, - { "ATI2", true, false, 4, 16, Image::FORMAT_ATI2 }, { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 }, { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, diff --git a/modules/gdnative/godot/godot_array.cpp b/modules/gdnative/godot/godot_array.cpp index bf2ef35972..8cf6d1b8ef 100644 --- a/modules/gdnative/godot/godot_array.cpp +++ b/modules/gdnative/godot/godot_array.cpp @@ -49,6 +49,12 @@ void GDAPI godot_array_new(godot_array *p_arr) { memnew_placement(a, Array); } +void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src) { + Array *dest = (Array *)p_dest; + const Array *src = (const Array *)p_src; + memnew_placement(dest, Array(*src)); +} + void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca) { Array *a = (Array *)p_arr; PoolVector<Color> *pca = (PoolVector<Color> *)p_pca; diff --git a/modules/gdnative/godot/godot_array.h b/modules/gdnative/godot/godot_array.h index f7150950fc..5db0031b8c 100644 --- a/modules/gdnative/godot/godot_array.h +++ b/modules/gdnative/godot/godot_array.h @@ -49,6 +49,7 @@ typedef struct godot_array { #include "../godot.h" void GDAPI godot_array_new(godot_array *p_arr); +void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src); void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca); void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a); void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a); diff --git a/modules/gdnative/godot/godot_dictionary.cpp b/modules/gdnative/godot/godot_dictionary.cpp index b98ee5b5c9..deec5f8ffb 100644 --- a/modules/gdnative/godot/godot_dictionary.cpp +++ b/modules/gdnative/godot/godot_dictionary.cpp @@ -44,6 +44,12 @@ void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { memnew_placement(dest, Dictionary); } +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src) { + Dictionary *dest = (Dictionary *)r_dest; + const Dictionary *src = (const Dictionary *)r_src; + memnew_placement(dest, Dictionary(*src)); +} + void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) { Dictionary *self = (Dictionary *)p_self; self->~Dictionary(); diff --git a/modules/gdnative/godot/godot_dictionary.h b/modules/gdnative/godot/godot_dictionary.h index 42f7f872a1..a89bd4bba1 100644 --- a/modules/gdnative/godot/godot_dictionary.h +++ b/modules/gdnative/godot/godot_dictionary.h @@ -48,6 +48,7 @@ typedef struct godot_dictionary { #include "godot_variant.h" void GDAPI godot_dictionary_new(godot_dictionary *r_dest); +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src); void GDAPI godot_dictionary_destroy(godot_dictionary *p_self); godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self); diff --git a/modules/gdnative/godot/godot_pool_arrays.cpp b/modules/gdnative/godot/godot_pool_arrays.cpp index 10d5d6d939..ff4586ebe7 100644 --- a/modules/gdnative/godot/godot_pool_arrays.cpp +++ b/modules/gdnative/godot/godot_pool_arrays.cpp @@ -49,6 +49,12 @@ void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba) { memnew_placement(pba, PoolVector<uint8_t>); } +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)p_dest; + const PoolVector<uint8_t> *src = (const PoolVector<uint8_t> *)p_src; + memnew_placement(dest, PoolVector<uint8_t>(*src)); +} + void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a) { PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; Array *a = (Array *)p_a; @@ -118,14 +124,20 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba) { // int void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + memnew_placement(pba, PoolVector<godot_int>); +} + +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)p_dest; + const PoolVector<godot_int> *src = (const PoolVector<godot_int> *)p_src; + memnew_placement(dest, PoolVector<godot_int>(*src)); } void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(pba, PoolVector<godot_int>); pba->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { @@ -191,14 +203,20 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pba) { // real void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + memnew_placement(pba, PoolVector<godot_real>); +} + +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)p_dest; + const PoolVector<godot_real> *src = (const PoolVector<godot_real> *)p_src; + memnew_placement(dest, PoolVector<godot_real>(*src)); } void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(pba, PoolVector<godot_real>); pba->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { @@ -268,6 +286,12 @@ void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_pba) { memnew_placement(pba, PoolVector<String>); } +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src) { + PoolVector<String> *dest = (PoolVector<String> *)p_dest; + const PoolVector<String> *src = (const PoolVector<String> *)p_src; + memnew_placement(dest, PoolVector<String>(*src)); +} + void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_pba, const godot_array *p_a) { PoolVector<String> *pba = (PoolVector<String> *)p_pba; Array *a = (Array *)p_a; @@ -349,6 +373,12 @@ void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pba) { memnew_placement(pba, PoolVector<Vector2>); } +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)p_dest; + const PoolVector<Vector2> *src = (const PoolVector<Vector2> *)p_src; + memnew_placement(dest, PoolVector<Vector2>(*src)); +} + void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pba, const godot_array *p_a) { PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; Array *a = (Array *)p_a; @@ -429,6 +459,12 @@ void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pba) { memnew_placement(pba, PoolVector<Vector3>); } +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)p_dest; + const PoolVector<Vector3> *src = (const PoolVector<Vector3> *)p_src; + memnew_placement(dest, PoolVector<Vector3>(*src)); +} + void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pba, const godot_array *p_a) { PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; Array *a = (Array *)p_a; @@ -509,6 +545,12 @@ void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pba) { memnew_placement(pba, PoolVector<Color>); } +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src) { + PoolVector<Color> *dest = (PoolVector<Color> *)p_dest; + const PoolVector<Color> *src = (const PoolVector<Color> *)p_src; + memnew_placement(dest, PoolVector<Color>(*src)); +} + void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pba, const godot_array *p_a) { PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; Array *a = (Array *)p_a; diff --git a/modules/gdnative/godot/godot_pool_arrays.h b/modules/gdnative/godot/godot_pool_arrays.h index 015be65c3e..8b0d0137fd 100644 --- a/modules/gdnative/godot/godot_pool_arrays.h +++ b/modules/gdnative/godot/godot_pool_arrays.h @@ -102,6 +102,7 @@ typedef struct godot_pool_color_array { // byte void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba); +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src); void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a); void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data); @@ -128,6 +129,7 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba); // int void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pia); +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src); void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pia, const godot_array *p_a); void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pia, const godot_int p_data); @@ -154,6 +156,7 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pia); // real void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pra); +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src); void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pra, const godot_array *p_a); void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pra, const godot_real p_data); @@ -180,6 +183,7 @@ void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pra); // string void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_psa); +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src); void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_psa, const godot_array *p_a); void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_psa, const godot_string *p_data); @@ -206,6 +210,7 @@ void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_psa); // vector2 void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pv2a); +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src); void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pv2a, const godot_array *p_a); void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); @@ -232,6 +237,7 @@ void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pv2a); // vector3 void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pv3a); +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src); void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pv3a, const godot_array *p_a); void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); @@ -258,6 +264,7 @@ void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pv3a); // color void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pca); +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src); void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pca, const godot_array *p_a); void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pca, const godot_color *p_data); diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 12b43d6060..d4ede4cb17 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1014,7 +1014,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } } break; - case GDParser::OperatorNode::OP_EXTENDS: { + case GDParser::OperatorNode::OP_IS: { ERR_FAIL_COND_V(on->arguments.size() != 2, false); diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index fb32d23ad5..e8a8e20927 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -358,12 +358,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (a->get_type() != Variant::OBJECT || a->operator Object *() == NULL) { - err_text = "Left operand of 'extends' is not an instance of anything."; + err_text = "Left operand of 'is' is not an instance of anything."; break; } if (b->get_type() != Variant::OBJECT || b->operator Object *() == NULL) { - err_text = "Right operand of 'extends' is not a class."; + err_text = "Right operand of 'is' is not a class."; break; } #endif @@ -401,7 +401,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (!nc) { - err_text = "Right operand of 'extends' is not a class (type: '" + obj_B->get_class() + "')."; + err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "')."; break; } diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 4ae62eb1d0..d64cd86de6 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1077,7 +1077,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool case GDTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break; case GDTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break; case GDTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break; - case GDTokenizer::TK_PR_EXTENDS: op = OperatorNode::OP_EXTENDS; break; + case GDTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break; case GDTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break; case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break; default: valid = false; break; @@ -1117,7 +1117,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool switch (expression[i].op) { - case OperatorNode::OP_EXTENDS: + case OperatorNode::OP_IS: priority = -1; break; //before anything @@ -1420,7 +1420,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { } } - if (op->op == OperatorNode::OP_EXTENDS) { + if (op->op == OperatorNode::OP_IS) { //nothing much return op; } diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 7e7e19de1b..3ad3466624 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -216,7 +216,7 @@ public: OP_CALL, OP_PARENT_CALL, OP_YIELD, - OP_EXTENDS, + OP_IS, //indexing operator OP_INDEX, OP_INDEX_NAMED, diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 173014b138..dcc0e24098 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1812,6 +1812,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "breakpoint", "class", "extends", + "is", "func", "preload", "setget", diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 5e1a48ae86..f4e0cc8e29 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -90,6 +90,7 @@ const char *GDTokenizer::token_names[TK_MAX] = { "func", "class", "extends", + "is", "onready", "tool", "static", @@ -864,6 +865,7 @@ void GDTokenizerText::_advance() { { TK_PR_FUNCTION, "func" }, { TK_PR_CLASS, "class" }, { TK_PR_EXTENDS, "extends" }, + { TK_PR_IS, "is" }, { TK_PR_ONREADY, "onready" }, { TK_PR_TOOL, "tool" }, { TK_PR_STATIC, "static" }, diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index ea7629b661..c051176097 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -96,6 +96,7 @@ public: TK_PR_FUNCTION, TK_PR_CLASS, TK_PR_EXTENDS, + TK_PR_IS, TK_PR_ONREADY, TK_PR_TOOL, TK_PR_STATIC, diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index e567e08c79..121b403f64 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -560,7 +560,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu else return false; - return do_input_action(p_camera, Point2(mb->get_pos().x, mb->get_pos().y), true); + return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); } else { if ( @@ -604,7 +604,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (mm.is_valid()) { - return do_input_action(p_camera, mm->get_pos(), false); + return do_input_action(p_camera, mm->get_position(), false); } } else if (edit_mode->get_selected() == 1) { @@ -616,7 +616,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Point2 point = mb->get_pos(); + Point2 point = mb->get_position(); Camera *camera = p_camera; Vector3 from = camera->project_ray_origin(point); diff --git a/modules/hdr/SCsub b/modules/hdr/SCsub new file mode 100644 index 0000000000..c960e8126b --- /dev/null +++ b/modules/hdr/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_hdr = env_modules.Clone() + +# Godot's own source files +env_hdr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/hdr/config.py b/modules/hdr/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/hdr/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp new file mode 100644 index 0000000000..85819104cf --- /dev/null +++ b/modules/hdr/image_loader_hdr.cpp @@ -0,0 +1,161 @@ +/*************************************************************************/ +/* image_loader_jpegd.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_loader_hdr.h" + +#include "os/os.h" +#include "print_string.h" + +#include "thirdparty/tinyexr/tinyexr.h" + +Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + String header = f->get_token(); + + print_line("HEADER: " + header); + ERR_FAIL_COND_V(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED); + + while (true) { + String format = f->get_token(); + ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED); + if (format.begins_with("FORMAT=") && format != "FORMAT=32-bit_rle_rgbe") { + ERR_EXPLAIN("Only 32-bit_rle_rgbe is supported for .hdr files."); + return ERR_FILE_UNRECOGNIZED; + } + if (format == "FORMAT=32-bit_rle_rgbe") + break; + } + + String token = f->get_token(); + + ERR_FAIL_COND_V(token != "-Y", ERR_FILE_CORRUPT); + + int height = f->get_token().to_int(); + + token = f->get_token(); + + ERR_FAIL_COND_V(token != "+X", ERR_FILE_CORRUPT); + + int width = f->get_line().to_int(); + + print_line("HDR w: " + itos(width) + " h:" + itos(height)); + + PoolVector<uint8_t> imgdata; + + imgdata.resize(height * width * sizeof(uint32_t)); + + { + + PoolVector<uint8_t>::Write w = imgdata.write(); + + uint8_t *ptr = (uint8_t *)w.ptr(); + + if (width < 8 || width >= 32768) { + // Read flat data + + f->get_buffer(ptr, width * height * 4); + } else { + // Read RLE-encoded data + + for (int j = 0; j < height; ++j) { + int c1 = f->get_8(); + int c2 = f->get_8(); + int len = f->get_8(); + if (c1 != 2 || c2 != 2 || (len & 0x80)) { + // not run-length encoded, so we have to actually use THIS data as a decoded + // pixel (note this can't be a valid pixel--one of RGB must be >= 128) + + ptr[(j * width) * 4 + 0] = uint8_t(c1); + ptr[(j * width) * 4 + 1] = uint8_t(c2); + ptr[(j * width) * 4 + 2] = uint8_t(len); + ptr[(j * width) * 4 + 3] = f->get_8(); + + f->get_buffer(&ptr[(j * width + 1) * 4], (width - 1) * 4); + continue; + } + len <<= 8; + len |= f->get_8(); + + print_line("line: " + itos(len)); + if (len != width) { + ERR_EXPLAIN("invalid decoded scanline length, corrupt HDR"); + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + + for (int k = 0; k < 4; ++k) { + int i = 0; + while (i < width) { + int count = f->get_8(); + if (count > 128) { + // Run + int value = f->get_8(); + count -= 128; + for (int z = 0; z < count; ++z) + ptr[(j * width + i++) * 4 + k] = uint8_t(value); + } else { + // Dump + for (int z = 0; z < count; ++z) + ptr[(j * width + i++) * 4 + k] = f->get_8(); + } + } + } + } + } + + //convert + for (int i = 0; i < width * height; i++) { + + float exp = pow(2, ptr[3] - 128); + + Color c( + ptr[0] * exp / 255.0, + ptr[1] * exp / 255.0, + ptr[2] * exp / 255.0); + + if (p_force_linear) { + c = c.to_linear(); + } + + *(uint32_t *)ptr = c.to_rgbe9995(); + ptr += 4; + } + } + + p_image->create(width, height, false, Image::FORMAT_RGBE9995, imgdata); + + return OK; +} + +void ImageLoaderHDR::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("hdr"); +} + +ImageLoaderHDR::ImageLoaderHDR() { +} diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h new file mode 100644 index 0000000000..9bc1fadd13 --- /dev/null +++ b/modules/hdr/image_loader_hdr.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* image_loader_jpegd.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_LOADER_TINYEXR_H +#define IMAGE_LOADER_TINYEXR_H + +#include "io/image_loader.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ImageLoaderHDR : public ImageFormatLoader { + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderHDR(); +}; + +#endif diff --git a/modules/hdr/register_types.cpp b/modules/hdr/register_types.cpp new file mode 100644 index 0000000000..e4f7c14aa7 --- /dev/null +++ b/modules/hdr/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* 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_loader_hdr.h" + +static ImageLoaderHDR *image_loader_hdr = NULL; + +void register_hdr_types() { + + image_loader_hdr = memnew(ImageLoaderHDR); + ImageLoader::add_image_format_loader(image_loader_hdr); +} + +void unregister_hdr_types() { + + memdelete(image_loader_hdr); +} diff --git a/modules/hdr/register_types.h b/modules/hdr/register_types.h new file mode 100644 index 0000000000..3d901ea003 --- /dev/null +++ b/modules/hdr/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_hdr_types(); +void unregister_hdr_types(); diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index 0741dd198a..8c73b69f1b 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -89,7 +89,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p return OK; } -Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f) { +Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { PoolVector<uint8_t> src_image; int src_image_len = f->get_len(); diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index 57d7a2bb1c..aa073b493d 100644 --- a/modules/jpg/image_loader_jpegd.h +++ b/modules/jpg/image_loader_jpegd.h @@ -38,7 +38,7 @@ class ImageLoaderJPG : public ImageFormatLoader { public: - virtual Error load_image(Ref<Image> p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderJPG(); }; diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 5c53492034..e927f1ceaa 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -59,9 +59,9 @@ void image_decompress_squish(Image *p_image) { squish_flags = squish::kDxt3; } else if (p_image->get_format() == Image::FORMAT_DXT5) { squish_flags = squish::kDxt5; - } else if (p_image->get_format() == Image::FORMAT_ATI1) { + } else if (p_image->get_format() == Image::FORMAT_RGTC_R) { squish_flags = squish::kBc4; - } else if (p_image->get_format() == Image::FORMAT_ATI2) { + } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { squish_flags = squish::kBc5; } else { ERR_FAIL_COND(true); @@ -79,63 +79,89 @@ void image_decompress_squish(Image *p_image) { p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); } -void image_compress_squish(Image *p_image) { +void image_compress_squish(Image *p_image, bool p_srgb) { + + if (p_image->get_format() >= Image::FORMAT_DXT1) + return; //do not compress, already compressed int w = p_image->get_width(); int h = p_image->get_height(); - if (!p_image->has_mipmaps()) { - ERR_FAIL_COND(!w || w % 4 != 0); - ERR_FAIL_COND(!h || h % 4 != 0); - } else { - ERR_FAIL_COND(!w || w != nearest_power_of_2(w)); - ERR_FAIL_COND(!h || h != nearest_power_of_2(h)); - }; + if (p_image->get_format() <= Image::FORMAT_RGBA8) { - if (p_image->get_format() >= Image::FORMAT_DXT1) - return; //do not compress, already compressed + int squish_comp = squish::kColourRangeFit; + Image::Format target_format; - int shift = 0; - int squish_comp = squish::kColourRangeFit; // TODO: use lossy quality setting to determine the quality - Image::Format target_format; + Image::DetectChannels dc = p_image->get_detected_channels(); - if (p_image->get_format() == Image::FORMAT_LA8) { - //compressed normalmap - target_format = Image::FORMAT_DXT5; - squish_comp |= squish::kDxt5; - } else if (p_image->detect_alpha() != Image::ALPHA_NONE) { + p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert - target_format = Image::FORMAT_DXT3; - squish_comp |= squish::kDxt3; - } else { - target_format = Image::FORMAT_DXT1; - shift = 1; - squish_comp |= squish::kDxt1; - } + if (p_srgb && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + //R and RG do not support SRGB + dc = Image::DETECTED_RGB; + } - p_image->convert(Image::FORMAT_RGBA8); //always expects rgba + switch (dc) { + case Image::DETECTED_L: { - PoolVector<uint8_t> data; - int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); - int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; - data.resize(target_size); + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; + } break; + case Image::DETECTED_LA: { - PoolVector<uint8_t>::Read rb = p_image->get_data().read(); - PoolVector<uint8_t>::Write wb = data.write(); + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; + } break; + case Image::DETECTED_R: { - int dst_ofs = 0; + target_format = Image::FORMAT_RGTC_R; + squish_comp |= squish::kBc4; + } break; + case Image::DETECTED_RG: { - for (int i = 0; i <= mm_count; i++) { + target_format = Image::FORMAT_RGTC_RG; + squish_comp |= squish::kBc5; + } break; + case Image::DETECTED_RGB: { - int src_ofs = p_image->get_mipmap_offset(i); - squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); - dst_ofs += (MAX(4, w) * MAX(4, h)) >> shift; - w >>= 1; - h >>= 1; - } + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; + } break; + case Image::DETECTED_RGBA: { - rb = PoolVector<uint8_t>::Read(); - wb = PoolVector<uint8_t>::Write(); + //TODO, should convert both, then measure which one does a better job + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; - p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); + } break; + } + + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; + data.resize(target_size); + int shift = Image::get_format_pixel_rshift(target_format); + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + PoolVector<uint8_t>::Write wb = data.write(); + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + + int bw = w % 4 != 0 ? w + (4 - w % 4) : w; + int bh = h % 4 != 0 ? h + (4 - h % 4) : h; + + int src_ofs = p_image->get_mipmap_offset(i); + squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); + dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; + w >>= 1; + h >>= 1; + } + + rb = PoolVector<uint8_t>::Read(); + wb = PoolVector<uint8_t>::Write(); + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); + } } diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 519e3537ef..8d859b8e0b 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -32,7 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image); +void image_compress_squish(Image *p_image, bool p_srgb); void image_decompress_squish(Image *p_image); #endif // IMAGE_COMPRESS_SQUISH_H diff --git a/modules/tinyexr/SCsub b/modules/tinyexr/SCsub new file mode 100644 index 0000000000..38fd00cc65 --- /dev/null +++ b/modules/tinyexr/SCsub @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tinyexr = env_modules.Clone() + +# Thirdparty source files +# Not unbundled for now as they are not commonly available as shared library +thirdparty_dir = "#thirdparty/tinyexr/" +thirdparty_sources = [ + "tinyexr.cc", +] +thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + +env_tinyexr.add_source_files(env.modules_sources, thirdparty_sources) +env_tinyexr.Append(CPPPATH=[thirdparty_dir]) + +# Godot's own source files +env_tinyexr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/tinyexr/config.py b/modules/tinyexr/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/tinyexr/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp new file mode 100644 index 0000000000..4eb91da10b --- /dev/null +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -0,0 +1,168 @@ +/*************************************************************************/ +/* image_loader_jpegd.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_loader_tinyexr.h" + +#include "os/os.h" +#include "print_string.h" + +#include "thirdparty/tinyexr/tinyexr.h" + +Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + PoolVector<uint8_t>::Write w = src_image.write(); + + f->get_buffer(&w[0], src_image_len); + + f->close(); + + EXRVersion exr_version; + EXRImage exr_image; + EXRHeader exr_header; + const char *err = NULL; + + InitEXRHeader(&exr_header); + + int ret = ParseEXRVersionFromMemory(&exr_version, w.ptr(), src_image_len); + if (ret != TINYEXR_SUCCESS) { + + return ERR_FILE_CORRUPT; + } + + ret = ParseEXRHeaderFromMemory(&exr_header, &exr_version, w.ptr(), src_image_len, &err); + if (ret != TINYEXR_SUCCESS) { + if (err) { + ERR_PRINTS(String(err)); + } + return ERR_FILE_CORRUPT; + } + + InitEXRImage(&exr_image); + ret = LoadEXRImageFromMemory(&exr_image, &exr_header, w.ptr(), src_image_len, &err); + if (ret != TINYEXR_SUCCESS) { + if (err) { + ERR_PRINTS(String(err)); + } + return ERR_FILE_CORRUPT; + } + + // RGBA + int idxR = -1; + int idxG = -1; + int idxB = -1; + int idxA = -1; + for (int c = 0; c < exr_header.num_channels; c++) { + if (strcmp(exr_header.channels[c].name, "R") == 0) { + idxR = c; + } else if (strcmp(exr_header.channels[c].name, "G") == 0) { + idxG = c; + } else if (strcmp(exr_header.channels[c].name, "B") == 0) { + idxB = c; + } else if (strcmp(exr_header.channels[c].name, "A") == 0) { + idxA = c; + } + } + + if (idxR == -1) { + ERR_PRINT("R channel not found"); + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + if (idxG == -1) { + ERR_PRINT("G channel not found\n") + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + if (idxB == -1) { + ERR_PRINT("B channel not found\n") + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + PoolVector<uint8_t> imgdata; + Image::Format format; + + if (idxA > 0) { + + imgdata.resize(exr_image.width * exr_image.height * 8); //RGBA16 + format = Image::FORMAT_RGBAH; + } else { + + imgdata.resize(exr_image.width * exr_image.height * 6); //RGB16 + format = Image::FORMAT_RGBH; + } + + { + + PoolVector<uint8_t>::Write wd = imgdata.write(); + uint16_t *iw = (uint16_t *)wd.ptr(); + + // Assume `out_rgba` have enough memory allocated. + for (int i = 0; i < exr_image.width * exr_image.height; i++) { + + Color color( + reinterpret_cast<float **>(exr_image.images)[idxR][i], + reinterpret_cast<float **>(exr_image.images)[idxG][i], + reinterpret_cast<float **>(exr_image.images)[idxB][i]); + + if (p_force_linear) + color = color.to_linear(); + + *iw++ = Math::make_half_float(color.r); + *iw++ = Math::make_half_float(color.g); + *iw++ = Math::make_half_float(color.b); + + if (idxA > 0) { + *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxA][i]); + } + } + } + + print_line("EXR w: " + itos(exr_image.width) + " h:" + itos(exr_image.height) + " format " + Image::get_format_name(format)); + p_image->create(exr_image.width, exr_image.height, false, format, imgdata); + + w = PoolVector<uint8_t>::Write(); + + return OK; +} + +void ImageLoaderTinyEXR::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("exr"); +} + +ImageLoaderTinyEXR::ImageLoaderTinyEXR() { +} diff --git a/modules/tinyexr/image_loader_tinyexr.h b/modules/tinyexr/image_loader_tinyexr.h new file mode 100644 index 0000000000..a52894b12b --- /dev/null +++ b/modules/tinyexr/image_loader_tinyexr.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* image_loader_jpegd.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_LOADER_TINYEXR_H +#define IMAGE_LOADER_TINYEXR_H + +#include "io/image_loader.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ImageLoaderTinyEXR : public ImageFormatLoader { + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTinyEXR(); +}; + +#endif diff --git a/modules/tinyexr/register_types.cpp b/modules/tinyexr/register_types.cpp new file mode 100644 index 0000000000..73f3131276 --- /dev/null +++ b/modules/tinyexr/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* 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_loader_tinyexr.h" + +static ImageLoaderTinyEXR *image_loader_tinyexr = NULL; + +void register_tinyexr_types() { + + image_loader_tinyexr = memnew(ImageLoaderTinyEXR); + ImageLoader::add_image_format_loader(image_loader_tinyexr); +} + +void unregister_tinyexr_types() { + + memdelete(image_loader_tinyexr); +} diff --git a/modules/tinyexr/register_types.h b/modules/tinyexr/register_types.h new file mode 100644 index 0000000000..f3c7372359 --- /dev/null +++ b/modules/tinyexr/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_tinyexr_types(); +void unregister_tinyexr_types(); diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 7313cb6c7c..87c2e811b3 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -115,7 +115,7 @@ static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { return img; } -Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f) { +Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { uint32_t size = f->get_len(); PoolVector<uint8_t> src_image; diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h index ba817e0ecd..1ac2196a71 100644 --- a/modules/webp/image_loader_webp.h +++ b/modules/webp/image_loader_webp.h @@ -38,7 +38,7 @@ class ImageLoaderWEBP : public ImageFormatLoader { public: - virtual Error load_image(Ref<Image> p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderWEBP(); }; |