diff --git a/src/sail-codecs/png/helpers.c b/src/sail-codecs/png/helpers.c index 90ac5cb7..5156ed60 100644 --- a/src/sail-codecs/png/helpers.c +++ b/src/sail-codecs/png/helpers.c @@ -154,7 +154,6 @@ enum SailPixelFormat png_private_png_color_type_to_pixel_format(int color_type, } break; } - case PNG_COLOR_TYPE_GRAY_ALPHA: { switch (bit_depth) { case 8: return SAIL_PIXEL_FORMAT_BPP16_GRAYSCALE_ALPHA; @@ -162,7 +161,6 @@ enum SailPixelFormat png_private_png_color_type_to_pixel_format(int color_type, } break; } - case PNG_COLOR_TYPE_PALETTE: { switch (bit_depth) { case 1: return SAIL_PIXEL_FORMAT_BPP1_INDEXED; @@ -172,7 +170,6 @@ enum SailPixelFormat png_private_png_color_type_to_pixel_format(int color_type, } break; } - case PNG_COLOR_TYPE_RGB: { switch (bit_depth) { case 8: return SAIL_PIXEL_FORMAT_BPP24_RGB; @@ -180,7 +177,6 @@ enum SailPixelFormat png_private_png_color_type_to_pixel_format(int color_type, } break; } - case PNG_COLOR_TYPE_RGB_ALPHA: { switch (bit_depth) { case 8: return SAIL_PIXEL_FORMAT_BPP32_RGBA; @@ -204,39 +200,68 @@ sail_status_t png_private_pixel_format_to_png_color_type(enum SailPixelFormat pi *bit_depth = 1; return SAIL_OK; } - case SAIL_PIXEL_FORMAT_BPP2_INDEXED: { *color_type = PNG_COLOR_TYPE_PALETTE; *bit_depth = 2; return SAIL_OK; } - case SAIL_PIXEL_FORMAT_BPP4_INDEXED: { *color_type = PNG_COLOR_TYPE_PALETTE; *bit_depth = 4; return SAIL_OK; } - case SAIL_PIXEL_FORMAT_BPP8_INDEXED: { *color_type = PNG_COLOR_TYPE_PALETTE; *bit_depth = 8; return SAIL_OK; } - + case SAIL_PIXEL_FORMAT_BPP1_GRAYSCALE: { + *color_type = PNG_COLOR_TYPE_GRAY; + *bit_depth = 1; + return SAIL_OK; + } + case SAIL_PIXEL_FORMAT_BPP2_GRAYSCALE: { + *color_type = PNG_COLOR_TYPE_GRAY; + *bit_depth = 2; + return SAIL_OK; + } + case SAIL_PIXEL_FORMAT_BPP4_GRAYSCALE: { + *color_type = PNG_COLOR_TYPE_GRAY; + *bit_depth = 4; + return SAIL_OK; + } + case SAIL_PIXEL_FORMAT_BPP8_GRAYSCALE: { + *color_type = PNG_COLOR_TYPE_GRAY; + *bit_depth = 8; + return SAIL_OK; + } + case SAIL_PIXEL_FORMAT_BPP16_GRAYSCALE: { + *color_type = PNG_COLOR_TYPE_GRAY; + *bit_depth = 16; + return SAIL_OK; + } + case SAIL_PIXEL_FORMAT_BPP16_GRAYSCALE_ALPHA: { + *color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + *bit_depth = 8; + return SAIL_OK; + } + case SAIL_PIXEL_FORMAT_BPP32_GRAYSCALE_ALPHA: { + *color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + *bit_depth = 16; + return SAIL_OK; + } case SAIL_PIXEL_FORMAT_BPP24_RGB: case SAIL_PIXEL_FORMAT_BPP24_BGR: { *color_type = PNG_COLOR_TYPE_RGB; *bit_depth = 8; return SAIL_OK; } - case SAIL_PIXEL_FORMAT_BPP48_RGB: case SAIL_PIXEL_FORMAT_BPP48_BGR: { *color_type = PNG_COLOR_TYPE_RGB; *bit_depth = 16; return SAIL_OK; } - case SAIL_PIXEL_FORMAT_BPP32_RGBA: case SAIL_PIXEL_FORMAT_BPP32_BGRA: case SAIL_PIXEL_FORMAT_BPP32_ARGB: @@ -245,7 +270,6 @@ sail_status_t png_private_pixel_format_to_png_color_type(enum SailPixelFormat pi *bit_depth = 8; return SAIL_OK; } - case SAIL_PIXEL_FORMAT_BPP64_RGBA: case SAIL_PIXEL_FORMAT_BPP64_BGRA: case SAIL_PIXEL_FORMAT_BPP64_ARGB: @@ -254,7 +278,6 @@ sail_status_t png_private_pixel_format_to_png_color_type(enum SailPixelFormat pi *bit_depth = 16; return SAIL_OK; } - default: { SAIL_LOG_AND_RETURN(SAIL_ERROR_UNSUPPORTED_PIXEL_FORMAT); } diff --git a/src/sail-codecs/png/png.c b/src/sail-codecs/png/png.c index 75d41e2e..61df3349 100644 --- a/src/sail-codecs/png/png.c +++ b/src/sail-codecs/png/png.c @@ -537,9 +537,8 @@ SAIL_EXPORT sail_status_t sail_codec_write_seek_next_frame_v6_png(void *state, s int color_type; int bit_depth; - SAIL_TRY_OR_EXECUTE(png_private_pixel_format_to_png_color_type(image->pixel_format, &color_type, &bit_depth), - /* cleanup */ SAIL_LOG_ERROR("PNG: %s pixel format is not currently supported for writing", sail_pixel_format_to_string(image->pixel_format)); - return __sail_error_result); + SAIL_TRY_OR_CLEANUP(png_private_pixel_format_to_png_color_type(image->pixel_format, &color_type, &bit_depth), + /* cleanup */ SAIL_LOG_ERROR("PNG: %s pixel format is not currently supported for writing", sail_pixel_format_to_string(image->pixel_format))); /* Write meta data. */ if (png_state->write_options->options & SAIL_OPTION_META_DATA && image->meta_data_node != NULL) { @@ -583,11 +582,11 @@ SAIL_EXPORT sail_status_t sail_codec_write_seek_next_frame_v6_png(void *state, s } if (image->palette->pixel_format != SAIL_PIXEL_FORMAT_BPP24_RGB) { - SAIL_LOG_ERROR("PNG: Palette not in BPP24-RGB format is not supported"); + SAIL_LOG_ERROR("PNG: Only BPP24-RGB palette is currently supported"); SAIL_LOG_AND_RETURN(SAIL_ERROR_UNSUPPORTED_PIXEL_FORMAT); } - /* Palette is deep copied. */ + /* Deep copy palette. */ png_set_PLTE(png_state->png_ptr, png_state->info_ptr, image->palette->data, image->palette->color_count); } diff --git a/src/sail-codecs/png/png.codec.info.in b/src/sail-codecs/png/png.codec.info.in index 77158f21..7afb0ac3 100644 --- a/src/sail-codecs/png/png.codec.info.in +++ b/src/sail-codecs/png/png.codec.info.in @@ -17,7 +17,7 @@ tuning=png-filter [write-features] features=STATIC;META-DATA;INTERLACED;ICCP tuning= -output-pixel-formats=BPP1-INDEXED;BPP2-INDEXED;BPP4-INDEXED;BPP8-INDEXED;BPP24-RGB;BPP24-BGR;BPP48-RGB;BPP48-BGR;BPP32-RGBA;BPP32-BGRA;BPP32-ARGB;BPP32-ABGR;BPP64-RGBA;BPP64-BGRA;BPP64-ARGB;BPP64-ABGR +output-pixel-formats=BPP1-INDEXED;BPP2-INDEXED;BPP4-INDEXED;BPP8-INDEXED;BPP1-GRAYSCALE;BPP2-GRAYSCALE;BPP4-GRAYSCALE;BPP8-GRAYSCALE;BPP16-GRAYSCALE;BPP16-GRAYSCALE-ALPHA;BPP32-GRAYSCALE-ALPHA;BPP24-RGB;BPP24-BGR;BPP48-RGB;BPP48-BGR;BPP32-RGBA;BPP32-BGRA;BPP32-ARGB;BPP32-ABGR;BPP64-RGBA;BPP64-BGRA;BPP64-ARGB;BPP64-ABGR properties= compression-types=DEFLATE default-compression=DEFLATE