cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % TTTTT X X TTTTT % |
| 7 | % T X X T % |
| 8 | % T X T % |
| 9 | % T X X T % |
| 10 | % T X X T % |
| 11 | % % |
| 12 | % % |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 13 | % Render Text Onto A Canvas Image. % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +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 | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | Forward declarations. |
| 73 | */ |
| 74 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 75 | WriteTXTImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 79 | % % |
| 80 | % % |
| 81 | % % |
| 82 | % I s T X T % |
| 83 | % % |
| 84 | % % |
| 85 | % % |
| 86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 87 | % |
| 88 | % IsTXT() returns MagickTrue if the image format type, identified by the magick |
| 89 | % string, is TXT. |
| 90 | % |
| 91 | % The format of the IsTXT method is: |
| 92 | % |
| 93 | % MagickBooleanType IsTXT(const unsigned char *magick,const size_t length) |
| 94 | % |
| 95 | % A description of each parameter follows: |
| 96 | % |
| 97 | % o magick: compare image format pattern against these bytes. |
| 98 | % |
| 99 | % o length: Specifies the length of the magick string. |
| 100 | % |
| 101 | */ |
| 102 | static MagickBooleanType IsTXT(const unsigned char *magick,const size_t length) |
| 103 | { |
| 104 | #define MagickID "# ImageMagick pixel enumeration:" |
| 105 | |
| 106 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 107 | colorspace[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | |
| 109 | ssize_t |
| 110 | count; |
| 111 | |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 112 | unsigned long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | columns, |
| 114 | depth, |
| 115 | rows; |
| 116 | |
| 117 | if (length < 40) |
| 118 | return(MagickFalse); |
| 119 | if (LocaleNCompare((const char *) magick,MagickID,strlen(MagickID)) != 0) |
| 120 | return(MagickFalse); |
| 121 | count=(ssize_t) sscanf((const char *) magick+32,"%lu,%lu,%lu,%s",&columns, |
| 122 | &rows,&depth,colorspace); |
| 123 | if (count != 4) |
| 124 | return(MagickFalse); |
| 125 | return(MagickTrue); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 130 | % % |
| 131 | % % |
| 132 | % % |
| 133 | % R e a d T E X T I m a g e % |
| 134 | % % |
| 135 | % % |
| 136 | % % |
| 137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 138 | % |
| 139 | % ReadTEXTImage() reads a text file and returns it as an image. It |
| 140 | % allocates the memory necessary for the new Image structure and returns a |
| 141 | % pointer to the new image. |
| 142 | % |
| 143 | % The format of the ReadTEXTImage method is: |
| 144 | % |
| 145 | % Image *ReadTEXTImage(const ImageInfo *image_info,Image *image, |
| 146 | % char *text,ExceptionInfo *exception) |
| 147 | % |
| 148 | % A description of each parameter follows: |
| 149 | % |
| 150 | % o image_info: the image info. |
| 151 | % |
| 152 | % o image: the image. |
| 153 | % |
| 154 | % o text: the text storage buffer. |
| 155 | % |
| 156 | % o exception: return any errors or warnings in this structure. |
| 157 | % |
| 158 | */ |
| 159 | static Image *ReadTEXTImage(const ImageInfo *image_info,Image *image, |
| 160 | char *text,ExceptionInfo *exception) |
| 161 | { |
| 162 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 163 | filename[MagickPathExtent], |
| 164 | geometry[MagickPathExtent], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | *p; |
| 166 | |
| 167 | DrawInfo |
| 168 | *draw_info; |
| 169 | |
| 170 | Image |
| 171 | *texture; |
| 172 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | MagickBooleanType |
| 174 | status; |
| 175 | |
| 176 | PointInfo |
| 177 | delta; |
| 178 | |
| 179 | RectangleInfo |
| 180 | page; |
| 181 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 182 | ssize_t |
| 183 | offset; |
| 184 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | TypeMetric |
| 186 | metrics; |
| 187 | |
| 188 | /* |
| 189 | Open image file. |
| 190 | */ |
| 191 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 192 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | if (image_info->debug != MagickFalse) |
| 194 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 195 | image_info->filename); |
| 196 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 197 | assert(exception->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 198 | /* |
| 199 | Set the page geometry. |
| 200 | */ |
| 201 | delta.x=DefaultResolution; |
| 202 | delta.y=DefaultResolution; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 203 | if ((image->resolution.x == 0.0) || (image->resolution.y == 0.0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | { |
| 205 | GeometryInfo |
| 206 | geometry_info; |
| 207 | |
| 208 | MagickStatusType |
| 209 | flags; |
| 210 | |
| 211 | flags=ParseGeometry(PSDensityGeometry,&geometry_info); |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 212 | image->resolution.x=geometry_info.rho; |
| 213 | image->resolution.y=geometry_info.sigma; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | if ((flags & SigmaValue) == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 215 | image->resolution.y=image->resolution.x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | } |
| 217 | page.width=612; |
| 218 | page.height=792; |
| 219 | page.x=43; |
| 220 | page.y=43; |
| 221 | if (image_info->page != (char *) NULL) |
| 222 | (void) ParseAbsoluteGeometry(image_info->page,&page); |
| 223 | /* |
| 224 | Initialize Image structure. |
| 225 | */ |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 226 | image->columns=(size_t) floor((((double) page.width*image->resolution.x)/ |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 227 | delta.x)+0.5); |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 228 | image->rows=(size_t) floor((((double) page.height*image->resolution.y)/ |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 229 | delta.y)+0.5); |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 230 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 231 | if (status == MagickFalse) |
| 232 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | image->page.x=0; |
| 234 | image->page.y=0; |
| 235 | texture=(Image *) NULL; |
| 236 | if (image_info->texture != (char *) NULL) |
| 237 | { |
| 238 | ImageInfo |
| 239 | *read_info; |
| 240 | |
| 241 | read_info=CloneImageInfo(image_info); |
| 242 | SetImageInfoBlob(read_info,(void *) NULL,0); |
| 243 | (void) CopyMagickString(read_info->filename,image_info->texture, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 244 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | texture=ReadImage(read_info,exception); |
| 246 | read_info=DestroyImageInfo(read_info); |
| 247 | } |
| 248 | /* |
| 249 | Annotate the text image. |
| 250 | */ |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 251 | (void) SetImageBackgroundColor(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); |
| 253 | (void) CloneString(&draw_info->text,image_info->filename); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 254 | (void) FormatLocaleString(geometry,MagickPathExtent,"0x0%+ld%+ld",(long) page.x, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 255 | (long) page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 256 | (void) CloneString(&draw_info->geometry,geometry); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 257 | status=GetTypeMetrics(image,draw_info,&metrics,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 258 | if (status == MagickFalse) |
| 259 | ThrowReaderException(TypeError,"UnableToGetTypeMetrics"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 260 | page.y=(ssize_t) ceil((double) page.y+metrics.ascent-0.5); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 261 | (void) FormatLocaleString(geometry,MagickPathExtent,"0x0%+ld%+ld",(long) page.x, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 262 | (long) page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | (void) CloneString(&draw_info->geometry,geometry); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 264 | (void) CopyMagickString(filename,image_info->filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 265 | if (*draw_info->text != '\0') |
| 266 | *draw_info->text='\0'; |
| 267 | p=text; |
| 268 | for (offset=2*page.y; p != (char *) NULL; ) |
| 269 | { |
| 270 | /* |
| 271 | Annotate image with text. |
| 272 | */ |
| 273 | (void) ConcatenateString(&draw_info->text,text); |
| 274 | (void) ConcatenateString(&draw_info->text,"\n"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 275 | offset+=(ssize_t) (metrics.ascent-metrics.descent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 276 | if (image->previous == (Image *) NULL) |
| 277 | { |
| 278 | status=SetImageProgress(image,LoadImageTag,offset,image->rows); |
| 279 | if (status == MagickFalse) |
| 280 | break; |
| 281 | } |
| 282 | p=ReadBlobString(image,text); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 283 | if ((offset < (ssize_t) image->rows) && (p != (char *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 284 | continue; |
| 285 | if (texture != (Image *) NULL) |
| 286 | { |
| 287 | MagickProgressMonitor |
| 288 | progress_monitor; |
| 289 | |
| 290 | progress_monitor=SetImageProgressMonitor(image, |
| 291 | (MagickProgressMonitor) NULL,image->client_data); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 292 | (void) TextureImage(image,texture,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | (void) SetImageProgressMonitor(image,progress_monitor, |
| 294 | image->client_data); |
| 295 | } |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 296 | (void) AnnotateImage(image,draw_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | if (p == (char *) NULL) |
| 298 | break; |
| 299 | /* |
| 300 | Page is full-- allocate next image structure. |
| 301 | */ |
| 302 | *draw_info->text='\0'; |
| 303 | offset=2*page.y; |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 304 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 305 | if (GetNextImageInList(image) == (Image *) NULL) |
| 306 | { |
| 307 | image=DestroyImageList(image); |
| 308 | return((Image *) NULL); |
| 309 | } |
| 310 | image->next->columns=image->columns; |
| 311 | image->next->rows=image->rows; |
| 312 | image=SyncNextImageInList(image); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 313 | (void) CopyMagickString(image->filename,filename,MagickPathExtent); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 314 | (void) SetImageBackgroundColor(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 315 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 316 | GetBlobSize(image)); |
| 317 | if (status == MagickFalse) |
| 318 | break; |
| 319 | } |
| 320 | if (texture != (Image *) NULL) |
| 321 | { |
| 322 | MagickProgressMonitor |
| 323 | progress_monitor; |
| 324 | |
| 325 | progress_monitor=SetImageProgressMonitor(image, |
| 326 | (MagickProgressMonitor) NULL,image->client_data); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 327 | (void) TextureImage(image,texture,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | (void) SetImageProgressMonitor(image,progress_monitor,image->client_data); |
| 329 | } |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 330 | (void) AnnotateImage(image,draw_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 331 | if (texture != (Image *) NULL) |
| 332 | texture=DestroyImage(texture); |
| 333 | draw_info=DestroyDrawInfo(draw_info); |
| 334 | (void) CloseBlob(image); |
| 335 | return(GetFirstImageInList(image)); |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 340 | % % |
| 341 | % % |
| 342 | % % |
| 343 | % R e a d T X T I m a g e % |
| 344 | % % |
| 345 | % % |
| 346 | % % |
| 347 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 348 | % |
| 349 | % ReadTXTImage() reads a text file and returns it as an image. It allocates |
| 350 | % the memory necessary for the new Image structure and returns a pointer to |
| 351 | % the new image. |
| 352 | % |
| 353 | % The format of the ReadTXTImage method is: |
| 354 | % |
| 355 | % Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 356 | % |
| 357 | % A description of each parameter follows: |
| 358 | % |
| 359 | % o image_info: the image info. |
| 360 | % |
| 361 | % o exception: return any errors or warnings in this structure. |
| 362 | % |
| 363 | */ |
| 364 | static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 365 | { |
| 366 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 367 | colorspace[MagickPathExtent], |
| 368 | text[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 369 | |
| 370 | Image |
| 371 | *image; |
| 372 | |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 373 | long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 374 | type, |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 375 | x_offset, |
| 376 | y, |
| 377 | y_offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 378 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 379 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 380 | pixel; |
| 381 | |
| 382 | MagickBooleanType |
| 383 | status; |
| 384 | |
| 385 | QuantumAny |
| 386 | range; |
| 387 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 388 | register ssize_t |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 389 | i, |
| 390 | x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 392 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 393 | *q; |
| 394 | |
| 395 | ssize_t |
| 396 | count; |
| 397 | |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 398 | unsigned long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | depth, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 400 | height, |
| 401 | max_value, |
| 402 | width; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | Open image file. |
| 406 | */ |
| 407 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 408 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | if (image_info->debug != MagickFalse) |
| 410 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 411 | image_info->filename); |
| 412 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 413 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 414 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 415 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 416 | if (status == MagickFalse) |
| 417 | { |
| 418 | image=DestroyImageList(image); |
| 419 | return((Image *) NULL); |
| 420 | } |
| 421 | (void) ResetMagickMemory(text,0,sizeof(text)); |
| 422 | (void) ReadBlobString(image,text); |
| 423 | if (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) != 0) |
| 424 | return(ReadTEXTImage(image_info,image,text,exception)); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 425 | do |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 426 | { |
cristy | e7f2a36 | 2014-02-07 00:04:28 +0000 | [diff] [blame] | 427 | width=0; |
| 428 | height=0; |
| 429 | max_value=0; |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 430 | *colorspace='\0'; |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 431 | count=(ssize_t) sscanf(text+32,"%lu,%lu,%lu,%s",&width,&height,&max_value, |
| 432 | colorspace); |
cristy | e7f2a36 | 2014-02-07 00:04:28 +0000 | [diff] [blame] | 433 | if ((count != 4) || (width == 0) || (height == 0) || (max_value == 0)) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 434 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 435 | image->columns=width; |
| 436 | image->rows=height; |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 437 | for (depth=1; (GetQuantumRange(depth)+1) < max_value; depth++) ; |
| 438 | image->depth=depth; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 439 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 440 | if (status == MagickFalse) |
| 441 | return(DestroyImageList(image)); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 442 | LocaleLower(colorspace); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 443 | i=(ssize_t) strlen(colorspace)-1; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 444 | image->alpha_trait=UndefinedPixelTrait; |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 445 | if ((i > 0) && (colorspace[i] == 'a')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 446 | { |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 447 | colorspace[i]='\0'; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 448 | image->alpha_trait=BlendPixelTrait; |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 449 | } |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 450 | type=ParseCommandOption(MagickColorspaceOptions,MagickFalse,colorspace); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 451 | if (type < 0) |
| 452 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 453 | (void) SetImageBackgroundColor(image,exception); |
cristy | caf4580 | 2012-06-16 18:28:54 +0000 | [diff] [blame] | 454 | (void) SetImageColorspace(image,(ColorspaceType) type,exception); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 455 | GetPixelInfo(image,&pixel); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 456 | range=GetQuantumRange(image->depth); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 457 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 458 | { |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 459 | double |
| 460 | alpha, |
| 461 | black, |
| 462 | blue, |
| 463 | green, |
| 464 | red; |
| 465 | |
cristy | 4d246fc | 2014-01-15 22:33:44 +0000 | [diff] [blame] | 466 | red=0.0; |
| 467 | green=0.0; |
| 468 | blue=0.0; |
| 469 | black=0.0; |
| 470 | alpha=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 471 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 472 | { |
| 473 | if (ReadBlobString(image,text) == (char *) NULL) |
| 474 | break; |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 475 | switch (image->colorspace) |
| 476 | { |
| 477 | case GRAYColorspace: |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 478 | { |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 479 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 480 | { |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 481 | count=(ssize_t) sscanf(text,"%ld,%ld: (%lf%*[%,]%lf%*[%,]", |
| 482 | &x_offset,&y_offset,&red,&alpha); |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 483 | green=red; |
| 484 | blue=red; |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 485 | break; |
| 486 | } |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 487 | count=(ssize_t) sscanf(text,"%ld,%ld: (%lf%*[%,]",&x_offset, |
| 488 | &y_offset,&red); |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 489 | green=red; |
| 490 | blue=red; |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 491 | break; |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 492 | } |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 493 | case CMYKColorspace: |
| 494 | { |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 495 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 496 | { |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 497 | count=(ssize_t) sscanf(text, |
| 498 | "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]", |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 499 | &x_offset,&y_offset,&red,&green,&blue,&black,&alpha); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 500 | break; |
| 501 | } |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 502 | count=(ssize_t) sscanf(text, |
| 503 | "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]",&x_offset, |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 504 | &y_offset,&red,&green,&blue,&black); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 505 | break; |
| 506 | } |
| 507 | default: |
| 508 | { |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 509 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 510 | { |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 511 | count=(ssize_t) sscanf(text, |
| 512 | "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]", |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 513 | &x_offset,&y_offset,&red,&green,&blue,&alpha); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 514 | break; |
| 515 | } |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 516 | count=(ssize_t) sscanf(text, |
| 517 | "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]",&x_offset, |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 518 | &y_offset,&red,&green,&blue); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 519 | break; |
| 520 | } |
| 521 | } |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 522 | if (strchr(text,'%') != (char *) NULL) |
| 523 | { |
| 524 | red*=0.01*range; |
| 525 | green*=0.01*range; |
| 526 | blue*=0.01*range; |
| 527 | black*=0.01*range; |
| 528 | alpha*=0.01*range; |
| 529 | } |
cristy | c534932 | 2012-11-27 02:36:11 +0000 | [diff] [blame] | 530 | if (image->colorspace == LabColorspace) |
cristy | 2409861 | 2012-11-27 02:18:38 +0000 | [diff] [blame] | 531 | { |
cristy | 45fce9f | 2014-07-03 12:53:58 +0000 | [diff] [blame] | 532 | green+=(range+1)/2.0; |
| 533 | blue+=(range+1)/2.0; |
cristy | 2409861 | 2012-11-27 02:18:38 +0000 | [diff] [blame] | 534 | } |
cristy | 9333f75 | 2012-10-10 23:49:45 +0000 | [diff] [blame] | 535 | pixel.red=ScaleAnyToQuantum((QuantumAny) (red+0.5),range); |
| 536 | pixel.green=ScaleAnyToQuantum((QuantumAny) (green+0.5),range); |
| 537 | pixel.blue=ScaleAnyToQuantum((QuantumAny) (blue+0.5),range); |
| 538 | pixel.black=ScaleAnyToQuantum((QuantumAny) (black+0.5),range); |
| 539 | pixel.alpha=ScaleAnyToQuantum((QuantumAny) (alpha+0.5),range); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 540 | q=GetAuthenticPixels(image,x_offset,y_offset,1,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 541 | if (q == (Quantum *) NULL) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 542 | continue; |
cristy | 11a06d3 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 543 | SetPixelViaPixelInfo(image,&pixel,q); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 544 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 545 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | } |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 547 | } |
| 548 | (void) ReadBlobString(image,text); |
| 549 | if (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 550 | { |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 551 | /* |
| 552 | Allocate next image structure. |
| 553 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 554 | AcquireNextImage(image_info,image,exception); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 555 | if (GetNextImageInList(image) == (Image *) NULL) |
| 556 | { |
| 557 | image=DestroyImageList(image); |
| 558 | return((Image *) NULL); |
| 559 | } |
| 560 | image=SyncNextImageInList(image); |
| 561 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 562 | GetBlobSize(image)); |
| 563 | if (status == MagickFalse) |
| 564 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 565 | } |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 566 | } while (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) == 0); |
| 567 | (void) CloseBlob(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 568 | return(GetFirstImageInList(image)); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 573 | % % |
| 574 | % % |
| 575 | % % |
| 576 | % R e g i s t e r T X T I m a g e % |
| 577 | % % |
| 578 | % % |
| 579 | % % |
| 580 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 581 | % |
| 582 | % RegisterTXTImage() adds attributes for the TXT image format to the |
| 583 | % list of supported formats. The attributes include the image format |
| 584 | % tag, a method to read and/or write the format, whether the format |
| 585 | % supports the saving of more than one frame to the same file or blob, |
| 586 | % whether the format supports native in-memory I/O, and a brief |
| 587 | % description of the format. |
| 588 | % |
| 589 | % The format of the RegisterTXTImage method is: |
| 590 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 591 | % size_t RegisterTXTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 592 | % |
| 593 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 594 | ModuleExport size_t RegisterTXTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 595 | { |
| 596 | MagickInfo |
| 597 | *entry; |
| 598 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 599 | entry=AcquireMagickInfo("TXT","SPARSE-COLOR","Sparse Color"); |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 600 | entry->encoder=(EncodeImageHandler *) WriteTXTImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 601 | entry->flags|=CoderRawSupportFlag; |
| 602 | entry->flags|=CoderEndianSupportFlag; |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 603 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 604 | entry=AcquireMagickInfo("TXT","TEXT","Text"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | entry->decoder=(DecodeImageHandler *) ReadTXTImage; |
| 606 | entry->encoder=(EncodeImageHandler *) WriteTXTImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 607 | entry->flags|=CoderRawSupportFlag; |
| 608 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 609 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 610 | entry=AcquireMagickInfo("TXT","TXT","Text"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 611 | entry->decoder=(DecodeImageHandler *) ReadTXTImage; |
| 612 | entry->encoder=(EncodeImageHandler *) WriteTXTImage; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | entry->magick=(IsImageFormatHandler *) IsTXT; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 614 | (void) RegisterMagickInfo(entry); |
| 615 | return(MagickImageCoderSignature); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 620 | % % |
| 621 | % % |
| 622 | % % |
| 623 | % U n r e g i s t e r T X T I m a g e % |
| 624 | % % |
| 625 | % % |
| 626 | % % |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % |
| 629 | % UnregisterTXTImage() removes format registrations made by the |
| 630 | % TXT module from the list of supported format. |
| 631 | % |
| 632 | % The format of the UnregisterTXTImage method is: |
| 633 | % |
| 634 | % UnregisterTXTImage(void) |
| 635 | % |
| 636 | */ |
| 637 | ModuleExport void UnregisterTXTImage(void) |
| 638 | { |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 639 | (void) UnregisterMagickInfo("SPARSE-COLOR"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 640 | (void) UnregisterMagickInfo("TEXT"); |
| 641 | (void) UnregisterMagickInfo("TXT"); |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 646 | % % |
| 647 | % % |
| 648 | % % |
| 649 | % W r i t e T X T I m a g e % |
| 650 | % % |
| 651 | % % |
| 652 | % % |
| 653 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 654 | % |
| 655 | % WriteTXTImage writes the pixel values as text numbers. |
| 656 | % |
| 657 | % The format of the WriteTXTImage method is: |
| 658 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 659 | % MagickBooleanType WriteTXTImage(const ImageInfo *image_info, |
| 660 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 661 | % |
| 662 | % A description of each parameter follows. |
| 663 | % |
| 664 | % o image_info: the image info. |
| 665 | % |
| 666 | % o image: The image. |
| 667 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 668 | % o exception: return any errors or warnings in this structure. |
| 669 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | */ |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 671 | static MagickBooleanType WriteTXTImage(const ImageInfo *image_info,Image *image, |
| 672 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 673 | { |
| 674 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 675 | buffer[MagickPathExtent], |
| 676 | colorspace[MagickPathExtent], |
| 677 | tuple[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 678 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | MagickBooleanType |
| 680 | status; |
| 681 | |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 682 | MagickOffsetType |
| 683 | scene; |
| 684 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 685 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 686 | pixel; |
| 687 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 688 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | *p; |
| 690 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 691 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 692 | x; |
| 693 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 694 | ssize_t |
| 695 | y; |
| 696 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 697 | /* |
| 698 | Open output image file. |
| 699 | */ |
| 700 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 701 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 702 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 703 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | if (image->debug != MagickFalse) |
| 705 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 706 | status=OpenBlob(image_info,image,WriteBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 707 | if (status == MagickFalse) |
| 708 | return(status); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 709 | scene=0; |
| 710 | do |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 711 | { |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 712 | ComplianceType |
| 713 | compliance; |
| 714 | |
Cristy | 1401044 | 2015-08-15 11:05:42 -0400 | [diff] [blame^] | 715 | const char |
| 716 | *value; |
| 717 | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 718 | (void) CopyMagickString(colorspace,CommandOptionToMnemonic( |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 719 | MagickColorspaceOptions,(ssize_t) image->colorspace),MagickPathExtent); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 720 | LocaleLower(colorspace); |
| 721 | image->depth=GetImageQuantumDepth(image,MagickTrue); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 722 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 723 | (void) ConcatenateMagickString(colorspace,"a",MagickPathExtent); |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 724 | compliance=NoCompliance; |
Cristy | 1401044 | 2015-08-15 11:05:42 -0400 | [diff] [blame^] | 725 | value=GetImageOption(image_info,"txt:compliance"); |
| 726 | if (value != (char *) NULL) |
| 727 | compliance=(ComplianceType) ParseCommandOption(MagickComplianceOptions, |
| 728 | MagickFalse,value); |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 729 | if (LocaleCompare(image_info->magick,"SPARSE-COLOR") != 0) |
| 730 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 731 | (void) FormatLocaleString(buffer,MagickPathExtent, |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 732 | "# ImageMagick pixel enumeration: %.20g,%.20g,%.20g,%s\n",(double) |
cristy | 1a59895 | 2013-09-06 13:11:23 +0000 | [diff] [blame] | 733 | image->columns,(double) image->rows,(double) ((MagickOffsetType) |
| 734 | GetQuantumRange(image->depth)),colorspace); |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 735 | (void) WriteBlobString(image,buffer); |
| 736 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 737 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 738 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 739 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 740 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 741 | if (p == (const Quantum *) NULL) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 742 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 743 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 744 | { |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 745 | GetPixelInfoPixel(image,p,&pixel); |
cristy | 2409861 | 2012-11-27 02:18:38 +0000 | [diff] [blame] | 746 | if (pixel.colorspace == LabColorspace) |
| 747 | { |
cristy | 681068f | 2014-07-03 12:48:42 +0000 | [diff] [blame] | 748 | pixel.green-=(QuantumRange+1)/2.0; |
| 749 | pixel.blue-=(QuantumRange+1)/2.0; |
cristy | 2409861 | 2012-11-27 02:18:38 +0000 | [diff] [blame] | 750 | } |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 751 | if (LocaleCompare(image_info->magick,"SPARSE-COLOR") == 0) |
| 752 | { |
| 753 | /* |
| 754 | Sparse-color format. |
| 755 | */ |
| 756 | if (GetPixelAlpha(image,p) == (Quantum) OpaqueAlpha) |
| 757 | { |
cristy | 0e339ba | 2013-03-18 00:20:48 +0000 | [diff] [blame] | 758 | GetColorTuple(&pixel,MagickFalse,tuple); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 759 | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g,%.20g,", |
cristy | e6ee749 | 2013-03-16 15:04:42 +0000 | [diff] [blame] | 760 | (double) x,(double) y); |
| 761 | (void) WriteBlobString(image,buffer); |
| 762 | (void) WriteBlobString(image,tuple); |
| 763 | (void) WriteBlobString(image," "); |
| 764 | } |
| 765 | p+=GetPixelChannels(image); |
| 766 | continue; |
| 767 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 768 | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g,%.20g: ",(double) |
cristy | bbb9b90 | 2013-03-13 10:25:06 +0000 | [diff] [blame] | 769 | x,(double) y); |
| 770 | (void) WriteBlobString(image,buffer); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 771 | (void) CopyMagickString(tuple,"(",MagickPathExtent); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 772 | if (pixel.colorspace == GRAYColorspace) |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 773 | ConcatenateColorComponent(&pixel,GrayPixelChannel,compliance, |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 774 | tuple); |
| 775 | else |
| 776 | { |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 777 | ConcatenateColorComponent(&pixel,RedPixelChannel,compliance,tuple); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 778 | (void) ConcatenateMagickString(tuple,",",MagickPathExtent); |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 779 | ConcatenateColorComponent(&pixel,GreenPixelChannel,compliance, |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 780 | tuple); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 781 | (void) ConcatenateMagickString(tuple,",",MagickPathExtent); |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 782 | ConcatenateColorComponent(&pixel,BluePixelChannel,compliance,tuple); |
cristy | e913961 | 2012-01-03 02:19:10 +0000 | [diff] [blame] | 783 | } |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 784 | if (pixel.colorspace == CMYKColorspace) |
| 785 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 786 | (void) ConcatenateMagickString(tuple,",",MagickPathExtent); |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 787 | ConcatenateColorComponent(&pixel,BlackPixelChannel,compliance, |
cristy | fa806a7 | 2011-07-04 02:06:13 +0000 | [diff] [blame] | 788 | tuple); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 789 | } |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 790 | if (pixel.alpha_trait != UndefinedPixelTrait) |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 791 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 792 | (void) ConcatenateMagickString(tuple,",",MagickPathExtent); |
cristy | 2c992db | 2013-09-02 02:12:55 +0000 | [diff] [blame] | 793 | ConcatenateColorComponent(&pixel,AlphaPixelChannel,compliance, |
cristy | fa806a7 | 2011-07-04 02:06:13 +0000 | [diff] [blame] | 794 | tuple); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 795 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 796 | (void) ConcatenateMagickString(tuple,")",MagickPathExtent); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 797 | (void) WriteBlobString(image,tuple); |
| 798 | (void) WriteBlobString(image," "); |
| 799 | GetColorTuple(&pixel,MagickTrue,tuple); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 800 | (void) FormatLocaleString(buffer,MagickPathExtent,"%s",tuple); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 801 | (void) WriteBlobString(image,buffer); |
| 802 | (void) WriteBlobString(image," "); |
cristy | 269c941 | 2011-10-13 23:41:15 +0000 | [diff] [blame] | 803 | (void) QueryColorname(image,&pixel,SVGCompliance,tuple,exception); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 804 | (void) WriteBlobString(image,tuple); |
| 805 | (void) WriteBlobString(image,"\n"); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 806 | p+=GetPixelChannels(image); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 807 | } |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 808 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 2aac09a | 2010-06-06 16:46:43 +0000 | [diff] [blame] | 809 | image->rows); |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 810 | if (status == MagickFalse) |
| 811 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 812 | } |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 813 | if (GetNextImageInList(image) == (Image *) NULL) |
| 814 | break; |
| 815 | image=SyncNextImageInList(image); |
| 816 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 817 | GetImageListLength(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 818 | if (status == MagickFalse) |
| 819 | break; |
cristy | 9c7e2af | 2010-05-23 23:13:27 +0000 | [diff] [blame] | 820 | } while (image_info->adjoin != MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 821 | (void) CloseBlob(image); |
| 822 | return(MagickTrue); |
| 823 | } |