diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-05-17 07:36:47 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-05-17 07:37:45 -0300 |
commit | 98a329670227c726a5d7a196e5cba8dbdd54301b (patch) | |
tree | 7346f7a3e38eb35b784ac1a68a227d07cc8881b4 /drivers | |
parent | d801ff2b3db2de105c1b36a74ce116e360143d4e (diff) |
Removal of Image from Variant, converted to a Resource.
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 4 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 8 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 67 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 8 | ||||
-rw-r--r-- | drivers/png/image_loader_png.cpp | 42 | ||||
-rw-r--r-- | drivers/png/image_loader_png.h | 4 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.cpp | 26 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.h | 3 |
9 files changed, 85 insertions, 79 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 60282fb3fa..3c543365f0 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -342,12 +342,12 @@ void RasterizerGLES2::_draw_primitive(int p_points, const Vector3 *p_vertices, c /* TEXTURE API */ -Image RasterizerGLES2::_get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, int &r_gl_components, bool &r_has_alpha_cache, bool &r_compressed) { +Ref<Image> RasterizerGLES2::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, int &r_gl_components, bool &r_has_alpha_cache, bool &r_compressed) { r_has_alpha_cache = false; r_compressed = false; r_gl_format = 0; - Image image = p_image; + Ref<Image> image = p_image; switch (p_format) { diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index db814ec721..aa4150cbe4 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -271,9 +271,9 @@ void RasterizerGLES3::clear_render_target(const Color &p_color) { storage->frame.clear_request_color = p_color; } -void RasterizerGLES3::set_boot_image(const Image &p_image, const Color &p_color, bool p_scale) { +void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) { - if (p_image.empty()) + if (p_image.is_null() || p_image->empty()) return; begin_frame(); @@ -290,10 +290,10 @@ void RasterizerGLES3::set_boot_image(const Image &p_image, const Color &p_color, canvas->canvas_begin(); RID texture = storage->texture_create(); - storage->texture_allocate(texture, p_image.get_width(), p_image.get_height(), p_image.get_format(), VS::TEXTURE_FLAG_FILTER); + storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), p_image->get_format(), VS::TEXTURE_FLAG_FILTER); storage->texture_set_data(texture, p_image); - Rect2 imgrect(0, 0, p_image.get_width(), p_image.get_height()); + Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); Rect2 screenrect; if (p_scale) { diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h index 12014cd814..ce18d6b6c1 100644 --- a/drivers/gles3/rasterizer_gles3.h +++ b/drivers/gles3/rasterizer_gles3.h @@ -48,7 +48,7 @@ public: virtual RasterizerCanvas *get_canvas(); virtual RasterizerScene *get_scene(); - virtual void set_boot_image(const Image &p_image, const Color &p_color, bool p_scale); + virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale); virtual void initialize(); virtual void begin_frame(); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 1025acceb4..7db2f23d47 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -101,11 +101,11 @@ GLuint RasterizerStorageGLES3::system_fbo = 0; -Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) { +Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &srgb) { r_compressed = false; r_gl_format = 0; - Image image = p_image; + Ref<Image> image = p_image; srgb = false; bool need_decompress = false; @@ -538,16 +538,17 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image &p_image, Ima } break; default: { - ERR_FAIL_V(Image()); + ERR_FAIL_V(Ref<Image>()); } } if (need_decompress) { - if (!image.empty()) { - image.decompress(); - ERR_FAIL_COND_V(image.is_compressed(), image); - image.convert(Image::FORMAT_RGBA8); + if (!image.is_null()) { + image = image->duplicate(); + image->decompress(); + ERR_FAIL_COND_V(image->is_compressed(), image); + image->convert(Image::FORMAT_RGBA8); } r_gl_format = GL_RGBA; @@ -607,7 +608,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ texture->stored_cube_sides = 0; texture->target = (p_flags & VS::TEXTURE_FLAG_CUBEMAP) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; - _get_gl_image_and_format(Image(), texture->format, texture->flags, format, internal_format, type, compressed, srgb); + _get_gl_image_and_format(Ref<Image>(), texture->format, texture->flags, format, internal_format, type, compressed, srgb); texture->alloc_width = texture->width; texture->alloc_height = texture->height; @@ -631,15 +632,15 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ texture->active = true; } -void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side) { +void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p_image, VS::CubeMapSide p_cube_side) { Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(!texture->active); ERR_FAIL_COND(texture->render_target); - ERR_FAIL_COND(texture->format != p_image.get_format()); - ERR_FAIL_COND(p_image.empty()); + ERR_FAIL_COND(texture->format != p_image->get_format()); + ERR_FAIL_COND(p_image.is_null()); GLenum type; GLenum format; @@ -651,31 +652,31 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_imag texture->images[p_cube_side] = p_image; } - Image img = _get_gl_image_and_format(p_image, p_image.get_format(), texture->flags, format, internal_format, type, compressed, srgb); + Ref<Image> img = _get_gl_image_and_format(p_image, p_image->get_format(), texture->flags, format, internal_format, type, compressed, srgb); - if (config.shrink_textures_x2 && (p_image.has_mipmaps() || !p_image.is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { + if (config.shrink_textures_x2 && (p_image->has_mipmaps() || !p_image->is_compressed()) && !(texture->flags & VS::TEXTURE_FLAG_USED_FOR_STREAMING)) { texture->alloc_height = MAX(1, texture->alloc_height / 2); texture->alloc_width = MAX(1, texture->alloc_width / 2); - if (texture->alloc_width == img.get_width() / 2 && texture->alloc_height == img.get_height() / 2) { + if (texture->alloc_width == img->get_width() / 2 && texture->alloc_height == img->get_height() / 2) { - img.shrink_x2(); - } else if (img.get_format() <= Image::FORMAT_RGB565) { + img->shrink_x2(); + } else if (img->get_format() <= Image::FORMAT_RGB565) { - img.resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR); + img->resize(texture->alloc_width, texture->alloc_height, Image::INTERPOLATE_BILINEAR); } }; GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP) ? _cube_side_enum[p_cube_side] : GL_TEXTURE_2D; - texture->data_size = img.get_data().size(); - PoolVector<uint8_t>::Read read = img.get_data().read(); + texture->data_size = img->get_data().size(); + PoolVector<uint8_t>::Read read = img->get_data().read(); glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target, texture->tex_id); - texture->ignore_mipmaps = compressed && !img.has_mipmaps(); + texture->ignore_mipmaps = compressed && !img->has_mipmaps(); if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, config.use_fast_texture_filter ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); @@ -761,16 +762,16 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_imag } } - int mipmaps = (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && img.has_mipmaps()) ? img.get_mipmap_count() + 1 : 1; + int mipmaps = (texture->flags & VS::TEXTURE_FLAG_MIPMAPS && img->has_mipmaps()) ? img->get_mipmap_count() + 1 : 1; - int w = img.get_width(); - int h = img.get_height(); + int w = img->get_width(); + int h = img->get_height(); int tsize = 0; for (int i = 0; i < mipmaps; i++) { int size, ofs; - img.get_mipmap_offset_and_size(i, ofs, size); + img->get_mipmap_offset_and_size(i, ofs, size); //print_line("mipmap: "+itos(i)+" size: "+itos(size)+" w: "+itos(mm_w)+", h: "+itos(mm_h)); @@ -813,16 +814,16 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Image &p_imag //texture_set_flags(p_texture,texture->flags); } -Image RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const { +Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const { Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture, Image()); - ERR_FAIL_COND_V(!texture->active, Image()); - ERR_FAIL_COND_V(texture->data_size == 0, Image()); - ERR_FAIL_COND_V(texture->render_target, Image()); + ERR_FAIL_COND_V(!texture, Ref<Image>()); + ERR_FAIL_COND_V(!texture->active, Ref<Image>()); + ERR_FAIL_COND_V(texture->data_size == 0, Ref<Image>()); + ERR_FAIL_COND_V(texture->render_target, Ref<Image>()); - if (!texture->images[p_cube_side].empty()) { + if (!texture->images[p_cube_side].is_null()) { return texture->images[p_cube_side]; } @@ -867,13 +868,13 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSide p_ data.resize(data_size); - Image img(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data); + Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data)); - return img; + return Ref<Image>(img); #else ERR_EXPLAIN("Sorry, It's not posible to obtain images back in OpenGL ES"); - return Image(); + return Ref<Image>(); #endif } diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index bb4a7e23a1..c700b7cb1c 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -240,7 +240,7 @@ public: RenderTarget *render_target; - Image images[6]; + Ref<Image> images[6]; VisualServer::TextureDetectCallback detect_3d; void *detect_3d_ud; @@ -280,12 +280,12 @@ public: mutable RID_Owner<Texture> texture_owner; - Image _get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb); + Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_type, bool &r_compressed, bool &srgb); virtual RID texture_create(); virtual void texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT); - virtual void texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT); - virtual Image texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) const; + virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT); + virtual Ref<Image> texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) const; virtual void texture_set_flags(RID p_texture, uint32_t p_flags); virtual uint32_t texture_get_flags(RID p_texture) const; virtual Image::Format texture_get_format(RID p_texture) const; diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index c9677bed11..fe2372e3af 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -68,7 +68,7 @@ static void _png_warn_function(png_structp, png_const_charp text) { typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp)); -Error ImageLoaderPNG::_load_image(void *rf_up, png_rw_ptr p_func, Image *p_image) { +Error ImageLoaderPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Image> p_image) { png_structp png; png_infop info; @@ -201,7 +201,7 @@ Error ImageLoaderPNG::_load_image(void *rf_up, png_rw_ptr p_func, Image *p_image return OK; } -Error ImageLoaderPNG::load_image(Image *p_image, FileAccess *f) { +Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f) { Error err = _load_image(f, _read_png_data, p_image); f->close(); @@ -238,25 +238,26 @@ static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t p_len } } -static Image _load_mem_png(const uint8_t *p_png, int p_size) { +static Ref<Image> _load_mem_png(const uint8_t *p_png, int p_size) { PNGReadStatus prs; prs.image = p_png; prs.offset = 0; prs.size = p_size; - Image img; - Error err = ImageLoaderPNG::_load_image(&prs, user_read_data, &img); - ERR_FAIL_COND_V(err, Image()); + Ref<Image> img; + img.instance(); + Error err = ImageLoaderPNG::_load_image(&prs, user_read_data, img); + ERR_FAIL_COND_V(err, Ref<Image>()); return img; } -static Image _lossless_unpack_png(const PoolVector<uint8_t> &p_data) { +static Ref<Image> _lossless_unpack_png(const PoolVector<uint8_t> &p_data) { int len = p_data.size(); PoolVector<uint8_t>::Read r = p_data.read(); - ERR_FAIL_COND_V(r[0] != 'P' || r[1] != 'N' || r[2] != 'G' || r[3] != ' ', Image()); + ERR_FAIL_COND_V(r[0] != 'P' || r[1] != 'N' || r[2] != 'G' || r[3] != ' ', Ref<Image>()); return _load_mem_png(&r[4], len - 4); } @@ -271,13 +272,14 @@ static void _write_png_data(png_structp png_ptr, png_bytep data, png_size_t p_le //print_line("png write: "+itos(p_length)); } -static PoolVector<uint8_t> _lossless_pack_png(const Image &p_image) { +static PoolVector<uint8_t> _lossless_pack_png(const Ref<Image> &p_image) { - Image img = p_image; - if (img.is_compressed()) - img.decompress(); + Ref<Image> img = p_image->duplicate(); - ERR_FAIL_COND_V(img.is_compressed(), PoolVector<uint8_t>()); + if (img->is_compressed()) + img->decompress(); + + ERR_FAIL_COND_V(img->is_compressed(), PoolVector<uint8_t>()); png_structp png_ptr; png_infop info_ptr; @@ -311,7 +313,7 @@ static PoolVector<uint8_t> _lossless_pack_png(const Image &p_image) { int pngf = 0; int cs = 0; - switch (img.get_format()) { + switch (img->get_format()) { case Image::FORMAT_L8: { @@ -335,22 +337,22 @@ static PoolVector<uint8_t> _lossless_pack_png(const Image &p_image) { } break; default: { - if (img.detect_alpha()) { + if (img->detect_alpha()) { - img.convert(Image::FORMAT_RGBA8); + img->convert(Image::FORMAT_RGBA8); pngf = PNG_COLOR_TYPE_RGB_ALPHA; cs = 4; } else { - img.convert(Image::FORMAT_RGB8); + img->convert(Image::FORMAT_RGB8); pngf = PNG_COLOR_TYPE_RGB; cs = 3; } } } - int w = img.get_width(); - int h = img.get_height(); + int w = img->get_width(); + int h = img->get_height(); png_set_IHDR(png_ptr, info_ptr, w, h, 8, pngf, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -362,7 +364,7 @@ static PoolVector<uint8_t> _lossless_pack_png(const Image &p_image) { ERR_FAIL_V(PoolVector<uint8_t>()); } - PoolVector<uint8_t>::Read r = img.get_data().read(); + PoolVector<uint8_t>::Read r = img->get_data().read(); row_pointers = (png_bytep *)memalloc(sizeof(png_bytep) * h); for (int i = 0; i < h; i++) { diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h index 78e4252e26..f94b8bce6e 100644 --- a/drivers/png/image_loader_png.h +++ b/drivers/png/image_loader_png.h @@ -42,8 +42,8 @@ class ImageLoaderPNG : public ImageFormatLoader { static void _read_png_data(png_structp png_ptr, png_bytep data, png_size_t p_length); public: - static Error _load_image(void *rf_up, png_rw_ptr p_func, Image *p_image); - virtual Error load_image(Image *p_image, FileAccess *f); + static Error _load_image(void *rf_up, png_rw_ptr p_func, Ref<Image> p_image); + virtual Error load_image(Ref<Image> p_image, FileAccess *f); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderPNG(); }; diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index b754ef97b4..1700603489 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -50,7 +50,7 @@ Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32 ERR_EXPLAIN("Can't save empty texture as PNG"); ERR_FAIL_COND_V(!texture->get_width() || !texture->get_height(), ERR_INVALID_PARAMETER); - Image img = texture->get_data(); + Ref<Image> img = texture->get_data(); Error err = save_image(p_path, img); @@ -95,12 +95,14 @@ Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32 return err; }; -Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) { +Error ResourceSaverPNG::save_image(const String &p_path, const Ref<Image> &p_img) { - if (p_img.is_compressed()) - p_img.decompress(); + Ref<Image> img = p_img->duplicate(); - ERR_FAIL_COND_V(p_img.is_compressed(), ERR_INVALID_PARAMETER); + if (img->is_compressed()) + img->decompress(); + + ERR_FAIL_COND_V(img->is_compressed(), ERR_INVALID_PARAMETER); png_structp png_ptr; png_infop info_ptr; @@ -135,7 +137,7 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) { int pngf = 0; int cs = 0; - switch (p_img.get_format()) { + switch (img->get_format()) { case Image::FORMAT_L8: { @@ -159,22 +161,22 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) { } break; default: { - if (p_img.detect_alpha()) { + if (img->detect_alpha()) { - p_img.convert(Image::FORMAT_RGBA8); + img->convert(Image::FORMAT_RGBA8); pngf = PNG_COLOR_TYPE_RGB_ALPHA; cs = 4; } else { - p_img.convert(Image::FORMAT_RGB8); + img->convert(Image::FORMAT_RGB8); pngf = PNG_COLOR_TYPE_RGB; cs = 3; } } } - int w = p_img.get_width(); - int h = p_img.get_height(); + int w = img->get_width(); + int h = img->get_height(); png_set_IHDR(png_ptr, info_ptr, w, h, 8, pngf, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -187,7 +189,7 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) { ERR_FAIL_V(ERR_CANT_OPEN); } - PoolVector<uint8_t>::Read r = p_img.get_data().read(); + PoolVector<uint8_t>::Read r = img->get_data().read(); row_pointers = (png_bytep *)memalloc(sizeof(png_bytep) * h); for (int i = 0; i < h; i++) { diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h index c25a01c1f6..31ec35c192 100644 --- a/drivers/png/resource_saver_png.h +++ b/drivers/png/resource_saver_png.h @@ -30,11 +30,12 @@ #ifndef RESOURCE_SAVER_PNG_H #define RESOURCE_SAVER_PNG_H +#include "image.h" #include "io/resource_saver.h" class ResourceSaverPNG : public ResourceFormatSaver { public: - static Error save_image(const String &p_path, Image &p_img); + static Error save_image(const String &p_path, const Ref<Image> &p_img); virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); virtual bool recognize(const RES &p_resource) const; |