Make some Image methods static

This commit is contained in:
kobewi 2022-07-22 20:06:19 +02:00
parent 39534a7aec
commit 072f6feaba
51 changed files with 168 additions and 292 deletions

View File

@ -982,7 +982,7 @@ void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) {
} }
void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use create() or create_from_data() first."); ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use set_data() first.");
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats.");
bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */; bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */;
@ -1017,7 +1017,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
} }
bool interpolate_mipmaps = mipmap_aware && mip1 != mip2; bool interpolate_mipmaps = mipmap_aware && mip1 != mip2;
if (interpolate_mipmaps) { if (interpolate_mipmaps) {
dst2.create(p_width, p_height, false, format); dst2.initialize_data(p_width, p_height, false, format);
} }
bool had_mipmaps = mipmaps; bool had_mipmaps = mipmaps;
@ -2016,9 +2016,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
uint8_t* wr = imgdata.ptrw(); uint8_t* wr = imgdata.ptrw();
memcpy(wr.ptr(), ptr, size); memcpy(wr.ptr(), ptr, size);
wr = uint8_t*(); wr = uint8_t*();
Ref<Image> im; Ref<Image> im = Image::create_from_data(w, h, false, format, imgdata);
im.instantiate();
im->create(w, h, false, format, imgdata);
im->save_png("res://mipmap_" + itos(i) + ".png"); im->save_png("res://mipmap_" + itos(i) + ".png");
} }
#endif #endif
@ -2051,7 +2049,25 @@ Vector<uint8_t> Image::get_data() const {
return data; return data;
} }
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { Ref<Image> Image::create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
Ref<Image> image;
image.instantiate();
image->initialize_data(p_width, p_height, p_use_mipmaps, p_format);
return image;
}
Ref<Image> Image::create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
Ref<Image> image;
image.instantiate();
image->initialize_data(p_width, p_height, p_use_mipmaps, p_format, p_data);
return image;
}
void Image::set_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
initialize_data(p_width, p_height, p_use_mipmaps, p_format, p_data);
}
void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
ERR_FAIL_COND_MSG(p_width <= 0, "The Image width specified (" + itos(p_width) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_width <= 0, "The Image width specified (" + itos(p_width) + " pixels) must be greater than 0 pixels.");
ERR_FAIL_COND_MSG(p_height <= 0, "The Image height specified (" + itos(p_height) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_height <= 0, "The Image height specified (" + itos(p_height) + " pixels) must be greater than 0 pixels.");
ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, ERR_FAIL_COND_MSG(p_width > MAX_WIDTH,
@ -2077,7 +2093,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
format = p_format; format = p_format;
} }
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
ERR_FAIL_COND_MSG(p_width <= 0, "The Image width specified (" + itos(p_width) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_width <= 0, "The Image width specified (" + itos(p_width) + " pixels) must be greater than 0 pixels.");
ERR_FAIL_COND_MSG(p_height <= 0, "The Image height specified (" + itos(p_height) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_height <= 0, "The Image height specified (" + itos(p_height) + " pixels) must be greater than 0 pixels.");
ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, ERR_FAIL_COND_MSG(p_width > MAX_WIDTH,
@ -2115,7 +2131,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
mipmaps = p_use_mipmaps; mipmaps = p_use_mipmaps;
} }
void Image::create(const char **p_xpm) { void Image::initialize_data(const char **p_xpm) {
int size_width = 0; int size_width = 0;
int size_height = 0; int size_height = 0;
int pixelchars = 0; int pixelchars = 0;
@ -2230,7 +2246,7 @@ void Image::create(const char **p_xpm) {
} }
if (line == colormap_size) { if (line == colormap_size) {
status = READING_PIXELS; status = READING_PIXELS;
create(size_width, size_height, false, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8); initialize_data(size_width, size_height, false, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8);
data_write = data.ptrw(); data_write = data.ptrw();
pixel_size = has_alpha ? 4 : 3; pixel_size = has_alpha ? 4 : 3;
} }
@ -2559,7 +2575,7 @@ Image::Image(const char **p_xpm) {
mipmaps = false; mipmaps = false;
format = FORMAT_L8; format = FORMAT_L8;
create(p_xpm); initialize_data(p_xpm);
} }
Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
@ -2568,7 +2584,7 @@ Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
mipmaps = p_use_mipmaps; mipmaps = p_use_mipmaps;
format = FORMAT_L8; format = FORMAT_L8;
create(p_width, p_height, p_use_mipmaps, p_format); initialize_data(p_width, p_height, p_use_mipmaps, p_format);
} }
Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
@ -2577,7 +2593,7 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const V
mipmaps = p_mipmaps; mipmaps = p_mipmaps;
format = FORMAT_L8; format = FORMAT_L8;
create(p_width, p_height, p_mipmaps, p_format, p_data); initialize_data(p_width, p_height, p_mipmaps, p_format, p_data);
} }
Rect2i Image::get_used_rect() const { Rect2i Image::get_used_rect() const {
@ -2931,7 +2947,7 @@ void Image::_set_data(const Dictionary &p_data) {
ERR_FAIL_COND(ddformat == FORMAT_MAX); ERR_FAIL_COND(ddformat == FORMAT_MAX);
create(dwidth, dheight, dmipmaps, ddformat, ddata); initialize_data(dwidth, dheight, dmipmaps, ddformat, ddata);
} }
Dictionary Image::_get_data() const { Dictionary Image::_get_data() const {
@ -3294,8 +3310,9 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_mipmaps", "renormalize"), &Image::generate_mipmaps, DEFVAL(false)); ClassDB::bind_method(D_METHOD("generate_mipmaps", "renormalize"), &Image::generate_mipmaps, DEFVAL(false));
ClassDB::bind_method(D_METHOD("clear_mipmaps"), &Image::clear_mipmaps); ClassDB::bind_method(D_METHOD("clear_mipmaps"), &Image::clear_mipmaps);
ClassDB::bind_method(D_METHOD("create", "width", "height", "use_mipmaps", "format"), &Image::create_empty); ClassDB::bind_static_method("Image", D_METHOD("create", "width", "height", "use_mipmaps", "format"), &Image::create_empty);
ClassDB::bind_method(D_METHOD("create_from_data", "width", "height", "use_mipmaps", "format", "data"), &Image::create_from_data); ClassDB::bind_static_method("Image", D_METHOD("create_from_data", "width", "height", "use_mipmaps", "format", "data"), &Image::create_from_data);
ClassDB::bind_method(D_METHOD("set_data", "width", "height", "use_mipmaps", "format", "data"), &Image::set_data);
ClassDB::bind_method(D_METHOD("is_empty"), &Image::is_empty); ClassDB::bind_method(D_METHOD("is_empty"), &Image::is_empty);
@ -3460,9 +3477,7 @@ Ref<Image> Image::rgbe_to_srgb() {
ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>()); ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>());
Ref<Image> new_image; Ref<Image> new_image = create_empty(width, height, false, Image::FORMAT_RGB8);
new_image.instantiate();
new_image->create(width, height, false, Image::FORMAT_RGB8);
for (int row = 0; row < height; row++) { for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) { for (int col = 0; col < width; col++) {

View File

@ -279,12 +279,12 @@ public:
void normalize(); //for normal maps void normalize(); //for normal maps
/** /**
* Create a new image of a given size and format. Current image will be lost * Creates new internal image data of a given size and format. Current image will be lost.
*/ */
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format); void initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data); void initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
void initialize_data(const char **p_xpm);
void create(const char **p_xpm);
/** /**
* returns true when the image is empty (0,0) in size * returns true when the image is empty (0,0) in size
*/ */
@ -303,13 +303,9 @@ public:
Error save_webp(const String &p_path, const bool p_lossy = false, const float p_quality = 0.75f) const; Error save_webp(const String &p_path, const bool p_lossy = false, const float p_quality = 0.75f) const;
Vector<uint8_t> save_webp_to_buffer(const bool p_lossy = false, const float p_quality = 0.75f) const; Vector<uint8_t> save_webp_to_buffer(const bool p_lossy = false, const float p_quality = 0.75f) const;
void create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { static Ref<Image> create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
create(p_width, p_height, p_use_mipmaps, p_format); static Ref<Image> create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
} void set_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
void create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
create(p_width, p_height, p_use_mipmaps, p_format, p_data);
}
/** /**
* create an empty image * create an empty image

View File

@ -111,8 +111,8 @@
Copies [param src] image to this image. Copies [param src] image to this image.
</description> </description>
</method> </method>
<method name="create"> <method name="create" qualifiers="static">
<return type="void" /> <return type="Image" />
<param index="0" name="width" type="int" /> <param index="0" name="width" type="int" />
<param index="1" name="height" type="int" /> <param index="1" name="height" type="int" />
<param index="2" name="use_mipmaps" type="bool" /> <param index="2" name="use_mipmaps" type="bool" />
@ -121,8 +121,8 @@
Creates an empty image of given size and format. See [enum Format] constants. If [param use_mipmaps] is [code]true[/code] then generate mipmaps for this image. See the [method generate_mipmaps]. Creates an empty image of given size and format. See [enum Format] constants. If [param use_mipmaps] is [code]true[/code] then generate mipmaps for this image. See the [method generate_mipmaps].
</description> </description>
</method> </method>
<method name="create_from_data"> <method name="create_from_data" qualifiers="static">
<return type="void" /> <return type="Image" />
<param index="0" name="width" type="int" /> <param index="0" name="width" type="int" />
<param index="1" name="height" type="int" /> <param index="1" name="height" type="int" />
<param index="2" name="use_mipmaps" type="bool" /> <param index="2" name="use_mipmaps" type="bool" />
@ -454,6 +454,17 @@
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If [param lossy] is true, the image will be saved lossy, using the [param quality] setting between 0.0 and 1.0 (inclusive). Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If [param lossy] is true, the image will be saved lossy, using the [param quality] setting between 0.0 and 1.0 (inclusive).
</description> </description>
</method> </method>
<method name="set_data">
<return type="void" />
<param index="0" name="width" type="int" />
<param index="1" name="height" type="int" />
<param index="2" name="use_mipmaps" type="bool" />
<param index="3" name="format" type="int" enum="Image.Format" />
<param index="4" name="data" type="PackedByteArray" />
<description>
Overwrites data of an existing [Image]. Non-static equivalent of [method create_from_data].
</description>
</method>
<method name="set_pixel"> <method name="set_pixel">
<return type="void" /> <return type="void" />
<param index="0" name="x" type="int" /> <param index="0" name="x" type="int" />

View File

@ -59,9 +59,7 @@ TextureStorage::TextureStorage() {
{ //create default textures { //create default textures
{ // White Textures { // White Textures
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, true, Image::FORMAT_RGBA8);
image->fill(Color(1, 1, 1, 1)); image->fill(Color(1, 1, 1, 1));
image->generate_mipmaps(); image->generate_mipmaps();
@ -90,9 +88,7 @@ TextureStorage::TextureStorage() {
} }
{ // black { // black
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, true, Image::FORMAT_RGBA8);
image->fill(Color(0, 0, 0, 1)); image->fill(Color(0, 0, 0, 1));
image->generate_mipmaps(); image->generate_mipmaps();
@ -116,9 +112,7 @@ TextureStorage::TextureStorage() {
} }
{ // transparent black { // transparent black
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, true, Image::FORMAT_RGBA8);
image->fill(Color(0, 0, 0, 0)); image->fill(Color(0, 0, 0, 0));
image->generate_mipmaps(); image->generate_mipmaps();
@ -127,9 +121,7 @@ TextureStorage::TextureStorage() {
} }
{ {
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, true, Image::FORMAT_RGBA8);
image->fill(Color(0.5, 0.5, 1, 1)); image->fill(Color(0.5, 0.5, 1, 1));
image->generate_mipmaps(); image->generate_mipmaps();
@ -138,9 +130,7 @@ TextureStorage::TextureStorage() {
} }
{ {
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, true, Image::FORMAT_RGBA8);
image->fill(Color(1.0, 0.5, 1, 1)); image->fill(Color(1.0, 0.5, 1, 1));
image->generate_mipmaps(); image->generate_mipmaps();
@ -745,9 +735,7 @@ void TextureStorage::texture_proxy_update(RID p_texture, RID p_proxy_to) {
void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) { void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) {
//this could be better optimized to reuse an existing image , done this way //this could be better optimized to reuse an existing image , done this way
//for now to get it working //for now to get it working
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, false, Image::FORMAT_RGBA8);
image->fill(Color(1, 0, 1, 1)); image->fill(Color(1, 0, 1, 1));
texture_2d_initialize(p_texture, image); texture_2d_initialize(p_texture, image);
@ -756,9 +744,7 @@ void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) {
void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) { void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) {
//this could be better optimized to reuse an existing image , done this way //this could be better optimized to reuse an existing image , done this way
//for now to get it working //for now to get it working
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, false, Image::FORMAT_RGBA8);
image->fill(Color(1, 0, 1, 1)); image->fill(Color(1, 0, 1, 1));
Vector<Ref<Image>> images; Vector<Ref<Image>> images;
@ -777,9 +763,7 @@ void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, Re
void TextureStorage::texture_3d_placeholder_initialize(RID p_texture) { void TextureStorage::texture_3d_placeholder_initialize(RID p_texture) {
//this could be better optimized to reuse an existing image , done this way //this could be better optimized to reuse an existing image , done this way
//for now to get it working //for now to get it working
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, false, Image::FORMAT_RGBA8);
image->fill(Color(1, 0, 1, 1)); image->fill(Color(1, 0, 1, 1));
Vector<Ref<Image>> images; Vector<Ref<Image>> images;
@ -833,9 +817,7 @@ Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const {
data.resize(data_size); data.resize(data_size);
ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); ERR_FAIL_COND_V(data.size() == 0, Ref<Image>());
Ref<Image> image; Ref<Image> image = Image::create_from_data(texture->width, texture->height, texture->mipmaps > 1, texture->real_format, data);
image.instantiate();
image->create(texture->width, texture->height, texture->mipmaps > 1, texture->real_format, data);
ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); ERR_FAIL_COND_V(image->is_empty(), Ref<Image>());
if (texture->format != texture->real_format) { if (texture->format != texture->real_format) {
image->convert(texture->format); image->convert(texture->format);

View File

@ -119,7 +119,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, bool p_force_linear,
ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT); ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT);
//print_line("png width: "+itos(png_img.width)+" height: "+itos(png_img.height)); //print_line("png width: "+itos(png_img.width)+" height: "+itos(png_img.height));
p_image->create(png_img.width, png_img.height, false, dest_format, buffer); p_image->set_data(png_img.width, png_img.height, false, dest_format, buffer);
return OK; return OK;
} }

View File

@ -308,9 +308,7 @@ void EditorProfiler::_update_plot() {
} }
} }
Ref<Image> img; Ref<Image> img = Image::create_from_data(w, h, false, Image::FORMAT_RGBA8, graph_image);
img.instantiate();
img->create(w, h, false, Image::FORMAT_RGBA8, graph_image);
if (reset_texture) { if (reset_texture) {
if (graph_texture.is_null()) { if (graph_texture.is_null()) {

View File

@ -298,9 +298,7 @@ void EditorVisualProfiler::_update_plot() {
} }
} }
Ref<Image> img; Ref<Image> img = Image::create_from_data(w, h, false, Image::FORMAT_RGBA8, graph_image);
img.instantiate();
img->create(w, h, false, Image::FORMAT_RGBA8, graph_image);
if (reset_texture) { if (reset_texture) {
if (graph_texture.is_null()) { if (graph_texture.is_null()) {

View File

@ -1618,7 +1618,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
// which would result in an invalid texture. // which would result in an invalid texture.
if (c3d == 0 && c2d == 0) { if (c3d == 0 && c2d == 0) {
img.instantiate(); img.instantiate();
img->create(1, 1, false, Image::FORMAT_RGB8); img->initialize_data(1, 1, false, Image::FORMAT_RGB8);
} else if (c3d < c2d) { } else if (c3d < c2d) {
Ref<ViewportTexture> viewport_texture = scene_root->get_texture(); Ref<ViewportTexture> viewport_texture = scene_root->get_texture();
if (viewport_texture->get_width() > 0 && viewport_texture->get_height() > 0) { if (viewport_texture->get_width() > 0 && viewport_texture->get_height() > 0) {

View File

@ -186,9 +186,7 @@ void ResourceImporterLayeredTexture::_save_tex(Vector<Ref<Image>> p_images, cons
int mm_d = MAX(1, d >> 1); int mm_d = MAX(1, d >> 1);
for (int i = 0; i < mm_d; i++) { for (int i = 0; i < mm_d; i++) {
Ref<Image> mm; Ref<Image> mm = Image::create_empty(mm_w, mm_h, false, p_images[0]->get_format());
mm.instantiate();
mm->create(mm_w, mm_h, false, p_images[0]->get_format());
Vector3 pos; Vector3 pos;
pos.z = float(i) * float(d) / float(mm_d) + 0.5; pos.z = float(i) * float(d) / float(mm_d) + 0.5;
for (int x = 0; x < mm_w; x++) { for (int x = 0; x < mm_w; x++) {

View File

@ -273,9 +273,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
EditorAtlasPacker::chart_pack(charts, atlas_width, atlas_height); EditorAtlasPacker::chart_pack(charts, atlas_width, atlas_height);
//blit the atlas //blit the atlas
Ref<Image> new_atlas; Ref<Image> new_atlas = Image::create_empty(atlas_width, atlas_height, false, Image::FORMAT_RGBA8);
new_atlas.instantiate();
new_atlas->create(atlas_width, atlas_height, false, Image::FORMAT_RGBA8);
for (int i = 0; i < pack_data_files.size(); i++) { for (int i = 0; i < pack_data_files.size(); i++) {
PackData &pack_data = pack_data_files.write[i]; PackData &pack_data = pack_data_files.write[i];

View File

@ -128,14 +128,11 @@ void AnimationPlayerEditor::_notification(int p_what) {
{ {
Ref<Image> autoplay_img = autoplay_icon->get_image(); Ref<Image> autoplay_img = autoplay_icon->get_image();
Ref<Image> reset_img = reset_icon->get_image(); Ref<Image> reset_img = reset_icon->get_image();
Ref<Image> autoplay_reset_img;
Size2 icon_size = autoplay_img->get_size(); Size2 icon_size = autoplay_img->get_size();
autoplay_reset_img.instantiate(); Ref<Image> autoplay_reset_img = Image::create_empty(icon_size.x * 2, icon_size.y, false, autoplay_img->get_format());
autoplay_reset_img->create(icon_size.x * 2, icon_size.y, false, autoplay_img->get_format());
autoplay_reset_img->blit_rect(autoplay_img, Rect2i(Point2i(), icon_size), Point2i()); autoplay_reset_img->blit_rect(autoplay_img, Rect2i(Point2i(), icon_size), Point2i());
autoplay_reset_img->blit_rect(reset_img, Rect2i(Point2i(), icon_size), Point2i(icon_size.x, 0)); autoplay_reset_img->blit_rect(reset_img, Rect2i(Point2i(), icon_size), Point2i(icon_size.x, 0));
autoplay_reset_icon.instantiate(); autoplay_reset_icon = ImageTexture::create_from_image(autoplay_reset_img);
autoplay_reset_icon->set_image(autoplay_reset_img);
} }
stop->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons"))); stop->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));

View File

@ -805,7 +805,7 @@ Ref<Texture2D> CurvePreviewGenerator::generate(const Ref<Resource> &p_from, cons
img_ref.instantiate(); img_ref.instantiate();
Image &im = **img_ref; Image &im = **img_ref;
im.create(thumbnail_size, thumbnail_size / 2, false, Image::FORMAT_RGBA8); im.initialize_data(thumbnail_size, thumbnail_size / 2, false, Image::FORMAT_RGBA8);
Color bg_color(0.1, 0.1, 0.1, 1.0); Color bg_color(0.1, 0.1, 0.1, 1.0);

View File

@ -210,9 +210,7 @@ Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const Ref<Resource> &p_from,
} }
} }
Ref<Image> img; Ref<Image> img = Image::create_from_data(bm->get_size().width, bm->get_size().height, false, Image::FORMAT_L8, data);
img.instantiate();
img->create(bm->get_size().width, bm->get_size().height, false, Image::FORMAT_L8, data);
if (img->is_compressed()) { if (img->is_compressed()) {
if (img->decompress() != OK) { if (img->decompress() != OK) {
@ -483,10 +481,8 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const Ref<Resource> &p_from,
int line = 0; int line = 0;
int col = 0; int col = 0;
Ref<Image> img;
img.instantiate();
int thumbnail_size = MAX(p_size.x, p_size.y); int thumbnail_size = MAX(p_size.x, p_size.y);
img->create(thumbnail_size, thumbnail_size, false, Image::FORMAT_RGBA8); Ref<Image> img = Image::create_empty(thumbnail_size, thumbnail_size, false, Image::FORMAT_RGBA8);
Color bg_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/background_color"); Color bg_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/background_color");
Color keyword_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/keyword_color"); Color keyword_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/keyword_color");
@ -660,9 +656,7 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const Ref<Resource> &p_f
//post_process_preview(img); //post_process_preview(img);
Ref<Image> image; Ref<Image> image = Image::create_from_data(w, h, false, Image::FORMAT_RGB8, img);
image.instantiate();
image->create(w, h, false, Image::FORMAT_RGB8, img);
return ImageTexture::create_from_image(image); return ImageTexture::create_from_image(image);
} }

View File

@ -299,7 +299,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
} }
img.instantiate(); img.instantiate();
img->create(w, h, false, Image::FORMAT_RGF, texdata); img->set_data(w, h, false, Image::FORMAT_RGF, texdata);
pm->set_emission_point_texture(ImageTexture::create_from_image(img)); pm->set_emission_point_texture(ImageTexture::create_from_image(img));
pm->set_emission_point_count(vpc); pm->set_emission_point_count(vpc);
@ -315,7 +315,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
} }
img.instantiate(); img.instantiate();
img->create(w, h, false, Image::FORMAT_RGBA8, colordata); img->set_data(w, h, false, Image::FORMAT_RGBA8, colordata);
pm->set_emission_color_texture(ImageTexture::create_from_image(img)); pm->set_emission_color_texture(ImageTexture::create_from_image(img));
} }
@ -335,7 +335,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
} }
img.instantiate(); img.instantiate();
img->create(w, h, false, Image::FORMAT_RGF, normdata); img->set_data(w, h, false, Image::FORMAT_RGF, normdata);
pm->set_emission_normal_texture(ImageTexture::create_from_image(img)); pm->set_emission_normal_texture(ImageTexture::create_from_image(img));
} else { } else {

View File

@ -47,9 +47,7 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
merged_mapping.clear(); merged_mapping.clear();
if (p_atlas_sources.size() >= 2) { if (p_atlas_sources.size() >= 2) {
Ref<Image> output_image; Ref<Image> output_image = Image::create_empty(1, 1, false, Image::FORMAT_RGBA8);
output_image.instantiate();
output_image->create(1, 1, false, Image::FORMAT_RGBA8);
// Compute the new texture region size. // Compute the new texture region size.
Vector2i new_texture_region_size; Vector2i new_texture_region_size;

View File

@ -2127,7 +2127,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
} else { } else {
// Create a 1×1 transparent image. This will effectively hide the splash image. // Create a 1×1 transparent image. This will effectively hide the splash image.
boot_logo.instantiate(); boot_logo.instantiate();
boot_logo->create(1, 1, false, Image::FORMAT_RGBA8); boot_logo->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0)); boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0));
} }

View File

@ -253,7 +253,7 @@ static Ref<Image> basis_universal_unpacker_ptr(const uint8_t *p_data, int p_size
}; };
image.instantiate(); image.instantiate();
image->create(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata); image->set_data(info.m_width, info.m_height, info.m_total_levels > 1, imgfmt, gpudata);
return image; return image;
} }

View File

@ -156,7 +156,7 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image,
if (p_color_buffer == nullptr || color_table_size == 0) { // regular pixels if (p_color_buffer == nullptr || color_table_size == 0) { // regular pixels
p_image->create(width, height, false, Image::FORMAT_RGBA8, data); p_image->set_data(width, height, false, Image::FORMAT_RGBA8, data);
} else { // data is in indexed format, extend it } else { // data is in indexed format, extend it
@ -194,7 +194,7 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image,
dest += 4; dest += 4;
} }
p_image->create(width, height, false, Image::FORMAT_RGBA8, extended_data); p_image->set_data(width, height, false, Image::FORMAT_RGBA8, extended_data);
} }
} }
return err; return err;

View File

@ -158,7 +158,7 @@
memcpy(w, dataY, new_width * new_height); memcpy(w, dataY, new_width * new_height);
img[0].instantiate(); img[0].instantiate();
img[0]->create(new_width, new_height, 0, Image::FORMAT_R8, img_data[0]); img[0]->set_data(new_width, new_height, 0, Image::FORMAT_R8, img_data[0]);
} }
{ {
@ -177,7 +177,7 @@
///TODO OpenGL doesn't support FORMAT_RG8, need to do some form of conversion ///TODO OpenGL doesn't support FORMAT_RG8, need to do some form of conversion
img[1].instantiate(); img[1].instantiate();
img[1]->create(new_width, new_height, 0, Image::FORMAT_RG8, img_data[1]); img[1]->set_data(new_width, new_height, 0, Image::FORMAT_RG8, img_data[1]);
} }
// set our texture... // set our texture...

View File

@ -230,7 +230,7 @@ void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChann
h = MAX(h / 2, 1); h = MAX(h / 2, 1);
} }
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); p_image->set_data(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
} }
void image_decompress_cvtt(Image *p_image) { void image_decompress_cvtt(Image *p_image) {
@ -339,5 +339,5 @@ void image_decompress_cvtt(Image *p_image) {
w >>= 1; w >>= 1;
h >>= 1; h >>= 1;
} }
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); p_image->set_data(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
} }

View File

@ -51,7 +51,7 @@ Ref<Image> LightmapDenoiserOIDN::denoise_image(const Ref<Image> &p_image) {
return p_image; return p_image;
} }
img->create(img->get_width(), img->get_height(), false, img->get_format(), data); img->set_data(img->get_width(), img->get_height(), false, img->get_format(), data);
return img; return img;
} }

View File

@ -233,7 +233,7 @@ void _compress_etcpak(EtcpakType p_compresstype, Image *r_img, float p_lossy_qua
} }
// Replace original image with compressed one. // Replace original image with compressed one.
r_img->create(width, height, mipmaps, target_format, dest_data); r_img->set_data(width, height, mipmaps, target_format, dest_data);
print_verbose(vformat("ETCPAK encode took %s ms.", rtos(OS::get_singleton()->get_ticks_msec() - start_time))); print_verbose(vformat("ETCPAK encode took %s ms.", rtos(OS::get_singleton()->get_ticks_msec() - start_time)));
} }

View File

@ -3484,7 +3484,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
height = albedo_texture->get_height(); height = albedo_texture->get_height();
width = albedo_texture->get_width(); width = albedo_texture->get_width();
} }
orm_image->create(width, height, false, Image::FORMAT_RGBA8); orm_image->initialize_data(width, height, false, Image::FORMAT_RGBA8);
if (ao_image.is_valid() && ao_image->get_size() != Vector2(width, height)) { if (ao_image.is_valid() && ao_image->get_size() != Vector2(width, height)) {
ao_image->resize(width, height, Image::INTERPOLATE_LANCZOS); ao_image->resize(width, height, Image::INTERPOLATE_LANCZOS);
} }
@ -3860,13 +3860,11 @@ void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Re
if (r_spec_gloss->diffuse_img.is_null()) { if (r_spec_gloss->diffuse_img.is_null()) {
return; return;
} }
Ref<Image> rm_img;
rm_img.instantiate();
bool has_roughness = false; bool has_roughness = false;
bool has_metal = false; bool has_metal = false;
p_material->set_roughness(1.0f); p_material->set_roughness(1.0f);
p_material->set_metallic(1.0f); p_material->set_metallic(1.0f);
rm_img->create(r_spec_gloss->spec_gloss_img->get_width(), r_spec_gloss->spec_gloss_img->get_height(), false, Image::FORMAT_RGBA8); Ref<Image> rm_img = Image::create_empty(r_spec_gloss->spec_gloss_img->get_width(), r_spec_gloss->spec_gloss_img->get_height(), false, Image::FORMAT_RGBA8);
r_spec_gloss->spec_gloss_img->decompress(); r_spec_gloss->spec_gloss_img->decompress();
if (r_spec_gloss->diffuse_img.is_valid()) { if (r_spec_gloss->diffuse_img.is_valid()) {
r_spec_gloss->diffuse_img->decompress(); r_spec_gloss->diffuse_img->decompress();

View File

@ -140,7 +140,7 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField
} }
} }
p_image->create(width, height, false, Image::FORMAT_RGBE9995, imgdata); p_image->set_data(width, height, false, Image::FORMAT_RGBE9995, imgdata);
return OK; return OK;
} }

View File

@ -99,7 +99,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
fmt = Image::FORMAT_RGB8; fmt = Image::FORMAT_RGB8;
} }
p_image->create(image_width, image_height, false, fmt, data); p_image->set_data(image_width, image_height, false, fmt, data);
return OK; return OK;
} }

View File

@ -251,15 +251,11 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_
} }
for (int i = 0; i < atlas_slices; i++) { for (int i = 0; i < atlas_slices; i++) {
Ref<Image> albedo; Ref<Image> albedo = Image::create_empty(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBA8);
albedo.instantiate();
albedo->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBA8);
albedo->set_as_black(); albedo->set_as_black();
albedo_images.write[i] = albedo; albedo_images.write[i] = albedo;
Ref<Image> emission; Ref<Image> emission = Image::create_empty(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH);
emission.instantiate();
emission->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH);
emission->set_as_black(); emission->set_as_black();
emission_images.write[i] = emission; emission_images.write[i] = emission;
} }
@ -478,9 +474,7 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i
grid_usage.write[j] = count > 0 ? 255 : 0; grid_usage.write[j] = count > 0 ? 255 : 0;
} }
Ref<Image> img; Ref<Image> img = Image::create_from_data(grid_size, grid_size, false, Image::FORMAT_L8, grid_usage);
img.instantiate();
img->create(grid_size, grid_size, false, Image::FORMAT_L8, grid_usage);
img->save_png("res://grid_layer_" + itos(1000 + i).substr(1, 3) + ".png"); img->save_png("res://grid_layer_" + itos(1000 + i).substr(1, 3) + ".png");
} }
#endif #endif
@ -660,9 +654,7 @@ LightmapperRD::BakeError LightmapperRD::_dilate(RenderingDevice *rd, Ref<RDShade
#ifdef DEBUG_TEXTURES #ifdef DEBUG_TEXTURES
for (int i = 0; i < atlas_slices; i++) { for (int i = 0; i < atlas_slices; i++) {
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img->convert(Image::FORMAT_RGBA8); img->convert(Image::FORMAT_RGBA8);
img->save_png("res://5_dilated_" + itos(i) + ".png"); img->save_png("res://5_dilated_" + itos(i) + ".png");
} }
@ -778,7 +770,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
panorama_tex->convert(Image::FORMAT_RGBAF); panorama_tex->convert(Image::FORMAT_RGBAF);
} else { } else {
panorama_tex.instantiate(); panorama_tex.instantiate();
panorama_tex->create(8, 8, false, Image::FORMAT_RGBAF); panorama_tex->initialize_data(8, 8, false, Image::FORMAT_RGBAF);
panorama_tex->fill(Color(0, 0, 0, 1)); panorama_tex->fill(Color(0, 0, 0, 1));
} }
@ -953,13 +945,11 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
for (int i = 0; i < atlas_slices; i++) { for (int i = 0; i < atlas_slices; i++) {
Vector<uint8_t> s = rd->texture_get_data(position_tex, i); Vector<uint8_t> s = rd->texture_get_data(position_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAF, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAF, s);
img->save_exr("res://1_position_" + itos(i) + ".exr", false); img->save_exr("res://1_position_" + itos(i) + ".exr", false);
s = rd->texture_get_data(normal_tex, i); s = rd->texture_get_data(normal_tex, i);
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s); img->set_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img->save_exr("res://1_normal_" + itos(i) + ".exr", false); img->save_exr("res://1_normal_" + itos(i) + ".exr", false);
} }
#endif #endif
@ -1182,9 +1172,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
for (int i = 0; i < atlas_slices; i++) { for (int i = 0; i < atlas_slices; i++) {
Vector<uint8_t> s = rd->texture_get_data(light_source_tex, i); Vector<uint8_t> s = rd->texture_get_data(light_source_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img->save_exr("res://2_light_primary_" + itos(i) + ".exr", false); img->save_exr("res://2_light_primary_" + itos(i) + ".exr", false);
} }
#endif #endif
@ -1415,14 +1403,10 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
#if 0 #if 0
for (int i = 0; i < probe_positions.size(); i++) { for (int i = 0; i < probe_positions.size(); i++) {
Ref<Image> img; Ref<Image> img = Image::create_empty(6, 4, false, Image::FORMAT_RGB8);
img.instantiate();
img->create(6, 4, false, Image::FORMAT_RGB8);
for (int j = 0; j < 6; j++) { for (int j = 0; j < 6; j++) {
Vector<uint8_t> s = rd->texture_get_data(lightprobe_tex, i * 6 + j); Vector<uint8_t> s = rd->texture_get_data(lightprobe_tex, i * 6 + j);
Ref<Image> img2; Ref<Image> img2 = Image::create_from_data(2, 2, false, Image::FORMAT_RGBAF, s);
img2.instantiate();
img2->create(2, 2, false, Image::FORMAT_RGBAF, s);
img2->convert(Image::FORMAT_RGB8); img2->convert(Image::FORMAT_RGB8);
img->blit_rect(img2, Rect2i(0, 0, 2, 2), Point2i((j % 3) * 2, (j / 3) * 2)); img->blit_rect(img2, Rect2i(0, 0, 2, 2), Point2i((j % 3) * 2, (j / 3) * 2));
} }
@ -1449,9 +1433,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
if (denoiser.is_valid()) { if (denoiser.is_valid()) {
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
Ref<Image> denoised = denoiser->denoise_image(img); Ref<Image> denoised = denoiser->denoise_image(img);
if (denoised != img) { if (denoised != img) {
@ -1484,9 +1466,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img->save_exr("res://4_light_secondary_" + itos(i) + ".exr", false); img->save_exr("res://4_light_secondary_" + itos(i) + ".exr", false);
} }
#endif #endif
@ -1640,9 +1620,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img->save_exr("res://5_blendseams" + itos(i) + ".exr", false); img->save_exr("res://5_blendseams" + itos(i) + ".exr", false);
} }
#endif #endif
@ -1652,9 +1630,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i); Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
Ref<Image> img; Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img.instantiate();
img->create(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
img->convert(Image::FORMAT_RGBH); //remove alpha img->convert(Image::FORMAT_RGBH); //remove alpha
bake_textures.push_back(img); bake_textures.push_back(img);
} }
@ -1667,9 +1643,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
#ifdef DEBUG_TEXTURES #ifdef DEBUG_TEXTURES
{ {
Ref<Image> img2; Ref<Image> img2 = Image::create_from_data(probe_values.size(), 1, false, Image::FORMAT_RGBAF, probe_data);
img2.instantiate();
img2->create(probe_values.size(), 1, false, Image::FORMAT_RGBAF, probe_data);
img2->save_exr("res://6_lightprobes.exr", false); img2->save_exr("res://6_lightprobes.exr", false);
} }
#endif #endif

View File

@ -176,9 +176,7 @@ Ref<Image> NoiseTexture2D::_modulate_with_gradient(Ref<Image> p_image, Ref<Gradi
int width = p_image->get_width(); int width = p_image->get_width();
int height = p_image->get_height(); int height = p_image->get_height();
Ref<Image> new_image; Ref<Image> new_image = Image::create_empty(width, height, false, Image::FORMAT_RGBA8);
new_image.instantiate();
new_image->create(width, height, false, Image::FORMAT_RGBA8);
for (int row = 0; row < height; row++) { for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) { for (int col = 0; col < width; col++) {

View File

@ -70,7 +70,7 @@ void image_decompress_squish(Image *p_image) {
h >>= 1; h >>= 1;
} }
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); p_image->set_data(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
if (p_image->get_format() == Image::FORMAT_DXT5_RA_AS_RG) { if (p_image->get_format() == Image::FORMAT_DXT5_RA_AS_RG) {
p_image->convert_ra_rgba8_to_rg(); p_image->convert_ra_rgba8_to_rg();

View File

@ -135,7 +135,7 @@ void ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, String p_strin
res = sw_canvas->clear(true); res = sw_canvas->clear(true);
memfree(buffer); memfree(buffer);
p_image->create(width, height, false, Image::FORMAT_RGBA8, image); p_image->set_data(width, height, false, Image::FORMAT_RGBA8, image);
} }
void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const { void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const {

View File

@ -2494,9 +2494,7 @@ void TextServerAdvanced::_font_set_texture_image(const RID &p_font_rid, const Ve
tex.texture_h = p_image->get_height(); tex.texture_h = p_image->get_height();
tex.format = p_image->get_format(); tex.format = p_image->get_format();
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -2515,11 +2513,7 @@ Ref<Image> TextServerAdvanced::_font_get_texture_image(const RID &p_font_rid, co
ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), Ref<Image>()); ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), Ref<Image>());
const FontTexture &tex = fd->cache[size]->textures[p_texture_index]; const FontTexture &tex = fd->cache[size]->textures[p_texture_index];
Ref<Image> img; return Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
return img;
} }
void TextServerAdvanced::_font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) { void TextServerAdvanced::_font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) {
@ -2853,9 +2847,7 @@ RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const
if (gl[p_glyph | mod].texture_idx != -1) { if (gl[p_glyph | mod].texture_idx != -1) {
if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -2901,9 +2893,7 @@ Size2 TextServerAdvanced::_font_get_glyph_texture_size(const RID &p_font_rid, co
if (gl[p_glyph | mod].texture_idx != -1) { if (gl[p_glyph | mod].texture_idx != -1) {
if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -3248,9 +3238,7 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
if (RenderingServer::get_singleton() != nullptr) { if (RenderingServer::get_singleton() != nullptr) {
if (fd->cache[size]->textures[gl.texture_idx].dirty) { if (fd->cache[size]->textures[gl.texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -3340,9 +3328,7 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
if (RenderingServer::get_singleton() != nullptr) { if (RenderingServer::get_singleton() != nullptr) {
if (fd->cache[size]->textures[gl.texture_idx].dirty) { if (fd->cache[size]->textures[gl.texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }

View File

@ -1588,9 +1588,7 @@ void TextServerFallback::_font_set_texture_image(const RID &p_font_rid, const Ve
tex.texture_h = p_image->get_height(); tex.texture_h = p_image->get_height();
tex.format = p_image->get_format(); tex.format = p_image->get_format();
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -1609,11 +1607,7 @@ Ref<Image> TextServerFallback::_font_get_texture_image(const RID &p_font_rid, co
ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), Ref<Image>()); ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), Ref<Image>());
const FontTexture &tex = fd->cache[size]->textures[p_texture_index]; const FontTexture &tex = fd->cache[size]->textures[p_texture_index];
Ref<Image> img; return Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
return img;
} }
void TextServerFallback::_font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) { void TextServerFallback::_font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) {
@ -1933,9 +1927,7 @@ RID TextServerFallback::_font_get_glyph_texture_rid(const RID &p_font_rid, const
if (gl[p_glyph | mod].texture_idx != -1) { if (gl[p_glyph | mod].texture_idx != -1) {
if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -1981,9 +1973,7 @@ Size2 TextServerFallback::_font_get_glyph_texture_size(const RID &p_font_rid, co
if (gl[p_glyph | mod].texture_idx != -1) { if (gl[p_glyph | mod].texture_idx != -1) {
if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) { if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -2310,9 +2300,7 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
if (RenderingServer::get_singleton() != nullptr) { if (RenderingServer::get_singleton() != nullptr) {
if (fd->cache[size]->textures[gl.texture_idx].dirty) { if (fd->cache[size]->textures[gl.texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }
@ -2402,9 +2390,7 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R
if (RenderingServer::get_singleton() != nullptr) { if (RenderingServer::get_singleton() != nullptr) {
if (fd->cache[size]->textures[gl.texture_idx].dirty) { if (fd->cache[size]->textures[gl.texture_idx].dirty) {
FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx]; FontTexture &tex = fd->cache[size]->textures.write[gl.texture_idx];
Ref<Image> img; Ref<Image> img = Image::create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
img.instantiate();
img->create_from_data(tex.texture_w, tex.texture_h, false, tex.format, tex.imgdata);
if (fd->mipmaps) { if (fd->mipmaps) {
img->generate_mipmaps(); img->generate_mipmaps();
} }

View File

@ -246,7 +246,7 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff
} }
} }
p_image->create(width, height, false, Image::FORMAT_RGBA8, image_data); p_image->initialize_data(width, height, false, Image::FORMAT_RGBA8, image_data);
return OK; return OK;
} }

View File

@ -336,9 +336,7 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
size.x = w; size.x = w;
size.y = h; size.y = h;
Ref<Image> img; Ref<Image> img = Image::create_empty(w, h, false, Image::FORMAT_RGBA8);
img.instantiate();
img->create(w, h, false, Image::FORMAT_RGBA8);
texture->set_image(img); texture->set_image(img);
} else { } else {

View File

@ -280,7 +280,7 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, Ref<FileAccess> f, BitF
} }
} }
p_image->create(exr_image.width, exr_image.height, false, format, imgdata); p_image->set_data(exr_image.width, exr_image.height, false, format, imgdata);
FreeEXRHeader(&exr_header); FreeEXRHeader(&exr_header);
FreeEXRImage(&exr_image); FreeEXRImage(&exr_image);

View File

@ -183,7 +183,7 @@ Error webp_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
ERR_FAIL_COND_V_MSG(errdec, ERR_FILE_CORRUPT, "Failed decoding WebP image."); ERR_FAIL_COND_V_MSG(errdec, ERR_FILE_CORRUPT, "Failed decoding WebP image.");
p_image->create(features.width, features.height, false, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); p_image->set_data(features.width, features.height, false, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image);
return OK; return OK;
} }

View File

@ -1551,7 +1551,7 @@ String EditorExportPlatformAndroid::load_splash_refs(Ref<Image> &splash_image, R
print_verbose("Creating splash background color image."); print_verbose("Creating splash background color image.");
splash_bg_color_image.instantiate(); splash_bg_color_image.instantiate();
splash_bg_color_image->create(splash_image->get_width(), splash_image->get_height(), false, splash_image->get_format()); splash_bg_color_image->initialize_data(splash_image->get_width(), splash_image->get_height(), false, splash_image->get_format());
splash_bg_color_image->fill(bg_color); splash_bg_color_image->fill(bg_color);
String processed_splash_config_xml = vformat(SPLASH_CONFIG_XML_CONTENT, bool_to_string(apply_filter)); String processed_splash_config_xml = vformat(SPLASH_CONFIG_XML_CONTENT, bool_to_string(apply_filter));

View File

@ -740,8 +740,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExp
img->resize(info.width, info.width / aspect_ratio); img->resize(info.width, info.width / aspect_ratio);
} }
} }
Ref<Image> new_img = memnew(Image); Ref<Image> new_img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
new_img->create(info.width, info.height, false, Image::FORMAT_RGBA8);
new_img->fill(boot_bg_color); new_img->fill(boot_bg_color);
_blend_and_rotate(new_img, img, false); _blend_and_rotate(new_img, img, false);
err = new_img->save_png(p_dest_dir + info.export_name); err = new_img->save_png(p_dest_dir + info.export_name);
@ -755,8 +754,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExp
} }
} else { } else {
// Generate loading screen from the splash screen // Generate loading screen from the splash screen
Ref<Image> img = memnew(Image); Ref<Image> img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
img->create(info.width, info.height, false, Image::FORMAT_RGBA8);
img->fill(boot_bg_color); img->fill(boot_bg_color);
Ref<Image> img_bs; Ref<Image> img_bs;

View File

@ -490,9 +490,7 @@ Ref<Image> GPUParticlesCollisionSDF3D::bake() {
params.thickness = th; params.thickness = th;
_compute_sdf(&params); _compute_sdf(&params);
Ref<Image> ret; Ref<Image> ret = Image::create_from_data(sdf_size.x, sdf_size.y * sdf_size.z, false, Image::FORMAT_RF, cells_data);
ret.instantiate();
ret->create(sdf_size.x, sdf_size.y * sdf_size.z, false, Image::FORMAT_RF, cells_data);
ret->convert(Image::FORMAT_RH); //convert to half, save space ret->convert(Image::FORMAT_RH); //convert to half, save space
ret->set_meta("depth", sdf_size.z); //hack, make sure to add to the docs of this function ret->set_meta("depth", sdf_size.z); //hack, make sure to add to the docs of this function

View File

@ -145,10 +145,7 @@ Array LightmapGIData::_get_light_textures_data() const {
for (int i = 0; i < texture_count; i++) { for (int i = 0; i < texture_count; i++) {
int texture_slice_count = (i == texture_count - 1 && last_count != 0) ? last_count : slices_per_texture; int texture_slice_count = (i == texture_count - 1 && last_count != 0) ? last_count : slices_per_texture;
Ref<Image> texture_image; Ref<Image> texture_image = Image::create_empty(slice_width, slice_height * texture_slice_count, false, images[0]->get_format());
texture_image.instantiate();
texture_image->create(slice_width, slice_height * texture_slice_count, false, images[0]->get_format());
for (int j = 0; j < texture_slice_count; j++) { for (int j = 0; j < texture_slice_count; j++) {
texture_image->blit_rect(images[i * slices_per_texture + j], Rect2i(0, 0, slice_width, slice_height), Point2i(0, slice_height * j)); texture_image->blit_rect(images[i * slices_per_texture + j], Rect2i(0, 0, slice_width, slice_height), Point2i(0, slice_height * j));
@ -818,7 +815,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
} }
md.albedo_on_uv2.instantiate(); md.albedo_on_uv2.instantiate();
md.albedo_on_uv2->create(lightmap_size.width, lightmap_size.height, false, Image::FORMAT_RGBA8, albedom); md.albedo_on_uv2->set_data(lightmap_size.width, lightmap_size.height, false, Image::FORMAT_RGBA8, albedom);
} }
md.emission_on_uv2 = images[RS::BAKE_CHANNEL_EMISSION]; md.emission_on_uv2 = images[RS::BAKE_CHANNEL_EMISSION];
@ -1054,7 +1051,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
} break; } break;
case ENVIRONMENT_MODE_CUSTOM_COLOR: { case ENVIRONMENT_MODE_CUSTOM_COLOR: {
environment_image.instantiate(); environment_image.instantiate();
environment_image->create(128, 64, false, Image::FORMAT_RGBAF); environment_image->initialize_data(128, 64, false, Image::FORMAT_RGBAF);
Color c = environment_custom_color; Color c = environment_custom_color;
c.r *= environment_custom_energy; c.r *= environment_custom_energy;
c.g *= environment_custom_energy; c.g *= environment_custom_energy;

View File

@ -77,9 +77,7 @@ Dictionary VoxelGIData::_get_data() const {
d["octree_cells"] = get_octree_cells(); d["octree_cells"] = get_octree_cells();
d["octree_data"] = get_data_cells(); d["octree_data"] = get_data_cells();
if (otsize != Vector3i()) { if (otsize != Vector3i()) {
Ref<Image> img; Ref<Image> img = Image::create_from_data(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field());
img.instantiate();
img->create(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field());
Vector<uint8_t> df_png = img->save_png_to_buffer(); Vector<uint8_t> df_png = img->save_png_to_buffer();
ERR_FAIL_COND_V(df_png.size() == 0, Dictionary()); ERR_FAIL_COND_V(df_png.size() == 0, Dictionary());
d["octree_df_png"] = df_png; d["octree_df_png"] = df_png;

View File

@ -639,9 +639,7 @@ void BitMap::resize(const Size2i &p_new_size) {
} }
Ref<Image> BitMap::convert_to_image() const { Ref<Image> BitMap::convert_to_image() const {
Ref<Image> image; Ref<Image> image = Image::create_empty(width, height, false, Image::FORMAT_L8);
image.instantiate();
image->create(width, height, false, Image::FORMAT_L8);
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) { for (int j = 0; j < height; j++) {

View File

@ -740,7 +740,7 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
} }
} }
image->create(w, h, true, mipmap_images[0]->get_format(), img_data); image->set_data(w, h, true, mipmap_images[0]->get_format(), img_data);
return image; return image;
} }
@ -766,10 +766,7 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
f->get_buffer(wr, data.size()); f->get_buffer(wr, data.size());
} }
Ref<Image> image; Ref<Image> image = Image::create_from_data(tw, th, mipmaps - i ? true : false, format, data);
image.instantiate();
image->create(tw, th, mipmaps - i ? true : false, format, data);
return image; return image;
} }
@ -2336,11 +2333,11 @@ void GradientTexture2D::_update() {
image.instantiate(); image.instantiate();
if (gradient->get_points_count() <= 1) { // No need to interpolate. if (gradient->get_points_count() <= 1) { // No need to interpolate.
image->create(width, height, false, (use_hdr) ? Image::FORMAT_RGBAF : Image::FORMAT_RGBA8); image->initialize_data(width, height, false, (use_hdr) ? Image::FORMAT_RGBAF : Image::FORMAT_RGBA8);
image->fill((gradient->get_points_count() == 1) ? gradient->get_color(0) : Color(0, 0, 0, 1)); image->fill((gradient->get_points_count() == 1) ? gradient->get_color(0) : Color(0, 0, 0, 1));
} else { } else {
if (use_hdr) { if (use_hdr) {
image->create(width, height, false, Image::FORMAT_RGBAF); image->initialize_data(width, height, false, Image::FORMAT_RGBAF);
Gradient &g = **gradient; Gradient &g = **gradient;
// `create()` isn't available for non-uint8_t data, so fill in the data manually. // `create()` isn't available for non-uint8_t data, so fill in the data manually.
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
@ -2367,7 +2364,7 @@ void GradientTexture2D::_update() {
} }
} }
} }
image->create(width, height, false, Image::FORMAT_RGBA8, data); image->set_data(width, height, false, Image::FORMAT_RGBA8, data);
} }
} }

View File

@ -1801,11 +1801,11 @@ Vector<Vector<Ref<Texture2D>>> TileSet::generate_terrains_icons(Size2i p_size) {
// Get the best tile. // Get the best tile.
Ref<Texture2D> texture = counts[terrain_set][terrain].texture; Ref<Texture2D> texture = counts[terrain_set][terrain].texture;
Rect2i region = counts[terrain_set][terrain].region; Rect2i region = counts[terrain_set][terrain].region;
image->create(region.size.x, region.size.y, false, Image::FORMAT_RGBA8); image->initialize_data(region.size.x, region.size.y, false, Image::FORMAT_RGBA8);
image->blit_rect(texture->get_image(), region, Point2i()); image->blit_rect(texture->get_image(), region, Point2i());
image->resize(p_size.x, p_size.y, Image::INTERPOLATE_NEAREST); image->resize(p_size.x, p_size.y, Image::INTERPOLATE_NEAREST);
} else { } else {
image->create(1, 1, false, Image::FORMAT_RGBA8); image->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain)); image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain));
} }
Ref<ImageTexture> icon = ImageTexture::create_from_image(image); Ref<ImageTexture> icon = ImageTexture::create_from_image(image);
@ -4602,9 +4602,7 @@ void TileSetAtlasSource::_update_padded_texture() {
return; return;
} }
Ref<Image> image; Ref<Image> image = Image::create_empty(size.x, size.y, false, src->get_format());
image.instantiate();
image->create(size.x, size.y, false, src->get_format());
for (KeyValue<Vector2i, TileAlternativesData> kv : tiles) { for (KeyValue<Vector2i, TileAlternativesData> kv : tiles) {
for (int frame = 0; frame < (int)kv.value.animation_frames_durations.size(); frame++) { for (int frame = 0; frame < (int)kv.value.animation_frames_durations.size(); frame++) {

View File

@ -460,9 +460,9 @@ void VisualShaderNodeParticleMeshEmitter::_update_texture(const Vector<Vector2>
image.instantiate(); image.instantiate();
if (p_array.size() == 0) { if (p_array.size() == 0) {
image->create(1, 1, false, Image::Format::FORMAT_RGBF); image->initialize_data(1, 1, false, Image::Format::FORMAT_RGBF);
} else { } else {
image->create(p_array.size(), 1, false, Image::Format::FORMAT_RGBF); image->initialize_data(p_array.size(), 1, false, Image::Format::FORMAT_RGBF);
} }
for (int i = 0; i < p_array.size(); i++) { for (int i = 0; i < p_array.size(); i++) {
@ -481,9 +481,9 @@ void VisualShaderNodeParticleMeshEmitter::_update_texture(const Vector<Vector3>
image.instantiate(); image.instantiate();
if (p_array.size() == 0) { if (p_array.size() == 0) {
image->create(1, 1, false, Image::Format::FORMAT_RGBF); image->initialize_data(1, 1, false, Image::Format::FORMAT_RGBF);
} else { } else {
image->create(p_array.size(), 1, false, Image::Format::FORMAT_RGBF); image->initialize_data(p_array.size(), 1, false, Image::Format::FORMAT_RGBF);
} }
for (int i = 0; i < p_array.size(); i++) { for (int i = 0; i < p_array.size(); i++) {
@ -502,9 +502,9 @@ void VisualShaderNodeParticleMeshEmitter::_update_texture(const Vector<Color> &p
image.instantiate(); image.instantiate();
if (p_array.size() == 0) { if (p_array.size() == 0) {
image->create(1, 1, false, Image::Format::FORMAT_RGBA8); image->initialize_data(1, 1, false, Image::Format::FORMAT_RGBA8);
} else { } else {
image->create(p_array.size(), 1, false, Image::Format::FORMAT_RGBA8); image->initialize_data(p_array.size(), 1, false, Image::Format::FORMAT_RGBA8);
} }
for (int i = 0; i < p_array.size(); i++) { for (int i = 0; i < p_array.size(); i++) {

View File

@ -2335,7 +2335,7 @@ void GI::SDFGI::render_region(Ref<RenderSceneBuffersRD> p_render_buffers, int p_
img.instantiate(); img.instantiate();
for (uint32_t i = 0; i < cascade_size; i++) { for (uint32_t i = 0; i < cascade_size; i++) {
Vector<uint8_t> subarr = data.slice(128 * 128 * i, 128 * 128 * (i + 1)); Vector<uint8_t> subarr = data.slice(128 * 128 * i, 128 * 128 * (i + 1));
img->create(cascade_size, cascade_size, false, Image::FORMAT_L8, subarr); img->set_data(cascade_size, cascade_size, false, Image::FORMAT_L8, subarr);
img->save_png("res://cascade_sdf_" + itos(cascade) + "_" + itos(i) + ".png"); img->save_png("res://cascade_sdf_" + itos(cascade) + "_" + itos(i) + ".png");
} }

View File

@ -772,9 +772,7 @@ Ref<Image> SkyRD::Sky::bake_panorama(float p_energy, int p_roughness_layers, con
Vector<uint8_t> data = RD::get_singleton()->texture_get_data(rad_tex, 0); Vector<uint8_t> data = RD::get_singleton()->texture_get_data(rad_tex, 0);
RD::get_singleton()->free(rad_tex); RD::get_singleton()->free(rad_tex);
Ref<Image> img; Ref<Image> img = Image::create_from_data(p_size.width, p_size.height, false, Image::FORMAT_RGBAF, data);
img.instantiate();
img->create(p_size.width, p_size.height, false, Image::FORMAT_RGBAF, data);
for (int i = 0; i < p_size.width; i++) { for (int i = 0; i < p_size.width; i++) {
for (int j = 0; j < p_size.height; j++) { for (int j = 0; j < p_size.height; j++) {
Color c = img->get_pixel(i, j); Color c = img->get_pixel(i, j);

View File

@ -250,9 +250,7 @@ Ref<Image> RendererSceneRenderRD::environment_bake_panorama(RID p_env, bool p_ba
panorama_color = ambient_color.lerp(panorama_color, ambient_color_sky_mix); panorama_color = ambient_color.lerp(panorama_color, ambient_color_sky_mix);
} }
Ref<Image> panorama; Ref<Image> panorama = Image::create_empty(p_size.width, p_size.height, false, Image::FORMAT_RGBAF);
panorama.instantiate();
panorama->create(p_size.width, p_size.height, false, Image::FORMAT_RGBAF);
panorama->fill(panorama_color); panorama->fill(panorama_color);
return panorama; return panorama;
} }
@ -1305,36 +1303,28 @@ TypedArray<Image> RendererSceneRenderRD::bake_render_uv2(RID p_base, const Typed
{ {
PackedByteArray data = RD::get_singleton()->texture_get_data(albedo_alpha_tex, 0); PackedByteArray data = RD::get_singleton()->texture_get_data(albedo_alpha_tex, 0);
Ref<Image> img; Ref<Image> img = Image::create_from_data(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data);
img.instantiate();
img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data);
RD::get_singleton()->free(albedo_alpha_tex); RD::get_singleton()->free(albedo_alpha_tex);
ret.push_back(img); ret.push_back(img);
} }
{ {
PackedByteArray data = RD::get_singleton()->texture_get_data(normal_tex, 0); PackedByteArray data = RD::get_singleton()->texture_get_data(normal_tex, 0);
Ref<Image> img; Ref<Image> img = Image::create_from_data(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data);
img.instantiate();
img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data);
RD::get_singleton()->free(normal_tex); RD::get_singleton()->free(normal_tex);
ret.push_back(img); ret.push_back(img);
} }
{ {
PackedByteArray data = RD::get_singleton()->texture_get_data(orm_tex, 0); PackedByteArray data = RD::get_singleton()->texture_get_data(orm_tex, 0);
Ref<Image> img; Ref<Image> img = Image::create_from_data(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data);
img.instantiate();
img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBA8, data);
RD::get_singleton()->free(orm_tex); RD::get_singleton()->free(orm_tex);
ret.push_back(img); ret.push_back(img);
} }
{ {
PackedByteArray data = RD::get_singleton()->texture_get_data(emission_tex, 0); PackedByteArray data = RD::get_singleton()->texture_get_data(emission_tex, 0);
Ref<Image> img; Ref<Image> img = Image::create_from_data(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBAH, data);
img.instantiate();
img->create(p_image_size.width, p_image_size.height, false, Image::FORMAT_RGBAH, data);
RD::get_singleton()->free(emission_tex); RD::get_singleton()->free(emission_tex);
ret.push_back(img); ret.push_back(img);
} }

View File

@ -1124,9 +1124,7 @@ void TextureStorage::texture_proxy_update(RID p_texture, RID p_proxy_to) {
void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) { void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) {
//this could be better optimized to reuse an existing image , done this way //this could be better optimized to reuse an existing image , done this way
//for now to get it working //for now to get it working
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, false, Image::FORMAT_RGBA8);
image->fill(Color(1, 0, 1, 1)); image->fill(Color(1, 0, 1, 1));
texture_2d_initialize(p_texture, image); texture_2d_initialize(p_texture, image);
@ -1135,9 +1133,7 @@ void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) {
void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RS::TextureLayeredType p_layered_type) { void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RS::TextureLayeredType p_layered_type) {
//this could be better optimized to reuse an existing image , done this way //this could be better optimized to reuse an existing image , done this way
//for now to get it working //for now to get it working
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, false, Image::FORMAT_RGBA8);
image->fill(Color(1, 0, 1, 1)); image->fill(Color(1, 0, 1, 1));
Vector<Ref<Image>> images; Vector<Ref<Image>> images;
@ -1156,9 +1152,7 @@ void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RS
void TextureStorage::texture_3d_placeholder_initialize(RID p_texture) { void TextureStorage::texture_3d_placeholder_initialize(RID p_texture) {
//this could be better optimized to reuse an existing image , done this way //this could be better optimized to reuse an existing image , done this way
//for now to get it working //for now to get it working
Ref<Image> image; Ref<Image> image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8);
image.instantiate();
image->create(4, 4, false, Image::FORMAT_RGBA8);
image->fill(Color(1, 0, 1, 1)); image->fill(Color(1, 0, 1, 1));
Vector<Ref<Image>> images; Vector<Ref<Image>> images;
@ -1181,9 +1175,7 @@ Ref<Image> TextureStorage::texture_2d_get(RID p_texture) const {
#endif #endif
Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, 0); Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, 0);
ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); ERR_FAIL_COND_V(data.size() == 0, Ref<Image>());
Ref<Image> image; Ref<Image> image = Image::create_from_data(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data);
image.instantiate();
image->create(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data);
ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); ERR_FAIL_COND_V(image->is_empty(), Ref<Image>());
if (tex->format != tex->validated_format) { if (tex->format != tex->validated_format) {
image->convert(tex->format); image->convert(tex->format);
@ -1204,9 +1196,7 @@ Ref<Image> TextureStorage::texture_2d_layer_get(RID p_texture, int p_layer) cons
Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, p_layer); Vector<uint8_t> data = RD::get_singleton()->texture_get_data(tex->rd_texture, p_layer);
ERR_FAIL_COND_V(data.size() == 0, Ref<Image>()); ERR_FAIL_COND_V(data.size() == 0, Ref<Image>());
Ref<Image> image; Ref<Image> image = Image::create_from_data(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data);
image.instantiate();
image->create(tex->width, tex->height, tex->mipmaps > 1, tex->validated_format, data);
ERR_FAIL_COND_V(image->is_empty(), Ref<Image>()); ERR_FAIL_COND_V(image->is_empty(), Ref<Image>());
if (tex->format != tex->validated_format) { if (tex->format != tex->validated_format) {
image->convert(tex->format); image->convert(tex->format);
@ -1232,9 +1222,7 @@ Vector<Ref<Image>> TextureStorage::texture_3d_get(RID p_texture) const {
ERR_FAIL_COND_V(bs.offset + bs.buffer_size > (uint32_t)all_data.size(), Vector<Ref<Image>>()); ERR_FAIL_COND_V(bs.offset + bs.buffer_size > (uint32_t)all_data.size(), Vector<Ref<Image>>());
Vector<uint8_t> sub_region = all_data.slice(bs.offset, bs.offset + bs.buffer_size); Vector<uint8_t> sub_region = all_data.slice(bs.offset, bs.offset + bs.buffer_size);
Ref<Image> img; Ref<Image> img = Image::create_from_data(bs.size.width, bs.size.height, false, tex->validated_format, sub_region);
img.instantiate();
img->create(bs.size.width, bs.size.height, false, tex->validated_format, sub_region);
ERR_FAIL_COND_V(img->is_empty(), Vector<Ref<Image>>()); ERR_FAIL_COND_V(img->is_empty(), Vector<Ref<Image>>());
if (tex->format != tex->validated_format) { if (tex->format != tex->validated_format) {
img->convert(tex->format); img->convert(tex->format);

View File

@ -180,7 +180,7 @@ RID RendererSceneOcclusionCull::HZBuffer::get_debug_texture() {
ptrw[i] = MIN(mips[0][i] / debug_tex_range, 1.0) * 255; ptrw[i] = MIN(mips[0][i] / debug_tex_range, 1.0) * 255;
} }
debug_image->create(sizes[0].x, sizes[0].y, false, Image::FORMAT_L8, debug_data); debug_image->set_data(sizes[0].x, sizes[0].y, false, Image::FORMAT_L8, debug_data);
if (debug_texture.is_null()) { if (debug_texture.is_null()) {
debug_texture = RS::get_singleton()->texture_2d_create(debug_image); debug_texture = RS::get_singleton()->texture_2d_create(debug_image);

View File

@ -222,12 +222,7 @@ RID XRInterface::get_vrs_texture() {
data_ptr[d++] = density; data_ptr[d++] = density;
} }
} }
images.push_back(Image::create_from_data(vrs_sizei.x, vrs_sizei.y, false, Image::FORMAT_R8, data));
Ref<Image> image;
image.instantiate();
image->create_from_data(vrs_sizei.x, vrs_sizei.y, false, Image::FORMAT_R8, data);
images.push_back(image);
} }
if (images.size() == 1) { if (images.size() == 1) {

View File

@ -76,15 +76,11 @@ TEST_CASE("[BitMap] Create bit map from image alpha") {
bit_map.create_from_image_alpha(empty_img); bit_map.create_from_image_alpha(empty_img);
CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because bitmap creation from an empty image should fail."); CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because bitmap creation from an empty image should fail.");
Ref<Image> wrong_format_img; Ref<Image> wrong_format_img = Image::create_empty(3, 3, false, Image::Format::FORMAT_DXT1);
wrong_format_img.instantiate();
wrong_format_img->create(3, 3, false, Image::Format::FORMAT_DXT1);
bit_map.create_from_image_alpha(wrong_format_img); bit_map.create_from_image_alpha(wrong_format_img);
CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because converting from a compressed image should fail."); CHECK_MESSAGE(bit_map.get_size() == Size2i(256, 256), "Bitmap should have its old values because converting from a compressed image should fail.");
Ref<Image> img; Ref<Image> img = Image::create_empty(3, 3, false, Image::Format::FORMAT_RGBA8);
img.instantiate();
img->create(3, 3, false, Image::Format::FORMAT_RGBA8);
img->set_pixel(0, 0, Color(0, 0, 0, 0)); img->set_pixel(0, 0, Color(0, 0, 0, 0));
img->set_pixel(0, 1, Color(0, 0, 0, 0.09f)); img->set_pixel(0, 1, Color(0, 0, 0, 0.09f));
img->set_pixel(0, 2, Color(0, 0, 0, 0.25f)); img->set_pixel(0, 2, Color(0, 0, 0, 0.25f));