GraphicsMagick: ReadJXLImage(): Now based on ImportImagePixelArea()

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.35173.1671654123.1567.graphicsmagick-commit@lists.sourceforge.net>
changeset 9dec91f4bc2e in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=9dec91f4bc2e
summary: ReadJXLImage(): Now based on ImportImagePixelArea()

diffstat:

 ChangeLog                              |    5 +
 VisualMagick/installer/inc/version.isx |    4 +-
 coders/jxl.c                           |  590 ++++++--------------------------
 magick/version.h                       |    4 +-
 www/Changelog.html                     |    7 +
 5 files changed, 137 insertions(+), 473 deletions(-)

diffs (truncated from 698 to 500 lines):

diff -r aee8477213b0 -r 9dec91f4bc2e ChangeLog
--- a/ChangeLog	Tue Dec 20 15:52:28 2022 -0600
+++ b/ChangeLog	Wed Dec 21 14:21:50 2022 -0600
@@ -1,3 +1,8 @@
+2022-12-21  Bob Friesenhahn  <[email protected]>
+
+	* coders/jxl.c (ReadJXLImage): Now based on
+	ImportImagePixelArea().
+
 2022-12-20  Bob Friesenhahn  <[email protected]>
 
 	* coders/msl.c (MSLEntityDeclaration): Report an error if
diff -r aee8477213b0 -r 9dec91f4bc2e VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx	Tue Dec 20 15:52:28 2022 -0600
+++ b/VisualMagick/installer/inc/version.isx	Wed Dec 21 14:21:50 2022 -0600
@@ -10,5 +10,5 @@
 
 #define public MagickPackageName "GraphicsMagick"
 #define public MagickPackageVersion "1.4"
-#define public MagickPackageVersionAddendum ".020221220"
-#define public MagickPackageReleaseDate "snapshot-20221220"
+#define public MagickPackageVersionAddendum ".020221221"
+#define public MagickPackageReleaseDate "snapshot-20221221"
diff -r aee8477213b0 -r 9dec91f4bc2e coders/jxl.c
--- a/coders/jxl.c	Tue Dec 20 15:52:28 2022 -0600
+++ b/coders/jxl.c	Wed Dec 21 14:21:50 2022 -0600
@@ -24,10 +24,14 @@
 *
 * Features still to be completed:
 *
-*   * Support linear gray
-*   * Support CMYK
+*   * Support premultiplied alpha
+*   * Support Alpha bits != RGB sample bits
+*   * Support CMYK layers
+*   * Support progressive
 *   * Support embedded profiles
 *   * Support 16-bit float ("Half") format
+*   * Support progress monitor
+*   * Use import/export functions (ImportImagePixelArea()/ExportImagePixelArea())
 */
 
 #include "magick/studio.h"
@@ -135,452 +139,21 @@
     }
 }
 
