Skip to content

Conversation

@nico
Copy link
Contributor

@nico nico commented Oct 30, 2025

Now that we have a lossless CMYK encoder, we can add a roundtrip
test for CMYK encoding :^)

Since JPEG encoding is lossy, the JPEG test only checks that the image size
doesn't change during a roundtrip.

@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Oct 30, 2025
Copy link
Member

@LucasChollet LucasChollet left a comment

Choose a reason for hiding this comment

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

Nice, more tests!

Comment on lines 83 to 89
template<class Writer, class... ExtraArgs>
static ErrorOr<ByteBuffer> encode_bitmap(Gfx::CMYKBitmap const& bitmap, ExtraArgs... extra_args)
{
AllocatingMemoryStream stream;
TRY(Writer::encode(stream, bitmap, extra_args...));
return stream.read_until_eof();
}
Copy link
Member

Choose a reason for hiding this comment

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

Can't we make the Bitmap another template type and share the code with the function above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

I thought that was a great idea, but when I did it I discovered that it requires adding *s all over the place, so now I'm no longer sure which version I prefer 😅 I pushed a version that does your three suggested templatized versions, but I made them extra commits since they require quite a few changes to existing test code. (…and I think I'd keep it like that for merging.)

It's IMHO still slightly nicer with the templates than what I originally had – but please shout if you didn't think of the type checking impact and don't like it after all :)

Copy link
Member

@LucasChollet LucasChollet Oct 31, 2025

Choose a reason for hiding this comment

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

Actually, I wouldn't mind taking NonnullRefPtr (const& ?) for these functions 🤔
I know this is not idiomatic to the codebase but if that prevents ~20 *s that might be a good move.

{
// JPEG is lossy, so the roundtripped bitmap won't match the original bitmap. But it should still have the same size.
(void)TRY_OR_FAIL((get_roundtrip_bitmap<Gfx::JPEGWriter, Gfx::JPEGImageDecoderPlugin>(TRY_OR_FAIL(create_test_rgb_bitmap()))));
(void)TRY_OR_FAIL((get_roundtrip_bitmap<Gfx::JPEGWriter, Gfx::JPEGImageDecoderPlugin>(TRY_OR_FAIL(create_test_cmyk_bitmap()))));
Copy link
Member

Choose a reason for hiding this comment

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

We really need to implement some sort of safety net and have these tests check against a maximal accepted error. (Your commit is fine as is, I'm just thinking out loud).

nico added 3 commits October 31, 2025 07:44
Now that we have a lossless CMYK encoder, we can add a roundtrip
test for CMYK encoding :^)
Since JPEG encoding is lossy, this only checks that the image size
doesn't change during a roundtrip.
This allows us to remove the CMYKBitmap overload.

For CMYKBitmap, we'll always go down the `if constexpr`.

Requires manually converting all NonnullRefPtrs to const refs
due to the stricter type checking on templates.

No behavior change.
nico added 2 commits October 31, 2025 07:47
This allows us to share one version for Bitmap and CMYKBitmap overload.

Requires manually converting all NonnullRefPtrs to const refs
due to the stricter type checking on templates.

No behavior change.
This allows us to share one version for Bitmap and CMYKBitmap overload.

Requires manually converting all NonnullRefPtrs to const refs
due to the stricter type checking on templates.

No behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👀 pr-needs-review PR needs review from a maintainer or community member

2 participants