From 0a32b32498a41ef5ef1a511fff74d4a84df71433 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Fri, 6 Jan 2023 18:03:45 -0800 Subject: [PATCH 01/20] Simplify casting --- src/sail-codecs/avif/avif.c | 6 +++--- src/sail-codecs/bmp/bmp.c | 6 +++--- src/sail-codecs/common/bmp/bmp.c | 6 +++--- src/sail-codecs/gif/gif.c | 6 +++--- src/sail-codecs/ico/ico.c | 6 +++--- src/sail-codecs/jpeg/jpeg.c | 12 ++++++------ src/sail-codecs/pcx/pcx.c | 6 +++--- src/sail-codecs/png/png.c | 12 ++++++------ src/sail-codecs/psd/psd.c | 6 +++--- src/sail-codecs/qoi/qoi.c | 12 ++++++------ src/sail-codecs/svg/svg.c | 6 +++--- src/sail-codecs/tga/tga.c | 6 +++--- src/sail-codecs/tiff/tiff.c | 12 ++++++------ src/sail-codecs/wal/wal.c | 6 +++--- src/sail-codecs/webp/webp.c | 6 +++--- src/sail-codecs/xbm/xbm.c | 6 +++--- 16 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/sail-codecs/avif/avif.c b/src/sail-codecs/avif/avif.c index 1ce76577..c13a9afa 100644 --- a/src/sail-codecs/avif/avif.c +++ b/src/sail-codecs/avif/avif.c @@ -140,7 +140,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_avif(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_avif(void *state, struct sail_image **image) { - struct avif_state *avif_state = (struct avif_state *)state; + struct avif_state *avif_state = state; avifResult avif_result = avifDecoderNextImage(avif_state->avif_decoder); @@ -187,7 +187,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_avif(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_avif(void *state, struct sail_image *image) { - struct avif_state *avif_state = (struct avif_state *)state; + struct avif_state *avif_state = state; const struct avifImage *avif_image = avif_state->avif_decoder->image; avif_state->rgb_image.pixels = image->pixels; @@ -205,7 +205,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_avif(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_avif(void **state) { - struct avif_state *avif_state = (struct avif_state *)(*state); + struct avif_state *avif_state = *state; *state = NULL; diff --git a/src/sail-codecs/bmp/bmp.c b/src/sail-codecs/bmp/bmp.c index 8166cb86..46e701bd 100644 --- a/src/sail-codecs/bmp/bmp.c +++ b/src/sail-codecs/bmp/bmp.c @@ -95,7 +95,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_bmp(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_bmp(void *state, struct sail_image **image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; if (bmp_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -110,7 +110,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_bmp(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_bmp(void *state, struct sail_image *image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; SAIL_TRY(bmp_private_read_frame(bmp_state->common_bmp_state, bmp_state->io, image)); @@ -119,7 +119,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_bmp(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_bmp(void **state) { - struct bmp_state *bmp_state = (struct bmp_state *)(*state); + struct bmp_state *bmp_state = *state; *state = NULL; diff --git a/src/sail-codecs/common/bmp/bmp.c b/src/sail-codecs/common/bmp/bmp.c index d1420976..4734981e 100644 --- a/src/sail-codecs/common/bmp/bmp.c +++ b/src/sail-codecs/common/bmp/bmp.c @@ -325,7 +325,7 @@ sail_status_t bmp_private_read_init(struct sail_io *io, const struct sail_load_o sail_status_t bmp_private_read_seek_next_frame(void *state, struct sail_io *io, struct sail_image **image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; struct sail_image *image_local; SAIL_TRY(sail_alloc_image(&image_local)); @@ -383,7 +383,7 @@ sail_status_t bmp_private_read_seek_next_frame(void *state, struct sail_io *io, sail_status_t bmp_private_read_frame(void *state, struct sail_io *io, struct sail_image *image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; /* RLE-encoded images don't need to skip pad bytes. */ bool skip_pad_bytes = true; @@ -534,7 +534,7 @@ sail_status_t bmp_private_read_finish(void **state, struct sail_io *io) { (void)io; - struct bmp_state *bmp_state = (struct bmp_state *)(*state); + struct bmp_state *bmp_state = *state; *state = NULL; diff --git a/src/sail-codecs/gif/gif.c b/src/sail-codecs/gif/gif.c index eb34ee2b..56785315 100644 --- a/src/sail-codecs/gif/gif.c +++ b/src/sail-codecs/gif/gif.c @@ -177,7 +177,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_gif(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_gif(void *state, struct sail_image **image) { - struct gif_state *gif_state = (struct gif_state *)state; + struct gif_state *gif_state = state; struct sail_image *image_local; SAIL_TRY(sail_alloc_image(&image_local)); @@ -336,7 +336,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_gif(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_gif(void *state, struct sail_image *image) { - struct gif_state *gif_state = (struct gif_state *)state; + struct gif_state *gif_state = state; const int passes = image->source_image->interlaced ? 4 : 1; const int last_pass = passes - 1; @@ -427,7 +427,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_gif(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_gif(void **state) { - struct gif_state *gif_state = (struct gif_state *)(*state); + struct gif_state *gif_state = *state; *state = NULL; diff --git a/src/sail-codecs/ico/ico.c b/src/sail-codecs/ico/ico.c index f1e9f9b2..52579263 100644 --- a/src/sail-codecs/ico/ico.c +++ b/src/sail-codecs/ico/ico.c @@ -133,7 +133,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_ico(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_ico(void *state, struct sail_image **image) { - struct ico_state *ico_state = (struct ico_state *)state; + struct ico_state *ico_state = state; /* Skip non-BMP images. */ enum SailIcoImageType ico_image_type; @@ -182,7 +182,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_ico(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_ico(void *state, struct sail_image *image) { - struct ico_state *ico_state = (struct ico_state *)state; + struct ico_state *ico_state = state; SAIL_TRY(bmp_private_read_frame(ico_state->common_bmp_state, ico_state->io, image)); SAIL_TRY(bmp_private_read_finish(&ico_state->common_bmp_state, ico_state->io)); @@ -192,7 +192,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_ico(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_ico(void **state) { - struct ico_state *ico_state = (struct ico_state *)(*state); + struct ico_state *ico_state = *state; *state = NULL; diff --git a/src/sail-codecs/jpeg/jpeg.c b/src/sail-codecs/jpeg/jpeg.c index 6c728a47..7db894d7 100644 --- a/src/sail-codecs/jpeg/jpeg.c +++ b/src/sail-codecs/jpeg/jpeg.c @@ -157,7 +157,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_jpeg(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_jpeg(void *state, struct sail_image **image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -209,7 +209,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_jpeg(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg(void *state, struct sail_image *image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->libjpeg_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -232,7 +232,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_jpeg(void **state) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)(*state); + struct jpeg_state *jpeg_state = *state; *state = NULL; @@ -297,7 +297,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_jpeg(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_jpeg(void *state, const struct sail_image *image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->frame_saved) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -367,7 +367,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_jpeg(void *state, c SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_jpeg(void *state, const struct sail_image *image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->libjpeg_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -388,7 +388,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_jpeg(void *state, const struc SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_jpeg(void **state) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)(*state); + struct jpeg_state *jpeg_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/pcx/pcx.c b/src/sail-codecs/pcx/pcx.c index 700bbbdc..d7e18790 100644 --- a/src/sail-codecs/pcx/pcx.c +++ b/src/sail-codecs/pcx/pcx.c @@ -124,7 +124,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_pcx(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_pcx(void *state, struct sail_image **image) { - struct pcx_state *pcx_state = (struct pcx_state *)state; + struct pcx_state *pcx_state = state; if (pcx_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -176,7 +176,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_pcx(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_pcx(void *state, struct sail_image *image) { - const struct pcx_state *pcx_state = (struct pcx_state *)state; + const struct pcx_state *pcx_state = state; if (pcx_state->pcx_header.encoding == SAIL_PCX_NO_ENCODING) { SAIL_TRY(pcx_private_read_uncompressed(pcx_state->io, pcx_state->pcx_header.bytes_per_line, pcx_state->pcx_header.planes, pcx_state->scanline_buffer, image)); @@ -226,7 +226,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_pcx(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_pcx(void **state) { - struct pcx_state *pcx_state = (struct pcx_state *)(*state); + struct pcx_state *pcx_state = *state; *state = NULL; diff --git a/src/sail-codecs/png/png.c b/src/sail-codecs/png/png.c index 8536f03a..119136c6 100644 --- a/src/sail-codecs/png/png.c +++ b/src/sail-codecs/png/png.c @@ -270,7 +270,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_png(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_png(void *state, struct sail_image **image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->libpng_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -364,7 +364,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_png(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_png(void *state, struct sail_image *image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->libpng_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -433,7 +433,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_png(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_png(void **state) { - struct png_state *png_state = (struct png_state *)(*state); + struct png_state *png_state = *state; *state = NULL; @@ -503,7 +503,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_png(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_png(void *state, const struct sail_image *image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->frame_saved) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -612,7 +612,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_png(void *state, co SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_png(void *state, const struct sail_image *image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->libpng_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -635,7 +635,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_png(void *state, const struct SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_png(void **state) { - struct png_state *png_state = (struct png_state *)(*state); + struct png_state *png_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/psd/psd.c b/src/sail-codecs/psd/psd.c index 210f3854..4fb2689b 100644 --- a/src/sail-codecs/psd/psd.c +++ b/src/sail-codecs/psd/psd.c @@ -126,7 +126,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_psd(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_psd(void *state, struct sail_image **image) { - struct psd_state *psd_state = (struct psd_state *)state; + struct psd_state *psd_state = state; if (psd_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -243,7 +243,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_psd(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_image *image) { - const struct psd_state *psd_state = (struct psd_state *)state; + const struct psd_state *psd_state = state; const unsigned bpp = (psd_state->channels * psd_state->depth + 7) / 8; @@ -299,7 +299,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_psd(void **state) { - struct psd_state *psd_state = (struct psd_state *)(*state); + struct psd_state *psd_state = *state; *state = NULL; diff --git a/src/sail-codecs/qoi/qoi.c b/src/sail-codecs/qoi/qoi.c index a50fc724..8a140abf 100644 --- a/src/sail-codecs/qoi/qoi.c +++ b/src/sail-codecs/qoi/qoi.c @@ -110,7 +110,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_qoi(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_qoi(void *state, struct sail_image **image) { - struct qoi_state *qoi_state = (struct qoi_state *)state; + struct qoi_state *qoi_state = state; if (qoi_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -163,7 +163,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_qoi(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_qoi(void *state, struct sail_image *image) { - const struct qoi_state *qoi_state = (struct qoi_state *)state; + const struct qoi_state *qoi_state = state; const size_t pixels_size = (size_t)image->bytes_per_line * image->height; @@ -174,7 +174,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_qoi(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_qoi(void **state) { - struct qoi_state *qoi_state = (struct qoi_state *)(*state); + struct qoi_state *qoi_state = *state; *state = NULL; @@ -213,7 +213,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_qoi(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_qoi(void *state, const struct sail_image *image) { - struct qoi_state *qoi_state = (struct qoi_state *)state; + struct qoi_state *qoi_state = state; unsigned char channels; @@ -244,7 +244,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_qoi(void *state, co SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_qoi(void *state, const struct sail_image *image) { - struct qoi_state *qoi_state = (struct qoi_state *)state; + struct qoi_state *qoi_state = state; const size_t pixels_size = (size_t)image->bytes_per_line * image->height; @@ -255,7 +255,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_qoi(void *state, const struct SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_qoi(void **state) { - struct qoi_state *qoi_state = (struct qoi_state *)(*state); + struct qoi_state *qoi_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/svg/svg.c b/src/sail-codecs/svg/svg.c index eb8fe853..6849c3e1 100644 --- a/src/sail-codecs/svg/svg.c +++ b/src/sail-codecs/svg/svg.c @@ -114,7 +114,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_svg(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_svg(void *state, struct sail_image **image) { - struct svg_state *svg_state = (struct svg_state *)state; + struct svg_state *svg_state = state; if (svg_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -144,7 +144,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_svg(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_svg(void *state, struct sail_image *image) { - const struct svg_state *svg_state = (struct svg_state *)state; + const struct svg_state *svg_state = state; memset(image->pixels, 0, (size_t)image->bytes_per_line * image->height); @@ -157,7 +157,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_svg(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_svg(void **state) { - struct svg_state *svg_state = (struct svg_state *)(*state); + struct svg_state *svg_state = *state; *state = NULL; diff --git a/src/sail-codecs/tga/tga.c b/src/sail-codecs/tga/tga.c index 8128ff0f..ffe26cc1 100644 --- a/src/sail-codecs/tga/tga.c +++ b/src/sail-codecs/tga/tga.c @@ -113,7 +113,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_tga(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tga(void *state, struct sail_image **image) { - struct tga_state *tga_state = (struct tga_state *)state; + struct tga_state *tga_state = state; if (tga_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -197,7 +197,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tga(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tga(void *state, struct sail_image *image) { - struct tga_state *tga_state = (struct tga_state *)state; + struct tga_state *tga_state = state; switch (tga_state->file_header.image_type) { case TGA_INDEXED: @@ -254,7 +254,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tga(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_tga(void **state) { - struct tga_state *tga_state = (struct tga_state *)(*state); + struct tga_state *tga_state = *state; *state = NULL; diff --git a/src/sail-codecs/tiff/tiff.c b/src/sail-codecs/tiff/tiff.c index 1ad8ee0b..8ba081f4 100644 --- a/src/sail-codecs/tiff/tiff.c +++ b/src/sail-codecs/tiff/tiff.c @@ -129,7 +129,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_tiff(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tiff(void *state, struct sail_image **image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -202,7 +202,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tiff(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tiff(void *state, struct sail_image *image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -219,7 +219,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tiff(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_tiff(void **state) { - struct tiff_state *tiff_state = (struct tiff_state *)(*state); + struct tiff_state *tiff_state = *state; *state = NULL; @@ -282,7 +282,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_tiff(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_tiff(void *state, const struct sail_image *image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -320,7 +320,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_tiff(void *state, c SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_tiff(void *state, const struct sail_image *image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -341,7 +341,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_tiff(void *state, const struc SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_tiff(void **state) { - struct tiff_state *tiff_state = (struct tiff_state *)(*state); + struct tiff_state *tiff_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/wal/wal.c b/src/sail-codecs/wal/wal.c index a9a00720..1e0b9a6f 100644 --- a/src/sail-codecs/wal/wal.c +++ b/src/sail-codecs/wal/wal.c @@ -106,7 +106,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_wal(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_wal(void *state, struct sail_image **image) { - struct wal_state *wal_state = (struct wal_state *)state; + struct wal_state *wal_state = state; if (wal_state->frame_number == 4) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -147,7 +147,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_wal(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_wal(void *state, struct sail_image *image) { - struct wal_state *wal_state = (struct wal_state *)state; + struct wal_state *wal_state = state; SAIL_TRY(wal_state->io->strict_read(wal_state->io->stream, image->pixels, (size_t)image->bytes_per_line * image->height)); @@ -156,7 +156,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_wal(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_wal(void **state) { - struct wal_state *wal_state = (struct wal_state *)(*state); + struct wal_state *wal_state = *state; *state = NULL; diff --git a/src/sail-codecs/webp/webp.c b/src/sail-codecs/webp/webp.c index ab0bd789..f069677a 100644 --- a/src/sail-codecs/webp/webp.c +++ b/src/sail-codecs/webp/webp.c @@ -188,7 +188,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_webp(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_webp(void *state, struct sail_image **image) { - struct webp_state *webp_state = (struct webp_state *)state; + struct webp_state *webp_state = state; /* Start demuxing. */ if (webp_state->frame_number == 0) { @@ -255,7 +255,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_webp(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_webp(void *state, struct sail_image *image) { - struct webp_state *webp_state = (struct webp_state *)state; + struct webp_state *webp_state = state; switch (webp_state->frame_blend_method) { case WEBP_MUX_NO_BLEND: { @@ -302,7 +302,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_webp(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_webp(void **state) { - struct webp_state *webp_state = (struct webp_state *)(*state); + struct webp_state *webp_state = *state; *state = NULL; diff --git a/src/sail-codecs/xbm/xbm.c b/src/sail-codecs/xbm/xbm.c index 6dfd56f2..2c2cda38 100644 --- a/src/sail-codecs/xbm/xbm.c +++ b/src/sail-codecs/xbm/xbm.c @@ -101,7 +101,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_xbm(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_xbm(void *state, struct sail_image **image) { - struct xbm_state *xbm_state = (struct xbm_state *)state; + struct xbm_state *xbm_state = state; if (xbm_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -194,7 +194,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_xbm(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_xbm(void *state, struct sail_image *image) { - const struct xbm_state *xbm_state = (struct xbm_state *)state; + const struct xbm_state *xbm_state = state; unsigned literals_to_read; @@ -240,7 +240,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_xbm(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_xbm(void **state) { - struct xbm_state *xbm_state = (struct xbm_state *)(*state); + struct xbm_state *xbm_state = *state; *state = NULL; From 8e0c35ba58b659e6c3a9f9dedeae5c58cc2074c4 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Fri, 6 Jan 2023 18:18:50 -0800 Subject: [PATCH 02/20] Simplify casting --- src/sail-codecs/avif/avif.c | 6 +++--- src/sail-codecs/avif/io.c | 2 +- src/sail-codecs/bmp/bmp.c | 6 +++--- src/sail-codecs/common/bmp/bmp.c | 6 +++--- src/sail-codecs/gif/gif.c | 6 +++--- src/sail-codecs/gif/io.c | 4 ++-- src/sail-codecs/ico/ico.c | 6 +++--- src/sail-codecs/jpeg/io_dest.c | 6 +++--- src/sail-codecs/jpeg/io_src.c | 6 +++--- src/sail-codecs/jpeg/jpeg.c | 12 ++++++------ src/sail-codecs/jpeg2000/jpeg2000.c | 6 +++--- src/sail-codecs/pcx/pcx.c | 6 +++--- src/sail-codecs/png/io.c | 6 +++--- src/sail-codecs/png/png.c | 12 ++++++------ src/sail-codecs/psd/psd.c | 6 +++--- src/sail-codecs/qoi/qoi.c | 12 ++++++------ src/sail-codecs/svg/svg.c | 6 +++--- src/sail-codecs/tga/tga.c | 6 +++--- src/sail-codecs/tiff/tiff.c | 12 ++++++------ src/sail-codecs/wal/wal.c | 6 +++--- src/sail-codecs/webp/webp.c | 6 +++--- src/sail-codecs/xbm/xbm.c | 6 +++--- 22 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/sail-codecs/avif/avif.c b/src/sail-codecs/avif/avif.c index 1ce76577..c13a9afa 100644 --- a/src/sail-codecs/avif/avif.c +++ b/src/sail-codecs/avif/avif.c @@ -140,7 +140,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_avif(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_avif(void *state, struct sail_image **image) { - struct avif_state *avif_state = (struct avif_state *)state; + struct avif_state *avif_state = state; avifResult avif_result = avifDecoderNextImage(avif_state->avif_decoder); @@ -187,7 +187,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_avif(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_avif(void *state, struct sail_image *image) { - struct avif_state *avif_state = (struct avif_state *)state; + struct avif_state *avif_state = state; const struct avifImage *avif_image = avif_state->avif_decoder->image; avif_state->rgb_image.pixels = image->pixels; @@ -205,7 +205,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_avif(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_avif(void **state) { - struct avif_state *avif_state = (struct avif_state *)(*state); + struct avif_state *avif_state = *state; *state = NULL; diff --git a/src/sail-codecs/avif/io.c b/src/sail-codecs/avif/io.c index 11e0bfb5..3a456208 100644 --- a/src/sail-codecs/avif/io.c +++ b/src/sail-codecs/avif/io.c @@ -38,7 +38,7 @@ avifResult avif_private_read_proc(struct avifIO *io, uint32_t read_flags, uint64 SAIL_LOG_TRACE("AVIF: Read at offset %ld size %lu", (long)offset, (unsigned long)size); - struct sail_avif_context *avif_context = (struct sail_avif_context *)io->data; + struct sail_avif_context *avif_context = io->data; SAIL_TRY_OR_EXECUTE(avif_context->io->seek(avif_context->io->stream, (long)offset, SEEK_SET), /* on error */ return AVIF_RESULT_IO_ERROR); diff --git a/src/sail-codecs/bmp/bmp.c b/src/sail-codecs/bmp/bmp.c index 8166cb86..46e701bd 100644 --- a/src/sail-codecs/bmp/bmp.c +++ b/src/sail-codecs/bmp/bmp.c @@ -95,7 +95,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_bmp(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_bmp(void *state, struct sail_image **image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; if (bmp_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -110,7 +110,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_bmp(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_bmp(void *state, struct sail_image *image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; SAIL_TRY(bmp_private_read_frame(bmp_state->common_bmp_state, bmp_state->io, image)); @@ -119,7 +119,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_bmp(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_bmp(void **state) { - struct bmp_state *bmp_state = (struct bmp_state *)(*state); + struct bmp_state *bmp_state = *state; *state = NULL; diff --git a/src/sail-codecs/common/bmp/bmp.c b/src/sail-codecs/common/bmp/bmp.c index d1420976..4734981e 100644 --- a/src/sail-codecs/common/bmp/bmp.c +++ b/src/sail-codecs/common/bmp/bmp.c @@ -325,7 +325,7 @@ sail_status_t bmp_private_read_init(struct sail_io *io, const struct sail_load_o sail_status_t bmp_private_read_seek_next_frame(void *state, struct sail_io *io, struct sail_image **image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; struct sail_image *image_local; SAIL_TRY(sail_alloc_image(&image_local)); @@ -383,7 +383,7 @@ sail_status_t bmp_private_read_seek_next_frame(void *state, struct sail_io *io, sail_status_t bmp_private_read_frame(void *state, struct sail_io *io, struct sail_image *image) { - struct bmp_state *bmp_state = (struct bmp_state *)state; + struct bmp_state *bmp_state = state; /* RLE-encoded images don't need to skip pad bytes. */ bool skip_pad_bytes = true; @@ -534,7 +534,7 @@ sail_status_t bmp_private_read_finish(void **state, struct sail_io *io) { (void)io; - struct bmp_state *bmp_state = (struct bmp_state *)(*state); + struct bmp_state *bmp_state = *state; *state = NULL; diff --git a/src/sail-codecs/gif/gif.c b/src/sail-codecs/gif/gif.c index eb34ee2b..56785315 100644 --- a/src/sail-codecs/gif/gif.c +++ b/src/sail-codecs/gif/gif.c @@ -177,7 +177,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_gif(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_gif(void *state, struct sail_image **image) { - struct gif_state *gif_state = (struct gif_state *)state; + struct gif_state *gif_state = state; struct sail_image *image_local; SAIL_TRY(sail_alloc_image(&image_local)); @@ -336,7 +336,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_gif(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_gif(void *state, struct sail_image *image) { - struct gif_state *gif_state = (struct gif_state *)state; + struct gif_state *gif_state = state; const int passes = image->source_image->interlaced ? 4 : 1; const int last_pass = passes - 1; @@ -427,7 +427,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_gif(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_gif(void **state) { - struct gif_state *gif_state = (struct gif_state *)(*state); + struct gif_state *gif_state = *state; *state = NULL; diff --git a/src/sail-codecs/gif/io.c b/src/sail-codecs/gif/io.c index 5bf28a26..817bb44b 100644 --- a/src/sail-codecs/gif/io.c +++ b/src/sail-codecs/gif/io.c @@ -29,7 +29,7 @@ int my_read_proc(GifFileType *gif, GifByteType *buffer, int buffer_size) { - struct sail_io *io = (struct sail_io *)gif->UserData; + struct sail_io *io = gif->UserData; size_t nbytes; sail_status_t err = io->tolerant_read(io->stream, buffer, buffer_size, &nbytes); @@ -44,7 +44,7 @@ int my_read_proc(GifFileType *gif, GifByteType *buffer, int buffer_size) { int my_write_proc(GifFileType *gif, GifByteType *buffer, int buffer_size) { - struct sail_io *io = (struct sail_io *)gif->UserData; + struct sail_io *io = gif->UserData; size_t nbytes; sail_status_t err = io->tolerant_write(io->stream, buffer, buffer_size, &nbytes); diff --git a/src/sail-codecs/ico/ico.c b/src/sail-codecs/ico/ico.c index f1e9f9b2..52579263 100644 --- a/src/sail-codecs/ico/ico.c +++ b/src/sail-codecs/ico/ico.c @@ -133,7 +133,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_ico(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_ico(void *state, struct sail_image **image) { - struct ico_state *ico_state = (struct ico_state *)state; + struct ico_state *ico_state = state; /* Skip non-BMP images. */ enum SailIcoImageType ico_image_type; @@ -182,7 +182,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_ico(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_ico(void *state, struct sail_image *image) { - struct ico_state *ico_state = (struct ico_state *)state; + struct ico_state *ico_state = state; SAIL_TRY(bmp_private_read_frame(ico_state->common_bmp_state, ico_state->io, image)); SAIL_TRY(bmp_private_read_finish(&ico_state->common_bmp_state, ico_state->io)); @@ -192,7 +192,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_ico(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_ico(void **state) { - struct ico_state *ico_state = (struct ico_state *)(*state); + struct ico_state *ico_state = *state; *state = NULL; diff --git a/src/sail-codecs/jpeg/io_dest.c b/src/sail-codecs/jpeg/io_dest.c index 3d694e7a..a230b14a 100644 --- a/src/sail-codecs/jpeg/io_dest.c +++ b/src/sail-codecs/jpeg/io_dest.c @@ -130,9 +130,9 @@ void jpeg_private_sail_io_dest(j_compress_ptr cinfo, struct sail_io *io) * can be written to the same file without re-executing jpeg_stdio_dest. */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */ - cinfo->dest = (struct jpeg_destination_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr)cinfo, - JPOOL_PERMANENT, - sizeof(struct sail_jpeg_destination_mgr)); + cinfo->dest = cinfo->mem->alloc_small((j_common_ptr)cinfo, + JPOOL_PERMANENT, + sizeof(struct sail_jpeg_destination_mgr)); } else if (cinfo->dest->init_destination != init_destination) { /* It is unsafe to reuse the existing destination manager unless it was * created by this function. Otherwise, there is no guarantee that the diff --git a/src/sail-codecs/jpeg/io_src.c b/src/sail-codecs/jpeg/io_src.c index dbc49021..f8ee6313 100644 --- a/src/sail-codecs/jpeg/io_src.c +++ b/src/sail-codecs/jpeg/io_src.c @@ -177,9 +177,9 @@ void jpeg_private_sail_io_src(j_decompress_ptr cinfo, struct sail_io *io) { * one image, we'd likely lose the start of the next one.) */ if (cinfo->src == NULL) { /* first time for this JPEG object? */ - cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr)cinfo, - JPOOL_PERMANENT, - sizeof(struct sail_jpeg_source_mgr)); + cinfo->src = cinfo->mem->alloc_small((j_common_ptr)cinfo, + JPOOL_PERMANENT, + sizeof(struct sail_jpeg_source_mgr)); src = (struct sail_jpeg_source_mgr *)cinfo->src; src->buffer = (JOCTET *)(*cinfo->mem->alloc_small)((j_common_ptr)cinfo, JPOOL_PERMANENT, diff --git a/src/sail-codecs/jpeg/jpeg.c b/src/sail-codecs/jpeg/jpeg.c index 6c728a47..7db894d7 100644 --- a/src/sail-codecs/jpeg/jpeg.c +++ b/src/sail-codecs/jpeg/jpeg.c @@ -157,7 +157,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_jpeg(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_jpeg(void *state, struct sail_image **image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -209,7 +209,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_jpeg(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg(void *state, struct sail_image *image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->libjpeg_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -232,7 +232,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_jpeg(void **state) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)(*state); + struct jpeg_state *jpeg_state = *state; *state = NULL; @@ -297,7 +297,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_jpeg(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_jpeg(void *state, const struct sail_image *image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->frame_saved) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -367,7 +367,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_jpeg(void *state, c SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_jpeg(void *state, const struct sail_image *image) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)state; + struct jpeg_state *jpeg_state = state; if (jpeg_state->libjpeg_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -388,7 +388,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_jpeg(void *state, const struc SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_jpeg(void **state) { - struct jpeg_state *jpeg_state = (struct jpeg_state *)(*state); + struct jpeg_state *jpeg_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/jpeg2000/jpeg2000.c b/src/sail-codecs/jpeg2000/jpeg2000.c index 2e88e6f5..faa85b87 100644 --- a/src/sail-codecs/jpeg2000/jpeg2000.c +++ b/src/sail-codecs/jpeg2000/jpeg2000.c @@ -143,7 +143,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_jpeg2000(struct sail_io *io, c SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_jpeg2000(void *state, struct sail_image **image) { - struct jpeg2000_state *jpeg2000_state = (struct jpeg2000_state *)state; + struct jpeg2000_state *jpeg2000_state = state; if (jpeg2000_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -281,7 +281,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_jpeg2000(void *stat SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg2000(void *state, struct sail_image *image) { - const struct jpeg2000_state *jpeg2000_state = (struct jpeg2000_state *)state; + const struct jpeg2000_state *jpeg2000_state = state; for (unsigned row = 0; row < image->height; row++) { unsigned char *scan = (unsigned char *)image->pixels + row * image->bytes_per_line; @@ -311,7 +311,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_jpeg2000(void *state, struct SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_jpeg2000(void **state) { - struct jpeg2000_state *jpeg2000_state = (struct jpeg2000_state *)(*state); + struct jpeg2000_state *jpeg2000_state = *state; *state = NULL; diff --git a/src/sail-codecs/pcx/pcx.c b/src/sail-codecs/pcx/pcx.c index 700bbbdc..d7e18790 100644 --- a/src/sail-codecs/pcx/pcx.c +++ b/src/sail-codecs/pcx/pcx.c @@ -124,7 +124,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_pcx(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_pcx(void *state, struct sail_image **image) { - struct pcx_state *pcx_state = (struct pcx_state *)state; + struct pcx_state *pcx_state = state; if (pcx_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -176,7 +176,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_pcx(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_pcx(void *state, struct sail_image *image) { - const struct pcx_state *pcx_state = (struct pcx_state *)state; + const struct pcx_state *pcx_state = state; if (pcx_state->pcx_header.encoding == SAIL_PCX_NO_ENCODING) { SAIL_TRY(pcx_private_read_uncompressed(pcx_state->io, pcx_state->pcx_header.bytes_per_line, pcx_state->pcx_header.planes, pcx_state->scanline_buffer, image)); @@ -226,7 +226,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_pcx(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_pcx(void **state) { - struct pcx_state *pcx_state = (struct pcx_state *)(*state); + struct pcx_state *pcx_state = *state; *state = NULL; diff --git a/src/sail-codecs/png/io.c b/src/sail-codecs/png/io.c index 9d8df31a..d98d4310 100644 --- a/src/sail-codecs/png/io.c +++ b/src/sail-codecs/png/io.c @@ -38,7 +38,7 @@ void png_private_my_read_fn(png_structp png_ptr, png_bytep bytes, png_size_t byt return; } - struct sail_io *io = (struct sail_io *)png_get_io_ptr(png_ptr); + struct sail_io *io = png_get_io_ptr(png_ptr); sail_status_t err = io->strict_read(io->stream, bytes, bytes_size); @@ -53,7 +53,7 @@ void png_private_my_write_fn(png_structp png_ptr, png_bytep bytes, png_size_t by return; } - struct sail_io *io = (struct sail_io *)png_get_io_ptr(png_ptr); + struct sail_io *io = png_get_io_ptr(png_ptr); sail_status_t err = io->strict_write(io->stream, bytes, bytes_size); @@ -68,7 +68,7 @@ void png_private_my_flush_fn(png_structp png_ptr) { return; } - struct sail_io *io = (struct sail_io *)png_get_io_ptr(png_ptr); + struct sail_io *io = png_get_io_ptr(png_ptr); sail_status_t err = io->flush(io->stream); diff --git a/src/sail-codecs/png/png.c b/src/sail-codecs/png/png.c index 8536f03a..119136c6 100644 --- a/src/sail-codecs/png/png.c +++ b/src/sail-codecs/png/png.c @@ -270,7 +270,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_png(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_png(void *state, struct sail_image **image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->libpng_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -364,7 +364,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_png(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_png(void *state, struct sail_image *image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->libpng_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -433,7 +433,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_png(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_png(void **state) { - struct png_state *png_state = (struct png_state *)(*state); + struct png_state *png_state = *state; *state = NULL; @@ -503,7 +503,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_png(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_png(void *state, const struct sail_image *image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->frame_saved) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -612,7 +612,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_png(void *state, co SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_png(void *state, const struct sail_image *image) { - struct png_state *png_state = (struct png_state *)state; + struct png_state *png_state = state; if (png_state->libpng_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -635,7 +635,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_png(void *state, const struct SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_png(void **state) { - struct png_state *png_state = (struct png_state *)(*state); + struct png_state *png_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/psd/psd.c b/src/sail-codecs/psd/psd.c index 210f3854..4fb2689b 100644 --- a/src/sail-codecs/psd/psd.c +++ b/src/sail-codecs/psd/psd.c @@ -126,7 +126,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_psd(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_psd(void *state, struct sail_image **image) { - struct psd_state *psd_state = (struct psd_state *)state; + struct psd_state *psd_state = state; if (psd_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -243,7 +243,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_psd(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_image *image) { - const struct psd_state *psd_state = (struct psd_state *)state; + const struct psd_state *psd_state = state; const unsigned bpp = (psd_state->channels * psd_state->depth + 7) / 8; @@ -299,7 +299,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_psd(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_psd(void **state) { - struct psd_state *psd_state = (struct psd_state *)(*state); + struct psd_state *psd_state = *state; *state = NULL; diff --git a/src/sail-codecs/qoi/qoi.c b/src/sail-codecs/qoi/qoi.c index a50fc724..8a140abf 100644 --- a/src/sail-codecs/qoi/qoi.c +++ b/src/sail-codecs/qoi/qoi.c @@ -110,7 +110,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_qoi(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_qoi(void *state, struct sail_image **image) { - struct qoi_state *qoi_state = (struct qoi_state *)state; + struct qoi_state *qoi_state = state; if (qoi_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -163,7 +163,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_qoi(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_qoi(void *state, struct sail_image *image) { - const struct qoi_state *qoi_state = (struct qoi_state *)state; + const struct qoi_state *qoi_state = state; const size_t pixels_size = (size_t)image->bytes_per_line * image->height; @@ -174,7 +174,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_qoi(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_qoi(void **state) { - struct qoi_state *qoi_state = (struct qoi_state *)(*state); + struct qoi_state *qoi_state = *state; *state = NULL; @@ -213,7 +213,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_qoi(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_qoi(void *state, const struct sail_image *image) { - struct qoi_state *qoi_state = (struct qoi_state *)state; + struct qoi_state *qoi_state = state; unsigned char channels; @@ -244,7 +244,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_qoi(void *state, co SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_qoi(void *state, const struct sail_image *image) { - struct qoi_state *qoi_state = (struct qoi_state *)state; + struct qoi_state *qoi_state = state; const size_t pixels_size = (size_t)image->bytes_per_line * image->height; @@ -255,7 +255,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_qoi(void *state, const struct SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_qoi(void **state) { - struct qoi_state *qoi_state = (struct qoi_state *)(*state); + struct qoi_state *qoi_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/svg/svg.c b/src/sail-codecs/svg/svg.c index eb8fe853..6849c3e1 100644 --- a/src/sail-codecs/svg/svg.c +++ b/src/sail-codecs/svg/svg.c @@ -114,7 +114,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_svg(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_svg(void *state, struct sail_image **image) { - struct svg_state *svg_state = (struct svg_state *)state; + struct svg_state *svg_state = state; if (svg_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -144,7 +144,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_svg(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_svg(void *state, struct sail_image *image) { - const struct svg_state *svg_state = (struct svg_state *)state; + const struct svg_state *svg_state = state; memset(image->pixels, 0, (size_t)image->bytes_per_line * image->height); @@ -157,7 +157,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_svg(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_svg(void **state) { - struct svg_state *svg_state = (struct svg_state *)(*state); + struct svg_state *svg_state = *state; *state = NULL; diff --git a/src/sail-codecs/tga/tga.c b/src/sail-codecs/tga/tga.c index 8128ff0f..ffe26cc1 100644 --- a/src/sail-codecs/tga/tga.c +++ b/src/sail-codecs/tga/tga.c @@ -113,7 +113,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_tga(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tga(void *state, struct sail_image **image) { - struct tga_state *tga_state = (struct tga_state *)state; + struct tga_state *tga_state = state; if (tga_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -197,7 +197,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tga(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tga(void *state, struct sail_image *image) { - struct tga_state *tga_state = (struct tga_state *)state; + struct tga_state *tga_state = state; switch (tga_state->file_header.image_type) { case TGA_INDEXED: @@ -254,7 +254,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tga(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_tga(void **state) { - struct tga_state *tga_state = (struct tga_state *)(*state); + struct tga_state *tga_state = *state; *state = NULL; diff --git a/src/sail-codecs/tiff/tiff.c b/src/sail-codecs/tiff/tiff.c index 1ad8ee0b..8ba081f4 100644 --- a/src/sail-codecs/tiff/tiff.c +++ b/src/sail-codecs/tiff/tiff.c @@ -129,7 +129,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_tiff(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tiff(void *state, struct sail_image **image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -202,7 +202,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_tiff(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tiff(void *state, struct sail_image *image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -219,7 +219,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_tiff(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_tiff(void **state) { - struct tiff_state *tiff_state = (struct tiff_state *)(*state); + struct tiff_state *tiff_state = *state; *state = NULL; @@ -282,7 +282,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_init_v8_tiff(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_tiff(void *state, const struct sail_image *image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -320,7 +320,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_tiff(void *state, c SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_tiff(void *state, const struct sail_image *image) { - struct tiff_state *tiff_state = (struct tiff_state *)state; + struct tiff_state *tiff_state = state; if (tiff_state->libtiff_error) { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNDERLYING_CODEC); @@ -341,7 +341,7 @@ SAIL_EXPORT sail_status_t sail_codec_save_frame_v8_tiff(void *state, const struc SAIL_EXPORT sail_status_t sail_codec_save_finish_v8_tiff(void **state) { - struct tiff_state *tiff_state = (struct tiff_state *)(*state); + struct tiff_state *tiff_state = *state; /* Subsequent calls to finish() will expectedly fail in the above line. */ *state = NULL; diff --git a/src/sail-codecs/wal/wal.c b/src/sail-codecs/wal/wal.c index a9a00720..1e0b9a6f 100644 --- a/src/sail-codecs/wal/wal.c +++ b/src/sail-codecs/wal/wal.c @@ -106,7 +106,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_wal(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_wal(void *state, struct sail_image **image) { - struct wal_state *wal_state = (struct wal_state *)state; + struct wal_state *wal_state = state; if (wal_state->frame_number == 4) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -147,7 +147,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_wal(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_wal(void *state, struct sail_image *image) { - struct wal_state *wal_state = (struct wal_state *)state; + struct wal_state *wal_state = state; SAIL_TRY(wal_state->io->strict_read(wal_state->io->stream, image->pixels, (size_t)image->bytes_per_line * image->height)); @@ -156,7 +156,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_wal(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_wal(void **state) { - struct wal_state *wal_state = (struct wal_state *)(*state); + struct wal_state *wal_state = *state; *state = NULL; diff --git a/src/sail-codecs/webp/webp.c b/src/sail-codecs/webp/webp.c index ab0bd789..f069677a 100644 --- a/src/sail-codecs/webp/webp.c +++ b/src/sail-codecs/webp/webp.c @@ -188,7 +188,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_webp(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_webp(void *state, struct sail_image **image) { - struct webp_state *webp_state = (struct webp_state *)state; + struct webp_state *webp_state = state; /* Start demuxing. */ if (webp_state->frame_number == 0) { @@ -255,7 +255,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_webp(void *state, s SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_webp(void *state, struct sail_image *image) { - struct webp_state *webp_state = (struct webp_state *)state; + struct webp_state *webp_state = state; switch (webp_state->frame_blend_method) { case WEBP_MUX_NO_BLEND: { @@ -302,7 +302,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_webp(void *state, struct sail SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_webp(void **state) { - struct webp_state *webp_state = (struct webp_state *)(*state); + struct webp_state *webp_state = *state; *state = NULL; diff --git a/src/sail-codecs/xbm/xbm.c b/src/sail-codecs/xbm/xbm.c index 6dfd56f2..2c2cda38 100644 --- a/src/sail-codecs/xbm/xbm.c +++ b/src/sail-codecs/xbm/xbm.c @@ -101,7 +101,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_init_v8_xbm(struct sail_io *io, const SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_xbm(void *state, struct sail_image **image) { - struct xbm_state *xbm_state = (struct xbm_state *)state; + struct xbm_state *xbm_state = state; if (xbm_state->frame_loaded) { SAIL_LOG_AND_RETURN(SAIL_ERROR_NO_MORE_FRAMES); @@ -194,7 +194,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_xbm(void *state, st SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_xbm(void *state, struct sail_image *image) { - const struct xbm_state *xbm_state = (struct xbm_state *)state; + const struct xbm_state *xbm_state = state; unsigned literals_to_read; @@ -240,7 +240,7 @@ SAIL_EXPORT sail_status_t sail_codec_load_frame_v8_xbm(void *state, struct sail_ SAIL_EXPORT sail_status_t sail_codec_load_finish_v8_xbm(void **state) { - struct xbm_state *xbm_state = (struct xbm_state *)(*state); + struct xbm_state *xbm_state = *state; *state = NULL; From 416641a73e43665f3465d035219f0e6035a2a2af Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Sat, 7 Jan 2023 10:57:17 -0800 Subject: [PATCH 03/20] DOC: Update codec priorities --- FAQ.md | 2 +- src/libsail/codec_priority.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index dfee809d..39d1844b 100644 --- a/FAQ.md +++ b/FAQ.md @@ -283,7 +283,7 @@ version=1.0.0 # HIGHEST = one of the most popular image formats like JPEG # HIGH = pretty popular and common image format like SVG # MEDIUM = moderate popularity -# LOW = rare image format +# LOW = pretty rare image format # LOWEST = very rare and/or too specific and/or ancient image format # priority=MEDIUM diff --git a/src/libsail/codec_priority.h b/src/libsail/codec_priority.h index c7a4ff3f..8667a59e 100644 --- a/src/libsail/codec_priority.h +++ b/src/libsail/codec_priority.h @@ -29,10 +29,15 @@ /* Codec priority. */ enum SailCodecPriority { + /* One of the most popular image formats like JPEG. */ SAIL_CODEC_PRIORITY_HIGHEST, + /* Pretty popular and common image format like SVG. */ SAIL_CODEC_PRIORITY_HIGH, + /* Moderate popularity. */ SAIL_CODEC_PRIORITY_MEDIUM, + /* Pretty rare image format. */ SAIL_CODEC_PRIORITY_LOW, + /* Very rare and/or too specific and/or ancient image format. */ SAIL_CODEC_PRIORITY_LOWEST, }; From 44e921d228f7aa0cbb7f94caa5e2dffe6f0bfeb0 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Sat, 7 Jan 2023 16:12:17 -0800 Subject: [PATCH 04/20] COMMON: Fix order of case: --- src/libsail-common/common_serialize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsail-common/common_serialize.c b/src/libsail-common/common_serialize.c index a9d3a99d..c7cf44f8 100644 --- a/src/libsail-common/common_serialize.c +++ b/src/libsail-common/common_serialize.c @@ -391,8 +391,8 @@ enum SailCompression sail_compression_from_string(const char *str) { case UINT64_C(193470374): return SAIL_COMPRESSION_T85; case UINT64_C(13844775339661004164): return SAIL_COMPRESSION_THUNDERSCAN; case UINT64_C(6384644819): return SAIL_COMPRESSION_WEBP; - case UINT64_C(6384768458): return SAIL_COMPRESSION_ZSTD; case UINT64_C(193477496): return SAIL_COMPRESSION_ZIP; + case UINT64_C(6384768458): return SAIL_COMPRESSION_ZSTD; } return SAIL_COMPRESSION_UNKNOWN; From 17aa365dea4095828502603849c22b104c7a811b Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 13:32:38 +0300 Subject: [PATCH 05/20] SAIL: Apply fix from https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files --- CMakeLists.txt | 7 ++++++ cmake/JoinPaths.cmake | 23 +++++++++++++++++++ src/bindings/c++/pkgconfig/libsail-c++.pc.in | 4 ++-- .../pkgconfig/libsail-common.pc.in | 4 ++-- .../pkgconfig/libsail-manip.pc.in | 4 ++-- src/libsail/pkgconfig/libsail.pc.in | 4 ++-- 6 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 cmake/JoinPaths.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e573ade6..48fb4ab4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,13 @@ include(sail_install_cmake_config) include(sail_install_pdb) include(sail_test) +include(JoinPaths) + +# https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files +# +join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") +join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") + # Check features # sail_check_alignas() diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake new file mode 100644 index 00000000..fa0be17f --- /dev/null +++ b/cmake/JoinPaths.cmake @@ -0,0 +1,23 @@ +# This module provides function for joining paths +# known from most languages +# +# SPDX-License-Identifier: (MIT OR CC0-1.0) +# Copyright 2020 Jan Tojnar +# https://github.com/jtojnar/cmake-snips +# +# Modelled after Python’s os.path.join +# https://docs.python.org/3.7/library/os.path.html#os.path.join +# Windows not supported +function(join_paths joined_path first_path_segment) + set(temp_path "${first_path_segment}") + foreach(current_segment IN LISTS ARGN) + if(NOT ("${current_segment}" STREQUAL "")) + if(IS_ABSOLUTE "${current_segment}") + set(temp_path "${current_segment}") + else() + set(temp_path "${temp_path}/${current_segment}") + endif() + endif() + endforeach() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction() diff --git a/src/bindings/c++/pkgconfig/libsail-c++.pc.in b/src/bindings/c++/pkgconfig/libsail-c++.pc.in index efbd3b18..7abb2ec9 100644 --- a/src/bindings/c++/pkgconfig/libsail-c++.pc.in +++ b/src/bindings/c++/pkgconfig/libsail-c++.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/sail +libdir=@libdir_for_pc_file@ +includedir=@includedir_for_pc_file@/sail Name: libsail-c++ Description: SAIL C++ client library diff --git a/src/libsail-common/pkgconfig/libsail-common.pc.in b/src/libsail-common/pkgconfig/libsail-common.pc.in index 0461bf0b..fd6eb0de 100644 --- a/src/libsail-common/pkgconfig/libsail-common.pc.in +++ b/src/libsail-common/pkgconfig/libsail-common.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/sail +libdir=@libdir_for_pc_file@ +includedir=@includedir_for_pc_file@/sail Name: libsail-common Description: SAIL common client library diff --git a/src/libsail-manip/pkgconfig/libsail-manip.pc.in b/src/libsail-manip/pkgconfig/libsail-manip.pc.in index 582947b7..467816cf 100644 --- a/src/libsail-manip/pkgconfig/libsail-manip.pc.in +++ b/src/libsail-manip/pkgconfig/libsail-manip.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/sail +libdir=@libdir_for_pc_file@ +includedir=@includedir_for_pc_file@/sail Name: libsail-manip Description: SAIL image manipulation library diff --git a/src/libsail/pkgconfig/libsail.pc.in b/src/libsail/pkgconfig/libsail.pc.in index 3978e089..3c244a81 100644 --- a/src/libsail/pkgconfig/libsail.pc.in +++ b/src/libsail/pkgconfig/libsail.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/sail +libdir=@libdir_for_pc_file@ +includedir=@includedir_for_pc_file@/sail Name: libsail Description: SAIL client library From 533f8df45570eaf2598272fee83a2a1a17e9f8e3 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 13:38:07 +0300 Subject: [PATCH 06/20] SAIL: Rename pkg-config variables to have SAIL_ naming --- CMakeLists.txt | 4 ++-- src/bindings/c++/pkgconfig/libsail-c++.pc.in | 4 ++-- src/libsail-common/pkgconfig/libsail-common.pc.in | 4 ++-- src/libsail-manip/pkgconfig/libsail-manip.pc.in | 4 ++-- src/libsail/pkgconfig/libsail.pc.in | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48fb4ab4..129c95bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,8 @@ include(JoinPaths) # https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files # -join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") -join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") +join_paths(SAIL_LIBDIR_FOR_PKG_CONFIG "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") +join_paths(SAIL_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") # Check features # diff --git a/src/bindings/c++/pkgconfig/libsail-c++.pc.in b/src/bindings/c++/pkgconfig/libsail-c++.pc.in index 7abb2ec9..d160a360 100644 --- a/src/bindings/c++/pkgconfig/libsail-c++.pc.in +++ b/src/bindings/c++/pkgconfig/libsail-c++.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=@libdir_for_pc_file@ -includedir=@includedir_for_pc_file@/sail +libdir=@SAIL_LIBDIR_FOR_PKG_CONFIG@ +includedir=@SAIL_INCLUDEDIR_FOR_PKG_CONFIG@/sail Name: libsail-c++ Description: SAIL C++ client library diff --git a/src/libsail-common/pkgconfig/libsail-common.pc.in b/src/libsail-common/pkgconfig/libsail-common.pc.in index fd6eb0de..8e8efc87 100644 --- a/src/libsail-common/pkgconfig/libsail-common.pc.in +++ b/src/libsail-common/pkgconfig/libsail-common.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=@libdir_for_pc_file@ -includedir=@includedir_for_pc_file@/sail +libdir=@SAIL_LIBDIR_FOR_PKG_CONFIG@ +includedir=@SAIL_INCLUDEDIR_FOR_PKG_CONFIG@/sail Name: libsail-common Description: SAIL common client library diff --git a/src/libsail-manip/pkgconfig/libsail-manip.pc.in b/src/libsail-manip/pkgconfig/libsail-manip.pc.in index 467816cf..8bc4c0e1 100644 --- a/src/libsail-manip/pkgconfig/libsail-manip.pc.in +++ b/src/libsail-manip/pkgconfig/libsail-manip.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=@libdir_for_pc_file@ -includedir=@includedir_for_pc_file@/sail +libdir=@SAIL_LIBDIR_FOR_PKG_CONFIG@ +includedir=@SAIL_INCLUDEDIR_FOR_PKG_CONFIG@/sail Name: libsail-manip Description: SAIL image manipulation library diff --git a/src/libsail/pkgconfig/libsail.pc.in b/src/libsail/pkgconfig/libsail.pc.in index 3c244a81..1b1582a3 100644 --- a/src/libsail/pkgconfig/libsail.pc.in +++ b/src/libsail/pkgconfig/libsail.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=@libdir_for_pc_file@ -includedir=@includedir_for_pc_file@/sail +libdir=@SAIL_LIBDIR_FOR_PKG_CONFIG@ +includedir=@SAIL_INCLUDEDIR_FOR_PKG_CONFIG@/sail Name: libsail Description: SAIL client library From 3fe2815f4902b9e9437a018d2ca29272f4172cd8 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 14:19:16 +0300 Subject: [PATCH 07/20] COMMON: Added bytes reverse functions --- CMakeLists.txt | 6 ++ cmake/sail_check_builtin_bswap.cmake | 33 +++++++++++ src/config.h.in | 9 +++ src/libsail-common/utils.c | 49 ++++++++++++++++ src/libsail-common/utils.h | 21 +++++++ src/sail-codecs/psd/helpers.c | 12 ++-- tests/sail-common/CMakeLists.txt | 1 + tests/sail-common/utils.c | 86 ++++++++++++++++++++++++++++ 8 files changed, 209 insertions(+), 8 deletions(-) create mode 100644 cmake/sail_check_builtin_bswap.cmake create mode 100644 tests/sail-common/utils.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e573ade6..577a5637 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ include(CMakePushCheckState) # set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}") include(sail_check_alignas) +include(sail_check_builtin_bswap) include(sail_check_c11_thread_local) include(sail_check_include) include(sail_check_init_once_execute_once) @@ -30,6 +31,7 @@ include(sail_test) # Check features # sail_check_alignas() +sail_check_builtin_bswap() # Check for required includes # @@ -308,6 +310,10 @@ message("* Build SDL example: ${SAIL_SDL_EXAMPLE}") message("* Build tests: ${SAIL_BUILD_TESTS}") message("* Install PDB files: ${SAIL_INSTALL_PDB}") message("*") +message("* SAIL_HAVE_BUILTIN_BSWAP16: ${SAIL_HAVE_BUILTIN_BSWAP16}") +message("* SAIL_HAVE_BUILTIN_BSWAP32: ${SAIL_HAVE_BUILTIN_BSWAP32}") +message("* SAIL_HAVE_BUILTIN_BSWAP64: ${SAIL_HAVE_BUILTIN_BSWAP64}") +message("*") message("* [*] - these options depend on other options, their values may be altered by CMake.") message("* For example, if you configure with -DBUILD_SHARED_LIBS=OFF -DSAIL_COMBINE_CODECS=OFF,") message("* the final value of SAIL_COMBINE_CODECS will be ON.") diff --git a/cmake/sail_check_builtin_bswap.cmake b/cmake/sail_check_builtin_bswap.cmake new file mode 100644 index 00000000..aef75ca8 --- /dev/null +++ b/cmake/sail_check_builtin_bswap.cmake @@ -0,0 +1,33 @@ +# Intended to be included by SAIL. +# +function(sail_check_builtin_bswap) + cmake_push_check_state(RESET) + check_c_source_compiles( + " + int main(int argc, char *argv[]) { + __builtin_bswap16(0); + return 0; + } + " + SAIL_HAVE_BUILTIN_BSWAP16 + ) + check_c_source_compiles( + " + int main(int argc, char *argv[]) { + __builtin_bswap32(0); + return 0; + } + " + SAIL_HAVE_BUILTIN_BSWAP32 + ) + check_c_source_compiles( + " + int main(int argc, char *argv[]) { + __builtin_bswap64(0); + return 0; + } + " + SAIL_HAVE_BUILTIN_BSWAP64 + ) + cmake_pop_check_state() +endfunction() diff --git a/src/config.h.in b/src/config.h.in index 522887fe..6077b407 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -75,4 +75,13 @@ /* Enable working in multi-threaded environments. */ #cmakedefine SAIL_THREAD_SAFE +/* Enable __builtin_bswap16. */ +#cmakedefine SAIL_HAVE_BUILTIN_BSWAP16 + +/* Enable __builtin_bswap32. */ +#cmakedefine SAIL_HAVE_BUILTIN_BSWAP32 + +/* Enable __builtin_bswap64. */ +#cmakedefine SAIL_HAVE_BUILTIN_BSWAP64 + #endif diff --git a/src/libsail-common/utils.c b/src/libsail-common/utils.c index 80d2ff6f..aea1c0e1 100644 --- a/src/libsail-common/utils.c +++ b/src/libsail-common/utils.c @@ -763,3 +763,52 @@ sail_status_t sail_data_to_hex_string(const void *data, size_t data_size, char * return SAIL_OK; } + +uint16_t sail_reverse_uint16_t(uint16_t v) +{ +#if defined(SAIL_HAVE_BUILTIN_BSWAP16) + return __builtin_bswap16(v); +#elif defined(_MSC_VER) + return _byteswap_ushort(v); +#else + const uint8_t *view = (uint8_t *)&v; + + return (view[0] << 8) | view[1]; +#endif +} + +uint32_t sail_reverse_uint32_t(uint32_t v) +{ +#if defined(SAIL_HAVE_BUILTIN_BSWAP32) + return __builtin_bswap32(v); +#elif defined(_MSC_VER) + return (uint32_t)_byteswap_ulong(v); +#else + const uint8_t *view = (uint8_t *)&v; + + return (view[0] << 24) | + (view[1] << 16) | + (view[2] << 8) | + (view[3] << 0); +#endif +} + +uint64_t sail_reverse_uint64_t(uint64_t v) +{ +#if defined(SAIL_HAVE_BUILTIN_BSWAP64) + return __builtin_bswap64(v); +#elif defined(_MSC_VER) + return (uint64_t)_byteswap_uint64(v); +#else + const uint8_t *view = (uint8_t *)&v; + + return ((uint64_t)view[0] << 56) | + ((uint64_t)view[1] << 48) | + ((uint64_t)view[2] << 40) | + ((uint64_t)view[3] << 32) | + (view[4] << 24) | + (view[5] << 16) | + (view[6] << 8) | + (view[7] << 0); +#endif +} diff --git a/src/libsail-common/utils.h b/src/libsail-common/utils.h index 5c95d972..ea739d1e 100644 --- a/src/libsail-common/utils.h +++ b/src/libsail-common/utils.h @@ -245,6 +245,27 @@ SAIL_EXPORT sail_status_t sail_data_into_hex_string(const void *data, size_t dat */ SAIL_EXPORT sail_status_t sail_data_to_hex_string(const void *data, size_t data_size, char **str); +/* + * Reverses the input value byte order. + * + * Returns the reversed value. + */ +SAIL_EXPORT uint16_t sail_reverse_uint16_t(uint16_t v); + +/* + * Reverses the input value byte order. + * + * Returns the reversed value. + */ +SAIL_EXPORT uint32_t sail_reverse_uint32_t(uint32_t v); + +/* + * Reverses the input value byte order. + * + * Returns the reversed value. + */ +SAIL_EXPORT uint64_t sail_reverse_uint64_t(uint64_t v); + /* extern "C" */ #ifdef __cplusplus } diff --git a/src/sail-codecs/psd/helpers.c b/src/sail-codecs/psd/helpers.c index 8eabe6e9..1ff542d3 100644 --- a/src/sail-codecs/psd/helpers.c +++ b/src/sail-codecs/psd/helpers.c @@ -29,22 +29,18 @@ sail_status_t psd_private_get_big_endian_uint16_t(struct sail_io *io, uint16_t *v) { - SAIL_TRY(io->strict_read(io->stream, v, sizeof(uint16_t))); + SAIL_TRY(io->strict_read(io->stream, v, sizeof(*v))); - unsigned char *view = (unsigned char *)v; - - *v = (view[0] << 8) + view[1]; + *v = sail_reverse_uint16_t(*v); return SAIL_OK; } sail_status_t psd_private_get_big_endian_uint32_t(struct sail_io *io, uint32_t *v) { - SAIL_TRY(io->strict_read(io->stream, v, sizeof(uint32_t))); - - unsigned char *view = (unsigned char *)v; + SAIL_TRY(io->strict_read(io->stream, v, sizeof(*v))); - *v = (view[0] << 24) + (view[1] << 16) + (view[2] << 8) + view[3]; + *v = sail_reverse_uint32_t(*v); return SAIL_OK; } diff --git a/tests/sail-common/CMakeLists.txt b/tests/sail-common/CMakeLists.txt index dd4cb5ef..109d39a5 100644 --- a/tests/sail-common/CMakeLists.txt +++ b/tests/sail-common/CMakeLists.txt @@ -9,4 +9,5 @@ sail_test(TARGET malloc SOURCES malloc.c LINK sail-com sail_test(TARGET meta-data SOURCES meta_data.c LINK sail-common sail-comparators) sail_test(TARGET palette SOURCES palette.c LINK sail-common) sail_test(TARGET save-options SOURCES save_options.c LINK sail-common) +sail_test(TARGET utils SOURCES utils.c LINK sail-common) sail_test(TARGET variant SOURCES variant.c LINK sail-common) diff --git a/tests/sail-common/utils.c b/tests/sail-common/utils.c new file mode 100644 index 00000000..cc40a5b6 --- /dev/null +++ b/tests/sail-common/utils.c @@ -0,0 +1,86 @@ +/* This file is part of SAIL (https://github.com/HappySeaFox/sail) + + Copyright (c) 2023 Dmitry Baryshev + + The MIT License + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include + +#include "sail-common.h" + +#include "munit.h" + +static MunitResult test_reverse_uint16_t(const MunitParameter params[], void *user_data) { + (void)params; + (void)user_data; + + munit_assert_uint16(sail_reverse_uint16_t(0), ==, 0); + munit_assert_uint16(sail_reverse_uint16_t(100), ==, 25600); + munit_assert_uint16(sail_reverse_uint16_t(1000), ==, 59395); + + return MUNIT_OK; +} + +static MunitResult test_reverse_uint32_t(const MunitParameter params[], void *user_data) { + (void)params; + (void)user_data; + + munit_assert_uint32(sail_reverse_uint32_t(0), ==, 0); + munit_assert_uint32(sail_reverse_uint32_t(100), ==, 1677721600); + munit_assert_uint32(sail_reverse_uint32_t(1000), ==, 3892510720); + munit_assert_uint32(sail_reverse_uint32_t(100000), ==, 2693136640); + + return MUNIT_OK; +} + +static MunitResult test_reverse_uint64_t(const MunitParameter params[], void *user_data) { + (void)params; + (void)user_data; + + munit_assert_uint64(sail_reverse_uint64_t(0), ==, 0); + munit_assert_uint64(sail_reverse_uint64_t(100), ==, 7205759403792793600); + munit_assert_uint64(sail_reverse_uint64_t(1000), ==, 16718206241729413120); + munit_assert_uint64(sail_reverse_uint64_t(100000), ==, 11566933792459325440); + munit_assert_uint64(sail_reverse_uint64_t(10000000000), ==, 64188750128742400); + + return MUNIT_OK; +} + +static MunitTest test_suite_tests[] = { + { (char *)"/reverse-uint16-t", test_reverse_uint16_t, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint32-t", test_reverse_uint32_t, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint64-t", test_reverse_uint64_t, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } +}; + +static const MunitSuite test_suite = { + (char *)"/utils", + test_suite_tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE +}; + +int main(int argc, char *argv[MUNIT_ARRAY_PARAM(argc + 1)]) { + return munit_suite_main(&test_suite, NULL, argc, argv); +} From 0ca3d154e321048fafd1c51a19d34fa24a3037b5 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 14:30:18 +0300 Subject: [PATCH 08/20] COMMON: Rename functions and drop _t --- src/libsail-common/utils.c | 6 +++--- src/libsail-common/utils.h | 6 +++--- src/sail-codecs/psd/helpers.c | 4 ++-- tests/sail-common/utils.c | 36 +++++++++++++++++------------------ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/libsail-common/utils.c b/src/libsail-common/utils.c index aea1c0e1..1260bd19 100644 --- a/src/libsail-common/utils.c +++ b/src/libsail-common/utils.c @@ -764,7 +764,7 @@ sail_status_t sail_data_to_hex_string(const void *data, size_t data_size, char * return SAIL_OK; } -uint16_t sail_reverse_uint16_t(uint16_t v) +uint16_t sail_reverse_uint16(uint16_t v) { #if defined(SAIL_HAVE_BUILTIN_BSWAP16) return __builtin_bswap16(v); @@ -777,7 +777,7 @@ uint16_t sail_reverse_uint16_t(uint16_t v) #endif } -uint32_t sail_reverse_uint32_t(uint32_t v) +uint32_t sail_reverse_uint32(uint32_t v) { #if defined(SAIL_HAVE_BUILTIN_BSWAP32) return __builtin_bswap32(v); @@ -793,7 +793,7 @@ uint32_t sail_reverse_uint32_t(uint32_t v) #endif } -uint64_t sail_reverse_uint64_t(uint64_t v) +uint64_t sail_reverse_uint64(uint64_t v) { #if defined(SAIL_HAVE_BUILTIN_BSWAP64) return __builtin_bswap64(v); diff --git a/src/libsail-common/utils.h b/src/libsail-common/utils.h index ea739d1e..b2f7a0e4 100644 --- a/src/libsail-common/utils.h +++ b/src/libsail-common/utils.h @@ -250,21 +250,21 @@ SAIL_EXPORT sail_status_t sail_data_to_hex_string(const void *data, size_t data_ * * Returns the reversed value. */ -SAIL_EXPORT uint16_t sail_reverse_uint16_t(uint16_t v); +SAIL_EXPORT uint16_t sail_reverse_uint16(uint16_t v); /* * Reverses the input value byte order. * * Returns the reversed value. */ -SAIL_EXPORT uint32_t sail_reverse_uint32_t(uint32_t v); +SAIL_EXPORT uint32_t sail_reverse_uint32(uint32_t v); /* * Reverses the input value byte order. * * Returns the reversed value. */ -SAIL_EXPORT uint64_t sail_reverse_uint64_t(uint64_t v); +SAIL_EXPORT uint64_t sail_reverse_uint64(uint64_t v); /* extern "C" */ #ifdef __cplusplus diff --git a/src/sail-codecs/psd/helpers.c b/src/sail-codecs/psd/helpers.c index 1ff542d3..781111b4 100644 --- a/src/sail-codecs/psd/helpers.c +++ b/src/sail-codecs/psd/helpers.c @@ -31,7 +31,7 @@ sail_status_t psd_private_get_big_endian_uint16_t(struct sail_io *io, uint16_t * { SAIL_TRY(io->strict_read(io->stream, v, sizeof(*v))); - *v = sail_reverse_uint16_t(*v); + *v = sail_reverse_uint16(*v); return SAIL_OK; } @@ -40,7 +40,7 @@ sail_status_t psd_private_get_big_endian_uint32_t(struct sail_io *io, uint32_t * { SAIL_TRY(io->strict_read(io->stream, v, sizeof(*v))); - *v = sail_reverse_uint32_t(*v); + *v = sail_reverse_uint32(*v); return SAIL_OK; } diff --git a/tests/sail-common/utils.c b/tests/sail-common/utils.c index cc40a5b6..25eaa1b0 100644 --- a/tests/sail-common/utils.c +++ b/tests/sail-common/utils.c @@ -29,46 +29,46 @@ #include "munit.h" -static MunitResult test_reverse_uint16_t(const MunitParameter params[], void *user_data) { +static MunitResult test_reverse_uint16(const MunitParameter params[], void *user_data) { (void)params; (void)user_data; - munit_assert_uint16(sail_reverse_uint16_t(0), ==, 0); - munit_assert_uint16(sail_reverse_uint16_t(100), ==, 25600); - munit_assert_uint16(sail_reverse_uint16_t(1000), ==, 59395); + munit_assert_uint16(sail_reverse_uint16(0), ==, 0); + munit_assert_uint16(sail_reverse_uint16(100), ==, 25600); + munit_assert_uint16(sail_reverse_uint16(1000), ==, 59395); return MUNIT_OK; } -static MunitResult test_reverse_uint32_t(const MunitParameter params[], void *user_data) { +static MunitResult test_reverse_uint32(const MunitParameter params[], void *user_data) { (void)params; (void)user_data; - munit_assert_uint32(sail_reverse_uint32_t(0), ==, 0); - munit_assert_uint32(sail_reverse_uint32_t(100), ==, 1677721600); - munit_assert_uint32(sail_reverse_uint32_t(1000), ==, 3892510720); - munit_assert_uint32(sail_reverse_uint32_t(100000), ==, 2693136640); + munit_assert_uint32(sail_reverse_uint32(0), ==, 0); + munit_assert_uint32(sail_reverse_uint32(100), ==, 1677721600); + munit_assert_uint32(sail_reverse_uint32(1000), ==, 3892510720); + munit_assert_uint32(sail_reverse_uint32(100000), ==, 2693136640); return MUNIT_OK; } -static MunitResult test_reverse_uint64_t(const MunitParameter params[], void *user_data) { +static MunitResult test_reverse_uint64(const MunitParameter params[], void *user_data) { (void)params; (void)user_data; - munit_assert_uint64(sail_reverse_uint64_t(0), ==, 0); - munit_assert_uint64(sail_reverse_uint64_t(100), ==, 7205759403792793600); - munit_assert_uint64(sail_reverse_uint64_t(1000), ==, 16718206241729413120); - munit_assert_uint64(sail_reverse_uint64_t(100000), ==, 11566933792459325440); - munit_assert_uint64(sail_reverse_uint64_t(10000000000), ==, 64188750128742400); + munit_assert_uint64(sail_reverse_uint64(0), ==, 0); + munit_assert_uint64(sail_reverse_uint64(100), ==, 7205759403792793600); + munit_assert_uint64(sail_reverse_uint64(1000), ==, 16718206241729413120); + munit_assert_uint64(sail_reverse_uint64(100000), ==, 11566933792459325440); + munit_assert_uint64(sail_reverse_uint64(10000000000), ==, 64188750128742400); return MUNIT_OK; } static MunitTest test_suite_tests[] = { - { (char *)"/reverse-uint16-t", test_reverse_uint16_t, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/reverse-uint32-t", test_reverse_uint32_t, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/reverse-uint64-t", test_reverse_uint64_t, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint16", test_reverse_uint16, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint32", test_reverse_uint32, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint64", test_reverse_uint64, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } }; From d84e50774810d0091a0d0d04771fee868f3b812f Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 14:43:03 +0300 Subject: [PATCH 09/20] TESTS: Added ull suffix --- tests/sail-common/utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/sail-common/utils.c b/tests/sail-common/utils.c index 25eaa1b0..654f7854 100644 --- a/tests/sail-common/utils.c +++ b/tests/sail-common/utils.c @@ -56,11 +56,11 @@ static MunitResult test_reverse_uint64(const MunitParameter params[], void *user (void)params; (void)user_data; - munit_assert_uint64(sail_reverse_uint64(0), ==, 0); - munit_assert_uint64(sail_reverse_uint64(100), ==, 7205759403792793600); - munit_assert_uint64(sail_reverse_uint64(1000), ==, 16718206241729413120); - munit_assert_uint64(sail_reverse_uint64(100000), ==, 11566933792459325440); - munit_assert_uint64(sail_reverse_uint64(10000000000), ==, 64188750128742400); + munit_assert_uint64(sail_reverse_uint64(0), ==, 0ull); + munit_assert_uint64(sail_reverse_uint64(100), ==, 7205759403792793600ull); + munit_assert_uint64(sail_reverse_uint64(1000), ==, 16718206241729413120ull); + munit_assert_uint64(sail_reverse_uint64(100000), ==, 11566933792459325440ull); + munit_assert_uint64(sail_reverse_uint64(10000000000), ==, 64188750128742400ull); return MUNIT_OK; } From 0e6f9c6e5a87b2f3d82cb578054a35ff92dc9c9f Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 15:30:39 +0300 Subject: [PATCH 10/20] SAIL: Create new cache variables for the bswap test results --- CMakeLists.txt | 6 +++--- cmake/sail_check_builtin_bswap.cmake | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 577a5637..7e444042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -310,9 +310,9 @@ message("* Build SDL example: ${SAIL_SDL_EXAMPLE}") message("* Build tests: ${SAIL_BUILD_TESTS}") message("* Install PDB files: ${SAIL_INSTALL_PDB}") message("*") -message("* SAIL_HAVE_BUILTIN_BSWAP16: ${SAIL_HAVE_BUILTIN_BSWAP16}") -message("* SAIL_HAVE_BUILTIN_BSWAP32: ${SAIL_HAVE_BUILTIN_BSWAP32}") -message("* SAIL_HAVE_BUILTIN_BSWAP64: ${SAIL_HAVE_BUILTIN_BSWAP64}") +message("* SAIL_HAVE_BUILTIN_BSWAP16: ${SAIL_HAVE_BUILTIN_BSWAP16_DISPLAY}") +message("* SAIL_HAVE_BUILTIN_BSWAP32: ${SAIL_HAVE_BUILTIN_BSWAP32_DISPLAY}") +message("* SAIL_HAVE_BUILTIN_BSWAP64: ${SAIL_HAVE_BUILTIN_BSWAP64_DISPLAY}") message("*") message("* [*] - these options depend on other options, their values may be altered by CMake.") message("* For example, if you configure with -DBUILD_SHARED_LIBS=OFF -DSAIL_COMBINE_CODECS=OFF,") diff --git a/cmake/sail_check_builtin_bswap.cmake b/cmake/sail_check_builtin_bswap.cmake index aef75ca8..4c1c77be 100644 --- a/cmake/sail_check_builtin_bswap.cmake +++ b/cmake/sail_check_builtin_bswap.cmake @@ -11,6 +11,18 @@ function(sail_check_builtin_bswap) " SAIL_HAVE_BUILTIN_BSWAP16 ) + # This variable is used for displaying the test result with message() + # in the main CMake file. + # + # The cache SAIL_HAVE_BUILTIN_BSWAP16 variable that is created by the test + # has a value of 1 or an empty string which is not a user friendly value. + # + if (SAIL_HAVE_BUILTIN_BSWAP16) + set(SAIL_HAVE_BUILTIN_BSWAP16_DISPLAY ON CACHE INTERNAL "") + else() + set(SAIL_HAVE_BUILTIN_BSWAP16_DISPLAY OFF CACHE INTERNAL "") + endif() + check_c_source_compiles( " int main(int argc, char *argv[]) { @@ -20,6 +32,12 @@ function(sail_check_builtin_bswap) " SAIL_HAVE_BUILTIN_BSWAP32 ) + if (SAIL_HAVE_BUILTIN_BSWAP32) + set(SAIL_HAVE_BUILTIN_BSWAP32_DISPLAY ON CACHE INTERNAL "") + else() + set(SAIL_HAVE_BUILTIN_BSWAP32_DISPLAY OFF CACHE INTERNAL "") + endif() + check_c_source_compiles( " int main(int argc, char *argv[]) { @@ -29,5 +47,10 @@ function(sail_check_builtin_bswap) " SAIL_HAVE_BUILTIN_BSWAP64 ) + if (SAIL_HAVE_BUILTIN_BSWAP64) + set(SAIL_HAVE_BUILTIN_BSWAP64_DISPLAY ON CACHE INTERNAL "") + else() + set(SAIL_HAVE_BUILTIN_BSWAP64_DISPLAY OFF CACHE INTERNAL "") + endif() cmake_pop_check_state() endfunction() From fe8aa1fa969b89ffffb5642c9e72ceee2fd83154 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 17:01:18 +0300 Subject: [PATCH 11/20] BINDINGS/C++: Added reverse_bytes() --- src/bindings/c++/utils-c++.cpp | 18 +++++++ src/bindings/c++/utils-c++.h | 9 ++++ tests/bindings/c++/CMakeLists.txt | 1 + tests/bindings/c++/utils.cpp | 84 +++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 tests/bindings/c++/utils.cpp diff --git a/src/bindings/c++/utils-c++.cpp b/src/bindings/c++/utils-c++.cpp index 948b63a6..e41e1a0a 100644 --- a/src/bindings/c++/utils-c++.cpp +++ b/src/bindings/c++/utils-c++.cpp @@ -91,4 +91,22 @@ sail_status_t read_io_contents(sail::abstract_io &abstract_io, sail::arbitrary_d return SAIL_OK; } +template<> +SAIL_EXPORT std::uint16_t reverse_bytes<>(std::uint16_t v) +{ + return sail_reverse_uint16(v); +} + +template<> +SAIL_EXPORT std::uint32_t reverse_bytes<>(std::uint32_t v) +{ + return sail_reverse_uint32(v); +} + +template<> +SAIL_EXPORT std::uint64_t reverse_bytes<>(std::uint64_t v) +{ + return sail_reverse_uint64(v); +} + } diff --git a/src/bindings/c++/utils-c++.h b/src/bindings/c++/utils-c++.h index 021fb468..7ceb3b20 100644 --- a/src/bindings/c++/utils-c++.h +++ b/src/bindings/c++/utils-c++.h @@ -92,6 +92,15 @@ SAIL_EXPORT sail_status_t read_file_contents(const std::string &path, sail::arbi */ SAIL_EXPORT sail_status_t read_io_contents(sail::abstract_io &abstract_io, sail::arbitrary_data *contents); +/* + * Reverses the input value byte order. Only std::uint16_t, std::uint32_t, and std::uint64_t + * types are supported. Other types will fail to link. + * + * Returns the reversed value. + */ +template +T reverse_bytes(T v); + } #endif diff --git a/tests/bindings/c++/CMakeLists.txt b/tests/bindings/c++/CMakeLists.txt index 02216271..33a9e303 100644 --- a/tests/bindings/c++/CMakeLists.txt +++ b/tests/bindings/c++/CMakeLists.txt @@ -6,4 +6,5 @@ sail_test(TARGET meta-data-c++ SOURCES meta_data.cpp LINK sail-c++) sail_test(TARGET palette-c++ SOURCES palette.cpp LINK sail-c++) sail_test(TARGET save-features-c++ SOURCES save_features.cpp LINK sail-c++) sail_test(TARGET save-options-c++ SOURCES save_options.cpp LINK sail-c++) +sail_test(TARGET utils-c++ SOURCES utils.cpp LINK sail-c++) sail_test(TARGET variant-c++ SOURCES variant.cpp LINK sail-c++) diff --git a/tests/bindings/c++/utils.cpp b/tests/bindings/c++/utils.cpp new file mode 100644 index 00000000..f80742f7 --- /dev/null +++ b/tests/bindings/c++/utils.cpp @@ -0,0 +1,84 @@ +/* This file is part of SAIL (https://github.com/HappySeaFox/sail) + + Copyright (c) 2023 Dmitry Baryshev + + The MIT License + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "sail-c++.h" + +#include "munit.h" + +static MunitResult test_reverse_uint16(const MunitParameter params[], void *user_data) { + (void)params; + (void)user_data; + + munit_assert_uint16(sail::reverse_bytes((std::uint16_t)0), ==, 0); + munit_assert_uint16(sail::reverse_bytes((std::uint16_t)100), ==, 25600); + munit_assert_uint16(sail::reverse_bytes((std::uint16_t)1000), ==, 59395); + + return MUNIT_OK; +} + +static MunitResult test_reverse_uint32(const MunitParameter params[], void *user_data) { + (void)params; + (void)user_data; + + munit_assert_uint32(sail::reverse_bytes((std::uint32_t)0), ==, 0); + munit_assert_uint32(sail::reverse_bytes((std::uint32_t)100), ==, 1677721600); + munit_assert_uint32(sail::reverse_bytes((std::uint32_t)1000), ==, 3892510720); + munit_assert_uint32(sail::reverse_bytes((std::uint32_t)100000), ==, 2693136640); + + return MUNIT_OK; +} + +static MunitResult test_reverse_uint64(const MunitParameter params[], void *user_data) { + (void)params; + (void)user_data; + + munit_assert_uint64(sail::reverse_bytes((std::uint64_t)0ull), ==, 0ull); + munit_assert_uint64(sail::reverse_bytes((std::uint64_t)100ull), ==, 7205759403792793600ull); + munit_assert_uint64(sail::reverse_bytes((std::uint64_t)1000ull), ==, 16718206241729413120ull); + munit_assert_uint64(sail::reverse_bytes((std::uint64_t)100000ull), ==, 11566933792459325440ull); + munit_assert_uint64(sail::reverse_bytes((std::uint64_t)10000000000ull), ==, 64188750128742400ull); + + return MUNIT_OK; +} + +static MunitTest test_suite_tests[] = { + { (char *)"/reverse-uint16", test_reverse_uint16, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint32", test_reverse_uint32, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { (char *)"/reverse-uint64", test_reverse_uint64, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + + { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } +}; + +static const MunitSuite test_suite = { + (char *)"/bindings/c++/utils", + test_suite_tests, + NULL, + 1, + MUNIT_SUITE_OPTION_NONE +}; + +int main(int argc, char *argv[MUNIT_ARRAY_PARAM(argc + 1)]) { + return munit_suite_main(&test_suite, NULL, argc, argv); +} From 9f3d0969648041a40cade9a981408ecd4e18b5aa Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 17:02:11 +0300 Subject: [PATCH 12/20] TESTS: Added more ull suffixes --- tests/sail-common/utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/sail-common/utils.c b/tests/sail-common/utils.c index 654f7854..7616e16d 100644 --- a/tests/sail-common/utils.c +++ b/tests/sail-common/utils.c @@ -56,11 +56,11 @@ static MunitResult test_reverse_uint64(const MunitParameter params[], void *user (void)params; (void)user_data; - munit_assert_uint64(sail_reverse_uint64(0), ==, 0ull); - munit_assert_uint64(sail_reverse_uint64(100), ==, 7205759403792793600ull); - munit_assert_uint64(sail_reverse_uint64(1000), ==, 16718206241729413120ull); - munit_assert_uint64(sail_reverse_uint64(100000), ==, 11566933792459325440ull); - munit_assert_uint64(sail_reverse_uint64(10000000000), ==, 64188750128742400ull); + munit_assert_uint64(sail_reverse_uint64(0ull), ==, 0ull); + munit_assert_uint64(sail_reverse_uint64(100ull), ==, 7205759403792793600ull); + munit_assert_uint64(sail_reverse_uint64(1000ull), ==, 16718206241729413120ull); + munit_assert_uint64(sail_reverse_uint64(100000ull), ==, 11566933792459325440ull); + munit_assert_uint64(sail_reverse_uint64(10000000000ull), ==, 64188750128742400ull); return MUNIT_OK; } From 8e0f7a10ba08b7d800b4030036fbca067fbd81ae Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Tue, 24 Jan 2023 17:02:51 +0300 Subject: [PATCH 13/20] TESTS: Remove unused include string.h --- tests/sail-common/utils.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/sail-common/utils.c b/tests/sail-common/utils.c index 7616e16d..f3183d64 100644 --- a/tests/sail-common/utils.c +++ b/tests/sail-common/utils.c @@ -23,8 +23,6 @@ SOFTWARE. */ -#include - #include "sail-common.h" #include "munit.h" From 58ca6d50ae9db3b81a6df641223b6b403caa7c58 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Wed, 25 Jan 2023 16:02:18 +0300 Subject: [PATCH 14/20] BINDINGS/C++: Added more types to reverse_bytes() --- src/bindings/c++/utils-c++.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/c++/utils-c++.h b/src/bindings/c++/utils-c++.h index 7ceb3b20..96e591d0 100644 --- a/src/bindings/c++/utils-c++.h +++ b/src/bindings/c++/utils-c++.h @@ -93,8 +93,8 @@ SAIL_EXPORT sail_status_t read_file_contents(const std::string &path, sail::arbi SAIL_EXPORT sail_status_t read_io_contents(sail::abstract_io &abstract_io, sail::arbitrary_data *contents); /* - * Reverses the input value byte order. Only std::uint16_t, std::uint32_t, and std::uint64_t - * types are supported. Other types will fail to link. + * Reverses the input value byte order. Only std::uint16_t, std::uint32_t, std::uint64_t, + * and their equivalent types are supported. Other types will fail to link. * * Returns the reversed value. */ From f2c9d06926631043389ecf6d535df943c5b170f8 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Thu, 26 Jan 2023 11:19:07 +0300 Subject: [PATCH 15/20] SAIL: Update SAIL_COMBINE_CODECS docs --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87324640..74b154cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,8 @@ option(SAIL_INSTALL_PDB "Install PDB files along with libraries." ON) set(SAIL_ONLY_CODECS "" CACHE STRING "Forcefully enable only the codecs specified in this ';'-separated list and disable the rest. \ If an enabled codec fails to find its dependencies, the configuration process fails.") option(BUILD_SHARED_LIBS "Build shared libs. When disabled, sets SAIL_COMBINE_CODECS to ON automatically." ON) -cmake_dependent_option(SAIL_COMBINE_CODECS "Combine all codecs into a single library." OFF "BUILD_SHARED_LIBS" ON) +cmake_dependent_option(SAIL_COMBINE_CODECS "Combine all codecs into a single library. When disabled, all codecs are implemented as \ +dynamically loaded plugins." OFF "BUILD_SHARED_LIBS" 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) From 7f6547a101e9ae8873e08ccaac56185be4d1fed7 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Thu, 26 Jan 2023 11:25:46 +0300 Subject: [PATCH 16/20] LIBSAIL: Update flag docs --- src/libsail/context.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libsail/context.h b/src/libsail/context.h index 857cf0f5..4af641c1 100644 --- a/src/libsail/context.h +++ b/src/libsail/context.h @@ -56,7 +56,10 @@ extern "C" { enum SailInitFlags { /* - * Preload all codecs in sail_init_with_flags(). Codecs are lazy-loaded by default. + * When SAIL is compiled with SAIL_COMBINE_CODECS disabled (default), + * preload all codecs in sail_init_with_flags(). Codecs are lazy-loaded + * by default. When SAIL is compiled with SAIL_COMBINE_CODECS enabled, + * this option has no effect. */ SAIL_FLAG_PRELOAD_CODECS = 1 << 0, }; From a58cf9ebdf4b23c7c285ddc32cdb851cf550c216 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Thu, 26 Jan 2023 11:59:04 +0300 Subject: [PATCH 17/20] DOC: Update docs on codecs --- FAQ.md | 19 ++++++++--------- src/bindings/c++/context-c++.h | 35 +++++++++++++++++--------------- src/libsail/context.h | 37 +++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/FAQ.md b/FAQ.md index 39d1844b..02253d29 100644 --- a/FAQ.md +++ b/FAQ.md @@ -19,10 +19,10 @@ Table of Contents * [SAIL\_COMBINE\_CODECS is OFF](#sail_combine_codecs-is-off) * [SAIL\_COMBINE\_CODECS is ON](#sail_combine_codecs-is-on) * [How does SAIL look for codecs?](#how-does-sail-look-for-codecs) - * [VCPKG port on any platform](#vcpkg-port-on-any-platform) - * [Standalone build or bundle, both compiled with SAIL\_COMBINE\_CODECS=ON](#standalone-build-or-bundle-both-compiled-with-sail_combine_codecson) - * [Windows standalone build or bundle, both compiled with SAIL\_COMBINE\_CODECS=OFF (the default)](#windows-standalone-build-or-bundle-both-compiled-with-sail_combine_codecsoff-the-default) - * [Unix including macOS (standalone build), compiled with SAIL\_COMBINE\_CODECS=OFF (the default)](#unix-including-macos-standalone-build-compiled-with-sail_combine_codecsoff-the-default) + + [VCPKG port on any platform](#vcpkg-port-on-any-platform) + + [Manually compiled on any platform with SAIL\_COMBINE\_CODECS=ON](#manually-compiled-on-any-platform-with-sail_combine_codecson) + + [Manually compiled on Windows with SAIL\_COMBINE\_CODECS=OFF (the default)](#manually-compiled-on-windows-with-sail_combine_codecsoff-the-default) + + [Manually compiled on Unix (including macOS) SAIL\_COMBINE\_CODECS=OFF (the default)](#manually-compiled-on-unix-including-macos-sail_combine_codecsoff-the-default) * [How can I point SAIL to my custom codecs?](#how-can-i-point-sail-to-my-custom-codecs) * [I'd like to reorganize the standard SAIL folder layout on Windows (for standalone build or bundle)](#id-like-to-reorganize-the-standard-sail-folder-layout-on-windows-for-standalone-build-or-bundle) * [Describe the memory management techniques implemented in SAIL](#describe-the-memory-management-techniques-implemented-in-sail) @@ -151,16 +151,17 @@ Codecs path search algorithm (first found path wins): Codecs are combined into a dynamically linked library, so no need to search them. -### Standalone build or bundle, both compiled with SAIL_COMBINE_CODECS=ON +### Manually compiled on any platform with SAIL_COMBINE_CODECS=ON -Same to VCPKG port. +Codecs are combined into a dynamically linked library, so no need to search them. -### Windows standalone build or bundle, both compiled with SAIL_COMBINE_CODECS=OFF (the default) +### Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) 1. `SAIL_CODECS_PATH` environment variable 2. `\lib\sail\codecs` 3. Hardcoded `SAIL_CODECS_PATH` in config.h -### Unix including macOS (standalone build), compiled with SAIL_COMBINE_CODECS=OFF (the default) +### Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) + 1. `SAIL_CODECS_PATH` environment variable 2. Hardcoded `SAIL_CODECS_PATH` in config.h @@ -181,7 +182,7 @@ On other platforms, `SAIL_THIRD_PARTY_CODECS_PATH/lib` is added to `LD_LIBRARY_P If `SAIL_THIRD_PARTY_CODECS_PATH` is `OFF`, loading custom codecs is disabled. -## I'd like to reorganize the standard SAIL folder layout on Windows (for standalone build or bundle) +## I'd like to reorganize the standard SAIL folder layout on Windows You can surely do that. However, with the standard layout SAIL detects the codecs' location automatically. If you reorganize the standard SAIL folder layout, you'll need to specify the new codecs' location by diff --git a/src/bindings/c++/context-c++.h b/src/bindings/c++/context-c++.h index 238e342f..9acc0659 100644 --- a/src/bindings/c++/context-c++.h +++ b/src/bindings/c++/context-c++.h @@ -62,7 +62,10 @@ class SAIL_EXPORT context /* * Initializes a new SAIL global static context with default flags. Does nothing - * if a global static context already exists. See also init() with flags. + * if a global context already exists. See also init(flags). + * + * In general, SAIL initializes a new global static context automatically. You can use + * this method if you want to initialize it explicitly for some reason. * * Returns SAIL_OK on success. */ @@ -79,24 +82,24 @@ class SAIL_EXPORT context * Codecs path search algorithm (first found path wins): * * 1. VCPKG port on any platform - * Codecs are combined into a dynamically linked library, so no need to search them. + * Codecs are combined into a dynamically linked library, so no need to search them. * - * 2. Standalone build or bundle, both compiled with SAIL_COMBINE_CODECS=ON - * Same to VCPKG port. + * 2. Manually compiled on any platform with SAIL_COMBINE_CODECS=ON + * Codecs are combined into a dynamically linked library, so no need to search them. * - * 3. Windows standalone build or bundle, both compiled with SAIL_COMBINE_CODECS=OFF (the default) - * 1. SAIL_CODECS_PATH environment variable - * 2. \lib\sail\codecs - * 3. Hardcoded SAIL_CODECS_PATH in config.h + * 3. Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) + * 1. SAIL_CODECS_PATH environment variable + * 2. \lib\sail\codecs + * 3. Hardcoded SAIL_CODECS_PATH in config.h * - * 4. Unix including macOS (standalone build), compiled with SAIL_COMBINE_CODECS=OFF (the default) - * 1. SAIL_CODECS_PATH environment variable - * 2. Hardcoded SAIL_CODECS_PATH in config.h + * 4. Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) + * 1. SAIL_CODECS_PATH environment variable + * 2. Hardcoded SAIL_CODECS_PATH in config.h * - * /lib is added to LD_LIBRARY_PATH. + * /lib is added to LD_LIBRARY_PATH. * * Additionally, SAIL_THIRD_PARTY_CODECS_PATH environment variable with a list of ';'-separated paths - * is searched if SAIL_THIRD_PARTY_CODECS_PATH is enabled in CMake, (the default) so you can load + * is searched if SAIL_THIRD_PARTY_CODECS_PATH is enabled in CMake (the default), so you can load * your own codecs from there. * * Returns SAIL_OK on success. @@ -112,7 +115,7 @@ class SAIL_EXPORT context * Warning: Make sure no loading or saving operations are in progress before calling unload_codecs(). * Failure to do so may lead to a crash. * - * Typical usage: This is a standalone method that can be called at any time. + * Typical usage: This is a standalone method that can be called at any time (with the restriction above). * * Returns SAIL_OK on success. */ @@ -123,14 +126,14 @@ class SAIL_EXPORT context * loading or saving functions. * * Unloads all codecs. All pointers to codec info objects, load and save features, and codecs - * get invalidated. Using them after calling finish() will lead to a crash. + * get invalidated. Using them after calling finish() may lead to a crash. * * It's possible to initialize a new global static context afterwards, implicitly or explicitly. * * Warning: Make sure no loading or saving operations are in progress before calling finish(). * Failure to do so may lead to a crash. * - * Typical usage: This is a standalone method that can be called at any time. + * Typical usage: This is a standalone method that can be called at any time (with the restriction above). */ static void finish(); }; diff --git a/src/libsail/context.h b/src/libsail/context.h index 4af641c1..62c3e13b 100644 --- a/src/libsail/context.h +++ b/src/libsail/context.h @@ -56,7 +56,7 @@ extern "C" { enum SailInitFlags { /* - * When SAIL is compiled with SAIL_COMBINE_CODECS disabled (default), + * When SAIL is compiled with SAIL_COMBINE_CODECS disabled (the default), * preload all codecs in sail_init_with_flags(). Codecs are lazy-loaded * by default. When SAIL is compiled with SAIL_COMBINE_CODECS enabled, * this option has no effect. @@ -68,6 +68,9 @@ enum SailInitFlags { * Initializes a new SAIL global static context with default flags. Does nothing * if a global context already exists. See also sail_init_with_flags(). * + * In general, SAIL initializes a new global static context automatically. You can use + * this function if you want to initialize it explicitly for some reason. + * * Returns SAIL_OK on success. */ SAIL_EXPORT sail_status_t sail_init(void); @@ -77,30 +80,30 @@ SAIL_EXPORT sail_status_t sail_init(void); * if a global context already exists. Builds a list of available SAIL codecs. See SailInitFlags. * * Use this method when you need specific features like preloading codecs. If you don't need - * specific features, using this method is optional. All loading or saving functions allocate + * specific features, using this function is optional. All loading or saving functions allocate * a global static context implicitly when they need it and when it doesn't exist yet. * * Codecs path search algorithm (first found path wins): * * 1. VCPKG port on any platform - * Codecs are combined into a dynamically linked library, so no need to search them. + * Codecs are combined into a dynamically linked library, so no need to search them. * - * 2. Standalone build or bundle, both compiled with SAIL_COMBINE_CODECS=ON - * Same to VCPKG port. + * 2. Manually compiled on any platform with SAIL_COMBINE_CODECS=ON + * Codecs are combined into a dynamically linked library, so no need to search them. * - * 3. Windows standalone build or bundle, both compiled with SAIL_COMBINE_CODECS=OFF (the default) - * 1. SAIL_CODECS_PATH environment variable - * 2. \lib\sail\codecs - * 3. Hardcoded SAIL_CODECS_PATH in config.h + * 3. Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) + * 1. SAIL_CODECS_PATH environment variable + * 2. \lib\sail\codecs + * 3. Hardcoded SAIL_CODECS_PATH in config.h * - * 4. Unix including macOS (standalone build), compiled with SAIL_COMBINE_CODECS=OFF (the default) - * 1. SAIL_CODECS_PATH environment variable - * 2. Hardcoded SAIL_CODECS_PATH in config.h + * 4. Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) + * 1. SAIL_CODECS_PATH environment variable + * 2. Hardcoded SAIL_CODECS_PATH in config.h * - * /lib is added to LD_LIBRARY_PATH. + * /lib is added to LD_LIBRARY_PATH. * * Additionally, SAIL_THIRD_PARTY_CODECS_PATH environment variable with a list of ';'-separated paths - * is searched if SAIL_THIRD_PARTY_CODECS_PATH is enabled in CMake, (the default) so you can load + * is searched if SAIL_THIRD_PARTY_CODECS_PATH is enabled in CMake (the default), so you can load * your own codecs from there. * * Returns SAIL_OK on success. @@ -116,7 +119,7 @@ SAIL_EXPORT sail_status_t sail_init_with_flags(int flags); * Warning: Make sure no loading or saving operations are in progress before calling sail_unload_codecs(). * Failure to do so may lead to a crash. * - * Typical usage: This is a standalone function that can be called at any time. + * Typical usage: This is a standalone function that can be called at any time (with the restriction above). * * Returns SAIL_OK on success. */ @@ -127,12 +130,14 @@ SAIL_EXPORT sail_status_t sail_unload_codecs(void); * loading or saving functions. * * Unloads all codecs. All pointers to codec info objects, load and save features, and codecs - * get invalidated. Using them after calling sail_finish() will lead to a crash. + * get invalidated. Using them after calling sail_finish() may lead to a crash. * * It's possible to initialize a new global static context afterwards, implicitly or explicitly. * * Warning: Make sure no loading or saving operations are in progress before calling sail_finish(). * Failure to do so may lead to a crash. + * + * Typical usage: This is a standalone function that can be called at any time (with the restriction above). */ SAIL_EXPORT void sail_finish(void); From cca1b33fb52912a7a0c3ae585220799791672e23 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Thu, 26 Jan 2023 12:04:21 +0300 Subject: [PATCH 18/20] DOC: Update docs on codecs --- FAQ.md | 5 +++++ src/bindings/c++/context-c++.h | 11 +++++++---- src/libsail/context.h | 11 +++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/FAQ.md b/FAQ.md index 02253d29..14ee6a65 100644 --- a/FAQ.md +++ b/FAQ.md @@ -19,6 +19,7 @@ Table of Contents * [SAIL\_COMBINE\_CODECS is OFF](#sail_combine_codecs-is-off) * [SAIL\_COMBINE\_CODECS is ON](#sail_combine_codecs-is-on) * [How does SAIL look for codecs?](#how-does-sail-look-for-codecs) + + [Conan recipe on any platform](#conan-recipe-on-any-platform) + [VCPKG port on any platform](#vcpkg-port-on-any-platform) + [Manually compiled on any platform with SAIL\_COMBINE\_CODECS=ON](#manually-compiled-on-any-platform-with-sail_combine_codecson) + [Manually compiled on Windows with SAIL\_COMBINE\_CODECS=OFF (the default)](#manually-compiled-on-windows-with-sail_combine_codecsoff-the-default) @@ -147,6 +148,10 @@ All codecs get loaded on application startup. Codecs path search algorithm (first found path wins): +### Conan recipe on any platform + +Codecs are combined into a dynamically linked library, so no need to search them. + ### VCPKG port on any platform Codecs are combined into a dynamically linked library, so no need to search them. diff --git a/src/bindings/c++/context-c++.h b/src/bindings/c++/context-c++.h index 9acc0659..ccab4ac7 100644 --- a/src/bindings/c++/context-c++.h +++ b/src/bindings/c++/context-c++.h @@ -81,18 +81,21 @@ class SAIL_EXPORT context * * Codecs path search algorithm (first found path wins): * - * 1. VCPKG port on any platform + * 1. Conan recipe on any platform * Codecs are combined into a dynamically linked library, so no need to search them. * - * 2. Manually compiled on any platform with SAIL_COMBINE_CODECS=ON + * 2. VCPKG port on any platform * Codecs are combined into a dynamically linked library, so no need to search them. * - * 3. Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) + * 3. Manually compiled on any platform with SAIL_COMBINE_CODECS=ON + * Codecs are combined into a dynamically linked library, so no need to search them. + * + * 4. Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) * 1. SAIL_CODECS_PATH environment variable * 2. \lib\sail\codecs * 3. Hardcoded SAIL_CODECS_PATH in config.h * - * 4. Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) + * 5. Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) * 1. SAIL_CODECS_PATH environment variable * 2. Hardcoded SAIL_CODECS_PATH in config.h * diff --git a/src/libsail/context.h b/src/libsail/context.h index 62c3e13b..fba56d34 100644 --- a/src/libsail/context.h +++ b/src/libsail/context.h @@ -85,18 +85,21 @@ SAIL_EXPORT sail_status_t sail_init(void); * * Codecs path search algorithm (first found path wins): * - * 1. VCPKG port on any platform + * 1. Conan recipe on any platform * Codecs are combined into a dynamically linked library, so no need to search them. * - * 2. Manually compiled on any platform with SAIL_COMBINE_CODECS=ON + * 2. VCPKG port on any platform * Codecs are combined into a dynamically linked library, so no need to search them. * - * 3. Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) + * 3. Manually compiled on any platform with SAIL_COMBINE_CODECS=ON + * Codecs are combined into a dynamically linked library, so no need to search them. + * + * 4. Manually compiled on Windows with SAIL_COMBINE_CODECS=OFF (the default) * 1. SAIL_CODECS_PATH environment variable * 2. \lib\sail\codecs * 3. Hardcoded SAIL_CODECS_PATH in config.h * - * 4. Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) + * 5. Manually compiled on Unix (including macOS) SAIL_COMBINE_CODECS=OFF (the default) * 1. SAIL_CODECS_PATH environment variable * 2. Hardcoded SAIL_CODECS_PATH in config.h * From 1dc790024bb5b9ae892c100739d6cfded029cf62 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Thu, 23 Feb 2023 13:50:21 +0300 Subject: [PATCH 19/20] SAIL: Require CMake 3.12 to link against object libraries --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74b154cf..b0eee775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(SAIL VERSION 0.9.0 DESCRIPTION "Squirrel Abstract Image Library" From 00c505689f7182d79e65c6175d1ff539a2593250 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshev Date: Thu, 23 Feb 2023 13:51:43 +0300 Subject: [PATCH 20/20] TIFF: Fix empty list of compressions in VCPKG mode --- src/sail-codecs/tiff/CMakeLists.txt | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/sail-codecs/tiff/CMakeLists.txt b/src/sail-codecs/tiff/CMakeLists.txt index 8d21f426..c4d74895 100644 --- a/src/sail-codecs/tiff/CMakeLists.txt +++ b/src/sail-codecs/tiff/CMakeLists.txt @@ -96,28 +96,28 @@ foreach (tiff_codec IN LISTS TIFF_CODECS) HAVE_TIFF_WRITE_${tiff_codec} ) cmake_pop_check_state() + endif() - if (HAVE_TIFF_WRITE_${tiff_codec}) - # Match the SAIL namings - # - string(REPLACE "_" "-" tiff_codec_fixed ${tiff_codec}) - string(REPLACE "CCITTRLE" "CCITT-RLE" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "CCITTRLEW" "CCITT-RLEW" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8BL" "IT8-BL" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8CTPAD" "IT8-CTPAD" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8LW" "IT8-LW" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "IT8MP" "IT8-MP" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "JP2000" "JPEG-2000" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "JXL" "JPEG-XL" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "PIXARLOG" "PIXAR-LOG" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "PIXARFILM" "PIXAR-FILM" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "SGILOG24" "SGI-LOG24" tiff_codec_fixed ${tiff_codec_fixed}) - string(REPLACE "SGILOG" "SGI-LOG" tiff_codec_fixed ${tiff_codec_fixed}) - - # Used in .codec.info - # - list(APPEND TIFF_CODEC_INFO_COMPRESSIONS ${tiff_codec_fixed}) - endif() + if (HAVE_TIFF_WRITE_${tiff_codec}) + # Match the SAIL namings + # + string(REPLACE "_" "-" tiff_codec_fixed ${tiff_codec}) + string(REPLACE "CCITTRLE" "CCITT-RLE" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "CCITTRLEW" "CCITT-RLEW" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8BL" "IT8-BL" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8CTPAD" "IT8-CTPAD" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8LW" "IT8-LW" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "IT8MP" "IT8-MP" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "JP2000" "JPEG-2000" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "JXL" "JPEG-XL" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "PIXARLOG" "PIXAR-LOG" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "PIXARFILM" "PIXAR-FILM" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "SGILOG24" "SGI-LOG24" tiff_codec_fixed ${tiff_codec_fixed}) + string(REPLACE "SGILOG" "SGI-LOG" tiff_codec_fixed ${tiff_codec_fixed}) + + # Used in .codec.info + # + list(APPEND TIFF_CODEC_INFO_COMPRESSIONS ${tiff_codec_fixed}) endif() endforeach()