]> granicus.if.org Git - imagemagick/blobdiff - coders/txt.c
(no commit message)
[imagemagick] / coders / txt.c
index db31a0df7b216fb60c54248041bc249c806f6439..52822789fe6126feaa3221675fc6d47c9749d1e6 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2013 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  %
@@ -432,11 +432,11 @@ static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
     image->depth=depth;
     LocaleLower(colorspace);
     i=(ssize_t) strlen(colorspace)-1;
-    image->matte=MagickFalse;
+    image->alpha_trait=UndefinedPixelTrait;
     if ((i > 0) && (colorspace[i] == 'a'))
       {
         colorspace[i]='\0';
-        image->matte=MagickTrue;
+        image->alpha_trait=BlendPixelTrait;
       }
     type=ParseCommandOption(MagickColorspaceOptions,MagickFalse,colorspace);
     if (type < 0)
@@ -447,6 +447,13 @@ static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
     range=GetQuantumRange(image->depth);
     for (y=0; y < (ssize_t) image->rows; y++)
     {
+      double
+        alpha,
+        black,
+        blue,
+        green,
+        red;
+
       for (x=0; x < (ssize_t) image->columns; x++)
       {
         if (ReadBlobString(image,text) == (char *) NULL)
@@ -455,52 +462,55 @@ static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
         {
           case GRAYColorspace:
           {
-            if (image->matte != MagickFalse)
+            if (image->alpha_trait == BlendPixelTrait)
               {
                 count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf",&x_offset,
-                  &y_offset,&pixel.red,&pixel.alpha);
-                pixel.green=pixel.red;
-                pixel.blue=pixel.red;
+                  &y_offset,&red,&alpha);
+                green=red;
+                blue=red;
                 break;
               }
             count=(ssize_t) sscanf(text,"%ld,%ld: (%lf",&x_offset,&y_offset,
-              &pixel.red);
-            pixel.green=pixel.red;
-            pixel.blue=pixel.red;
+              &red);
+            green=red;
+            blue=red;
             break;       
           }
           case CMYKColorspace:
           {
-            if (image->matte != MagickFalse)
+            if (image->alpha_trait == BlendPixelTrait)
               {
                 count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf,%lf,%lf",
-                  &x_offset,&y_offset,&pixel.red,&pixel.green,&pixel.blue,
-                  &pixel.black,&pixel.alpha);
+                  &x_offset,&y_offset,&red,&green,&blue,&black,&alpha);
                 break;
               }
             count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf,%lf",&x_offset,
-              &y_offset,&pixel.red,&pixel.green,&pixel.blue,&pixel.black);
+              &y_offset,&red,&green,&blue,&black);
             break;
           }
           default:
           {
-            if (image->matte != MagickFalse)
+            if (image->alpha_trait == BlendPixelTrait)
               {
                 count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf,%lf",
-                  &x_offset,&y_offset,&pixel.red,&pixel.green,&pixel.blue,
-                  &pixel.alpha);
+                  &x_offset,&y_offset,&red,&green,&blue,&alpha);
                 break;
               }
             count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf",&x_offset,
-              &y_offset,&pixel.red,&pixel.green,&pixel.blue);
+              &y_offset,&red,&green,&blue);
             break;       
           }
         }
-        pixel.red=ScaleAnyToQuantum(pixel.red,range);
-        pixel.green=ScaleAnyToQuantum(pixel.green,range);
-        pixel.blue=ScaleAnyToQuantum(pixel.blue,range);
-        pixel.black=ScaleAnyToQuantum(pixel.black,range);
-        pixel.alpha=ScaleAnyToQuantum(pixel.alpha,range);
+        if (image->colorspace == LabColorspace)
+          {
+            green+=(range+1)/2.0;
+            blue+=(range+1)/2.0;
+          }
+        pixel.red=ScaleAnyToQuantum((QuantumAny) (red+0.5),range);
+        pixel.green=ScaleAnyToQuantum((QuantumAny) (green+0.5),range);
+        pixel.blue=ScaleAnyToQuantum((QuantumAny) (blue+0.5),range);
+        pixel.black=ScaleAnyToQuantum((QuantumAny) (black+0.5),range);
+        pixel.alpha=ScaleAnyToQuantum((QuantumAny) (alpha+0.5),range);
         q=GetAuthenticPixels(image,x_offset,y_offset,1,1,exception);
         if (q == (Quantum *) NULL)
           continue;
@@ -638,7 +648,11 @@ static MagickBooleanType WriteTXTImage(const ImageInfo *image_info,Image *image,
     colorspace[MaxTextExtent],
     tuple[MaxTextExtent];
 
+  const char
+    *option;
+
   MagickBooleanType
+    sparse_color,
     status;
 
   MagickOffsetType
@@ -668,6 +682,8 @@ static MagickBooleanType WriteTXTImage(const ImageInfo *image_info,Image *image,
   status=OpenBlob(image_info,image,WriteBlobMode,exception);
   if (status == MagickFalse)
     return(status);
+  option=GetImageOption(image_info,"txt:sparse-color");
+  sparse_color=IsStringTrue(option);
   scene=0;
   do
   {
@@ -675,7 +691,7 @@ static MagickBooleanType WriteTXTImage(const ImageInfo *image_info,Image *image,
       MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent);
     LocaleLower(colorspace);
     image->depth=GetImageQuantumDepth(image,MagickTrue);
-    if (image->matte != MagickFalse)
+    if (image->alpha_trait == BlendPixelTrait)
       (void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
     (void) FormatLocaleString(buffer,MaxTextExtent,
       "# ImageMagick pixel enumeration: %.20g,%.20g,%.20g,%s\n",(double)
@@ -690,10 +706,33 @@ static MagickBooleanType WriteTXTImage(const ImageInfo *image_info,Image *image,
         break;
       for (x=0; x < (ssize_t) image->columns; x++)
       {
+        GetPixelInfoPixel(image,p,&pixel);
+        if (pixel.colorspace == LabColorspace)
+          {
+            pixel.green-=(QuantumRange+1)/2.0;
+            pixel.blue-=(QuantumRange+1)/2.0;
+          }
+        if (sparse_color != MagickFalse)
+          {
+            /*
+              Sparse-color format.
+            */
+            if (GetPixelAlpha(image,p) == (Quantum) OpaqueAlpha)
+              {
+                (void) QueryColorname(image,&pixel,SVGCompliance,tuple,
+                  exception);
+                (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g,%.20g ",
+                  (double) x,(double) y);
+                (void) WriteBlobString(image,buffer);
+                (void) WriteBlobString(image,tuple);
+                (void) WriteBlobString(image," ");
+              }
+            p+=GetPixelChannels(image);
+            continue;
+          }
         (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g,%.20g: ",(double)
           x,(double) y);
         (void) WriteBlobString(image,buffer);
-        GetPixelInfoPixel(image,p,&pixel);
         (void) CopyMagickString(tuple,"(",MaxTextExtent);
         if (pixel.colorspace == GRAYColorspace)
           ConcatenateColorComponent(&pixel,GrayPixelChannel,X11Compliance,
@@ -715,7 +754,7 @@ static MagickBooleanType WriteTXTImage(const ImageInfo *image_info,Image *image,
             ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,
               tuple);
           }
-        if (pixel.matte != MagickFalse)
+        if (pixel.alpha_trait == BlendPixelTrait)
           {
             (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
             ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,