Do not mutate source Image in Image::save_jpg and use encoder return value
This commit is contained in:
parent
4c96e9676b
commit
62cbd6805c
1 changed files with 9 additions and 4 deletions
|
@ -158,6 +158,7 @@ static Error _jpgd_save_to_output_stream(jpge::output_stream *p_output_stream, c
|
||||||
ERR_FAIL_COND_V(p_img.is_null() || p_img->is_empty(), ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_img.is_null() || p_img->is_empty(), ERR_INVALID_PARAMETER);
|
||||||
Ref<Image> image = p_img;
|
Ref<Image> image = p_img;
|
||||||
if (image->get_format() != Image::FORMAT_RGB8) {
|
if (image->get_format() != Image::FORMAT_RGB8) {
|
||||||
|
image = p_img->duplicate();
|
||||||
image->convert(Image::FORMAT_RGB8);
|
image->convert(Image::FORMAT_RGB8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,12 +170,16 @@ static Error _jpgd_save_to_output_stream(jpge::output_stream *p_output_stream, c
|
||||||
|
|
||||||
const uint8_t *src_data = image->get_data().ptr();
|
const uint8_t *src_data = image->get_data().ptr();
|
||||||
for (int i = 0; i < image->get_height(); i++) {
|
for (int i = 0; i < image->get_height(); i++) {
|
||||||
enc.process_scanline(&src_data[i * image->get_width() * 3]);
|
if (!enc.process_scanline(&src_data[i * image->get_width() * 3])) {
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enc.process_scanline(nullptr);
|
if (enc.process_scanline(nullptr)) {
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
} else {
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector<uint8_t> _jpgd_buffer_save_func(const Ref<Image> &p_img, float p_quality) {
|
static Vector<uint8_t> _jpgd_buffer_save_func(const Ref<Image> &p_img, float p_quality) {
|
||||||
|
|
Loading…
Reference in a new issue