diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-07-15 01:23:10 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-07-15 08:32:34 -0300 |
commit | 2e73be99d8d86d9dad7bcb99518a4d3cbb5c373c (patch) | |
tree | d863db50852afe5d4b0bc15b8452054498004cb1 /core/io | |
parent | e64b82ebfcc3475c7a7d2a9196bfe20d6c9e3614 (diff) |
Lots of work on Audio & Physics engine:
-Added new 3D stream player node
-Added ability for Area to capture sound from streams
-Added small features in physics to be able to properly guess distance to areas for sound
-Fixed 3D CollisionObject so shapes are added the same as in 2D, directly from children
-Fixed KinematicBody API to make it the same as 2D.
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/resource_format_binary.cpp | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index b474c2e078..728cd5d4ff 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "resource_format_binary.h" #include "global_config.h" +#include "image.h" #include "io/file_access_compressed.h" #include "io/marshalls.h" #include "os/dir_access.h" @@ -54,7 +55,6 @@ enum { VARIANT_TRANSFORM = 17, VARIANT_MATRIX32 = 18, VARIANT_COLOR = 20, - //VARIANT_IMAGE = 21, - no longer variant type VARIANT_NODE_PATH = 22, VARIANT_RID = 23, VARIANT_OBJECT = 24, @@ -70,7 +70,13 @@ enum { VARIANT_VECTOR2_ARRAY = 37, VARIANT_INT64 = 40, VARIANT_DOUBLE = 41, - +#ifndef DISABLE_DEPRECATED + VARIANT_IMAGE = 21, // - no longer variant type + IMAGE_ENCODING_EMPTY = 0, + IMAGE_ENCODING_RAW = 1, + IMAGE_ENCODING_LOSSLESS = 2, + IMAGE_ENCODING_LOSSY = 3, +#endif OBJECT_EMPTY = 0, OBJECT_EXTERNAL_RESOURCE = 1, OBJECT_INTERNAL_RESOURCE = 2, @@ -541,7 +547,69 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { w = PoolVector<Color>::Write(); r_v = array; } break; +#ifndef DISABLE_DEPRECATED + case VARIANT_IMAGE: { + uint32_t encoding = f->get_32(); + if (encoding == IMAGE_ENCODING_EMPTY) { + r_v = Ref<Image>(); + break; + } else if (encoding == IMAGE_ENCODING_RAW) { + uint32_t width = f->get_32(); + uint32_t height = f->get_32(); + uint32_t mipmaps = f->get_32(); + uint32_t format = f->get_32(); + const uint32_t format_version_shift = 24; + const uint32_t format_version_mask = format_version_shift - 1; + + uint32_t format_version = format >> format_version_shift; + + const uint32_t current_version = 0; + if (format_version > current_version) { + + ERR_PRINT("Format version for encoded binary image is too new"); + return ERR_PARSE_ERROR; + } + + Image::Format fmt = Image::Format(format & format_version_mask); //if format changes, we can add a compatibility bit on top + + uint32_t datalen = f->get_32(); + + PoolVector<uint8_t> imgdata; + imgdata.resize(datalen); + PoolVector<uint8_t>::Write w = imgdata.write(); + f->get_buffer(w.ptr(), datalen); + _advance_padding(datalen); + w = PoolVector<uint8_t>::Write(); + + Ref<Image> image; + image.instance(); + image->create(width, height, mipmaps, fmt, imgdata); + r_v = image; + + } else { + //compressed + PoolVector<uint8_t> data; + data.resize(f->get_32()); + PoolVector<uint8_t>::Write w = data.write(); + f->get_buffer(w.ptr(), data.size()); + w = PoolVector<uint8_t>::Write(); + + Ref<Image> image; + if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) { + + image = Image::lossy_unpacker(data); + } else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) { + + image = Image::lossless_unpacker(data); + } + _advance_padding(data.size()); + + r_v = image; + } + + } break; +#endif default: { ERR_FAIL_V(ERR_FILE_CORRUPT); } break; @@ -1644,7 +1712,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant get_string_index(np.get_property()); } break; - default: {} } } |