2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % DDDD EEEEE BBBB U U GGGG %
8 % D D EEE BBBB U U G GG %
10 % DDDD EEEEE BBBB UUU GGG %
13 % Image Pixel Values for Debugging. %
20 % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/annotate.h"
44 #include "MagickCore/attribute.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/blob-private.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colorspace.h"
51 #include "MagickCore/constitute.h"
52 #include "MagickCore/draw.h"
53 #include "MagickCore/exception.h"
54 #include "MagickCore/exception-private.h"
55 #include "MagickCore/geometry.h"
56 #include "MagickCore/image.h"
57 #include "MagickCore/image-private.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/monitor-private.h"
63 #include "MagickCore/option.h"
64 #include "MagickCore/pixel-accessor.h"
65 #include "MagickCore/quantum-private.h"
66 #include "MagickCore/static.h"
67 #include "MagickCore/statistic.h"
68 #include "MagickCore/string_.h"
69 #include "MagickCore/module.h"
74 static MagickBooleanType
75 WriteDEBUGImage(const ImageInfo *,Image *,ExceptionInfo *);
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % R e g i s t e r D E B U G I m a g e %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % RegisterDEBUGImage() adds attributes for the DEBUG image format to the
89 % list of supported formats. The attributes include the image format
90 % tag, a method to read and/or write the format, whether the format
91 % supports the saving of more than one frame to the same file or blob,
92 % whether the format supports native in-memory I/O, and a brief
93 % description of the format.
95 % The format of the RegisterDEBUGImage method is:
97 % size_t RegisterDEBUGImage(void)
100 ModuleExport size_t RegisterDEBUGImage(void)
105 entry=AcquireMagickInfo("DEBUG","DEBUG","Image pixel values for debugging");
106 entry->encoder=(EncodeImageHandler *) WriteDEBUGImage;
107 entry->flags|=CoderRawSupportFlag;
108 entry->flags|=CoderStealthFlag;
109 (void) RegisterMagickInfo(entry);
110 return(MagickImageCoderSignature);
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 % U n r e g i s t e r D E B U G I m a g e %
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 % UnregisterDEBUGImage() removes format registrations made by the
125 % DEBUG module from the list of supported format.
127 % The format of the UnregisterDEBUGImage method is:
129 % UnregisterDEBUGImage(void)
132 ModuleExport void UnregisterDEBUGImage(void)
134 (void) UnregisterMagickInfo("DEBUG");
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % W r i t e D E B U G I m a g e %
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 % WriteDEBUGImage writes the image pixel values with 20 places of precision.
150 % The format of the WriteDEBUGImage method is:
152 % MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
153 % Image *image,ExceptionInfo *exception)
155 % A description of each parameter follows.
157 % o image_info: the image info.
159 % o image: The image.
161 % o exception: return any errors or warnings in this structure.
164 static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
165 Image *image,ExceptionInfo *exception)
168 buffer[MagickPathExtent],
169 colorspace[MagickPathExtent],
170 tuple[MagickPathExtent];
184 register const Quantum
191 Open output image file.
193 assert(image_info != (const ImageInfo *) NULL);
194 assert(image_info->signature == MagickSignature);
195 assert(image != (Image *) NULL);
196 assert(image->signature == MagickSignature);
197 if (image->debug != MagickFalse)
198 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
199 status=OpenBlob(image_info,image,WriteBlobMode,exception);
200 if (status == MagickFalse)
205 (void) CopyMagickString(colorspace,CommandOptionToMnemonic(
206 MagickColorspaceOptions,(ssize_t) image->colorspace),MagickPathExtent);
207 LocaleLower(colorspace);
208 image->depth=GetImageQuantumDepth(image,MagickTrue);
209 if (image->alpha_trait != UndefinedPixelTrait)
210 (void) ConcatenateMagickString(colorspace,"a",MagickPathExtent);
211 (void) FormatLocaleString(buffer,MagickPathExtent,
212 "# ImageMagick pixel debugging: %.20g,%.20g,%.20g,%s\n",(double)
213 image->columns,(double) image->rows,(double) ((MagickOffsetType)
214 GetQuantumRange(image->depth)),colorspace);
215 (void) WriteBlobString(image,buffer);
216 GetPixelInfo(image,&pixel);
217 for (y=0; y < (ssize_t) image->rows; y++)
219 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
220 if (p == (const Quantum *) NULL)
222 for (x=0; x < (ssize_t) image->columns; x++)
224 (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g,%.20g: ",(double)
226 (void) WriteBlobString(image,buffer);
227 GetPixelInfoPixel(image,p,&pixel);
228 (void) FormatLocaleString(tuple,MagickPathExtent,"%.20g,%.20g,%.20g ",
229 (double) pixel.red,(double) pixel.green,(double) pixel.blue);
230 if (pixel.colorspace == CMYKColorspace)
233 black[MagickPathExtent];
235 (void) FormatLocaleString(black,MagickPathExtent,",%.20g ",
236 (double) pixel.black);
237 (void) ConcatenateMagickString(tuple,black,MagickPathExtent);
239 if (pixel.alpha_trait != UndefinedPixelTrait)
242 alpha[MagickPathExtent];
244 (void) FormatLocaleString(alpha,MagickPathExtent,",%.20g ",
245 (double) pixel.alpha);
246 (void) ConcatenateMagickString(tuple,alpha,MagickPathExtent);
248 (void) WriteBlobString(image,tuple);
249 (void) WriteBlobString(image,"\n");
250 p+=GetPixelChannels(image);
252 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
254 if (status == MagickFalse)
257 if (GetNextImageInList(image) == (Image *) NULL)
259 image=SyncNextImageInList(image);
260 status=SetImageProgress(image,SaveImagesTag,scene++,
261 GetImageListLength(image));
262 if (status == MagickFalse)
264 } while (image_info->adjoin != MagickFalse);
265 (void) CloseBlob(image);