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

Support horizontally flipped TGA images #68

Merged
merged 8 commits into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ build_script:
# The CMAKE_CONFIGURATION_TYPES CMake option make sure to not uselessly provide
# build configurations that will not be used.
- cmd: >
pip install colorama

echo %NUMBER_OF_PROCESSORS%

set CMAKE_BUILD_PARALLEL_LEVEL=%NUMBER_OF_PROCESSORS%
@@ -50,7 +52,8 @@ build_script:
set CXXFLAGS=/Wv:19.29.30037

cmake -Wdev -G"%generator%" -A"%platform%" -S. -Bbuild -DCMAKE_CONFIGURATION_TYPES=Release
-DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=ON
-DBUILD_CRUNCH=ON -DBUILD_EXAMPLES=ON
-DUSE_FAST_MATH=OFF

cmake --build build --config Release

10 changes: 9 additions & 1 deletion .azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ strategy:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-i686-linux-gnu
CXX_COMPILER: i686-linux-gnu-g++
COMPILER_FLAGS: -mfpmath=sse -msse
Linux arm64 GCC:
VM_IMAGE: 'ubuntu-20.04'
APT_PACKAGES: ninja-build g++-aarch64-linux-gnu qemu-user
@@ -64,15 +65,18 @@ strategy:
APT_PACKAGES: ninja-build g++-mingw-w64-i686 mingw-w64-i686-dev gcc-mingw-w64-i686-posix-runtime wine wine32
SETUP_COMMANDS: sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
TOOLCHAIN_FILE: cmake/cross-toolchain-mingw32.cmake
COMPILER_FLAGS: -mfpmath=sse -msse
CRUNCH_EXE_RUNNER: wine
CRUNCH_EXTENSION: .exe
RUNTIME_FILES: /usr/lib/gcc/i686-w64-mingw32/10-posix/libgcc_s_dw2-1.dll /usr/lib/gcc/i686-w64-mingw32/10-posix/libstdc++-6.dll /usr/i686-w64-mingw32/lib/libwinpthread-1.dll
macOS amd64 AppleClang:
VM_IMAGE: 'macOS-12'
PIP_PACKAGES: colorama
CMAKE_GENERATOR: Unix Makefiles
NPROC_COMMAND: sysctl -n hw.logicalcpu
macOS arm64 AppleClang:
VM_IMAGE: 'macOS-12'
PIP_PACKAGES: colorama
CMAKE_GENERATOR: Unix Makefiles
COMPILER_FLAGS: -target arm64-apple-macos11 -Wno-overriding-t-option
NPROC_COMMAND: sysctl -n hw.logicalcpu
@@ -97,6 +101,9 @@ steps:
if [ -n "${APT_PACKAGES:-}" ]; then
sudo apt-get update && sudo apt-get -y -q --no-install-recommends install ${APT_PACKAGES}
fi
if [ -n "${PIP_PACKAGES:-}" ]; then
pip install ${PIP_PACKAGES}
fi
if [ -n "${SETUP_COMMANDS:-}" ]; then
$(SETUP_COMMANDS)
fi
@@ -116,8 +123,9 @@ steps:
cmake_args+=(-DCMAKE_CXX_FLAGS="${COMPILER_FLAGS}")
fi
if [ -z "${SOURCE_DIR:-}" ]; then
cmake_args+=(-DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=ON)
cmake_args+=(-DBUILD_CRUNCH=ON -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON)
fi
cmake_args+=(-DUSE_FAST_MATH=OFF)
cmake -S"${SOURCE_DIR:-.}" -Bbuild "${cmake_args[@]}"
cmake --build build --config Release
displayName: 'Build'
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ jobs:
export CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"
echo "${CMAKE_BUILD_PARALLEL_LEVEL}"
cmake -Wdev -S. -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release \
-DBUILD_CRUNCH=ON -DBUILD_SHARED_LIBCRN=ON -DBUILD_EXAMPLES=OFF
-DBUILD_CRUNCH=ON -DBUILD_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON
cmake --build build

