Skip to content

Commit

Permalink
Improvements: DEBUG / INFO logging options + code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bedwardly-down committed Sep 23, 2024
1 parent db879d9 commit b53c003
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 16 deletions.
29 changes: 18 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ dynamically loaded plugins." OFF "SAIL_BUILD_SHARED_LIBS" ON)
option(SAIL_BUILD_TYPE "Set build type: Release, Debug, or RelWithDebugInfo." "Release")
option(SAIL_DEV "Enable developer mode. Be more strict when compiling source code, for example." OFF)
option(SAIL_ENABLE_OPENMP "Enable OpenMP support if it's available in the compiler." ON)
option(SAIL_ENABLE_EMBED "Enable this if Sail is a submodule for another project (like a game engine or developer tool). This disables top level cmake option caching, so you'll want to manually enable where needed." OFF)
option(SAIL_ENABLE_EMBED "Enable this if Sail is a submodule for another project (like a game engine or developer tool)." OFF)
option(SAIL_INSTALL_PDB "Install PDB files along with libraries." ON)
option(SAIL_THIRD_PARTY_CODECS_PATH "Enable loading third-party codecs from the ';'-separated paths specified in \
the SAIL_THIRD_PARTY_CODECS_PATH environment variable." ON)
option(SAIL_THREAD_SAFE "Enable working in multi-threaded environments by locking the internal context with a mutex." ON)
if (WIN32)
option(SAIL_WINDOWS_UTF8_PATHS "Convert file paths to UTF-8 on Windows." ON)
endif()

