Skip to content

Commit

Permalink
Fixes #153: Certain PNG color profiles are not loaded properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Oct 8, 2017
1 parent 1aad817 commit 7ee0b45
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
10 changes: 5 additions & 5 deletions c_components/imageflow_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ PUB void flow_context_profiler_start(flow_c * c, const char * name, bool allow_r
PUB void flow_context_profiler_stop(flow_c * c, const char * name, bool assert_started, bool stop_children);

typedef enum flow_codec_color_profile_source {
flow_codec_color_profile_source_null,
flow_codec_color_profile_source_ICCP,
flow_codec_color_profile_source_ICCP_GRAY,
flow_codec_color_profile_source_GAMA_CHRM,
flow_codec_color_profile_source_sRGB,
flow_codec_color_profile_source_null = 0,
flow_codec_color_profile_source_ICCP = 1,
flow_codec_color_profile_source_ICCP_GRAY = 2,
flow_codec_color_profile_source_GAMA_CHRM = 3,
flow_codec_color_profile_source_sRGB = 4,

} flow_codec_color_profile_source;

Expand Down
2 changes: 1 addition & 1 deletion c_components/lib/codecs_jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ static bool flow_codecs_jpg_decoder_interpret_metadata(flow_c * c, struct flow_c

if (state->color.source == flow_codec_color_profile_source_null) {
if (read_icc_profile(c, state->cinfo, &icc_buffer, &icc_buffer_len)) {
if (!flow_profile_is_srgb(icc_buffer, icc_buffer_len)) {
if (!flow_profile_is_srgb(icc_buffer, icc_buffer_len) && icc_buffer_len > 0) {
state->color.profile_buf = icc_buffer;
state->color.buf_length = icc_buffer_len;
state->color.source = flow_codec_color_profile_source_ICCP;
Expand Down
4 changes: 3 additions & 1 deletion c_components/lib/codecs_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static bool png_decoder_load_color_profile(flow_c * c, struct flow_codecs_png_de
// Pre-transform color_type (prior to all pre-decode format transforms)
int is_color_png = state->color_type & PNG_COLOR_MASK_COLOR;

if (png_get_iCCP(state->png_ptr, state->info_ptr, &(png_charp){ 0 }, &(int){ 0 }, &profile_buf, &profile_length)) {
if (png_get_iCCP(state->png_ptr, state->info_ptr, &(png_charp){ 0 }, &(int){ 0 }, &profile_buf, &profile_length) && profile_length > 0) {
if (!flow_profile_is_srgb(profile_buf, profile_length)) {

state->color.profile_buf = (uint8_t *) FLOW_malloc(c, profile_length);
Expand All @@ -135,6 +135,8 @@ static bool png_decoder_load_color_profile(flow_c * c, struct flow_codecs_png_de
return false;
}
memcpy(state->color.profile_buf, profile_buf, profile_length);
state->color.buf_length = profile_length;

if (is_color_png) {
state->color.source = flow_codec_color_profile_source_ICCP;
} else {
Expand Down
2 changes: 1 addition & 1 deletion imageflow_core/src/codecs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl ColorTransformCache{
// Skip first 80 bytes when hashing.
Some(imageflow_helpers::hashing::hash_64(&bytes[80..]) ^ pixel_format as u64)
} else {
unreachable!("Profile source should never be set to ICCP without a profile buffer");
unreachable!("Profile source should never be set to ICCP without a profile buffer. Buffer length {}", color.buffer_length);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions imageflow_core/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ pub struct RenderToCanvas1d {
#[repr(C)]
#[derive(Clone,Debug,Copy, PartialEq)]
pub enum ColorProfileSource {
Null,
ICCP,
ICCP_GRAY,
GAMA_CHRM,
sRGB,
Null = 0,
ICCP = 1,
ICCP_GRAY = 2,
GAMA_CHRM = 3,
sRGB = 4,

}

Expand Down

0 comments on commit 7ee0b45

Please sign in to comment.