boolean vs bool in jpeg codec

13 views
Skip to first unread message

Elad Lahav

unread,
Jul 8, 2024, 6:29:39 AM (14 days ago) Jul 8
to skia-discuss
I built skia (m127) on QNX, and ran into errors in the jpeg code. There are several places that use C++ true/false as values to libjpeg's boolean. That is clearly wrong, as these are two separate types. libjpeg (both vanilla and turbo) define TRUE and FALSE for that.
A quick search of this group shows a couple of related failures on macOS.

Fixes are trivial:

diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index a74ac9c140..83e16ddfcb 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -102,7 +102,7 @@ SkCodec::Result SkJpegCodec::ReadHeader(
}

// Read the jpeg header
- switch (jpeg_read_header(dinfo, true)) {
+ switch (jpeg_read_header(dinfo, TRUE)) {
case JPEG_HEADER_OK:
break;
case JPEG_SUSPENDED:
diff --git a/src/codec/SkJpegUtility.cpp b/src/codec/SkJpegUtility.cpp
index 99dee251a0..01cb2c6a0f 100644
--- a/src/codec/SkJpegUtility.cpp
+++ b/src/codec/SkJpegUtility.cpp
@@ -56,12 +56,12 @@ static boolean sk_fill_buffered_input_buffer(j_decompress_ptr dinfo) {
// Let libjpeg know that the buffer needs to be refilled
src->next_input_byte = nullptr;
src->bytes_in_buffer = 0;
- return false;
+ return FALSE;
}

src->next_input_byte = (const JOCTET*) src->fBuffer;
src->bytes_in_buffer = bytes;
- return true;
+ return TRUE;
}

/*
@@ -124,7 +124,7 @@ static boolean sk_fill_mem_input_buffer (j_decompress_ptr cinfo) {
* buffer, so any request for more data beyond the given buffer size
* is treated as an error.
*/
- return false;
+ return FALSE;
}

/*

(Apologies for any formatting errors, this is the first time I've used this interface)

--Elad

kjlu...@google.com

unread,
Jul 8, 2024, 6:34:22 AM (14 days ago) Jul 8
to skia-discuss
Elad,
Thanks for identifying both the issue and the fix!

To submit a patch, you need to install depot_tools and check out Skia (I presume you've done the latter, but just wanted to check on the former) https://skia.org/docs/user/download/ and then submit a patch to Gerrit (https://skia.org/docs/dev/contrib/submit/). You'll need to sign the CLA and then update the AUTHORS file along with the JPEG fixes.

Feel free to add me as a reviewer once you do and we'll get your fix landed.

Kaylee

Reply all
Reply to author
Forward
0 new messages