-#define FOR_PIXEL_PACKETS \
-  for (y=0; y < (long)image->rows; y++)                              \
-    {                                                                \
-       q=SetImagePixelsEx(image,0,y,image->columns,1,exception);     \
-       if (q == (PixelPacket *) NULL)                                \
-         return MagickFail;                                          \
-       for (x=0; x < (long)image->columns; x++)
-
-#define END_FOR_PIXEL_PACKETS      \
-      if (!SyncImagePixels(image)) \
-        return MagickFail;         \
-    }                              \
-
-static MagickBool fill_pixels_char(Image *image,
-                                   ExceptionInfo *exception,
-                                   unsigned char *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,ScaleCharToQuantum(*p)); p++;
-        SetGreenSample(q,ScaleCharToQuantum(*p)); p++;
-        SetBlueSample(q,ScaleCharToQuantum(*p)); p++;
-        SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(*p)); p++;
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,ScaleCharToQuantum(*p)); p++;
-        SetGreenSample(q,ScaleCharToQuantum(*p)); p++;
-        SetBlueSample(q,ScaleCharToQuantum(*p)); p++;
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
-}
-
-static MagickBool fill_pixels_short(Image *image,
-                                   ExceptionInfo *exception,
-                                   unsigned short *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,ScaleShortToQuantum(*p)); p++;
-        SetGreenSample(q,ScaleShortToQuantum(*p)); p++;
-        SetBlueSample(q,ScaleShortToQuantum(*p)); p++;
-        SetOpacitySample(q,MaxRGB-ScaleShortToQuantum(*p)); p++;
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,ScaleShortToQuantum(*p)); p++;
-        SetGreenSample(q,ScaleShortToQuantum(*p)); p++;
-        SetBlueSample(q,ScaleShortToQuantum(*p)); p++;
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
-}
-
-static MagickBool fill_pixels_float(Image *image,
-                                    ExceptionInfo *exception,
-                                    float *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        SetGreenSample(q,RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        SetBlueSample(q,RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        SetOpacitySample(q,MaxRGB-RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        SetGreenSample(q,RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        SetBlueSample(q,RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
-}
-
-static MagickBool fill_pixels_char_grayscale(Image *image, ExceptionInfo *exception,
-                                             unsigned char *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->storage_class == PseudoClass)
-    {
-      IndexPacket
-        index;
-
-      for (y=0; y < (long)image->rows; y++)
-        {
-          register IndexPacket
-            *indexes;
-
-          q=SetImagePixelsEx(image,0,y,image->columns,1,exception);
-          if (q == (PixelPacket *) NULL)
-            return MagickFail;
-
-          indexes=AccessMutableIndexes(image);
-          if (indexes == NULL)
-            return MagickFail;
-
-          for (x=0; x < (long)image->columns; x++)
-            {
-              index=(IndexPacket)(*p++);
-              VerifyColormapIndex(image,index);
-              indexes[x]=index;
-              *q++=image->colormap[index];
-            }
-        }
-
-      if (!SyncImagePixels(image))
-        return MagickFail;
-    }
-  else
-    {
-      if (image->matte) {
-        FOR_PIXEL_PACKETS
-          {
-            const Quantum s = ScaleCharToQuantum(*p); p++;
-            SetRedSample(q,s);
-            SetGreenSample(q,s);
-            SetBlueSample(q,s);
-            SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(*p)); p++;
-            q++;
-          }
-        END_FOR_PIXEL_PACKETS
-          } else {
-        FOR_PIXEL_PACKETS
-          {
-            const Quantum s = ScaleCharToQuantum(*p); p++;
-            SetRedSample(q,s);
-            SetGreenSample(q,s);
-            SetBlueSample(q,s); p++;
-            SetOpacitySample(q,OpaqueOpacity);
-            q++;
-          }
-        END_FOR_PIXEL_PACKETS
-      }
-    }
-  return MagickTrue;
-}
-
-static MagickBool fill_pixels_short_grayscale(Image *image, ExceptionInfo *exception,
-                                              unsigned short *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->storage_class == PseudoClass)
-    {
-      IndexPacket
-        index;
-
-      for (y=0; y < (long)image->rows; y++)
-        {
-          register IndexPacket
-            *indexes;
-
-          q=SetImagePixelsEx(image,0,y,image->columns,1,exception);
-          if (q == (PixelPacket *) NULL)
-            return MagickFail;
-
-          indexes=AccessMutableIndexes(image);
-          if (indexes == NULL)
-            return MagickFail;
-
-          for (x=0; x < (long)image->columns; x++)
-            {
-              index=(IndexPacket)(*p++);
-              VerifyColormapIndex(image,index);
-              indexes[x]=index;
-              *q++=image->colormap[index];
-            }
-        }
-
-      if (!SyncImagePixels(image))
-        return MagickFail;
-    }
-  else
-    {
-      if (image->matte) {
-        FOR_PIXEL_PACKETS
-          {
-            Quantum s = ScaleShortToQuantum(*p); p++;
-            SetRedSample(q,s);
-            SetGreenSample(q,s);
-            SetBlueSample(q,s);
-            SetOpacitySample(q,MaxRGB-ScaleShortToQuantum(*p)); p++;
-            q++;
-          }
-        END_FOR_PIXEL_PACKETS
-          } else {
-        FOR_PIXEL_PACKETS
-          {
-            Quantum s = ScaleShortToQuantum(*p); p++;
-            SetRedSample(q,s);
-            SetGreenSample(q,s);
-            SetBlueSample(q,s);
-            SetOpacitySample(q,OpaqueOpacity);
-            q++;
-          }
-        END_FOR_PIXEL_PACKETS
-      }
-    }
-  return MagickTrue;
-}
-
-
-static MagickBool fill_pixels_float_grayscale(Image *image,
-                                              ExceptionInfo *exception,
-                                              float *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  image->storage_class = DirectClass;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        Quantum s = RoundFloatToQuantum(*p * MaxRGBFloat); p++;
-        SetRedSample(q,s);
-        SetGreenSample(q,s);
-        SetBlueSample(q,s);
-        SetOpacitySample(q,MaxRGB-RoundFloatToQuantum(*p * MaxRGBFloat)); p++;
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        Quantum s = RoundFloatToQuantum(*p * MaxRGBFloat); p++;
-        SetRedSample(q,s);
-        SetGreenSample(q,s);
-        SetBlueSample(q,s);
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
-}
-
-
 /** Convert any linear RGB to SRGB
  *  Formula from wikipedia:
  *      https://en.wikipedia.org/wiki/SRGB
  */
-static Quantum linear2nonlinear(float p)
-{
-  if (p < 0.0031308) {
-    p=p * 12.92;
-  } else {
-    p=1.055 * powf(p, 1.0/2.4) - 0.055;
-  }
-  return RoundFloatToQuantum(p * MaxRGBFloat);
-}
-
-static MagickBool fill_pixels_float_linear(Image *image,
-                                           ExceptionInfo *exception,
-                                           float *p)
+static void linear2nonlinear_quantum(Quantum *q)
 {
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,linear2nonlinear(*p++));
-        SetGreenSample(q,linear2nonlinear(*p++));
-        SetBlueSample(q,linear2nonlinear(*p++));
-        SetOpacitySample(q,MaxRGB-linear2nonlinear(*p++));
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,linear2nonlinear(*p++));
-        SetGreenSample(q,linear2nonlinear(*p++));
-        SetBlueSample(q,linear2nonlinear(*p++));
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
-}
-
-static Quantum linear2nonlinear_char(unsigned char c)
-{
-  float p = c * (1.0f/256.0f);
-  if (p < 0.0031308) {
-    p=p * 12.92;
-  } else {
-    p=1.055 * powf(p, 1.0/2.4) - 0.055;
-  }
-  return RoundFloatToQuantum(p * MaxRGBFloat);
-}
-
-static Quantum linear2nonlinear_short(unsigned short s)
-{
-  double p = s * (1.0/256.0);
+  double p = *q * (1.0/256.0);
   if (p < 0.0031308) {
     p=p * 12.92;
   } else {
     p=1.055 * pow(p, 1.0/2.4) - 0.055;
   }
-  return RoundDoubleToQuantum(p * MaxRGBDouble);
-}
-
-static MagickBool fill_pixels_char_linear(Image *image,
-                                          ExceptionInfo *exception,
-                                          unsigned char *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,linear2nonlinear_char(*p++));
-        SetGreenSample(q,linear2nonlinear_char(*p++));
-        SetBlueSample(q,linear2nonlinear_char(*p++));
-        SetOpacitySample(q,MaxRGB-linear2nonlinear_char(*p++));
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,linear2nonlinear_char(*p++));
-        SetGreenSample(q,linear2nonlinear_char(*p++));
-        SetBlueSample(q,linear2nonlinear_char(*p++));
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
+  *q = RoundDoubleToQuantum(p * MaxRGBDouble);
 }
 
-static MagickBool fill_pixels_short_linear(Image *image,
-                                          ExceptionInfo *exception,
-                                          unsigned short *p)
-{
-  long
-    x,
-    y;
-
-  PixelPacket
-    *q;
-
-  if (image->matte) {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,linear2nonlinear_short(*p++));
-        SetGreenSample(q,linear2nonlinear_short(*p++));
-        SetBlueSample(q,linear2nonlinear_short(*p++));
-        SetOpacitySample(q,MaxRGB-linear2nonlinear_short(*p++));
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      } else {
-    FOR_PIXEL_PACKETS
-      {
-        SetRedSample(q,linear2nonlinear_short(*p++));
-        SetGreenSample(q,linear2nonlinear_short(*p++));
-        SetBlueSample(q,linear2nonlinear_short(*p++));
-        SetOpacitySample(q,OpaqueOpacity);
-        q++;
-      }
-    END_FOR_PIXEL_PACKETS
-      }
-
-  return MagickTrue;
-}
-
-
 static const char *JxlTransferFunctionAsString(const JxlTransferFunction fn)
 {
   const char *str = "Unknown";
@@ -956,7 +529,7 @@
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.