summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-05-17 07:36:47 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-05-17 07:37:45 -0300
commit98a329670227c726a5d7a196e5cba8dbdd54301b (patch)
tree7346f7a3e38eb35b784ac1a68a227d07cc8881b4 /core/io
parentd801ff2b3db2de105c1b36a74ce116e360143d4e (diff)
Removal of Image from Variant, converted to a Resource.
Diffstat (limited to 'core/io')
-rw-r--r--core/io/image_loader.cpp3
-rw-r--r--core/io/image_loader.h4
-rw-r--r--core/io/marshalls.cpp56
-rw-r--r--core/io/resource_format_binary.cpp134
4 files changed, 5 insertions, 192 deletions
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 4864c18831..6ed20ac015 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -43,7 +43,8 @@ bool ImageFormatLoader::recognize(const String &p_extension) const {
return false;
}
-Error ImageLoader::load_image(String p_file, Image *p_image, FileAccess *p_custom) {
+Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom) {
+ ERR_FAIL_COND_V(p_image.is_null(), ERR_INVALID_PARAMETER);
FileAccess *f = p_custom;
if (!f) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 37149dbe9d..7114cbf8ad 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -56,7 +56,7 @@ class ImageFormatLoader {
friend class ImageLoader;
protected:
- virtual Error load_image(Image *p_image, FileAccess *p_fileaccess) = 0;
+ virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess) = 0;
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
bool recognize(const String &p_extension) const;
@@ -75,7 +75,7 @@ class ImageLoader {
protected:
public:
- static Error load_image(String p_file, Image *p_image, FileAccess *p_custom = NULL);
+ static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL);
static void get_recognized_extensions(List<String> *p_extensions);
static bool recognize(const String &p_extension);
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 5e66b7f7f5..fd14011a81 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -276,38 +276,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 4 * 4;
} break;
- case Variant::IMAGE: {
-
- ERR_FAIL_COND_V(len < (int)5 * 4, ERR_INVALID_DATA);
- Image::Format fmt = (Image::Format)decode_uint32(&buf[0]);
- ERR_FAIL_INDEX_V(fmt, Image::FORMAT_MAX, ERR_INVALID_DATA);
- uint32_t mipmaps = decode_uint32(&buf[4]);
- uint32_t w = decode_uint32(&buf[8]);
- uint32_t h = decode_uint32(&buf[12]);
- uint32_t datalen = decode_uint32(&buf[16]);
-
- Image img;
- if (datalen > 0) {
- len -= 5 * 4;
- ERR_FAIL_COND_V(len < datalen, ERR_INVALID_DATA);
- PoolVector<uint8_t> data;
- data.resize(datalen);
- PoolVector<uint8_t>::Write wr = data.write();
- copymem(&wr[0], &buf[20], datalen);
- wr = PoolVector<uint8_t>::Write();
-
- img = Image(w, h, mipmaps, fmt, data);
- }
-
- r_variant = img;
- if (r_len) {
- if (datalen % 4)
- (*r_len) += 4 - datalen % 4;
-
- (*r_len) += 4 * 5 + datalen;
- }
-
- } break;
case Variant::NODE_PATH: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
@@ -1078,30 +1046,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
r_len += 4 * 4;
} break;
- case Variant::IMAGE: {
-
- Image image = p_variant;
- PoolVector<uint8_t> data = image.get_data();
-
- if (buf) {
-
- encode_uint32(image.get_format(), &buf[0]);
- encode_uint32(image.has_mipmaps(), &buf[4]);
- encode_uint32(image.get_width(), &buf[8]);
- encode_uint32(image.get_height(), &buf[12]);
- int ds = data.size();
- encode_uint32(ds, &buf[16]);
- PoolVector<uint8_t>::Read r = data.read();
- copymem(&buf[20], &r[0], ds);
- }
-
- int pad = 0;
- if (data.size() % 4)
- pad = 4 - data.size() % 4;
-
- r_len += data.size() + 5 * 4 + pad;
-
- } break;
/*case Variant::RESOURCE: {
ERR_EXPLAIN("Can't marshallize resources");
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index fc18a44ed3..d6e2925d57 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -54,7 +54,7 @@ enum {
VARIANT_TRANSFORM = 17,
VARIANT_MATRIX32 = 18,
VARIANT_COLOR = 20,
- VARIANT_IMAGE = 21,
+ //VARIANT_IMAGE = 21, - no longer variant type
VARIANT_NODE_PATH = 22,
VARIANT_RID = 23,
VARIANT_OBJECT = 24,
@@ -71,11 +71,6 @@ enum {
VARIANT_INT64 = 40,
VARIANT_DOUBLE = 41,
- IMAGE_ENCODING_EMPTY = 0,
- IMAGE_ENCODING_RAW = 1,
- IMAGE_ENCODING_LOSSLESS = 2,
- IMAGE_ENCODING_LOSSY = 3,
-
OBJECT_EMPTY = 0,
OBJECT_EXTERNAL_RESOURCE = 1,
OBJECT_INTERNAL_RESOURCE = 2,
@@ -259,74 +254,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
- case VARIANT_IMAGE: {
-
- uint32_t encoding = f->get_32();
- if (encoding == IMAGE_ENCODING_EMPTY) {
- r_v = Variant();
- 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();
- print_line("image format: " + String(Image::get_format_name(fmt)) + " datalen " + itos(datalen));
-
- 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();
-
-#ifdef TOOLS_ENABLED
- //compatibility
- int correct_size = Image::get_image_data_size(width, height, fmt, mipmaps ? -1 : 0);
- if (correct_size < datalen) {
- WARN_PRINT("Image data was too large, shrinking for compatibility")
- imgdata.resize(correct_size);
- }
-#endif
- r_v = Image(width, height, mipmaps, fmt, imgdata);
-
- } 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();
-
- Image img;
-
- if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) {
-
- img = Image::lossy_unpacker(data);
- } else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) {
-
- img = Image::lossless_unpacker(data);
- }
- _advance_padding(data.size());
-
- r_v = img;
- }
- } break;
case VARIANT_NODE_PATH: {
Vector<StringName> names;
@@ -1469,67 +1397,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property,
f->store_real(val.a);
} break;
- case Variant::IMAGE: {
-
- f->store_32(VARIANT_IMAGE);
- Image val = p_property;
- if (val.empty()) {
- f->store_32(IMAGE_ENCODING_EMPTY);
- break;
- }
-
- int encoding = IMAGE_ENCODING_RAW;
- float quality = 0.7;
-
- if (!val.is_compressed()) {
- //can only compress uncompressed stuff
-
- if (p_hint.hint == PROPERTY_HINT_IMAGE_COMPRESS_LOSSY && Image::lossy_packer) {
- encoding = IMAGE_ENCODING_LOSSY;
- float qs = p_hint.hint_string.to_double();
- if (qs != 0.0)
- quality = qs;
-
- } else if (p_hint.hint == PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS && Image::lossless_packer) {
- encoding = IMAGE_ENCODING_LOSSLESS;
- }
- }
-
- f->store_32(encoding); //raw encoding
-
- if (encoding == IMAGE_ENCODING_RAW) {
-
- f->store_32(val.get_width());
- f->store_32(val.get_height());
- f->store_32(val.has_mipmaps());
- f->store_32(val.get_format()); //if format changes we can add a compatibility version bit
- int dlen = val.get_data().size();
- f->store_32(dlen);
- PoolVector<uint8_t>::Read r = val.get_data().read();
- f->store_buffer(r.ptr(), dlen);
- _pad_buffer(dlen);
- } else {
-
- PoolVector<uint8_t> data;
- if (encoding == IMAGE_ENCODING_LOSSY) {
- data = Image::lossy_packer(val, quality);
-
- } else if (encoding == IMAGE_ENCODING_LOSSLESS) {
- data = Image::lossless_packer(val);
- }
-
- int ds = data.size();
- f->store_32(ds);
- if (ds > 0) {
- PoolVector<uint8_t>::Read r = data.read();
- f->store_buffer(r.ptr(), ds);
-
- _pad_buffer(ds);
- }
- }
-
- } break;
case Variant::NODE_PATH: {
f->store_32(VARIANT_NODE_PATH);
NodePath np = p_property;