--- ImageMagick-6.1.3/coders/jp2.c_orig 2004-11-10 14:52:21.000000000 +0100 +++ ImageMagick-6.1.3/coders/jp2.c 2004-11-10 14:53:35.000000000 +0100 @@ -54,6 +54,7 @@ #include "magick/memory_.h" #include "magick/monitor.h" #include "magick/option.h" +#include "magick/profile.h" #include "magick/static.h" #include "magick/string_.h" #if defined(HasJP2) @@ -283,6 +284,12 @@ jas_stream_t *jp2_stream; + jas_cmprof_t + *jp2_cmprof; + + jas_iccprof_t + *jp2_iccprof; + MagickBooleanType status; @@ -555,6 +562,42 @@ break; } } + + /* extract the icc profile, handle errors without much noise */ + if ((jp2_cmprof=jas_image_cmprof(jp2_image)) != NULL && + (jp2_iccprof=jas_iccprof_createfromcmprof(jp2_cmprof)) != NULL) { + jas_stream_t *jp2_iccstream; + if ((jp2_iccstream=jas_stream_memopen(NULL, 0)) != NULL && + jas_iccprof_save(jp2_iccprof,jp2_iccstream) == 0 && + jas_stream_flush(jp2_iccstream) == 0) { + StringInfo *profile; + StringInfo *icc_profile; + jas_stream_memobj_t *jp2_memobj; + jp2_memobj=(jas_stream_memobj_t *)jp2_iccstream->obj_; + if ((profile=AcquireStringInfo(jp2_memobj->len_)) != NULL) { + if (image->debug != MagickFalse) { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + "Profile: ICC, %lu bytes",(unsigned long) jp2_memobj->len_); + } + for(i=0; i < jp2_memobj->len_; i++) { + profile->datum[i]=jp2_memobj->buf_[i]; + } + icc_profile=GetImageProfile(image,"icc"); + if (icc_profile != (StringInfo *) NULL) + { + ConcatenateStringInfo(icc_profile,profile); + profile=DestroyStringInfo(profile); + } + else + { + SetImageProfile(image,"icc",profile); + profile=DestroyStringInfo(profile); + } + } + (void) jas_stream_close(jp2_iccstream); + } + } + (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); for (i=0; i < (long) number_components; i++)