add png_internal, YAZE_LIB_PNG definition

This commit is contained in:
scawful
2024-08-13 00:30:14 -04:00
parent d94735baf5
commit feaee62462
2 changed files with 9 additions and 2 deletions

View File

@@ -12,6 +12,9 @@ set(YAZE_INSTALL_CLIB OFF)
set(YAZE_BUILD_TESTS OFF) set(YAZE_BUILD_TESTS OFF)
set(YAZE_BUILD_EXTENSIONS ON) set(YAZE_BUILD_EXTENSIONS ON)
# libpng features in bitmap.cc
add_definitions("-DYAZE_LIB_PNG=1")
# C++ Standard and CMake Specifications # C++ Standard and CMake Specifications
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)

View File

@@ -24,6 +24,8 @@ namespace gfx {
using core::SDL_Surface_Deleter; using core::SDL_Surface_Deleter;
using core::SDL_Texture_Deleter; using core::SDL_Texture_Deleter;
#if YAZE_LIB_PNG == 1
namespace png_internal { namespace png_internal {
void PngWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length) { void PngWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length) {
@@ -70,7 +72,7 @@ bool ConvertSurfaceToPNG(SDL_Surface *surface, std::vector<uint8_t> &buffer) {
return false; return false;
} }
png_set_write_fn(png_ptr, &buffer, PngWriteCallback, NULL); png_set_write_fn(png_ptr, &buffer, png_internal::PngWriteCallback, NULL);
png_colorp pal_ptr; png_colorp pal_ptr;
@@ -142,7 +144,7 @@ void ConvertPngToSurface(const std::vector<uint8_t> &png_data,
} }
// Set our custom read function // Set our custom read function
png_set_read_fn(png_ptr, &data, PngReadCallback); png_set_read_fn(png_ptr, &data, png_internal::PngReadCallback);
// Read the PNG info // Read the PNG info
png_read_info(png_ptr, info_ptr); png_read_info(png_ptr, info_ptr);
@@ -185,6 +187,8 @@ void ConvertPngToSurface(const std::vector<uint8_t> &png_data,
SDL_Log("Successfully created SDL_Surface from PNG data"); SDL_Log("Successfully created SDL_Surface from PNG data");
} }
#endif // YAZE_LIB_PNG
namespace { namespace {
void GrayscalePalette(SDL_Palette *palette) { void GrayscalePalette(SDL_Palette *palette) {