Optional newlines to "sparse-color:"
Posted: 2015-01-22T16:51:46-07:00
The "-sparse-color" operator can read an at-file where pixels are on separate lines. However, the output format "sparse-color:" currently writes the pixels on a single line, each followed by a space. Processing these can be painful.
I propose a "-define" option is added which, if set, will issue a newline "\n" instead of a space after each pixel. For example:
The diff file below to coders\txt.c, from v6.9.0-0, implements this change.
If implemented, this would also need an addition to documentation http://www.imagemagick.org/script/comma ... php#define :
I propose a "-define" option is added which, if set, will issue a newline "\n" instead of a space after each pixel. For example:
Code: Select all
convert -size 1x5 gradient: sparse-color:
0,0,white 0,1,srgb(75%,75%,75%) 0,2,srgb(50%,50%,50%) 0,3,srgb(25%,25%,25%) 0,4,black
convert -size 1x5 gradient: -define sparse-color:newline=true sparse-color:
0,0,white
0,1,srgb(75%,75%,75%)
0,2,srgb(50%,50%,50%)
0,3,srgb(25%,25%,25%)
0,4,black
If implemented, this would also need an addition to documentation http://www.imagemagick.org/script/comma ... php#define :
sparse-color:newline[=true]
By default, the output format "sparse-color:" issues a space after each pixel. When this option is defined, a newline is issued instead.
Code: Select all
--- /home/Alan/ImageMagick-6.9.0-0/factory/txt.c 2014-07-03 13:53:23.000000000 +0100
+++ /home/Alan/ImageMagick-6.9.0-0//coders/txt.c 2015-01-22 23:31:03.282992500 +0000
@@ -41,6 +41,7 @@
*/
#include "magick/studio.h"
#include "magick/annotate.h"
+#include "magick/artifact.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
@@ -723,6 +724,9 @@
ComplianceType
compliance;
+ MagickBooleanType
+ NeedNewLine;
+
(void) CopyMagickString(colorspace,CommandOptionToMnemonic(
MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent);
LocaleLower(colorspace);
@@ -730,8 +734,16 @@
if (image->matte != MagickFalse)
(void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
compliance=NoCompliance;
- if (LocaleCompare(image_info->magick,"SPARSE-COLOR") != 0)
+ NeedNewLine=MagickFalse;
+ if (LocaleCompare(image_info->magick,"SPARSE-COLOR") == 0)
{
+ const char
+ *value;
+ value=GetImageOption(image_info,"sparse-color:newline");
+ if (value == NULL)
+ value=GetImageArtifact(image,"sparse-color:newline");
+ NeedNewLine = (value != NULL);
+ } else {
(void) FormatLocaleString(buffer,MaxTextExtent,
"# ImageMagick pixel enumeration: %.20g,%.20g,%.20g,%s\n",(double)
image->columns,(double) image->rows,(double) ((MagickOffsetType)
@@ -768,7 +780,7 @@
(double) x,(double) y);
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,tuple);
- (void) WriteBlobString(image," ");
+ (void) WriteBlobString(image, NeedNewLine ? "\n" : " ");
}
p++;
continue;