From: cristy Date: Thu, 2 Jan 2014 13:28:18 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~3008 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2599725a6c1f299a7d44edd55abf77ca5537b5d8;p=imagemagick --- diff --git a/Makefile.in b/Makefile.in index c362aa7c1..ff200659d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -673,7 +673,7 @@ am__objects_1 = MagickCore/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGI @WINGDI32_DELEGATE_TRUE@ coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-emf.lo @JBIG_DELEGATE_TRUE@am__objects_8 = coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-jbig.lo @JPEG_DELEGATE_TRUE@am__objects_9 = coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-jpeg.lo -@JP2_DELEGATE_TRUE@am__objects_10 = coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-jp2.lo +@LIBOPENJP2_DELEGATE_TRUE@am__objects_10 = coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-jp2.lo @PNG_DELEGATE_TRUE@am__objects_11 = coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-png.lo @TIFF_DELEGATE_TRUE@am__objects_12 = coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-ept.lo \ @TIFF_DELEGATE_TRUE@ coders/MagickCore_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la-tiff.lo @@ -1185,14 +1185,15 @@ coders_jnx_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(coders_jnx_la_LDFLAGS) $(LDFLAGS) -o $@ @WITH_MODULES_TRUE@am_coders_jnx_la_rpath = -rpath $(codersdir) coders_jp2_la_DEPENDENCIES = $(MAGICKCORE_LIBS) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) + $(am__DEPENDENCIES_1) am_coders_jp2_la_OBJECTS = coders/coders_jp2_la-jp2.lo coders_jp2_la_OBJECTS = $(am_coders_jp2_la_OBJECTS) coders_jp2_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(coders_jp2_la_LDFLAGS) $(LDFLAGS) -o $@ -@JP2_DELEGATE_TRUE@@WITH_MODULES_TRUE@am_coders_jp2_la_rpath = -rpath \ -@JP2_DELEGATE_TRUE@@WITH_MODULES_TRUE@ $(codersdir) +@LIBOPENJP2_DELEGATE_TRUE@@WITH_MODULES_TRUE@am_coders_jp2_la_rpath = \ +@LIBOPENJP2_DELEGATE_TRUE@@WITH_MODULES_TRUE@ -rpath \ +@LIBOPENJP2_DELEGATE_TRUE@@WITH_MODULES_TRUE@ $(codersdir) coders_jpeg_la_DEPENDENCIES = $(MAGICKCORE_LIBS) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) am_coders_jpeg_la_OBJECTS = coders/coders_jpeg_la-jpeg.lo @@ -2639,7 +2640,6 @@ INT64_F = @INT64_F@ INT64_T = @INT64_T@ INT8_T = @INT8_T@ JBIG_LIBS = @JBIG_LIBS@ -JP2_LIBS = @JP2_LIBS@ JPEG_LIBS = @JPEG_LIBS@ JXRDecodeDelegate = @JXRDecodeDelegate@ JXREncodeDelegate = @JXREncodeDelegate@ @@ -3103,8 +3103,8 @@ codersdir = $(CODER_PATH) @JBIG_DELEGATE_TRUE@MAGICKCORE_JBIG_SRCS = coders/jbig.c @JPEG_DELEGATE_TRUE@MAGICKCORE_JPEG_MODULES = coders/jpeg.la @JPEG_DELEGATE_TRUE@MAGICKCORE_JPEG_SRCS = coders/jpeg.c -@JP2_DELEGATE_TRUE@MAGICKCORE_JP2_MODULES = coders/jp2.la -@JP2_DELEGATE_TRUE@MAGICKCORE_JP2_SRCS = coders/jp2.c +@LIBOPENJP2_DELEGATE_TRUE@MAGICKCORE_JP2_MODULES = coders/jp2.la +@LIBOPENJP2_DELEGATE_TRUE@MAGICKCORE_JP2_SRCS = coders/jp2.c @PNG_DELEGATE_TRUE@MAGICKCORE_PNG_MODULES = coders/png.la @PNG_DELEGATE_TRUE@MAGICKCORE_PNG_SRCS = coders/png.c @TIFF_DELEGATE_TRUE@MAGICKCORE_TIFF_MODULES = coders/ept.la coders/tiff.la @@ -3633,10 +3633,9 @@ coders_jpeg_la_LIBADD = $(MAGICKCORE_LIBS) $(JPEG_LIBS) $(MATH_LIBS) # JPEG 2000 coder module coders_jp2_la_SOURCES = coders/jp2.c -coders_jp2_la_CPPFLAGS = $(MODULE_EXTRA_CPPFLAGS) +coders_jp2_la_CPPFLAGS = $(MODULE_EXTRA_CPPFLAGS) $(LIBOPENJP2_CFLAGS) coders_jp2_la_LDFLAGS = $(MODULECOMMONFLAGS) -coders_jp2_la_LIBADD = $(MAGICKCORE_LIBS) $(JP2_LIBS) $(JPEG_LIBS) $(MATH_LIBS) -# coders_jp2_la_LIBADD = $(MAGICKCORE_LIBS) $(LIBOPENJP2_LIBS) $(MATH_LIBS) +coders_jp2_la_LIBADD = $(MAGICKCORE_LIBS) $(LIBOPENJP2_LIBS) $(MATH_LIBS) # LABEL coder module coders_label_la_SOURCES = coders/label.c diff --git a/coders/Makefile.am b/coders/Makefile.am index 67c762cb8..13b0ea27f 100644 --- a/coders/Makefile.am +++ b/coders/Makefile.am @@ -47,7 +47,7 @@ MAGICKCORE_JPEG_MODULES = coders/jpeg.la MAGICKCORE_JPEG_SRCS = coders/jpeg.c endif -if JP2_DELEGATE +if LIBOPENJP2_DELEGATE MAGICKCORE_JP2_MODULES = coders/jp2.la MAGICKCORE_JP2_SRCS = coders/jp2.c endif @@ -600,10 +600,9 @@ coders_jpeg_la_LIBADD = $(MAGICKCORE_LIBS) $(JPEG_LIBS) $(MATH_LIBS) # JPEG 2000 coder module coders_jp2_la_SOURCES = coders/jp2.c -coders_jp2_la_CPPFLAGS = $(MODULE_EXTRA_CPPFLAGS) +coders_jp2_la_CPPFLAGS = $(MODULE_EXTRA_CPPFLAGS) $(LIBOPENJP2_CFLAGS) coders_jp2_la_LDFLAGS = $(MODULECOMMONFLAGS) -coders_jp2_la_LIBADD = $(MAGICKCORE_LIBS) $(JP2_LIBS) $(JPEG_LIBS) $(MATH_LIBS) -# coders_jp2_la_LIBADD = $(MAGICKCORE_LIBS) $(LIBOPENJP2_LIBS) $(MATH_LIBS) +coders_jp2_la_LIBADD = $(MAGICKCORE_LIBS) $(LIBOPENJP2_LIBS) $(MATH_LIBS) # LABEL coder module coders_label_la_SOURCES = coders/label.c diff --git a/coders/jp2.c b/coders/jp2.c index 4134bb59a..20277e122 100644 --- a/coders/jp2.c +++ b/coders/jp2.c @@ -39,77 +39,43 @@ /* Include declarations. */ -#include "MagickCore/studio.h" -#include "MagickCore/artifact.h" -#include "MagickCore/attribute.h" -#include "MagickCore/blob.h" -#include "MagickCore/blob-private.h" -#include "MagickCore/cache.h" -#include "MagickCore/colorspace.h" -#include "MagickCore/colorspace-private.h" -#include "MagickCore/color.h" -#include "MagickCore/color-private.h" -#include "MagickCore/exception.h" -#include "MagickCore/exception-private.h" -#include "MagickCore/image.h" -#include "MagickCore/image-private.h" -#include "MagickCore/list.h" -#include "MagickCore/magick.h" -#include "MagickCore/memory_.h" -#include "MagickCore/monitor.h" -#include "MagickCore/monitor-private.h" -#include "MagickCore/option.h" -#include "MagickCore/pixel-accessor.h" -#include "MagickCore/profile.h" -#include "MagickCore/quantum-private.h" -#include "MagickCore/static.h" -#include "MagickCore/statistic.h" -#include "MagickCore/string_.h" -#include "MagickCore/module.h" -#if defined(MAGICKCORE_JP2_DELEGATE) -#ifndef JAS_IMAGE_CM_GRAY -#define JAS_IMAGE_CM_GRAY JAS_IMAGE_CS_GRAY -#endif -#ifndef JAS_IMAGE_CM_RGB -#define JAS_IMAGE_CM_RGB JAS_IMAGE_CS_RGB -#endif -#if !defined(uchar) -#define uchar unsigned char -#endif -#if !defined(ushort) -#define ushort unsigned short -#endif -#if !defined(uint) -#define uint unsigned int -#endif -#if !defined(ssize_tssize_t) -#define ssize_tssize_t long long -#endif -#if !defined(ussize_tssize_t) -#define ussize_tssize_t unsigned long long -#endif - -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#include "jasper/jasper.h" -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION - +#include "magick/studio.h" +#include "magick/artifact.h" +#include "magick/attribute.h" +#include "magick/blob.h" +#include "magick/blob-private.h" +#include "magick/cache.h" +#include "magick/colorspace.h" +#include "magick/colorspace-private.h" +#include "magick/color.h" +#include "magick/color-private.h" +#include "magick/exception.h" +#include "magick/exception-private.h" +#include "magick/image.h" +#include "magick/image-private.h" +#include "magick/list.h" +#include "magick/magick.h" +#include "magick/memory_.h" +#include "magick/monitor.h" +#include "magick/monitor-private.h" +#include "magick/option.h" +#include "magick/pixel-accessor.h" +#include "magick/profile.h" +#include "magick/quantum-private.h" +#include "magick/static.h" +#include "magick/statistic.h" +#include "magick/string_.h" +#include "magick/module.h" +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) +#include #endif /* Forward declarations. */ -#if defined(MAGICKCORE_JP2_DELEGATE) +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) static MagickBooleanType - WriteJP2Image(const ImageInfo *,Image *,ExceptionInfo *); - -static volatile MagickBooleanType - instantiate_jp2 = MagickFalse; + WriteJP2Image(const ImageInfo *,Image *); #endif /* @@ -210,124 +176,73 @@ static MagickBooleanType IsJPC(const unsigned char *magick,const size_t length) % o exception: return any errors or warnings in this structure. % */ -#if defined(MAGICKCORE_JP2_DELEGATE) - -typedef struct _StreamManager -{ - jas_stream_t - *stream; - - Image - *image; -} StreamManager; - -static int BlobRead(jas_stream_obj_t *object,char *buffer,const int length) +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) +static void JP2ErrorHandler(const char *message,void *client_data) { - ssize_t - count; + ExceptionInfo + *exception; - StreamManager - *source; - - source=(StreamManager *) object; - count=ReadBlob(source->image,(size_t) length,(unsigned char *) buffer); - return((int) count); + exception=(ExceptionInfo *) client_data; + (void) ThrowMagickException(exception,GetMagickModule(),CoderError, + message,"`%s'","OpenJP2"); } -static int BlobWrite(jas_stream_obj_t *object,char *buffer,const int length) +static OPJ_SIZE_T JP2ReadHandler(void *buffer,OPJ_SIZE_T length,void *context) { + Image + *image; + ssize_t count; - StreamManager - *source; - - source=(StreamManager *) object; - count=WriteBlob(source->image,(size_t) length,(unsigned char *) buffer); - return((int) count); + image=(Image *) context; + count=ReadBlob(image,(ssize_t) length,(unsigned char *) buffer); + if (count == 0) + return(-1); + return((OPJ_SIZE_T) count); } -static long BlobSeek(jas_stream_obj_t *object,long offset,int origin) +static OPJ_BOOL JP2SeekHandler(OPJ_OFF_T offset,void *context) { - StreamManager - *source; + Image + *image; - source=(StreamManager *) object; - return((long) SeekBlob(source->image,offset,origin)); + image=(Image *) context; + return(SeekBlob(image,offset,SEEK_SET) == 0 ? 1 : 0); } -static int BlobClose(jas_stream_obj_t *object) +static OPJ_OFF_T JP2SkipHandler(OPJ_OFF_T length,void *context) { - StreamManager - *source; + Image + *image; - source=(StreamManager *) object; - (void) CloseBlob(source->image); - free(source); - source=(StreamManager *) NULL; - return(0); + image=(Image *) context; + if (DiscardBlobBytes(image,(size_t) length) == MagickFalse) + return(0); + return(length); } -static inline size_t MagickMax(const size_t x,const size_t y) +static void JP2WarningHandler(const char *message,void *client_data) { - if (x > y) - return(x); - return(y); -} + ExceptionInfo + *exception; -static inline size_t MagickMin(const size_t x,const size_t y) -{ - if (x < y) - return(x); - return(y); + exception=(ExceptionInfo *) client_data; + (void) ThrowMagickException(exception,GetMagickModule(),CoderWarning, + message,"`%s'","OpenJP2"); } -static jas_stream_t *JP2StreamManager(Image *image) +static OPJ_SIZE_T JP2WriteHandler(void *buffer,OPJ_SIZE_T length,void *context) { - static jas_stream_ops_t - StreamOperators = - { - BlobRead, - BlobWrite, - BlobSeek, - BlobClose - }; - - jas_stream_t - *stream; + Image + *image; - StreamManager - *source; + ssize_t + count; - stream=(jas_stream_t *) jas_malloc(sizeof(*stream)); - if (stream == (jas_stream_t *) NULL) - return((jas_stream_t *) NULL); - (void) ResetMagickMemory(stream,0,sizeof(*stream)); - stream->rwlimit_=(-1); - stream->obj_=(jas_stream_obj_t *) jas_malloc(sizeof(StreamManager)); - if (stream->obj_ == (jas_stream_obj_t *) NULL) - return((jas_stream_t *) NULL); - (void) ResetMagickMemory(stream->obj_,0,sizeof(StreamManager)); - stream->ops_=(&StreamOperators); - stream->openmode_=JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY; - stream->bufbase_=(unsigned char *) jas_malloc(JAS_STREAM_BUFSIZE+ - JAS_STREAM_MAXPUTBACK); - if (stream->bufbase_ == (void *) NULL) - { - stream->bufbase_=stream->tinybuf_; - stream->bufsize_=1; - } - else - { - stream->bufmode_=JAS_STREAM_FREEBUF | JAS_STREAM_BUFMODEMASK; - stream->bufsize_=JAS_STREAM_BUFSIZE; - } - stream->bufstart_=(&stream->bufbase_[JAS_STREAM_MAXPUTBACK]); - stream->ptr_=stream->bufstart_; - stream->cnt_=0; - source=(StreamManager *) stream->obj_; - source->image=image; - return(stream); + image=(Image *) context; + count=WriteBlob(image,(ssize_t) length,(unsigned char *) buffer); + return((OPJ_SIZE_T) count); } static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception) @@ -335,43 +250,29 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception) Image *image; - jas_cmprof_t - *cm_profile; - - jas_iccprof_t - *icc_profile; - - jas_image_t - *jp2_image; - - jas_matrix_t - *pixels[4]; - - jas_stream_t - *jp2_stream; + int + factor, + jp2_status; MagickBooleanType status; - QuantumAny - pixel, - range[4]; + opj_codec_t + *jp2_codec; - register Quantum - *q; + opj_dparameters_t + parameters; - register ssize_t - i, - x; + opj_image_t + *jp2_image; + + opj_stream_t + *jp2_stream; - size_t - maximum_component_depth, - number_components, - x_step[4], - y_step[4]; + register ssize_t + i; ssize_t - components[4], y; /* @@ -384,7 +285,7 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception) image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); - image=AcquireImage(image_info,exception); + image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { @@ -392,238 +293,162 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception) return((Image *) NULL); } /* - Initialize JPEG 2000 API. + Initialize JP2 codec. */ - jp2_stream=JP2StreamManager(image); - if (jp2_stream == (jas_stream_t *) NULL) - ThrowReaderException(DelegateError,"UnableToManageJP2Stream"); - jp2_image=jas_image_decode(jp2_stream,-1,0); - if (jp2_image == (jas_image_t *) NULL) - { - (void) jas_stream_close(jp2_stream); - ThrowReaderException(DelegateError,"UnableToDecodeImageFile"); - } - image->columns=jas_image_width(jp2_image); - image->rows=jas_image_height(jp2_image); - image->compression=JPEG2000Compression; - switch (jas_clrspc_fam(jas_image_clrspc(jp2_image))) - { - case JAS_CLRSPC_FAM_RGB: - { - SetImageColorspace(image,RGBColorspace,exception); - components[0]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_RGB_R); - components[1]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_RGB_G); - components[2]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_RGB_B); - if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) - { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CorruptImageError,"MissingImageChannel"); - } - number_components=3; - components[3]=jas_image_getcmptbytype(jp2_image,3); - if (components[3] > 0) - { - image->alpha_trait=BlendPixelTrait; - number_components++; - } - break; - } - case JAS_CLRSPC_FAM_GRAY: + if (LocaleCompare(image_info->magick,"JPT") == 0) + jp2_codec=opj_create_decompress(OPJ_CODEC_JPT); + else + if (LocaleCompare(image_info->magick,"J2K") == 0) + jp2_codec=opj_create_decompress(OPJ_CODEC_J2K); + else + jp2_codec=opj_create_decompress(OPJ_CODEC_JP2); + opj_set_warning_handler(jp2_codec,JP2WarningHandler,exception); + opj_set_error_handler(jp2_codec,JP2ErrorHandler,exception); + opj_set_default_decoder_parameters(¶meters); + if (opj_setup_decoder(jp2_codec,¶meters) == 0) { - SetImageColorspace(image,GRAYColorspace,exception); - components[0]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_GRAY_Y); - if (components[0] < 0) - { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CorruptImageError,"MissingImageChannel"); - } - number_components=1; - break; + opj_destroy_codec(jp2_codec); + ThrowReaderException(DelegateError,"UnableToManageJP2Stream"); } - case JAS_CLRSPC_FAM_YCBCR: + jp2_stream=opj_stream_create(1024,1); + opj_stream_set_read_function(jp2_stream,JP2ReadHandler); + opj_stream_set_write_function(jp2_stream,JP2WriteHandler); + opj_stream_set_seek_function(jp2_stream,JP2SeekHandler); + opj_stream_set_skip_function(jp2_stream,JP2SkipHandler); + opj_stream_set_user_data(jp2_stream,image); + opj_stream_set_user_data_length(jp2_stream,GetBlobSize(image)); + if (opj_read_header(jp2_stream,jp2_codec,&jp2_image) == 0) { - SetImageColorspace(image,YCbCrColorspace,exception); - components[0]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_YCBCR_Y); - components[1]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_YCBCR_CB); - components[2]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_YCBCR_CR); - if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) - { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CorruptImageError,"MissingImageChannel"); - } - number_components=3; - components[3]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_UNKNOWN); - if (components[3] > 0) - { - image->alpha_trait=BlendPixelTrait; - number_components++; - } - break; + opj_stream_set_user_data(jp2_stream,NULL); + opj_stream_destroy_v3(jp2_stream); + opj_destroy_codec(jp2_codec); + ThrowReaderException(DelegateError,"UnableToDecodeImageFile"); } - case JAS_CLRSPC_FAM_XYZ: + factor=0; + if (opj_set_decoded_resolution_factor(jp2_codec,factor) == 0) { - SetImageColorspace(image,XYZColorspace,exception); - components[0]=jas_image_getcmptbytype(jp2_image,0); - components[1]=jas_image_getcmptbytype(jp2_image,1); - components[2]=jas_image_getcmptbytype(jp2_image,2); - if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) - { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CorruptImageError,"MissingImageChannel"); - } - number_components=3; - components[3]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_UNKNOWN); - if (components[3] > 0) - { - image->alpha_trait=BlendPixelTrait; - number_components++; - } - break; + opj_stream_set_user_data(jp2_stream,NULL); + opj_stream_destroy_v3(jp2_stream); + opj_destroy_codec(jp2_codec); + opj_image_destroy(jp2_image); + ThrowReaderException(DelegateError,"UnableToDecodeImageFile"); } - case JAS_CLRSPC_FAM_LAB: + jp2_status=opj_set_decode_area(jp2_codec,jp2_image,parameters.DA_x0, + parameters.DA_y0,parameters.DA_x1,parameters.DA_y1); + if (jp2_status == 0) { - SetImageColorspace(image,LabColorspace,exception); - components[0]=jas_image_getcmptbytype(jp2_image,0); - components[1]=jas_image_getcmptbytype(jp2_image,1); - components[2]=jas_image_getcmptbytype(jp2_image,2); - if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) - { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CorruptImageError,"MissingImageChannel"); - } - number_components=3; - components[3]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_UNKNOWN); - if (components[3] > 0) - { - image->alpha_trait=BlendPixelTrait; - number_components++; - } - break; + opj_stream_set_user_data(jp2_stream,NULL); + opj_stream_destroy_v3(jp2_stream); + opj_destroy_codec(jp2_codec); + opj_image_destroy(jp2_image); + ThrowReaderException(DelegateError,"UnableToDecodeImageFile"); } - default: + if ((opj_decode(jp2_codec,jp2_stream,jp2_image) == 0) || + (opj_end_decompress(jp2_codec,jp2_stream) == 0)) { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CoderError,"ColorspaceModelIsNotSupported"); + opj_stream_set_user_data(jp2_stream,NULL); + opj_stream_destroy_v3(jp2_stream); + opj_destroy_codec(jp2_codec); + opj_image_destroy(jp2_image); + ThrowReaderException(DelegateError,"UnableToDecodeImageFile"); } - } - for (i=0; i < (ssize_t) number_components; i++) + opj_stream_set_user_data(jp2_stream,NULL); + opj_stream_destroy_v3(jp2_stream); + for (i=0; i < (ssize_t) jp2_image->numcomps; i++) { - size_t - height, - width; - - width=(size_t) (jas_image_cmptwidth(jp2_image,components[i])* - jas_image_cmpthstep(jp2_image,components[i])); - height=(size_t) (jas_image_cmptheight(jp2_image,components[i])* - jas_image_cmptvstep(jp2_image,components[i])); - x_step[i]=(unsigned int) jas_image_cmpthstep(jp2_image,components[i]); - y_step[i]=(unsigned int) jas_image_cmptvstep(jp2_image,components[i]); - if ((width != image->columns) || (height != image->rows) || - (jas_image_cmpttlx(jp2_image,components[i]) != 0) || - (jas_image_cmpttly(jp2_image,components[i]) != 0) || - (jas_image_cmptsgnd(jp2_image,components[i]) != MagickFalse)) + if ((jp2_image->comps[i].dx == 0) || (jp2_image->comps[i].dy == 0)) { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - ThrowReaderException(CoderError,"IrregularChannelGeometryNotSupported"); + opj_stream_set_user_data(jp2_stream,NULL); + opj_destroy_codec(jp2_codec); + opj_image_destroy(jp2_image); + ThrowReaderException(CoderError,"IrregularChannelGeometryNotSupported") } } /* - Convert JPEG 2000 pixels. + Convert JP2 image. */ - image->alpha_trait=number_components > 3 ? BlendPixelTrait : - UndefinedPixelTrait; - maximum_component_depth=0; - for (i=0; i < (ssize_t) number_components; i++) + image->columns=(size_t) jp2_image->comps[0].w; + image->rows=(size_t) jp2_image->comps[0].h; + image->compression=JPEG2000Compression; + if (jp2_image->numcomps <= 2) + { + SetImageColorspace(image,GRAYColorspace); + if (jp2_image->numcomps > 1) + image->matte=MagickTrue; + } + if (jp2_image->numcomps > 3) + image->matte=MagickTrue; + for (i=0; i < (ssize_t) jp2_image->numcomps; i++) { - maximum_component_depth=(unsigned int) MagickMax((size_t) - jas_image_cmptprec(jp2_image,components[i]),(size_t) - maximum_component_depth); - pixels[i]=jas_matrix_create(1,(int) (image->columns/x_step[i])); - if (pixels[i] == (jas_matrix_t *) NULL) + if ((jp2_image->comps[i].dx == 0) || (jp2_image->comps[i].dy == 0)) { - for (--i; i >= 0; i--) - jas_matrix_destroy(pixels[i]); - jas_image_destroy(jp2_image); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + opj_stream_set_user_data(jp2_stream,NULL); + opj_destroy_codec(jp2_codec); + opj_image_destroy(jp2_image); + ThrowReaderException(CoderError,"IrregularChannelGeometryNotSupported") } + if ((jp2_image->comps[i].dx > 1) || (jp2_image->comps[i].dy > 1)) + image->colorspace=YUVColorspace; } - image->depth=maximum_component_depth; - if (image_info->ping != MagickFalse) - { - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - return(GetFirstImageInList(image)); - } - for (i=0; i < (ssize_t) number_components; i++) - range[i]=GetQuantumRange((size_t) jas_image_cmptprec(jp2_image, - components[i])); for (y=0; y < (ssize_t) image->rows; y++) { + register PixelPacket + *restrict q; + + register ssize_t + x; + q=GetAuthenticPixels(image,0,y,image->columns,1,exception); - if (q == (Quantum *) NULL) + if (q == (PixelPacket *) NULL) break; - for (i=0; i < (ssize_t) number_components; i++) - (void) jas_image_readcmpt(jp2_image,(short) components[i],0, - (jas_image_coord_t) (y/y_step[i]),(jas_image_coord_t) (image->columns/ - x_step[i]),1,pixels[i]); - switch (number_components) + for (x=0; x < (ssize_t) image->columns; x++) { - case 1: - { - /* - Grayscale. - */ - for (x=0; x < (ssize_t) image->columns; x++) - { - pixel=(QuantumAny) jas_matrix_getv(pixels[0],x/x_step[0]); - SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) pixel,range[0]),q); - q+=GetPixelChannels(image); - } - break; - } - case 3: - { - /* - RGB. - */ - for (x=0; x < (ssize_t) image->columns; x++) - { - pixel=(QuantumAny) jas_matrix_getv(pixels[0],x/x_step[0]); - SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) pixel,range[0]),q); - pixel=(QuantumAny) jas_matrix_getv(pixels[1],x/x_step[1]); - SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) pixel,range[1]),q); - pixel=(QuantumAny) jas_matrix_getv(pixels[2],x/x_step[2]); - SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) pixel,range[2]),q); - q+=GetPixelChannels(image); - } - break; - } - case 4: + register ssize_t + i; + + for (i=0; i < (ssize_t) jp2_image->numcomps; i++) { - /* - RGBA. - */ - for (x=0; x < (ssize_t) image->columns; x++) + double + pixel, + scale; + + scale=QuantumRange/(double) ((1UL << jp2_image->comps[i].prec)-1); + pixel=scale*(jp2_image->comps[i].data[y/jp2_image->comps[i].dy* + image->columns/jp2_image->comps[i].dx+x/jp2_image->comps[i].dx]+ + (jp2_image->comps[i].sgnd ? 1UL << (jp2_image->comps[i].prec-1) : 0)); + switch (i) { - pixel=(QuantumAny) jas_matrix_getv(pixels[0],x/x_step[0]); - SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) pixel,range[0]),q); - pixel=(QuantumAny) jas_matrix_getv(pixels[1],x/x_step[1]); - SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) pixel,range[1]),q); - pixel=(QuantumAny) jas_matrix_getv(pixels[2],x/x_step[2]); - SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) pixel,range[2]),q); - pixel=(QuantumAny) jas_matrix_getv(pixels[3],x/x_step[3]); - SetPixelAlpha(image,ScaleAnyToQuantum((QuantumAny) pixel,range[3]),q); - q+=GetPixelChannels(image); + case 0: + { + SetPixelRed(image,ClampToQuantum(pixel),q); + SetPixelGreen(image,ClampToQuantum(pixel),q); + SetPixelBlue(image,ClampToQuantum(pixel),q); + SetPixelAlpha(image,OpaqueAlpha,q); + break; + } + case 1: + { + if (jp2_image->numcomps == 2) + { + SetPixelAlpha(image,ClampToQuantum(pixel),q); + break; + } + SetPixelGreen(image,ClampToQuantum(pixel),q); + break; + } + case 2: + { + SetPixelBlue(image,ClampToQuantum(pixel),q); + break; + } + case 3: + { + SetPixelAlpha(image,ClampToQuantum(pixel),q); + break; + } } - break; } + q+=GetPixelChannels(image); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; @@ -632,51 +457,11 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception) if (status == MagickFalse) break; } - cm_profile=jas_image_cmprof(jp2_image); - icc_profile=(jas_iccprof_t *) NULL; - if (cm_profile != (jas_cmprof_t *) NULL) - icc_profile=jas_iccprof_createfromcmprof(cm_profile); - if (icc_profile != (jas_iccprof_t *) NULL) - { - jas_stream_t - *icc_stream; - - icc_stream=jas_stream_memopen(NULL,0); - if ((icc_stream != (jas_stream_t *) NULL) && - (jas_iccprof_save(icc_profile,icc_stream) == 0) && - (jas_stream_flush(icc_stream) == 0)) - { - jas_stream_memobj_t - *blob; - - StringInfo - *icc_profile, - *profile; - - /* - Extract the icc profile, handle errors without much noise. - */ - blob=(jas_stream_memobj_t *) icc_stream->obj_; - if (image->debug != MagickFalse) - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - "Profile: ICC, %.20g bytes",(double) blob->len_); - profile=BlobToStringInfo(blob->buf_,blob->len_); - if (profile == (StringInfo *) NULL) - ThrowReaderException(CorruptImageError,"MemoryAllocationFailed"); - icc_profile=(StringInfo *) GetImageProfile(image,"icc"); - if (icc_profile == (StringInfo *) NULL) - (void) SetImageProfile(image,"icc",profile,exception); - else - (void) ConcatenateStringInfo(icc_profile,profile); - profile=DestroyStringInfo(profile); - (void) jas_stream_close(icc_stream); - } - jas_iccprof_destroy(icc_profile); - } - (void) jas_stream_close(jp2_stream); - jas_image_destroy(jp2_image); - for (i=0; i < (ssize_t) number_components; i++) - jas_matrix_destroy(pixels[i]); + /* + Free resources. + */ + opj_destroy_codec(jp2_codec); + opj_image_destroy(jp2_image); return(GetFirstImageInList(image)); } #endif @@ -716,33 +501,7 @@ ModuleExport size_t RegisterJP2Image(void) entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->thread_support=NoThreadSupport; -#if defined(MAGICKCORE_JP2_DELEGATE) - entry->decoder=(DecodeImageHandler *) ReadJP2Image; - entry->encoder=(EncodeImageHandler *) WriteJP2Image; -#endif - (void) RegisterMagickInfo(entry); - entry=SetMagickInfo("JPC"); - entry->description=ConstantString("JPEG-2000 Code Stream Syntax"); - entry->mime_type=ConstantString("image/jp2"); - entry->module=ConstantString("JP2"); - entry->magick=(IsImageFormatHandler *) IsJPC; - entry->adjoin=MagickFalse; - entry->seekable_stream=MagickTrue; - entry->thread_support=NoThreadSupport; -#if defined(MAGICKCORE_JP2_DELEGATE) - entry->decoder=(DecodeImageHandler *) ReadJP2Image; - entry->encoder=(EncodeImageHandler *) WriteJP2Image; -#endif - (void) RegisterMagickInfo(entry); - entry=SetMagickInfo("J2C"); - entry->description=ConstantString("JPEG-2000 Code Stream Syntax"); - entry->mime_type=ConstantString("image/jp2"); - entry->module=ConstantString("JP2"); - entry->magick=(IsImageFormatHandler *) IsJPC; - entry->adjoin=MagickFalse; - entry->seekable_stream=MagickTrue; - entry->thread_support=NoThreadSupport; -#if defined(MAGICKCORE_JP2_DELEGATE) +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) entry->decoder=(DecodeImageHandler *) ReadJP2Image; entry->encoder=(EncodeImageHandler *) WriteJP2Image; #endif @@ -755,43 +514,24 @@ ModuleExport size_t RegisterJP2Image(void) entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->thread_support=NoThreadSupport; -#if defined(MAGICKCORE_JP2_DELEGATE) +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) entry->decoder=(DecodeImageHandler *) ReadJP2Image; entry->encoder=(EncodeImageHandler *) WriteJP2Image; #endif (void) RegisterMagickInfo(entry); - entry=SetMagickInfo("JPX"); + entry=SetMagickInfo("JPT"); entry->description=ConstantString("JPEG-2000 File Format Syntax"); entry->mime_type=ConstantString("image/jp2"); entry->module=ConstantString("JP2"); - entry->magick=(IsImageFormatHandler *) IsJPC; + entry->magick=(IsImageFormatHandler *) IsJP2; entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->thread_support=NoThreadSupport; -#if defined(MAGICKCORE_JP2_DELEGATE) +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) entry->decoder=(DecodeImageHandler *) ReadJP2Image; entry->encoder=(EncodeImageHandler *) WriteJP2Image; #endif (void) RegisterMagickInfo(entry); - entry=SetMagickInfo("PGX"); - entry->description=ConstantString("JPEG-2000 VM Format"); - entry->mime_type=ConstantString("image/jp2"); - entry->module=ConstantString("JP2"); - entry->magick=(IsImageFormatHandler *) IsJPC; - entry->adjoin=MagickFalse; - entry->seekable_stream=MagickTrue; - entry->thread_support=NoThreadSupport; -#if defined(MAGICKCORE_JP2_DELEGATE) - entry->decoder=(DecodeImageHandler *) ReadJP2Image; -#endif - (void) RegisterMagickInfo(entry); -#if defined(MAGICKCORE_JP2_DELEGATE) - if (instantiate_jp2 == MagickFalse) - { - jas_init(); - instantiate_jp2=MagickTrue; - } -#endif return(MagickImageCoderSignature); } @@ -816,21 +556,12 @@ ModuleExport size_t RegisterJP2Image(void) */ ModuleExport void UnregisterJP2Image(void) { - (void) UnregisterMagickInfo("PGX"); - (void) UnregisterMagickInfo("J2K"); - (void) UnregisterMagickInfo("J2C"); - (void) UnregisterMagickInfo("JPC"); + (void) UnregisterMagickInfo("JPT"); (void) UnregisterMagickInfo("JP2"); -#if defined(MAGICKCORE_JP2_DELEGATE) - if (instantiate_jp2 != MagickFalse) - { - jas_cleanup(); - instantiate_jp2=MagickFalse; - } -#endif + (void) UnregisterMagickInfo("J2K"); } -#if defined(MAGICKCORE_JP2_DELEGATE) +#if defined(MAGICKCORE_LIBOPENJP2_DELEGATE) /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % @@ -848,8 +579,7 @@ ModuleExport void UnregisterJP2Image(void) % % The format of the WriteJP2Image method is: % -% MagickBooleanType WriteJP2Image(const ImageInfo *image_info, -% Image *image,ExceptionInfo *exception) +% MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image) % % A description of each parameter follows. % @@ -857,52 +587,12 @@ ModuleExport void UnregisterJP2Image(void) % % o image: The image. % -% o exception: return any errors or warnings in this structure. -% */ -static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image, - ExceptionInfo *exception) +static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image) { - char - *key, - magick[MaxTextExtent], - *options; - - const char - *option; - - jas_image_cmptparm_t - component_info[4]; - - jas_image_t - *jp2_image; - - jas_matrix_t - *pixels[4]; - - jas_stream_t - *jp2_stream; - MagickBooleanType status; - QuantumAny - range; - - register const Quantum - *p; - - register ssize_t - i, - x; - - size_t - number_components; - - ssize_t - format, - y; - /* Open image file. */ @@ -912,242 +602,14 @@ static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image, assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); - assert(exception != (ExceptionInfo *) NULL); - assert(exception->signature == MagickSignature); - status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); + status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); if (status == MagickFalse) return(status); /* Initialize JPEG 2000 API. */ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse) - (void) TransformImageColorspace(image,sRGBColorspace,exception); - jp2_stream=JP2StreamManager(image); - if (jp2_stream == (jas_stream_t *) NULL) - ThrowWriterException(DelegateError,"UnableToManageJP2Stream"); - number_components=image->alpha_trait ? 4UL : 3UL; - if (IsGrayColorspace(image->colorspace) != MagickFalse) - number_components=1; - if ((image->columns != (unsigned int) image->columns) || - (image->rows != (unsigned int) image->rows)) - ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); - (void) ResetMagickMemory(&component_info,0,sizeof(component_info)); - for (i=0; i < (ssize_t) number_components; i++) - { - component_info[i].tlx=0; - component_info[i].tly=0; - component_info[i].hstep=1; - component_info[i].vstep=1; - component_info[i].width=(unsigned int) image->columns; - component_info[i].height=(unsigned int) image->rows; - component_info[i].prec=(int) MagickMax(MagickMin(image->depth,16),2); - component_info[i].sgnd=MagickFalse; - } - jp2_image=jas_image_create((int) number_components,component_info, - JAS_CLRSPC_UNKNOWN); - if (jp2_image == (jas_image_t *) NULL) - ThrowWriterException(DelegateError,"UnableToCreateImage"); - switch (image->colorspace) - { - case RGBColorspace: - case sRGBColorspace: - { - /* - RGB colorspace. - */ - jas_image_setclrspc(jp2_image,JAS_CLRSPC_SRGB); - jas_image_setcmpttype(jp2_image,0, - (jas_image_cmpttype_t) JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R)); - jas_image_setcmpttype(jp2_image,1, - (jas_image_cmpttype_t) JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G)); - jas_image_setcmpttype(jp2_image,2, - (jas_image_cmpttype_t) JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B)); - if (number_components == 4) - jas_image_setcmpttype(jp2_image,3,JAS_IMAGE_CT_OPACITY); - break; - } - case GRAYColorspace: - { - /* - Grayscale colorspace. - */ - jas_image_setclrspc(jp2_image,JAS_CLRSPC_SGRAY); - jas_image_setcmpttype(jp2_image,0, - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y)); - break; - } - case YCbCrColorspace: - { - /* - YCbCr colorspace. - */ - jas_image_setclrspc(jp2_image,JAS_CLRSPC_SYCBCR); - jas_image_setcmpttype(jp2_image,0,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(0)); - jas_image_setcmpttype(jp2_image,1,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(1)); - jas_image_setcmpttype(jp2_image,2,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(2)); - if (number_components == 4) - jas_image_setcmpttype(jp2_image,3,JAS_IMAGE_CT_OPACITY); - break; - } - case XYZColorspace: - { - /* - XYZ colorspace. - */ - jas_image_setclrspc(jp2_image,JAS_CLRSPC_CIEXYZ); - jas_image_setcmpttype(jp2_image,0,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(0)); - jas_image_setcmpttype(jp2_image,1,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(1)); - jas_image_setcmpttype(jp2_image,2,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(2)); - if (number_components == 4) - jas_image_setcmpttype(jp2_image,3,JAS_IMAGE_CT_OPACITY); - break; - } - case LabColorspace: - { - /* - Lab colorspace. - */ - jas_image_setclrspc(jp2_image,JAS_CLRSPC_CIELAB); - jas_image_setcmpttype(jp2_image,0,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(0)); - jas_image_setcmpttype(jp2_image,1,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(1)); - jas_image_setcmpttype(jp2_image,2,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(2)); - if (number_components == 4) - jas_image_setcmpttype(jp2_image,3,JAS_IMAGE_CT_OPACITY); - break; - } - default: - { - /* - Unknow. - */ - jas_image_setclrspc(jp2_image,JAS_CLRSPC_UNKNOWN); - jas_image_setcmpttype(jp2_image,0,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(0)); - jas_image_setcmpttype(jp2_image,1,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(1)); - jas_image_setcmpttype(jp2_image,2,(jas_image_cmpttype_t) - JAS_IMAGE_CT_COLOR(2)); - if (number_components == 4) - jas_image_setcmpttype(jp2_image,3,JAS_IMAGE_CT_OPACITY); - break; - } - } - /* - Convert to JPEG 2000 pixels. - */ - for (i=0; i < (ssize_t) number_components; i++) - { - pixels[i]=jas_matrix_create(1,(int) image->columns); - if (pixels[i] == (jas_matrix_t *) NULL) - { - for (x=0; x < i; x++) - jas_matrix_destroy(pixels[x]); - jas_image_destroy(jp2_image); - ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); - } - } - range=GetQuantumRange((size_t) component_info[0].prec); - for (y=0; y < (ssize_t) image->rows; y++) - { - p=GetVirtualPixels(image,0,y,image->columns,1,exception); - if (p == (const Quantum *) NULL) - break; - for (x=0; x < (ssize_t) image->columns; x++) - { - if (number_components == 1) - jas_matrix_setv(pixels[0],x,(jas_seqent_t) ScaleQuantumToAny( - ClampToQuantum(GetPixelLuma(image,p)),range)); - else - { - jas_matrix_setv(pixels[0],x,(jas_seqent_t) ScaleQuantumToAny( - GetPixelRed(image,p),range)); - jas_matrix_setv(pixels[1],x,(jas_seqent_t) ScaleQuantumToAny( - GetPixelGreen(image,p),range)); - jas_matrix_setv(pixels[2],x,(jas_seqent_t) ScaleQuantumToAny( - GetPixelBlue(image,p),range)); - if (number_components > 3) - jas_matrix_setv(pixels[3],x,(jas_seqent_t) ScaleQuantumToAny( - GetPixelAlpha(image,p),range)); - } - p+=GetPixelChannels(image); - } - for (i=0; i < (ssize_t) number_components; i++) - (void) jas_image_writecmpt(jp2_image,(short) i,0,(unsigned int) y, - (unsigned int) image->columns,1,pixels[i]); - status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, - image->rows); - if (status == MagickFalse) - break; - } - (void) CopyMagickString(magick,image_info->magick,MaxTextExtent); - if (LocaleCompare(magick,"J2C") == 0) - (void) CopyMagickString(magick,"JPC",MaxTextExtent); - LocaleLower(magick); - format=jas_image_strtofmt(magick); - options=(char *) NULL; - ResetImageOptionIterator(image_info); - key=GetNextImageOption(image_info); - for ( ; key != (char *) NULL; key=GetNextImageOption(image_info)) - { - option=GetImageOption(image_info,key); - if (option == (const char *) NULL) - continue; - if (LocaleNCompare(key,"jp2:",4) == 0) - { - (void) ConcatenateString(&options,key+4); - if (*option != '\0') - { - (void) ConcatenateString(&options,"="); - (void) ConcatenateString(&options,option); - } - (void) ConcatenateString(&options," "); - } - } - option=GetImageOption(image_info,"jp2:rate"); - if ((option == (const char *) NULL) && - (image_info->compression != LosslessJPEGCompression) && - (image->quality != UndefinedCompressionQuality) && - ((double) image->quality <= 99.5) && - ((image->rows*image->columns) > 2500)) - { - char - option[MaxTextExtent]; - - double - alpha, - header_size, - number_pixels, - rate, - target_size; - - alpha=115.0-image->quality; - rate=100.0/(alpha*alpha); - header_size=550.0; - header_size+=(number_components-1)*142; - number_pixels=(double) image->rows*image->columns*number_components* - (GetImageQuantumDepth(image,MagickTrue)/8); - target_size=(number_pixels*rate)+header_size; - rate=target_size/number_pixels; - (void) FormatLocaleString(option,MaxTextExtent,"rate=%g",rate); - (void) ConcatenateString(&options,option); - } - status=jas_image_encode(jp2_image,jp2_stream,format,options) != 0 ? - MagickTrue : MagickFalse; - if (options != (char *) NULL) - options=DestroyString(options); - (void) jas_stream_close(jp2_stream); - for (i=0; i < (ssize_t) number_components; i++) - jas_matrix_destroy(pixels[i]); - jas_image_destroy(jp2_image); + (void) TransformImageColorspace(image,sRGBColorspace); if (status != MagickFalse) ThrowWriterException(DelegateError,"UnableToEncodeImageFile"); return(MagickTrue); diff --git a/config/config.h.in b/config/config.h.in index 68dfa1270..e49ca2a0a 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -721,9 +721,6 @@ /* Define if you have JBIG library */ #undef JBIG_DELEGATE -/* Define if you have JPEG version 2 "Jasper" library */ -#undef JP2_DELEGATE - /* Define if you have JPEG library */ #undef JPEG_DELEGATE diff --git a/configure b/configure index 4e93fd524..46600e72b 100755 --- a/configure +++ b/configure @@ -810,9 +810,6 @@ LIBOPENJP2_CFLAGS LCMS_LIBS LCMS_DELEGATE_FALSE LCMS_DELEGATE_TRUE -JP2_LIBS -JP2_DELEGATE_FALSE -JP2_DELEGATE_TRUE JPEG_LIBS JPEG_DELEGATE_FALSE JPEG_DELEGATE_TRUE @@ -1184,7 +1181,6 @@ with_gs_font_dir with_gvc with_jbig with_jpeg -with_jp2 with_lcms with_lcms2 with_openjp2 @@ -1956,7 +1952,6 @@ Optional Packages: --with-gvc enable GVC support --without-jbig disable JBIG support --without-jpeg disable JPEG support - --without-jp2 disable JPEG-2000 support --without-lcms disable lcms (v1.1X) support --without-lcms2 disable lcms (v2.X) support --without-openjp2 disable OpenJP2 support @@ -3703,7 +3698,7 @@ MAGICK_PATCHLEVEL_VERSION=0 MAGICK_VERSION=7.0.0-0 -MAGICK_SVN_REVISION=14085:14096M +MAGICK_SVN_REVISION=14085:14100M # Substitute library versioning @@ -29825,116 +29820,6 @@ fi -# -# Check for JPEG Version 2 delegate library. -# - -# Check whether --with-jp2 was given. -if test "${with_jp2+set}" = set; then : - withval=$with_jp2; with_jp2=$withval -else - with_jp2='yes' -fi - - -if test "$with_jp2" != 'yes'; then - DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-jp2=$with_jp2 " -fi - -have_jp2='no' -JP2_LIBS='' -if test "$with_jp2" != 'no'; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: -------------------------------------------------------------" >&5 -$as_echo "-------------------------------------------------------------" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for JPEG Version 2" >&5 -$as_echo_n "checking for JPEG Version 2... " >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5 -$as_echo "" >&6; } - failed=0 - passed=0 - ac_fn_c_check_header_mongrel "$LINENO" "jasper/jasper.h" "ac_cv_header_jasper_jasper_h" "$ac_includes_default" -if test "x$ac_cv_header_jasper_jasper_h" = xyes; then : - passed=`expr $passed + 1` -else - failed=`expr $failed + 1` -fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for jas_stream_fopen in -ljasper" >&5 -$as_echo_n "checking for jas_stream_fopen in -ljasper... " >&6; } -if ${ac_cv_lib_jasper_jas_stream_fopen+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-ljasper $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char jas_stream_fopen (); -int -main () -{ -return jas_stream_fopen (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_jasper_jas_stream_fopen=yes -else - ac_cv_lib_jasper_jas_stream_fopen=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jasper_jas_stream_fopen" >&5 -$as_echo "$ac_cv_lib_jasper_jas_stream_fopen" >&6; } -if test "x$ac_cv_lib_jasper_jas_stream_fopen" = xyes; then : - passed=`expr $passed + 1` -else - failed=`expr $failed + 1` -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if JPEG version 2 support package is complete" >&5 -$as_echo_n "checking if JPEG version 2 support package is complete... " >&6; } - if test $passed -gt 0; then - if test $failed -gt 0; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no -- some components failed test" >&5 -$as_echo "no -- some components failed test" >&6; } - have_jp2='no (failed tests)' - else - JP2_LIBS='-ljasper' - LIBS="$JP2_LIBS $LIBS" - -$as_echo "#define JP2_DELEGATE 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - have_jp2='yes' - fi - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - fi -fi - if test "$have_jp2" = 'yes'; then - JP2_DELEGATE_TRUE= - JP2_DELEGATE_FALSE='#' -else - JP2_DELEGATE_TRUE='#' - JP2_DELEGATE_FALSE= -fi - - - - # # Check for LCMS delegate library. # @@ -36011,7 +35896,7 @@ fi if test "$build_modules" != 'no'; then MAGICK_DEP_LIBS="$LCMS_LIBS $FREETYPE_LIBS $LQR_LIBS $FFTW_LIBS $FONTCONFIG_LIBS $XEXT_LIBS $IPC_LIBS $X11_LIBS $XT_LIBS $LZMA_LIBS $BZLIB_LIBS $ZLIB_LIBS $LTDL_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $THREAD_LIBS" else - MAGICK_DEP_LIBS="$JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JP2_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DJVU_LIBS $FFTW_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $OPENJPEG_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $THREAD_LIBS" + MAGICK_DEP_LIBS="$JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DJVU_LIBS $FFTW_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $OPENJPEG_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $THREAD_LIBS" fi @@ -36325,10 +36210,6 @@ if test -z "${JPEG_DELEGATE_TRUE}" && test -z "${JPEG_DELEGATE_FALSE}"; then as_fn_error $? "conditional \"JPEG_DELEGATE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${JP2_DELEGATE_TRUE}" && test -z "${JP2_DELEGATE_FALSE}"; then - as_fn_error $? "conditional \"JP2_DELEGATE\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi if test -z "${LCMS_DELEGATE_TRUE}" && test -z "${LCMS_DELEGATE_FALSE}"; then as_fn_error $? "conditional \"LCMS_DELEGATE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 diff --git a/configure.ac b/configure.ac index d0a5828e5..dce8f5362 100755 --- a/configure.ac +++ b/configure.ac @@ -2252,50 +2252,6 @@ AC_SUBST(JPEG_LIBS) dnl =========================================================================== -# -# Check for JPEG Version 2 delegate library. -# -AC_ARG_WITH([jp2], - [AC_HELP_STRING([--without-jp2], - [disable JPEG-2000 support])], - [with_jp2=$withval], - [with_jp2='yes']) - -if test "$with_jp2" != 'yes'; then - DISTCHECK_CONFIG_FLAGS="${DISTCHECK_CONFIG_FLAGS} --with-jp2=$with_jp2 " -fi - -have_jp2='no' -JP2_LIBS='' -if test "$with_jp2" != 'no'; then - AC_MSG_RESULT([-------------------------------------------------------------]) - AC_MSG_CHECKING([for JPEG Version 2]) - AC_MSG_RESULT([]) - failed=0 - passed=0 - AC_CHECK_HEADER(jasper/jasper.h,passed=`expr $passed + 1`,failed=`expr $failed + 1`) - AC_CHECK_LIB(jasper,jas_stream_fopen,passed=`expr $passed + 1`,failed=`expr $failed + 1`,) - AC_MSG_CHECKING([if JPEG version 2 support package is complete]) - if test $passed -gt 0; then - if test $failed -gt 0; then - AC_MSG_RESULT([no -- some components failed test]) - have_jp2='no (failed tests)' - else - JP2_LIBS='-ljasper' - LIBS="$JP2_LIBS $LIBS" - AC_DEFINE(JP2_DELEGATE,1,Define if you have JPEG version 2 "Jasper" library) - AC_MSG_RESULT([yes]) - have_jp2='yes' - fi - else - AC_MSG_RESULT([no]) - fi -fi -AM_CONDITIONAL(JP2_DELEGATE, test "$have_jp2" = 'yes') -AC_SUBST(JP2_LIBS) - -dnl =========================================================================== - # # Check for LCMS delegate library. # @@ -4016,7 +3972,7 @@ fi if test "$build_modules" != 'no'; then MAGICK_DEP_LIBS="$LCMS_LIBS $FREETYPE_LIBS $LQR_LIBS $FFTW_LIBS $FONTCONFIG_LIBS $XEXT_LIBS $IPC_LIBS $X11_LIBS $XT_LIBS $LZMA_LIBS $BZLIB_LIBS $ZLIB_LIBS $LTDL_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $THREAD_LIBS" else - MAGICK_DEP_LIBS="$JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JP2_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DJVU_LIBS $FFTW_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $OPENJPEG_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $THREAD_LIBS" + MAGICK_DEP_LIBS="$JBIG_LIBS $LCMS_LIBS $TIFF_LIBS $FREETYPE_LIBS $JPEG_LIBS $GS_LIBS $LQR_LIBS $PNG_LIBS $AUTOTRACE_LIBS $DJVU_LIBS $FFTW_LIBS $FPX_LIBS $FONTCONFIG_LIBS $WEBP_LIBS $WMF_LIBS $DPS_LIBS $XEXT_LIBS $XT_LIBS $IPC_LIBS $X11_LIBS $LZMA_LIBS $BZLIB_LIBS $OPENEXR_LIBS $OPENJPEG_LIBS $PANGO_LIBS $RSVG_LIBS $XML_LIBS $GVC_LIBS $ZLIB_LIBS $GDI32_LIBS $MATH_LIBS $GOMP_LIBS $CL_LIBS $UMEM_LIBS $THREAD_LIBS" fi AC_SUBST(MAGICK_DEP_LIBS)