# Embedded options
# Cached String options
#
set(SAIL_ENABLE_CODECS "" CACHE STRING "Forcefully enable the codecs specified in this ';'-separated list. \
If an enabled codec fails to find its dependencies, the configuration process fails. \
Expand All @@ -106,10 +109,6 @@ If an enabled codec fails to find its dependencies, the configuration process fa
One can also specify not just individual codecs but codec groups by their priority like that: highest-priority;xbm.")
set(SAIL_OPENMP_SCHEDULE "dynamic" CACHE STRING "OpenMP scheduling algorithm.")

if (WIN32)
option(SAIL_WINDOWS_UTF8_PATHS "Convert file paths to UTF-8 on Windows." ON)
endif()

if (SAIL_ENABLE_OPENMP)
sail_check_openmp()
else()
Expand Down Expand Up @@ -168,13 +167,20 @@ if (SAIL_DEV)
add_definitions(-DSAIL_DEV)
endif()

# Cosmetic change for developers - Brad
# Allow for building both Static and Shared libs at the same time with this
#
if (SAIL_BUILD_STATIC_LIBS)
set(SAIL_BUILD_STATIC_LIBS ON)
add_definitions(-DSAIL_STATIC)
endif()

# When building for release, print out less debug info unless the developer requests it
#
if (SAIL_BUILD_TYPE STREQUAL "Debug" OR "RelWithDebugInfo")
add_definitions(-DDEBUG)
if (SAIL_BUILD_TYPE STREQUAL "RelWithDebugInfo")
add_definitions(-DINFO)
endif()
endif()

# Enable as many warnings as possible
Expand Down Expand Up @@ -212,15 +218,15 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " " "-Wl,--no-undefined")
endif()
if (SAIL_BUILD_STATIC_LIBS)
string(APPEND CMAKE_STATIC_LINKER_FLAGS " " "-Wl,--no-undefined")
string(APPEND CMAKE_STATIC_LINKER_FLAGS " " "")
endif()
string(APPEND CMAKE_MODULE_LINKER_FLAGS " " "-Wl,--no-undefined")
elseif (CMAKE_C_COMPILER_ID MATCHES "Clang")
if (SAIL_BUILD_SHARED_LIBS)
string(APPEND CMAKE_SHARED_LINKER_FLAGS " " "-Wl,-undefined,error")
endif()
if (SAIL_BUILD_STATIC_LIBS)
string(APPEND CMAKE_STATIC_LINKER_FLAGS " " "-Wl,-undefined,error")
string(APPEND CMAKE_STATIC_LINKER_FLAGS " " "")
endif()
string(APPEND CMAKE_MODULE_LINKER_FLAGS " " "-Wl,-undefined,error")
endif()
Expand Down Expand Up @@ -364,9 +370,10 @@ message("* CMake static link flags: ${CMAKE_STATIC_LINKER_FLAGS}")
message("* CMake module link flags: ${CMAKE_MODULE_LINKER_FLAGS}")
message("*")
if (SAIL_ENABLE_EMBED)
message("* [*] - Embedded mode enabled. The following options can be set in any CMakeLists.txt file in")
message("* your project by using 'set(OPTION VALUE CACHE INTERNAL \"\")'. More information here:")
message("* [*] - Embedded mode enabled. The following options can be set in a CMakeLists.txt file in")
message("* a subdirectory containing Sail by using 'set(OPTION VALUE CACHE INTERNAL \"\")'. More information here:")
message("* https://cmake.org/cmake/help/book/mastering-cmake/chapter/CMake%20Cache.html")
message("* NOTE: This may break Cmake-GUI documentation. See: https://github.com/HappySeaFox/sail/issues/215#issuecomment-2366814504")
message("*")
endif()
message("* SAIL version: ${PROJECT_VERSION}")
Expand Down
2 changes: 2 additions & 0 deletions src/sail-codecs/avif/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ sail_status_t avif_private_fetch_iccp(const struct avifRWData *avif_iccp, struct

if (avif_iccp->data != NULL) {
SAIL_TRY(sail_alloc_iccp_from_data(avif_iccp->data, avif_iccp->size, iccp));
#ifdef DEBUG
SAIL_LOG_DEBUG("AVIF: Found ICC profile %u bytes long", (unsigned)avif_iccp->size);
} else {
SAIL_LOG_DEBUG("AVIF: ICC profile is not found");
#endif
}

return SAIL_OK;
Expand Down
2 changes: 2 additions & 0 deletions src/sail-codecs/common/bmp/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ sail_status_t bmp_private_read_init(struct sail_io *io, const struct sail_load_o
SAIL_TRY(bmp_private_bit_count_to_pixel_format(bmp_state->version == SAIL_BMP_V1 ? bmp_state->v1.bit_count : bmp_state->v2.bit_count,
&bmp_state->source_pixel_format));

#ifdef DEBUG
if (bmp_state->version < SAIL_BMP_V3) {
SAIL_LOG_DEBUG("BMP: Version(%d)", bmp_state->version);
} else {
SAIL_LOG_DEBUG("BMP: Version(%d), compression(%u)", bmp_state->version, bmp_state->v3.compression);
}
#endif

/* Read palette. */
if (bmp_state->version == SAIL_BMP_V1) {
Expand Down
2 changes: 2 additions & 0 deletions src/sail-codecs/jpeg/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ sail_status_t jpeg_private_fetch_iccp(struct jpeg_decompress_struct *decompress_
JOCTET *data = NULL;
unsigned data_size = 0;

#ifdef DEBUG
SAIL_LOG_DEBUG("JPEG: ICC profile is %sfound",
jpeg_read_icc_profile(decompress_context, &data, &data_size)
? "" : "not ");
#endif

if (data != NULL && data_size > 0) {
SAIL_TRY_OR_CLEANUP(sail_alloc_iccp_from_shallow_data(data, data_size, iccp),
Expand Down
4 changes: 4 additions & 0 deletions src/sail-codecs/jpeg/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,18 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_jpeg(void *state, c
/* Save meta data. */
if (jpeg_state->save_options->options & SAIL_OPTION_META_DATA && image->meta_data_node != NULL) {
SAIL_TRY(jpeg_private_write_meta_data(jpeg_state->compress_context, image->meta_data_node));
#ifdef DEBUG
SAIL_LOG_DEBUG("JPEG: Meta data has been written");
#endif
}

/* Save ICC profile. */
#ifdef SAIL_HAVE_JPEG_ICCP
if (jpeg_state->save_options->options & SAIL_OPTION_ICCP && image->iccp != NULL) {
jpeg_write_icc_profile(jpeg_state->compress_context, image->iccp->data, (unsigned)image->iccp->size);
#ifdef DEBUG
SAIL_LOG_DEBUG("JPEG: ICC profile has been written");
#endif
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/sail-codecs/png/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,15 @@ sail_status_t png_private_write_meta_data(png_structp png_ptr, png_infop info_pt
if (meta_data->value->type == SAIL_VARIANT_TYPE_DATA) {
/* Skip "Exif\0\0" if any. */
if (meta_data->value->size >= 4 && memcmp(sail_variant_to_data(meta_data->value), "Exif", 4) == 0) {
#ifdef DEBUG
SAIL_LOG_DEBUG("PNG: Saving raw EXIF %u bytes long w/o header", (unsigned)meta_data->value->size - 6);
#endif
png_set_eXIf_1(png_ptr, info_ptr, (png_uint_32)meta_data->value->size - 6,
((png_bytep)sail_variant_to_data(meta_data->value)) + 6);
} else {
#ifdef DEBUG
SAIL_LOG_DEBUG("PNG: Saving raw EXIF %u bytes long", (unsigned)meta_data->value->size);
#endif
png_set_eXIf_1(png_ptr, info_ptr, (png_uint_32)meta_data->value->size, meta_data->value->value);
}
} else {
Expand Down Expand Up @@ -478,9 +482,11 @@ sail_status_t png_private_fetch_iccp(png_structp png_ptr, png_infop info_ptr, st

if (ok) {
SAIL_TRY(sail_alloc_iccp_from_data(data, data_size, iccp));
#ifdef DEBUG
SAIL_LOG_DEBUG("PNG: Found ICC profile '%s' %u bytes long", name, data_size);
} else {
SAIL_LOG_DEBUG("PNG: ICC profile is not found");
#endif
}

return SAIL_OK;
Expand Down
6 changes: 6 additions & 0 deletions src/sail-codecs/png/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_png(void *state, st
if (png_state->is_apng) {
/* APNG feature: a hidden frame. */
if (!png_state->skipped_hidden && png_get_first_frame_is_hidden(png_state->png_ptr, png_state->info_ptr)) {
#ifdef DEBUG
SAIL_LOG_DEBUG("PNG: Skipping hidden frame");
#endif
SAIL_TRY_OR_CLEANUP(png_private_skip_hidden_frame(png_state->first_image->bytes_per_line,
png_state->first_image->height,
png_state->png_ptr,
Expand Down Expand Up @@ -531,7 +533,9 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_png(void *state, co
/* Save meta data. */
if (png_state->save_options->options & SAIL_OPTION_META_DATA && image->meta_data_node != NULL) {
SAIL_TRY(png_private_write_meta_data(png_state->png_ptr, png_state->info_ptr, image->meta_data_node));
#ifdef DEBUG
SAIL_LOG_DEBUG("PNG: Meta data has been written");
#endif
}

png_set_IHDR(png_state->png_ptr,
Expand All @@ -556,7 +560,9 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_png(void *state, co
(const png_bytep)image->iccp->data,
(unsigned)image->iccp->size);

#ifdef DEBUG
SAIL_LOG_DEBUG("PNG: ICC profile has been written");
#endif
}

/* Save palette. */
Expand Down
4 changes: 4 additions & 0 deletions src/sail-codecs/tiff/tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,16 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_tiff(void *state, c
/* Save ICC profile. */
if (tiff_state->save_options->options & SAIL_OPTION_ICCP && image->iccp != NULL) {
TIFFSetField(tiff_state->tiff, TIFFTAG_ICCPROFILE, image->iccp->size, image->iccp->data);
#ifdef DEBUG
SAIL_LOG_DEBUG("TIFF: ICC profile has been saved");
#endif
}

/* Save meta data. */
if (tiff_state->save_options->options & SAIL_OPTION_META_DATA && image->meta_data_node != NULL) {
#ifdef DEBUG
SAIL_LOG_DEBUG("TIFF: Saving meta data");
#endif
SAIL_TRY(tiff_private_write_meta_data(tiff_state->tiff, image->meta_data_node));
}

Expand Down
14 changes: 14 additions & 0 deletions src/sail/codec_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ sail_status_t sail_codec_info_from_path(const char *path, const struct sail_code
SAIL_CHECK_PTR(path);
SAIL_CHECK_PTR(codec_info);

#ifdef DEBUG
SAIL_LOG_DEBUG("Finding codec info for path '%s'", path);
#endif

const char *file_name;

Expand Down Expand Up @@ -135,7 +137,9 @@ sail_status_t sail_codec_info_by_magic_number_from_io(struct sail_io *io, const
}

*(hex_numbers_ptr-1) = '\0';
#ifdef DEBUG
SAIL_LOG_DEBUG("Read magic number: '%s'", hex_numbers);
#endif
}

/* Find the codec info. */
Expand Down Expand Up @@ -186,7 +190,9 @@ sail_status_t sail_codec_info_by_magic_number_from_io(struct sail_io *io, const
magic_number_node = magic_number_node->next;
} else {
*codec_info = codec_bundle->codec_info;
#ifdef DEBUG
SAIL_LOG_DEBUG("Found codec info: %s", (*codec_info)->name);
#endif
return SAIL_OK;
}
}
Expand All @@ -201,7 +207,9 @@ sail_status_t sail_codec_info_from_extension(const char *extension, const struct
SAIL_CHECK_PTR(extension);
SAIL_CHECK_PTR(codec_info);

#ifdef DEBUG
SAIL_LOG_DEBUG("Finding codec info for extension '%s'", extension);
#endif

struct sail_context *context;
SAIL_TRY(fetch_global_context_guarded(&context));
Expand All @@ -222,7 +230,9 @@ sail_status_t sail_codec_info_from_extension(const char *extension, const struct
if (strcmp(extension_node->string, extension_copy) == 0) {
sail_free(extension_copy);
*codec_info = codec_bundle->codec_info;
#ifdef DEBUG
SAIL_LOG_DEBUG("Found codec info: %s", (*codec_info)->name);
#endif
return SAIL_OK;
} else {
SAIL_LOG_TRACE("Extension mismatch '%s' != '%s'", extension_copy, extension_node->string);
Expand All @@ -242,7 +252,9 @@ sail_status_t sail_codec_info_from_mime_type(const char *mime_type, const struct
SAIL_CHECK_PTR(mime_type);
SAIL_CHECK_PTR(codec_info);

#ifdef DEBUG
SAIL_LOG_DEBUG("Finding codec info for mime type '%s'", mime_type);
#endif

struct sail_context *context;
SAIL_TRY(fetch_global_context_guarded(&context));
Expand All @@ -263,7 +275,9 @@ sail_status_t sail_codec_info_from_mime_type(const char *mime_type, const struct
if (strcmp(mime_type_node->string, mime_type_copy) == 0) {
sail_free(mime_type_copy);
*codec_info = codec_bundle->codec_info;
#ifdef DEBUG
SAIL_LOG_DEBUG("Found codec info: %s", (*codec_info)->name);
#endif
return SAIL_OK;
} else {
SAIL_LOG_TRACE("MIME type mismatch '%s' != '%s'", mime_type_copy, mime_type_node->string);
Expand Down
2 changes: 2 additions & 0 deletions src/sail/codec_info_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ sail_status_t codec_read_info_from_file(const char *path, struct sail_codec_info
SAIL_CHECK_PTR(path);
SAIL_CHECK_PTR(codec_info);

#ifdef DEBUG
SAIL_LOG_DEBUG("Loading codec info '%s'", path);
#endif

SAIL_TRY(codec_read_info_from_input(path, ini_parse, codec_info));

Expand Down
Loading

0 comments on commit b53c003

Please sign in to comment.