cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 1 | /* |
| 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 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 21 | % 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 | */ |
| 42 | #include "magick/studio.h" |
| 43 | #include "magick/annotate.h" |
| 44 | #include "magick/attribute.h" |
| 45 | #include "magick/blob.h" |
| 46 | #include "magick/blob-private.h" |
| 47 | #include "magick/cache.h" |
| 48 | #include "magick/color.h" |
| 49 | #include "magick/color-private.h" |
| 50 | #include "magick/colorspace.h" |
| 51 | #include "magick/constitute.h" |
| 52 | #include "magick/draw.h" |
| 53 | #include "magick/exception.h" |
| 54 | #include "magick/exception-private.h" |
| 55 | #include "magick/geometry.h" |
| 56 | #include "magick/image.h" |
| 57 | #include "magick/image-private.h" |
| 58 | #include "magick/list.h" |
| 59 | #include "magick/magick.h" |
| 60 | #include "magick/memory_.h" |
| 61 | #include "magick/monitor.h" |
| 62 | #include "magick/monitor-private.h" |
| 63 | #include "magick/option.h" |
| 64 | #include "magick/pixel-private.h" |
| 65 | #include "magick/quantum-private.h" |
| 66 | #include "magick/static.h" |
| 67 | #include "magick/statistic.h" |
| 68 | #include "magick/string_.h" |
| 69 | #include "magick/module.h" |
| 70 | |
| 71 | /* |
| 72 | Forward declarations. |
| 73 | */ |
| 74 | static MagickBooleanType |
| 75 | WriteDEBUGImage(const ImageInfo *,Image *); |
| 76 | |
| 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 | */ |
| 100 | ModuleExport 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 | */ |
| 134 | ModuleExport 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, |
| 155 | % Image *image) |
| 156 | % |
| 157 | % A description of each parameter follows. |
| 158 | % |
| 159 | % o image_info: the image info. |
| 160 | % |
| 161 | % o image: The image. |
| 162 | % |
| 163 | */ |
| 164 | static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info, |
| 165 | Image *image) |
| 166 | { |
| 167 | char |
| 168 | buffer[MaxTextExtent], |
| 169 | colorspace[MaxTextExtent], |
| 170 | tuple[MaxTextExtent]; |
| 171 | |
| 172 | ssize_t |
| 173 | y; |
| 174 | |
| 175 | MagickBooleanType |
| 176 | status; |
| 177 | |
| 178 | MagickOffsetType |
| 179 | scene; |
| 180 | |
| 181 | MagickPixelPacket |
| 182 | pixel; |
| 183 | |
| 184 | register const IndexPacket |
| 185 | *indexes; |
| 186 | |
| 187 | register const PixelPacket |
| 188 | *p; |
| 189 | |
| 190 | register ssize_t |
| 191 | x; |
| 192 | |
| 193 | /* |
| 194 | Open output image file. |
| 195 | */ |
| 196 | assert(image_info != (const ImageInfo *) NULL); |
| 197 | assert(image_info->signature == MagickSignature); |
| 198 | assert(image != (Image *) NULL); |
| 199 | assert(image->signature == MagickSignature); |
| 200 | if (image->debug != MagickFalse) |
| 201 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 202 | status=OpenBlob(image_info,image,WriteBlobMode,&image->exception); |
| 203 | if (status == MagickFalse) |
| 204 | return(status); |
| 205 | scene=0; |
| 206 | do |
| 207 | { |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 208 | (void) CopyMagickString(colorspace,CommandOptionToMnemonic( |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 209 | MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent); |
| 210 | LocaleLower(colorspace); |
| 211 | image->depth=GetImageQuantumDepth(image,MagickTrue); |
| 212 | if (image->matte != MagickFalse) |
| 213 | (void) ConcatenateMagickString(colorspace,"a",MaxTextExtent); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame^] | 214 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 215 | "# ImageMagick pixel debugging: %.20g,%.20g,%.20g,%s\n",(double) |
| 216 | image->columns,(double) image->rows,(double) |
| 217 | GetQuantumRange(image->depth),colorspace); |
| 218 | (void) WriteBlobString(image,buffer); |
| 219 | GetMagickPixelPacket(image,&pixel); |
| 220 | for (y=0; y < (ssize_t) image->rows; y++) |
| 221 | { |
| 222 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
| 223 | if (p == (const PixelPacket *) NULL) |
| 224 | break; |
| 225 | indexes=GetVirtualIndexQueue(image); |
| 226 | for (x=0; x < (ssize_t) image->columns; x++) |
| 227 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame^] | 228 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g,%.20g: ",(double) |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 229 | x,(double) y); |
| 230 | (void) WriteBlobString(image,buffer); |
| 231 | SetMagickPixelPacket(image,p,indexes+x,&pixel); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame^] | 232 | (void) FormatLocaleString(tuple,MaxTextExtent,"%.20g,%.20g,%.20g ", |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 233 | (double) pixel.red,(double) pixel.green,(double) pixel.blue); |
| 234 | if (pixel.colorspace == CMYKColorspace) |
| 235 | { |
| 236 | char |
| 237 | black[MaxTextExtent]; |
| 238 | |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame^] | 239 | (void) FormatLocaleString(black,MaxTextExtent,",%.20g ", |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 240 | (double) pixel.index); |
| 241 | (void) ConcatenateMagickString(tuple,black,MaxTextExtent); |
| 242 | } |
| 243 | if (pixel.matte != MagickFalse) |
| 244 | { |
| 245 | char |
| 246 | alpha[MaxTextExtent]; |
| 247 | |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame^] | 248 | (void) FormatLocaleString(alpha,MaxTextExtent,",%.20g ", |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 249 | (double) (QuantumRange-pixel.opacity)); |
| 250 | (void) ConcatenateMagickString(tuple,alpha,MaxTextExtent); |
| 251 | } |
cristy | 961ba3e | 2010-06-06 17:08:19 +0000 | [diff] [blame] | 252 | (void) WriteBlobString(image,tuple); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 253 | (void) WriteBlobString(image,"\n"); |
| 254 | p++; |
| 255 | } |
| 256 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 257 | image->rows); |
| 258 | if (status == MagickFalse) |
| 259 | break; |
| 260 | } |
| 261 | if (GetNextImageInList(image) == (Image *) NULL) |
| 262 | break; |
| 263 | image=SyncNextImageInList(image); |
| 264 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 265 | GetImageListLength(image)); |
| 266 | if (status == MagickFalse) |
| 267 | break; |
| 268 | } while (image_info->adjoin != MagickFalse); |
| 269 | (void) CloseBlob(image); |
| 270 | return(MagickTrue); |
| 271 | } |