]> granicus.if.org Git - imagemagick/blobdiff - coders/jp2.c
...
[imagemagick] / coders / jp2.c
index 94b775e1ca6e7f226732d3b2957d5383366e8cf8..1673656dee85d8c62ff5eafbd4d1c3dbd8132783 100644 (file)
@@ -17,7 +17,7 @@
 %                                 June 2001                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -391,7 +391,7 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception)
         (jp2_image->comps[0].dy != jp2_image->comps[i].dy) ||
         (jp2_image->comps[0].prec != jp2_image->comps[i].prec) ||
         (jp2_image->comps[0].sgnd != jp2_image->comps[i].sgnd) ||
-        (jp2_image->comps[i].data == NULL))
+        ((image->ping == MagickFalse) && (jp2_image->comps[i].data == NULL)))
       {
         opj_destroy_codec(jp2_codec);
         opj_image_destroy(jp2_image);
@@ -408,15 +408,18 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception)
   if (status == MagickFalse)
     return(DestroyImageList(image));
   image->compression=JPEG2000Compression;
-  if (jp2_image->color_space == 2)
-    {
-      SetImageColorspace(image,GRAYColorspace,exception);
-      if (jp2_image->numcomps > 1)
-        image->alpha_trait=BlendPixelTrait;
-    }
+  if (jp2_image->numcomps == 1)
+    SetImageColorspace(image,GRAYColorspace,exception);
   else
-    if (jp2_image->color_space == 3)
-      SetImageColorspace(image,Rec601YCbCrColorspace,exception);
+    if (jp2_image->color_space == 2)
+      {
+        SetImageColorspace(image,GRAYColorspace,exception);
+        if (jp2_image->numcomps > 1)
+          image->alpha_trait=BlendPixelTrait;
+      }
+    else
+      if (jp2_image->color_space == 3)
+        SetImageColorspace(image,Rec601YCbCrColorspace,exception);
   if (jp2_image->numcomps > 3)
     image->alpha_trait=BlendPixelTrait;
   if (jp2_image->icc_profile_buf != (unsigned char *) NULL)
@@ -466,6 +469,12 @@ static Image *ReadJP2Image(const ImageInfo *image_info,ExceptionInfo *exception)
         {
            case 0:
            {
+             if (jp2_image->numcomps == 1)
+               {
+                 SetPixelGray(image,ClampToQuantum(pixel),q);
+                 SetPixelAlpha(image,OpaqueAlpha,q);
+                 break;
+               }
              SetPixelRed(image,ClampToQuantum(pixel),q);
              SetPixelGreen(image,ClampToQuantum(pixel),q);
              SetPixelBlue(image,ClampToQuantum(pixel),q);
@@ -917,7 +926,7 @@ static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image,
       &parameters.subsampling_dx,&parameters.subsampling_dy);
   property=GetImageProperty(image,"comment",exception);
   if (property != (const char *) NULL)
-    parameters.cp_comment=ConstantString(property);
+    parameters.cp_comment=(char *) property;
   channels=3;
   jp2_colorspace=OPJ_CLRSPC_SRGB;
   if (image->colorspace == YUVColorspace)
@@ -1007,7 +1016,7 @@ static MagickBooleanType WriteJP2Image(const ImageInfo *image_info,Image *image,
           {
             if (jp2_colorspace == OPJ_CLRSPC_GRAY)
               {
-                *q=(int) (scale*GetPixelLuma(image,p));
+                *q=(int) (scale*GetPixelGray(image,p));
                 break;
               }
             *q=(int) (scale*GetPixelRed(image,p));