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 % Cristy % 17 % July 1992 % 18 % % 19 % % 20 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % 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 /* 41 Include declarations. 42 */ 43 #include "MagickCore/studio.h" 44 #include "MagickCore/annotate.h" 45 #include "MagickCore/attribute.h" 46 #include "MagickCore/blob.h" 47 #include "MagickCore/blob-private.h" 48 #include "MagickCore/cache.h" 49 #include "MagickCore/color.h" 50 #include "MagickCore/color-private.h" 51 #include "MagickCore/colorspace.h" 52 #include "MagickCore/constitute.h" 53 #include "MagickCore/draw.h" 54 #include "MagickCore/exception.h" 55 #include "MagickCore/exception-private.h" 56 #include "MagickCore/geometry.h" 57 #include "MagickCore/image.h" 58 #include "MagickCore/image-private.h" 59 #include "MagickCore/list.h" 60 #include "MagickCore/magick.h" 61 #include "MagickCore/memory_.h" 62 #include "MagickCore/monitor.h" 63 #include "MagickCore/monitor-private.h" 64 #include "MagickCore/option.h" 65 #include "MagickCore/pixel-accessor.h" 66 #include "MagickCore/quantum-private.h" 67 #include "MagickCore/static.h" 68 #include "MagickCore/statistic.h" 69 #include "MagickCore/string_.h" 70 #include "MagickCore/module.h" 71 72 /* 74 Forward declarations. 75 */ 76 static MagickBooleanType 77 WriteDEBUGImage(const ImageInfo *,Image *,ExceptionInfo *); 78 79 /* 81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 82 % % 83 % % 84 % % 85 % R e g i s t e r D E B U G I m a g e % 86 % % 87 % % 88 % % 89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 90 % 91 % RegisterDEBUGImage() adds attributes for the DEBUG image format to the 92 % list of supported formats. The attributes include the image format 93 % tag, a method to read and/or write the format, whether the format 94 % supports the saving of more than one frame to the same file or blob, 95 % whether the format supports native in-memory I/O, and a brief 96 % description of the format. 97 % 98 % The format of the RegisterDEBUGImage method is: 99 % 100 % size_t RegisterDEBUGImage(void) 101 % 102 */ 103 ModuleExport size_t RegisterDEBUGImage(void) 104 { 105 MagickInfo 106 *entry; 107 108 entry=AcquireMagickInfo("DEBUG","DEBUG","Image pixel values for debugging"); 109 entry->encoder=(EncodeImageHandler *) WriteDEBUGImage; 110 entry->flags|=CoderRawSupportFlag; 111 entry->flags|=CoderStealthFlag; 112 (void) RegisterMagickInfo(entry); 113 return(MagickImageCoderSignature); 114 } 115 116 /* 118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 119 % % 120 % % 121 % % 122 % U n r e g i s t e r D E B U G I m a g e % 123 % % 124 % % 125 % % 126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 127 % 128 % UnregisterDEBUGImage() removes format registrations made by the 129 % DEBUG module from the list of supported format. 130 % 131 % The format of the UnregisterDEBUGImage method is: 132 % 133 % UnregisterDEBUGImage(void) 134 % 135 */ 136 ModuleExport void UnregisterDEBUGImage(void) 137 { 138 (void) UnregisterMagickInfo("DEBUG"); 139 } 140 141 /* 143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 144 % % 145 % % 146 % % 147 % W r i t e D E B U G I m a g e % 148 % % 149 % % 150 % % 151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 152 % 153 % WriteDEBUGImage writes the image pixel values with 20 places of precision. 154 % 155 % The format of the WriteDEBUGImage method is: 156 % 157 % MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info, 158 % Image *image,ExceptionInfo *exception) 159 % 160 % A description of each parameter follows. 161 % 162 % o image_info: the image info. 163 % 164 % o image: The image. 165 % 166 % o exception: return any errors or warnings in this structure. 167 % 168 */ 169 static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info, 170 Image *image,ExceptionInfo *exception) 171 { 172 char 173 buffer[MagickPathExtent], 174 colorspace[MagickPathExtent], 175 tuple[MagickPathExtent]; 176 177 ssize_t 178 y; 179 180 MagickBooleanType 181 status; 182 183 MagickOffsetType 184 scene; 185 186 PixelInfo 187 pixel; 188 189 register const Quantum 190 *p; 191 192 register ssize_t 193 x; 194 195 /* 196 Open output image file. 197 */ 198 assert(image_info != (const ImageInfo *) NULL); 199 assert(image_info->signature == MagickCoreSignature); 200 assert(image != (Image *) NULL); 201 assert(image->signature == MagickCoreSignature); 202 if (image->debug != MagickFalse) 203 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 204 status=OpenBlob(image_info,image,WriteBlobMode,exception); 205 if (status == MagickFalse) 206 return(status); 207 scene=0; 208 do 209 { 210 (void) CopyMagickString(colorspace,CommandOptionToMnemonic( 211 MagickColorspaceOptions,(ssize_t) image->colorspace),MagickPathExtent); 212 LocaleLower(colorspace); 213 image->depth=GetImageQuantumDepth(image,MagickTrue); 214 if (image->alpha_trait != UndefinedPixelTrait) 215 (void) ConcatenateMagickString(colorspace,"a",MagickPathExtent); 216 (void) FormatLocaleString(buffer,MagickPathExtent, 217 "# ImageMagick pixel debugging: %.20g,%.20g,%.20g,%s\n",(double) 218 image->columns,(double) image->rows,(double) ((MagickOffsetType) 219 GetQuantumRange(image->depth)),colorspace); 220 (void) WriteBlobString(image,buffer); 221 GetPixelInfo(image,&pixel); 222 for (y=0; y < (ssize_t) image->rows; y++) 223 { 224 p=GetVirtualPixels(image,0,y,image->columns,1,exception); 225 if (p == (const Quantum *) NULL) 226 break; 227 for (x=0; x < (ssize_t) image->columns; x++) 228 { 229 (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g,%.20g: ",(double) 230 x,(double) y); 231 (void) WriteBlobString(image,buffer); 232 GetPixelInfoPixel(image,p,&pixel); 233 (void) FormatLocaleString(tuple,MagickPathExtent,"%.20g,%.20g,%.20g ", 234 (double) pixel.red,(double) pixel.green,(double) pixel.blue); 235 if (pixel.colorspace == CMYKColorspace) 236 { 237 char 238 black[MagickPathExtent]; 239 240 (void) FormatLocaleString(black,MagickPathExtent,",%.20g ", 241 (double) pixel.black); 242 (void) ConcatenateMagickString(tuple,black,MagickPathExtent); 243 } 244 if (pixel.alpha_trait != UndefinedPixelTrait) 245 { 246 char 247 alpha[MagickPathExtent]; 248 249 (void) FormatLocaleString(alpha,MagickPathExtent,",%.20g ", 250 (double) pixel.alpha); 251 (void) ConcatenateMagickString(tuple,alpha,MagickPathExtent); 252 } 253 (void) WriteBlobString(image,tuple); 254 (void) WriteBlobString(image,"\n"); 255 p+=GetPixelChannels(image); 256 } 257 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, 258 image->rows); 259 if (status == MagickFalse) 260 break; 261 } 262 if (GetNextImageInList(image) == (Image *) NULL) 263 break; 264 image=SyncNextImageInList(image); 265 status=SetImageProgress(image,SaveImagesTag,scene++, 266 GetImageListLength(image)); 267 if (status == MagickFalse) 268 break; 269 } while (image_info->adjoin != MagickFalse); 270 (void) CloseBlob(image); 271 return(MagickTrue); 272 } 273