Skip to content

Commit 4c96dcf

Browse files
committed
Merge pull request #92179 from aaronp64/image_import_memory
Improve memory usage for image import and `PortableCompressedTexture2D`
2 parents c4a899f + f81e0fc commit 4c96dcf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

editor/import/resource_importer_texture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ void ResourceImporterTexture::save_to_ctex_format(Ref<FileAccess> f, const Ref<I
269269
for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
270270
Vector<uint8_t> data;
271271
if (use_webp) {
272-
data = Image::webp_lossless_packer(p_image->get_image_from_mipmap(i));
272+
data = Image::webp_lossless_packer(i ? p_image->get_image_from_mipmap(i) : p_image);
273273
} else {
274-
data = Image::png_packer(p_image->get_image_from_mipmap(i));
274+
data = Image::png_packer(i ? p_image->get_image_from_mipmap(i) : p_image);
275275
}
276276
int data_len = data.size();
277277
f->store_32(data_len);
@@ -289,7 +289,7 @@ void ResourceImporterTexture::save_to_ctex_format(Ref<FileAccess> f, const Ref<I
289289
f->store_32(p_image->get_format());
290290

291291
for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
292-
Vector<uint8_t> data = Image::webp_lossy_packer(p_image->get_image_from_mipmap(i), p_lossy_quality);
292+
Vector<uint8_t> data = Image::webp_lossy_packer(i ? p_image->get_image_from_mipmap(i) : p_image, p_lossy_quality);
293293
int data_len = data.size();
294294
f->store_32(data_len);
295295

scene/resources/portable_compressed_texture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ void PortableCompressedTexture2D::create_from_image(const Ref<Image> &p_image, C
153153
for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) {
154154
Vector<uint8_t> data;
155155
if (p_compression_mode == COMPRESSION_MODE_LOSSY) {
156-
data = Image::webp_lossy_packer(p_image->get_image_from_mipmap(i), p_lossy_quality);
156+
data = Image::webp_lossy_packer(i ? p_image->get_image_from_mipmap(i) : p_image, p_lossy_quality);
157157
encode_uint16(DATA_FORMAT_WEBP, buffer.ptrw() + 2);
158158
} else {
159159
if (use_webp) {
160-
data = Image::webp_lossless_packer(p_image->get_image_from_mipmap(i));
160+
data = Image::webp_lossless_packer(i ? p_image->get_image_from_mipmap(i) : p_image);
161161
encode_uint16(DATA_FORMAT_WEBP, buffer.ptrw() + 2);
162162
} else {
163-
data = Image::png_packer(p_image->get_image_from_mipmap(i));
163+
data = Image::png_packer(i ? p_image->get_image_from_mipmap(i) : p_image);
164164
encode_uint16(DATA_FORMAT_PNG, buffer.ptrw() + 2);
165165
}
166166
}

0 commit comments

Comments
 (0)