You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Image: Make fill method also fill the mipmaps
This commit is contained in:
@@ -3071,13 +3071,13 @@ void Image::fill(const Color &p_color) {
|
|||||||
ERR_FAIL_COND_MSG(is_compressed(), "Cannot fill in compressed image formats.");
|
ERR_FAIL_COND_MSG(is_compressed(), "Cannot fill in compressed image formats.");
|
||||||
|
|
||||||
uint8_t *dst_data_ptr = data.ptrw();
|
uint8_t *dst_data_ptr = data.ptrw();
|
||||||
|
|
||||||
int pixel_size = get_format_pixel_size(format);
|
int pixel_size = get_format_pixel_size(format);
|
||||||
|
int64_t pixel_count = data.size() / pixel_size;
|
||||||
|
|
||||||
// Put first pixel with the format-aware API.
|
// Put first pixel with the format-aware API.
|
||||||
_set_color_at_ofs(dst_data_ptr, 0, p_color);
|
_set_color_at_ofs(dst_data_ptr, 0, p_color);
|
||||||
|
|
||||||
_repeat_pixel_over_subsequent_memory(dst_data_ptr, pixel_size, width * height);
|
_repeat_pixel_over_subsequent_memory(dst_data_ptr, pixel_size, pixel_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::fill_rect(const Rect2i &p_rect, const Color &p_color) {
|
void Image::fill_rect(const Rect2i &p_rect, const Color &p_color) {
|
||||||
|
|||||||
@@ -267,11 +267,15 @@ TEST_CASE("[Image] Modifying pixels of an image") {
|
|||||||
|
|
||||||
// Fill image with color
|
// Fill image with color
|
||||||
image2->fill(Color(0.5, 0.5, 0.5, 0.5));
|
image2->fill(Color(0.5, 0.5, 0.5, 0.5));
|
||||||
for (int y = 0; y < image2->get_height(); y++) {
|
for (int m = 0; m < image2->get_mipmap_count(); m++) {
|
||||||
for (int x = 0; x < image2->get_width(); x++) {
|
Ref<Image> mip_image = image2->get_image_from_mipmap(m);
|
||||||
CHECK_MESSAGE(
|
|
||||||
image2->get_pixel(x, y).r > 0.49,
|
for (int y = 0; y < mip_image->get_height(); y++) {
|
||||||
"fill() should colorize all pixels of the image.");
|
for (int x = 0; x < mip_image->get_width(); x++) {
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
mip_image->get_pixel(x, y).r > 0.49,
|
||||||
|
"fill() should colorize all pixels of the image.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user