]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Sun, 5 Mar 2017 14:15:03 +0000 (09:15 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sun, 5 Mar 2017 14:15:03 +0000 (09:15 -0500)
MagickCore/magic.c
MagickCore/static.c
MagickCore/static.h
coders/pgx.c [new file with mode: 0644]
configure

index 0cb69c40577f59047f3bc2c8a11fc97478650693..84af1cfe554c7844062f7356f2fb7d5245e08ed0 100644 (file)
@@ -168,6 +168,8 @@ static const MagicMapInfo
     { "PAM", 0, MagicPattern("P7") },
     { "PFM", 0, MagicPattern("PF") },
     { "PFM", 0, MagicPattern("Pf") },
+    { "PGX", 0, MagicPattern("PG ML") },
+    { "PGX", 0, MagicPattern("PG LM") },
     { "PS", 0, MagicPattern("%!") },
     { "PS", 0, MagicPattern("\004%!") },
     { "PS", 0, MagicPattern("\305\320\323\306") },
index 1df178433f85d25f9e9504d0e8b972e66ae4217d..bd3ee4e7ce5219c52e7733e638fb18ad8b93c844 100644 (file)
@@ -264,6 +264,7 @@ MagickExport void RegisterStaticModules(void)
   (void) RegisterPDBImage();
   (void) RegisterPDFImage();
   (void) RegisterPESImage();
+  (void) RegisterPGXImage();
   (void) RegisterPICTImage();
   (void) RegisterPIXImage();
   (void) RegisterPLASMAImage();
@@ -451,6 +452,7 @@ MagickExport void UnregisterStaticModules(void)
   UnregisterPDBImage();
   UnregisterPDFImage();
   UnregisterPESImage();
+  UnregisterPGXImage();
   UnregisterPICTImage();
   UnregisterPIXImage();
   UnregisterPLASMAImage();
index 585306bd23e2beb03e5a4772534a050c6076be33..5801ec2a284fca44ee62fcf3cc670e31162cd449 100644 (file)
@@ -122,6 +122,7 @@ extern ModuleExport size_t
   RegisterPDBImage(void),
   RegisterPDFImage(void),
   RegisterPESImage(void),
+  RegisterPGXImage(void),
   RegisterPICImage(void),
   RegisterPICTImage(void),
   RegisterPIXImage(void),
@@ -285,6 +286,7 @@ extern ModuleExport void
   UnregisterPDBImage(void),
   UnregisterPDFImage(void),
   UnregisterPESImage(void),
+  UnregisterPGXImage(void),
   UnregisterPICImage(void),
   UnregisterPICTImage(void),
   UnregisterPIXImage(void),
diff --git a/coders/pgx.c b/coders/pgx.c
new file mode 100644 (file)
index 0000000..e014905
--- /dev/null
@@ -0,0 +1,393 @@
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%                            PPPP    GGGG  X   X                              %
+%                            P   P  G       X X                               %
+%                            PPPP   G  GG    X                                %
+%                            P      G   G   X X                               %
+%                            P       GGG   X   X                              %
+%                                                                             %
+%                                                                             %
+%                           PGX JPEG 2000 Format                              %
+%                                                                             %
+%                              Software Design                                %
+%                                   Cristy                                    %
+%                                 July 2016                                   %
+%                                                                             %
+%                                                                             %
+%  Copyright 1999-2017 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  %
+%  obtain a copy of the License at                                            %
+%                                                                             %
+%    http://www.imagemagick.org/script/license.php                            %
+%                                                                             %
+%  Unless required by applicable law or agreed to in writing, software        %
+%  distributed under the License is distributed on an "AS IS" BASIS,          %
+%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
+%  See the License for the specific language governing permissions and        %
+%  limitations under the License.                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%
+*/
+\f
+/*
+  Include declarations.
+*/
+#include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/colormap.h"
+#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-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/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
+\f
+/*
+  Forward declarations.
+*/
+static MagickBooleanType
+  WritePGXImage(const ImageInfo *,Image *,ExceptionInfo *);
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   I s P G X                                                                 %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  IsPGXreturns True if the image format type, identified by the magick
+%  string, is PGX.
+%
+%  The format of the IsPGX method is:
+%
+%      unsigned int IsPGX(const unsigned char *magick,const size_t length)
+%
+%  A description of each parameter follows:
+%
+%    o status:  Method IsPGX returns True if the image format type is PGX.
+%
+%    o magick: This string is generally the first few bytes of an image file
+%      or blob.
+%
+%    o length: Specifies the length of the magick string.
+%
+%
+*/
+static unsigned int IsPGX(const unsigned char *magick,const size_t length)
+{
+  if (length < 5)
+    return(MagickFalse);
+  if ((memcmp(magick,"PG ML",5) == 0) || (memcmp(magick,"PG LM",5) == 0))
+    return(MagickTrue);
+  return(MagickFalse);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   R e a d P G X I m a g e                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ReadPGXImage() reads an image of raw bits in LSB order and returns it.
+%  It allocates the memory necessary for the new Image structure and returns
+%  a pointer to the new image.
+%
+%  The format of the ReadPGXImage method is:
+%
+%      Image *ReadPGXImage(const ImageInfo *image_info,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image_info: the image info.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+static Image *ReadPGXImage(const ImageInfo *image_info,ExceptionInfo *exception)
+{
+  char
+    buffer[MagickPathExtent],
+    endian[MagickPathExtent],
+    sans[MagickPathExtent],
+    sign[MagickPathExtent];
+
+  const unsigned char
+    *pixels;
+
+  Image
+    *image;
+
+  int
+    height,
+    precision,
+    width;
+
+  QuantumInfo
+    *quantum_info;
+
+  MagickBooleanType
+    status;
+
+  size_t
+    length;
+
+  ssize_t
+    count,
+    y;
+
+  /*
+    Open image file.
+  */
+  assert(image_info != (const ImageInfo *) NULL);
+  assert(image_info->signature == MagickCoreSignature);
+  if (image_info->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+      image_info->filename);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  image=AcquireImage(image_info,exception);
+  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+  if (status == MagickFalse)
+    {
+      image=DestroyImageList(image);
+      return((Image *) NULL);
+    }
+  if (ReadBlobString(image,buffer) == (char *) NULL)
+    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+  count=(ssize_t) sscanf(buffer,"PG%[ \t]%2s%[ \t+-]%d%[ \t]%d%[ \t]%d",sans,
+    endian,sign,&precision,sans,&width,sans,&height);
+  image->depth=(size_t) precision;
+  if (LocaleCompare(endian,"ML") == 0)
+    image->endian=MSBEndian;
+  image->columns=(size_t) width;
+  image->rows=(size_t) height;
+  if ((image->columns == 0) || (image->rows == 0))
+    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+  if (image_info->ping != MagickFalse)
+    {
+      (void) CloseBlob(image);
+      return(GetFirstImageInList(image));
+    }
+  status=SetImageExtent(image,image->columns,image->rows,exception);
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
+  /*
+    Convert PGX image.
+  */
+  (void) SetImageColorspace(image,GRAYColorspace,exception);
+  quantum_info=AcquireQuantumInfo(image_info,image);
+  if (quantum_info == (QuantumInfo *) NULL)
+    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+  length=GetQuantumExtent(image,quantum_info,GrayQuantum);
+  for (y=0; y < (ssize_t) image->rows; y++)
+  {
+    register Quantum
+      *magick_restrict q;
+
+    q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    pixels=(const unsigned char *) ReadBlobStream(image,length,
+      GetQuantumPixels(quantum_info),&count);
+    if (count != (ssize_t) length)
+      ThrowReaderException(CorruptImageError,"UnableToReadImageData");
+    (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+      GrayQuantum,pixels,exception);
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+    if (SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,image->rows) == MagickFalse)
+      break;
+  }
+  SetQuantumImageType(image,GrayQuantum);
+  quantum_info=DestroyQuantumInfo(quantum_info);
+  if (EOFBlob(image) != MagickFalse)
+    ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
+      image->filename);
+  (void) CloseBlob(image);
+  return(GetFirstImageInList(image));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   R e g i s t e r P G X I m a g e                                           %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  RegisterPGXImage() adds attributes for the PGX image format to
+%  the list of supported formats.  The attributes include the image format
+%  tag, a method to read and/or write the format, whether the format
+%  supports the saving of more than one frame to the same file or blob,
+%  whether the format supports native in-memory I/O, and a brief
+%  description of the format.
+%
+%  The format of the RegisterPGXImage method is:
+%
+%      size_t RegisterPGXImage(void)
+%
+*/
+ModuleExport size_t RegisterPGXImage(void)
+{
+  MagickInfo
+    *entry;
+
+  entry=AcquireMagickInfo("PGX","PGX","JPEG 2000 uncompressed format");
+  entry->decoder=(DecodeImageHandler *) ReadPGXImage;
+  entry->encoder=(EncodeImageHandler *) WritePGXImage;
+  entry->magick=(IsImageFormatHandler *) IsPGX;
+  entry->flags^=CoderAdjoinFlag;
+  entry->flags^=CoderUseExtensionFlag;
+  (void) RegisterMagickInfo(entry);
+  return(MagickImageCoderSignature);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   U n r e g i s t e r P G X I m a g e                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  UnregisterPGXImage() removes format registrations made by the
+%  PGX module from the list of supported formats.
+%
+%  The format of the UnregisterPGXImage method is:
+%
+%      UnregisterPGXImage(void)
+%
+*/
+ModuleExport void UnregisterPGXImage(void)
+{
+  (void) UnregisterMagickInfo("PGX");
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   W r i t e P G X I m a g e                                                 %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  WritePGXImage() writes an image of raw bits in LSB order to a file.
+%
+%  The format of the WritePGXImage method is:
+%
+%      MagickBooleanType WritePGXImage(const ImageInfo *image_info,
+%        Image *image,ExceptionInfo *exception)
+%
+%  A description of each parameter follows.
+%
+%    o image_info: the image info.
+%
+%    o image:  The image.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+static MagickBooleanType WritePGXImage(const ImageInfo *image_info,Image *image,
+  ExceptionInfo *exception)
+{
+  char
+    buffer[MagickPathExtent];
+
+  MagickBooleanType
+    status;
+
+  QuantumInfo
+    *quantum_info;
+
+  register const Quantum
+    *p;
+
+  size_t
+    length;
+
+  ssize_t
+    count,
+    y;
+
+  unsigned char
+    *pixels;
+
+  /*
+    Open output image file.
+  */
+  assert(image_info != (const ImageInfo *) NULL);
+  assert(image_info->signature == MagickCoreSignature);
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickCoreSignature);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
+  if (status == MagickFalse)
+    return(status);
+  (void) FormatLocaleString(buffer,MagickPathExtent,"PG ML + %ld %lu %lu\n",
+    image->depth,image->columns,image->rows);
+  (void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
+  (void) TransformImageColorspace(image,sRGBColorspace,exception);
+  quantum_info=AcquireQuantumInfo(image_info,image);
+  pixels=(unsigned char *) GetQuantumPixels(quantum_info);
+  for (y=0; y < (ssize_t) image->rows; y++)
+  {
+    p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+      GrayQuantum,pixels,exception);
+    count=WriteBlob(image,length,pixels);
+    if (count != (ssize_t) length)
+      ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
+    count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
+    status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+      image->rows);
+    if (status == MagickFalse)
+      break;
+  }
+  quantum_info=DestroyQuantumInfo(quantum_info);
+  (void) CloseBlob(image);
+  return(status);
+}
index 7c6a75f4b62dbbefe21cf2826bc869d3d82d0d60..dc210573ff40359acf6fea1462a97c290c9b01c4 100755 (executable)
--- a/configure
+++ b/configure
@@ -4519,7 +4519,7 @@ MAGICK_PATCHLEVEL_VERSION=2
 
 MAGICK_VERSION=7.0.5-2
 
-MAGICK_GIT_REVISION=19663:3734212:20170304
+MAGICK_GIT_REVISION=19673:9f4e013:20170305
 
 
 # Substitute library versioning