Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Image.save_jpg() does not write any file #66929

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

MladoniSzabi
Copy link
Contributor

The function that was supposed to implement the saving in image_loader_jpegd was returning OK without doing anything. Copied the code from _jpgd_buffer_save_func to _jpgd_save_func but changed the ImageLoaderJPGOSBufferto a ImageLoaderJPGOSFile to save to a file instead of memory. Changed the image format from FORMAT_ETC2_RGB8 to FORMAT_RGB8 since the first one was creating a weird greyscale interlaced image.

I am not sure how to merge the two functions or make the code more dry

Resolves #66650

@MladoniSzabi MladoniSzabi requested a review from a team as a code owner October 5, 2022 12:37
ERR_FAIL_COND_V(p_img.is_null() || p_img->is_empty(), ERR_INVALID_PARAMETER);
Ref<Image> image = p_img;
if (image->get_format() != Image::FORMAT_RGB8) {
image->convert(Image::FORMAT_RGB8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that _jpgd_buffer_save_func above does this check instead:

	if (image->get_format() != Image::FORMAT_RGB8) {
		image->convert(Image::FORMAT_ETC2_RGB8);
	}

Sounds like it's wrong and yours is better? If so should be fixed above too.

I don't know if the intention from #62122 was to do the implementation using ImageLoaderJPGOSFile as done here, or just getting a buffer from the file and calling the buffer version.

CC @reduz @Faless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a printf before and inside the if and it seems the image is already RGB8 and the conversion doesn't happen.
If i change the if to
if (image->get_format() != Image::FORMAT_ETC2_RGB8) { image->convert(Image::FORMAT_ETC2_RGB8); }
it gives an error
ERROR: Cannot convert to <-> from compressed formats. Use compress() and decompress() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the _jpgd_buffer_save_func to use FORMAT_RGB8.
Changed the include path to jpgd.h and jpge.h.
Merged duplicate code into one function.

Can still change the _jpgd_save_func to use the buffer from the _jpgd_buffer_save_func if need be

@akien-mga
Copy link
Member

It's not directly related to your fix but it's also a wrong change from #62122, so maybe you can include this in your commit if it ever requires an amend (otherwise I can include it in a future cleanup if I remember):

diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp
index ce20ac9060..8446e063a5 100644
--- a/modules/jpg/image_loader_jpegd.cpp
+++ b/modules/jpg/image_loader_jpegd.cpp
@@ -33,8 +33,8 @@
 #include "core/os/os.h"
 #include "core/string/print_string.h"
 
-#include "thirdparty/jpeg-compressor/jpgd.h"
-#include "thirdparty/jpeg-compressor/jpge.h"
+#include <jpgd.h>
+#include <jpge.h>
 #include <string.h>
 
 Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p_buffer_len) {

thirdparty/jpeg-compressor is in the CPPPATH so there's no reason to hardcode it. This would theoretically make it possible to link against a system packaged jpeg-compressor (even though realistically I don't think anyone will care for this tiny lib).

The function that was supposed to implement the saving in
image_loader_jpegd was just returning OK without doing anything.
Copied the code from _jpgd_buffer_save_func to _jpgd_save_func but
changed the ImageLoaderJPGOSBufferto a ImageLoaderJPGOSFile to save
to a file instead of memory. Changed the image format from
FORMAT_ETC2_RGB8 to FORMAT_RGB8 since the first one was creating
a weird greyscale interlaced image.
@MladoniSzabi
Copy link
Contributor Author

Is there something else I need to do on this PR?

@Calinou
Copy link
Member

Calinou commented Oct 22, 2022

Is there something else I need to do on this PR?

Code looks good from a quick glance, but I'll let someone else review just to make sure. Akien is currently not available for PR reviews.

@akien-mga akien-mga merged commit 62a778f into godotengine:master Oct 31, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image.save_jpg() does not write any file
3 participants