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 % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | Forward declarations. |
| 73 | */ |
| 74 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 75 | WriteDEBUGImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 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 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 105 | entry=AcquireMagickInfo("DEBUG","DEBUG","Image pixel values for debugging"); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 106 | entry->encoder=(EncodeImageHandler *) WriteDEBUGImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 107 | entry->flags|=CoderRawSupportFlag; |
| 108 | entry->flags|=CoderStealthFlag; |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 109 | (void) RegisterMagickInfo(entry); |
| 110 | return(MagickImageCoderSignature); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 115 | % % |
| 116 | % % |
| 117 | % % |
| 118 | % U n r e g i s t e r D E B U G I m a g e % |
| 119 | % % |
| 120 | % % |
| 121 | % % |
| 122 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 123 | % |
| 124 | % UnregisterDEBUGImage() removes format registrations made by the |
| 125 | % DEBUG module from the list of supported format. |
| 126 | % |
| 127 | % The format of the UnregisterDEBUGImage method is: |
| 128 | % |
| 129 | % UnregisterDEBUGImage(void) |
| 130 | % |
| 131 | */ |
| 132 | ModuleExport void UnregisterDEBUGImage(void) |
| 133 | { |
| 134 | (void) UnregisterMagickInfo("DEBUG"); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 139 | % % |
| 140 | % % |
| 141 | % % |
| 142 | % W r i t e D E B U G I m a g e % |
| 143 | % % |
| 144 | % % |
| 145 | % % |
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 147 | % |
| 148 | % WriteDEBUGImage writes the image pixel values with 20 places of precision. |
| 149 | % |
| 150 | % The format of the WriteDEBUGImage method is: |
| 151 | % |
| 152 | % MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 153 | % Image *image,ExceptionInfo *exception) |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 154 | % |
| 155 | % A description of each parameter follows. |
| 156 | % |
| 157 | % o image_info: the image info. |
| 158 | % |
| 159 | % o image: The image. |
| 160 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 161 | % o exception: return any errors or warnings in this structure. |
| 162 | % |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 163 | */ |
| 164 | static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 165 | Image *image,ExceptionInfo *exception) |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 166 | { |
| 167 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 168 | buffer[MagickPathExtent], |
| 169 | colorspace[MagickPathExtent], |
| 170 | tuple[MagickPathExtent]; |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 171 | |
| 172 | ssize_t |
| 173 | y; |
| 174 | |
| 175 | MagickBooleanType |
| 176 | status; |
| 177 | |
| 178 | MagickOffsetType |
| 179 | scene; |
| 180 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 181 | PixelInfo |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 182 | pixel; |
| 183 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 184 | register const Quantum |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 185 | *p; |
| 186 | |
| 187 | register ssize_t |
| 188 | x; |
| 189 | |
| 190 | /* |
| 191 | Open output image file. |
| 192 | */ |
| 193 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 194 | assert(image_info->signature == MagickCoreSignature); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 195 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 196 | assert(image->signature == MagickCoreSignature); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 197 | if (image->debug != MagickFalse) |
| 198 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 199 | status=OpenBlob(image_info,image,WriteBlobMode,exception); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 200 | if (status == MagickFalse) |
| 201 | return(status); |
| 202 | scene=0; |
| 203 | do |
| 204 | { |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 205 | (void) CopyMagickString(colorspace,CommandOptionToMnemonic( |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 206 | MagickColorspaceOptions,(ssize_t) image->colorspace),MagickPathExtent); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 207 | LocaleLower(colorspace); |
| 208 | image->depth=GetImageQuantumDepth(image,MagickTrue); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 209 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 210 | (void) ConcatenateMagickString(colorspace,"a",MagickPathExtent); |
| 211 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 212 | "# ImageMagick pixel debugging: %.20g,%.20g,%.20g,%s\n",(double) |
cristy | c932e2b | 2011-07-02 00:01:09 +0000 | [diff] [blame] | 213 | image->columns,(double) image->rows,(double) ((MagickOffsetType) |
| 214 | GetQuantumRange(image->depth)),colorspace); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 215 | (void) WriteBlobString(image,buffer); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 216 | GetPixelInfo(image,&pixel); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 217 | for (y=0; y < (ssize_t) image->rows; y++) |
| 218 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 219 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 220 | if (p == (const Quantum *) NULL) |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 221 | break; |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 222 | for (x=0; x < (ssize_t) image->columns; x++) |
| 223 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 224 | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g,%.20g: ",(double) |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 225 | x,(double) y); |
| 226 | (void) WriteBlobString(image,buffer); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 227 | GetPixelInfoPixel(image,p,&pixel); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 228 | (void) FormatLocaleString(tuple,MagickPathExtent,"%.20g,%.20g,%.20g ", |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 229 | (double) pixel.red,(double) pixel.green,(double) pixel.blue); |
| 230 | if (pixel.colorspace == CMYKColorspace) |
| 231 | { |
| 232 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 233 | black[MagickPathExtent]; |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 234 | |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 235 | (void) FormatLocaleString(black,MagickPathExtent,",%.20g ", |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 236 | (double) pixel.black); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 237 | (void) ConcatenateMagickString(tuple,black,MagickPathExtent); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 238 | } |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 239 | if (pixel.alpha_trait != UndefinedPixelTrait) |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 240 | { |
| 241 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 242 | alpha[MagickPathExtent]; |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 243 | |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 244 | (void) FormatLocaleString(alpha,MagickPathExtent,",%.20g ", |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 245 | (double) pixel.alpha); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 246 | (void) ConcatenateMagickString(tuple,alpha,MagickPathExtent); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 247 | } |
cristy | 961ba3e | 2010-06-06 17:08:19 +0000 | [diff] [blame] | 248 | (void) WriteBlobString(image,tuple); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 249 | (void) WriteBlobString(image,"\n"); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 250 | p+=GetPixelChannels(image); |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 251 | } |
| 252 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 253 | image->rows); |
| 254 | if (status == MagickFalse) |
| 255 | break; |
| 256 | } |
| 257 | if (GetNextImageInList(image) == (Image *) NULL) |
| 258 | break; |
| 259 | image=SyncNextImageInList(image); |
| 260 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 261 | GetImageListLength(image)); |
| 262 | if (status == MagickFalse) |
| 263 | break; |
| 264 | } while (image_info->adjoin != MagickFalse); |
| 265 | (void) CloseBlob(image); |
| 266 | return(MagickTrue); |
| 267 | } |