An error always occurs when calling `jpegli_create_decompress` in applications that include `windows.h`
- Dominant language
- C++
- Stars
- 401
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Name the application that includes `windows.h` as `WinApp`.
In `WinApp`, `boolean` is defined as `unsigned char`, so its size is 1 byte. However, in `jpegli`, due to the following code in `third_party/libjpeg-turbo/jmorecfg.h`, it becomes 4 bytes:
```h
#ifndef HAVE_BOOLEAN
typedef int boolean;
#endif
```
As a result, the size check for the `jpeg_decompress_struct` structure in the actual implementation of `jpegli_create_decompress`, which is `jpegli_CreateDecompress`, always causes an error.
**To Reproduce**
Steps to reproduce the behavior: Call `jpegli_create_decompress` from `WinApp`
**Expected behavior**
Define `boolean` as `unsigned char` in `jpegli` to prevent `jpegli_CreateDecompress` from raising an error.
**Screenshots**
N/A
**Environment**
- OS: Windows 11 24H2
- Compiler version: cl.exe Version 19.43.34810 for x64(Visual Studio 2022)
- CPU type: x86_64
- cjxl/djxl version string: djxl [JPEG XL decoder v0.12.0 3a5e278 [_AVX2_,SSE4,SSSE3,SSE2]]
**Additional context**
The following code is present in `jconfig.h.in` of `libjpeg-turbo version 2.1.91`, and it resolves the issue.
```h
#ifdef _WIN32
#undef RIGHT_SHIFT_IS_UNSIGNED
/* Define "boolean" as unsigned char, not int, per Windows custom */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
/* Define "INT32" as int, not long, per Windows custom */
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
typedef short INT16;
typedef signed int INT32;
#endif
#define XMD_H /* prevent jmorecfg.h from redefining it */
#else
/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
#cmakedefine RIGHT_SHIFT_IS_UNSIGNED 1
#endif
```
Contributor guide
Assessment
This issue has not been assessed yet.