- name: Perform CodeQL Analysis
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -80,6 +80,10 @@ if (MSVC)
# CMake already sets the /O2 flag on Release and RelWithDebInfo build and /O[1-2] already sets the /Oy flag.

if (USE_FAST_MATH)
# By default, the MSVC /fp:fast option enables /fp:contract (introduced in VS 2022).
# See https://learn.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior
# and https://devblogs.microsoft.com/cppblog/the-fpcontract-flag-and-changes-to-fp-modes-in-vs2022/
# By default, MSVC doesn't enable the /fp:fast option.
set_cxx_flag("/fp:fast")
endif()

@@ -109,7 +113,13 @@ else()
endif()

if (USE_FAST_MATH)
set_cxx_flag("-ffast-math -fno-math-errno")
# By default, GCC uses -ffp-contract=fast with -std=gnu* and uses -ffp-contract=off with -std=c*.
# See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# By default, GCC doesn't enable the -ffast-math option.
set_cxx_flag("-ffast-math -fno-math-errno -ffp-contract=fast")
else()
# By default, GCC uses -std=gnu* and then enables -ffp-contract=fast even if -ffast-math is not enabled.
set_cxx_flag("-ffp-contract=off")
endif()

# It should be done at the very end because it copies all compiler flags
35 changes: 29 additions & 6 deletions crnlib/stb_image.h
Original file line number Diff line number Diff line change
@@ -5884,8 +5884,8 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req
int tga_height = stbi__get16le(s);
int tga_bits_per_pixel = stbi__get8(s);
int tga_comp, tga_rgb16=0;
int tga_inverted = stbi__get8(s);
// int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?)
int tga_descriptor = stbi__get8(s);
// int tga_alpha_bits = tga_descriptor & 15; // the 4 lowest bits - unused (useless?)
// image data
unsigned char *tga_data;
unsigned char *tga_palette = NULL;
@@ -5907,7 +5907,8 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req
tga_image_type -= 8;
tga_is_RLE = 1;
}
tga_inverted = 1 - ((tga_inverted >> 5) & 1);
int tga_x_inverted = ((tga_descriptor >> 4) & 1);
int tga_y_inverted = 1 - ((tga_descriptor >> 5) & 1);

// If I'm paletted, then I'll use the number of bits from the palette
if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16);
@@ -5932,9 +5933,16 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req

if ( !tga_indexed && !tga_is_RLE && !tga_rgb16 ) {
for (i=0; i < tga_height; ++i) {
int row = tga_inverted ? tga_height -i - 1 : i;
int row = tga_y_inverted ? tga_height - i - 1 : i;
stbi_uc *tga_row = tga_data + row*tga_width*tga_comp;
stbi__getn(s, tga_row, tga_width * tga_comp);
if (tga_x_inverted) {
for (j = 0; j < tga_width; j++) {
int index = (tga_width - j - 1) * tga_comp;
stbi__getn(s, tga_row + index, tga_comp);
}
} else {
stbi__getn(s, tga_row, tga_width * tga_comp);
}
}
} else {
// do I need to load a palette?
@@ -6024,7 +6032,22 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req
--RLE_count;
}
// do I need to invert the image?
if ( tga_inverted )
if (tga_x_inverted)
{
for (j = 0; j < tga_height; j++) {
stbi_uc *row = tga_data + (j * tga_width * tga_comp);
for (int s = 0, d = tga_width - 1; s * 2 < tga_width; s++, d--) {
stbi_uc *src = row + (s * tga_comp);
stbi_uc *dest = row + (d * tga_comp);
for (i = 0; i < tga_comp; i++) {
stbi_uc temp = src[i];
src[i] = dest[i];
dest[i] = temp;
}
}
}
}
if (tga_y_inverted)
{
for (j = 0; j*2 < tga_height; ++j)
{
Loading