blob: d8be337d624b89bf72a4b5ae0d741262a17546cf [file] [log] [blame]
cristy2aac09a2010-06-06 16:46:43 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% DDDD EEEEE BBBB U U GGGG %
7% D D E B B U U G %
8% D D EEE BBBB U U G GG %
9% D D E B B U U G G %
10% DDDD EEEEE BBBB UUU GGG %
11% %
12% %
13% Image Pixel Values for Debugging. %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy2aac09a2010-06-06 16:46:43 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
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. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#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"
cristy2aac09a2010-06-06 16:46:43 +000070
71/*
72 Forward declarations.
73*/
74static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000075 WriteDEBUGImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy2aac09a2010-06-06 16:46:43 +000076
77/*
78%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79% %
80% %
81% %
82% R e g i s t e r D E B U G I m a g e %
83% %
84% %
85% %
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87%
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.
94%
95% The format of the RegisterDEBUGImage method is:
96%
97% size_t RegisterDEBUGImage(void)
98%
99*/
100ModuleExport size_t RegisterDEBUGImage(void)
101{
102 MagickInfo
103 *entry;
104
105 entry=SetMagickInfo("DEBUG");
106 entry->encoder=(EncodeImageHandler *) WriteDEBUGImage;
107 entry->raw=MagickTrue;
108 entry->stealth=MagickTrue;
109 entry->description=ConstantString("Image pixel values for debugging");
110 entry->module=ConstantString("DEBUG");
111 (void) RegisterMagickInfo(entry);
112 return(MagickImageCoderSignature);
113}
114
115/*
116%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117% %
118% %
119% %
120% U n r e g i s t e r D E B U G I m a g e %
121% %
122% %
123% %
124%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125%
126% UnregisterDEBUGImage() removes format registrations made by the
127% DEBUG module from the list of supported format.
128%
129% The format of the UnregisterDEBUGImage method is:
130%
131% UnregisterDEBUGImage(void)
132%
133*/
134ModuleExport void UnregisterDEBUGImage(void)
135{
136 (void) UnregisterMagickInfo("DEBUG");
137}
138
139/*
140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141% %
142% %
143% %
144% W r i t e D E B U G I m a g e %
145% %
146% %
147% %
148%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149%
150% WriteDEBUGImage writes the image pixel values with 20 places of precision.
151%
152% The format of the WriteDEBUGImage method is:
153%
154% MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000155% Image *image,ExceptionInfo *exception)
cristy2aac09a2010-06-06 16:46:43 +0000156%
157% A description of each parameter follows.
158%
159% o image_info: the image info.
160%
161% o image: The image.
162%
cristy1e178e72011-08-28 19:44:34 +0000163% o exception: return any errors or warnings in this structure.
164%
cristy2aac09a2010-06-06 16:46:43 +0000165*/
166static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000167 Image *image,ExceptionInfo *exception)
cristy2aac09a2010-06-06 16:46:43 +0000168{
169 char
170 buffer[MaxTextExtent],
171 colorspace[MaxTextExtent],
172 tuple[MaxTextExtent];
173
174 ssize_t
175 y;
176
177 MagickBooleanType
178 status;
179
180 MagickOffsetType
181 scene;
182
cristy4c08aed2011-07-01 19:47:50 +0000183 PixelInfo
cristy2aac09a2010-06-06 16:46:43 +0000184 pixel;
185
cristy4c08aed2011-07-01 19:47:50 +0000186 register const Quantum
cristy2aac09a2010-06-06 16:46:43 +0000187 *p;
188
189 register ssize_t
190 x;
191
192 /*
193 Open output image file.
194 */
195 assert(image_info != (const ImageInfo *) NULL);
196 assert(image_info->signature == MagickSignature);
197 assert(image != (Image *) NULL);
198 assert(image->signature == MagickSignature);
199 if (image->debug != MagickFalse)
200 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy1e178e72011-08-28 19:44:34 +0000201 status=OpenBlob(image_info,image,WriteBlobMode,exception);
cristy2aac09a2010-06-06 16:46:43 +0000202 if (status == MagickFalse)
203 return(status);
204 scene=0;
205 do
206 {
cristy042ee782011-04-22 18:48:30 +0000207 (void) CopyMagickString(colorspace,CommandOptionToMnemonic(
cristy2aac09a2010-06-06 16:46:43 +0000208 MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent);
209 LocaleLower(colorspace);
210 image->depth=GetImageQuantumDepth(image,MagickTrue);
211 if (image->matte != MagickFalse)
212 (void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
cristyb51dff52011-05-19 16:55:47 +0000213 (void) FormatLocaleString(buffer,MaxTextExtent,
cristy2aac09a2010-06-06 16:46:43 +0000214 "# ImageMagick pixel debugging: %.20g,%.20g,%.20g,%s\n",(double)
cristyc932e2b2011-07-02 00:01:09 +0000215 image->columns,(double) image->rows,(double) ((MagickOffsetType)
216 GetQuantumRange(image->depth)),colorspace);
cristy2aac09a2010-06-06 16:46:43 +0000217 (void) WriteBlobString(image,buffer);
cristy4c08aed2011-07-01 19:47:50 +0000218 GetPixelInfo(image,&pixel);
cristy2aac09a2010-06-06 16:46:43 +0000219 for (y=0; y < (ssize_t) image->rows; y++)
220 {
cristy1e178e72011-08-28 19:44:34 +0000221 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000222 if (p == (const Quantum *) NULL)
cristy2aac09a2010-06-06 16:46:43 +0000223 break;
cristy2aac09a2010-06-06 16:46:43 +0000224 for (x=0; x < (ssize_t) image->columns; x++)
225 {
cristyb51dff52011-05-19 16:55:47 +0000226 (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g,%.20g: ",(double)
cristy2aac09a2010-06-06 16:46:43 +0000227 x,(double) y);
228 (void) WriteBlobString(image,buffer);
cristy803640d2011-11-17 02:11:32 +0000229 GetPixelInfoPixel(image,p,&pixel);
cristyb51dff52011-05-19 16:55:47 +0000230 (void) FormatLocaleString(tuple,MaxTextExtent,"%.20g,%.20g,%.20g ",
cristy2aac09a2010-06-06 16:46:43 +0000231 (double) pixel.red,(double) pixel.green,(double) pixel.blue);
232 if (pixel.colorspace == CMYKColorspace)
233 {
234 char
235 black[MaxTextExtent];
236
cristyb51dff52011-05-19 16:55:47 +0000237 (void) FormatLocaleString(black,MaxTextExtent,",%.20g ",
cristy4c08aed2011-07-01 19:47:50 +0000238 (double) pixel.black);
cristy2aac09a2010-06-06 16:46:43 +0000239 (void) ConcatenateMagickString(tuple,black,MaxTextExtent);
240 }
241 if (pixel.matte != MagickFalse)
242 {
243 char
244 alpha[MaxTextExtent];
245
cristyb51dff52011-05-19 16:55:47 +0000246 (void) FormatLocaleString(alpha,MaxTextExtent,",%.20g ",
cristy4c08aed2011-07-01 19:47:50 +0000247 (double) pixel.alpha);
cristy2aac09a2010-06-06 16:46:43 +0000248 (void) ConcatenateMagickString(tuple,alpha,MaxTextExtent);
249 }
cristy961ba3e2010-06-06 17:08:19 +0000250 (void) WriteBlobString(image,tuple);
cristy2aac09a2010-06-06 16:46:43 +0000251 (void) WriteBlobString(image,"\n");
cristyed231572011-07-14 02:18:59 +0000252 p+=GetPixelChannels(image);
cristy2aac09a2010-06-06 16:46:43 +0000253 }
254 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
255 image->rows);
256 if (status == MagickFalse)
257 break;
258 }
259 if (GetNextImageInList(image) == (Image *) NULL)
260 break;
261 image=SyncNextImageInList(image);
262 status=SetImageProgress(image,SaveImagesTag,scene++,
263 GetImageListLength(image));
264 if (status == MagickFalse)
265 break;
266 } while (image_info->adjoin != MagickFalse);
267 (void) CloseBlob(image);
268 return(MagickTrue);
269}