Repository: godotengine/godot
File: editor/scene/texture/texture_editor_plugin.cpp (C++)

Code before:
		if (atlas.is_valid()) {
			image = atlas->get_image();
		}
	} else if (rd_texture.is_valid()) {
		if (RD::get_singleton()->texture_owner.get_or_null(rd_texture->get_texture_rd_rid()) == nullptr) {
			return -1;
		}
		image = p_texture->get_image();
	} else {
		image = p_texture->get_image();
	}

	if (image.is_valid()) {
		return image->get_mipmap_count();
	}
	return -1;
}

void TexturePreview::_update_metadata_label_text() {
	const Ref<Texture2D> texture = texture_display->get_texture();
	ERR_FAIL_COND(texture.is_null());

	Image::Format format;
	int mipmaps;

	Ref<Image> image = texture.ptr()->get_image();
	if (image.is_valid()) {
		format = image->get_format();
		mipmaps = image->get_mipmap_count();
	} else {
		format = get_texture_2d_format(texture.ptr());
		mipmaps = get_texture_mipmaps_count(texture);
	}

	const String format_name = format != Image::FORMAT_MAX ? Image::get_format_name(format) : texture->get_class();

	const Vector2i resolution = texture->get_size();

	if (format != Image::FORMAT_MAX) {
		// Avoid signed integer overflow that could occur with huge texture sizes by casting everything to uint64_t.
		uint64_t memory = uint64_t(resolution.x) * uint64_t(resolution.y) * uint64_t(Image::get_format_pixel_size(format));
		// Handle VRAM-compressed formats that are stored with 4 bpp.
		memory >>= Image::get_format_pixel_rshift(format);

		float mipmaps_multiplier = 1.0;
		float mipmap_increase = 0.25;
		for (int i = 0; i < mipmaps; i++) {
			// Each mip adds 25% memory usage of the previous one.
			// With a complete mipmap chain, memory usage increases by ~33%.
			mipmaps_multiplier += mipmap_increase;
			mipmap_increase *= 0.25;

Review comment (suggestion):
```suggestion
	Ref<Image> image = texture->get_image();
```
Redundant

Code after:
		}
	} else if (rd_texture.is_valid()) {
		if (RD::get_singleton() && RD::get_singleton()->texture_is_valid(rd_texture->get_texture_rd_rid())) {
			return -1;
		}
		image = p_texture->get_image();
	} else {
		image = p_texture->get_image();
	}

	if (image.is_valid()) {
		return image->get_mipmap_count();
	}
	return -1;
}

void TexturePreview::_update_metadata_label_text() {
	const Ref<Texture2D> texture = texture_display->get_texture();
	ERR_FAIL_COND(texture.is_null());

	Image::Format format;
	int mipmaps;

	Ref<Image> image = texture->get_image();
	if (image.is_valid()) {
		format = image->get_format();
		mipmaps = image->get_mipmap_count();
	} else {
		format = get_texture_2d_format(texture.ptr());
		mipmaps = get_texture_mipmaps_count(texture);
	}

	const String format_name = format != Image::FORMAT_MAX ? Image::get_format_name(format) : texture->get_class();

	const Vector2i resolution = texture->get_size();

	if (format != Image::FORMAT_MAX) {
		// Avoid signed integer overflow that could occur with huge texture sizes by casting everything to uint64_t.
		uint64_t memory = uint64_t(resolution.x) * uint64_t(resolution.y) * uint64_t(Image::get_format_pixel_size(format));
		// Handle VRAM-compressed formats that are stored with 4 bpp.
		memory >>= Image::get_format_pixel_rshift(format);

		float mipmaps_multiplier = 1.0;
		float mipmap_increase = 0.25;
		for (int i = 0; i < mipmaps; i++) {
			// Each mip adds 25% memory usage of the previous one.
			// With a complete mipmap chain, memory usage increases by ~33%.
			mipmaps_multiplier += mipmap_increase;
			mipmap_increase *= 0.25;
		}
		memory *= mipmaps_multiplier;