cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % V V IIIII CCCC AAA RRRR % |
| 7 | % V V I C A A R R % |
| 8 | % V V I C AAAAA RRRR % |
| 9 | % V V I C A A R R % |
| 10 | % V IIIII CCCC A A R R % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write VICAR Rasterfile Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 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" |
cristy | d9ecd04 | 2012-06-17 18:26:12 +0000 | [diff] [blame] | 43 | #include "MagickCore/attribute.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/colormap.h" |
| 48 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 49 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/exception.h" |
| 52 | #include "MagickCore/exception-private.h" |
| 53 | #include "MagickCore/image.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/module.h" |
| 59 | #include "MagickCore/monitor.h" |
| 60 | #include "MagickCore/monitor-private.h" |
| 61 | #include "MagickCore/quantum-private.h" |
| 62 | #include "MagickCore/quantum-private.h" |
| 63 | #include "MagickCore/static.h" |
| 64 | #include "MagickCore/string_.h" |
| 65 | #include "MagickCore/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | Forward declarations. |
| 69 | */ |
| 70 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 71 | WriteVICARImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 75 | % % |
| 76 | % % |
| 77 | % % |
| 78 | % I s V I C A R % |
| 79 | % % |
| 80 | % % |
| 81 | % % |
| 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 83 | % |
| 84 | % IsVICAR() returns MagickTrue if the image format type, identified by the |
| 85 | % magick string, is VICAR. |
| 86 | % |
| 87 | % The format of the IsVICAR method is: |
| 88 | % |
| 89 | % MagickBooleanType IsVICAR(const unsigned char *magick, |
| 90 | % const size_t length) |
| 91 | % |
| 92 | % A description of each parameter follows: |
| 93 | % |
| 94 | % o magick: compare image format pattern against these bytes. |
| 95 | % |
| 96 | % o length: Specifies the length of the magick string. |
| 97 | % |
| 98 | */ |
| 99 | static MagickBooleanType IsVICAR(const unsigned char *magick, |
| 100 | const size_t length) |
| 101 | { |
| 102 | if (length < 14) |
| 103 | return(MagickFalse); |
| 104 | if (LocaleNCompare((const char *) magick,"LBLSIZE",7) == 0) |
| 105 | return(MagickTrue); |
| 106 | if (LocaleNCompare((const char *) magick,"NJPL1I",6) == 0) |
| 107 | return(MagickTrue); |
| 108 | if (LocaleNCompare((const char *) magick,"PDS_VERSION_ID",14) == 0) |
| 109 | return(MagickTrue); |
| 110 | return(MagickFalse); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 115 | % % |
| 116 | % % |
| 117 | % % |
| 118 | % R e a d V I C A R I m a g e % |
| 119 | % % |
| 120 | % % |
| 121 | % % |
| 122 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 123 | % |
| 124 | % ReadVICARImage() reads a VICAR image file and returns it. It |
| 125 | % allocates the memory necessary for the new Image structure and returns a |
| 126 | % pointer to the new image. |
| 127 | % |
| 128 | % The format of the ReadVICARImage method is: |
| 129 | % |
| 130 | % Image *ReadVICARImage(const ImageInfo *image_info, |
| 131 | % ExceptionInfo *exception) |
| 132 | % |
| 133 | % A description of each parameter follows: |
| 134 | % |
| 135 | % o image: Method ReadVICARImage returns a pointer to the image after |
| 136 | % reading. A null image is returned if there is a memory shortage or if |
| 137 | % the image cannot be read. |
| 138 | % |
| 139 | % o image_info: the image info. |
| 140 | % |
| 141 | % o exception: return any errors or warnings in this structure. |
| 142 | % |
| 143 | % |
| 144 | */ |
| 145 | static Image *ReadVICARImage(const ImageInfo *image_info, |
| 146 | ExceptionInfo *exception) |
| 147 | { |
| 148 | char |
| 149 | keyword[MaxTextExtent], |
| 150 | value[MaxTextExtent]; |
| 151 | |
| 152 | Image |
| 153 | *image; |
| 154 | |
| 155 | int |
| 156 | c; |
| 157 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | MagickBooleanType |
| 159 | status, |
| 160 | value_expected; |
| 161 | |
| 162 | QuantumInfo |
| 163 | *quantum_info; |
| 164 | |
| 165 | QuantumType |
| 166 | quantum_type; |
| 167 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 168 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | *q; |
| 170 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | size_t |
| 172 | length; |
| 173 | |
cristy | 03533f2 | 2011-03-06 23:30:17 +0000 | [diff] [blame] | 174 | ssize_t |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 175 | count, |
| 176 | y; |
cristy | 03533f2 | 2011-03-06 23:30:17 +0000 | [diff] [blame] | 177 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 178 | unsigned char |
| 179 | *pixels; |
| 180 | |
| 181 | /* |
| 182 | Open image file. |
| 183 | */ |
| 184 | assert(image_info != (const ImageInfo *) NULL); |
| 185 | assert(image_info->signature == MagickSignature); |
| 186 | if (image_info->debug != MagickFalse) |
| 187 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 188 | image_info->filename); |
| 189 | assert(exception != (ExceptionInfo *) NULL); |
| 190 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 191 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 192 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 193 | if (status == MagickFalse) |
| 194 | { |
| 195 | image=DestroyImageList(image); |
| 196 | return((Image *) NULL); |
| 197 | } |
cristy | 65bda43 | 2012-06-21 11:22:10 +0000 | [diff] [blame^] | 198 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 199 | /* |
| 200 | Decode image header. |
| 201 | */ |
| 202 | c=ReadBlobByte(image); |
| 203 | count=1; |
| 204 | if (c == EOF) |
| 205 | { |
| 206 | image=DestroyImage(image); |
| 207 | return((Image *) NULL); |
| 208 | } |
| 209 | length=0; |
| 210 | image->columns=0; |
| 211 | image->rows=0; |
| 212 | while (isgraph(c) && ((image->columns == 0) || (image->rows == 0))) |
| 213 | { |
| 214 | if (isalnum(c) == MagickFalse) |
| 215 | { |
| 216 | c=ReadBlobByte(image); |
| 217 | count++; |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | register char |
| 222 | *p; |
| 223 | |
| 224 | /* |
| 225 | Determine a keyword and its value. |
| 226 | */ |
| 227 | p=keyword; |
| 228 | do |
| 229 | { |
| 230 | if ((size_t) (p-keyword) < (MaxTextExtent-1)) |
| 231 | *p++=c; |
| 232 | c=ReadBlobByte(image); |
| 233 | count++; |
| 234 | } while (isalnum(c) || (c == '_')); |
| 235 | *p='\0'; |
| 236 | value_expected=MagickFalse; |
| 237 | while ((isspace((int) ((unsigned char) c)) != 0) || (c == '=')) |
| 238 | { |
| 239 | if (c == '=') |
| 240 | value_expected=MagickTrue; |
| 241 | c=ReadBlobByte(image); |
| 242 | count++; |
| 243 | } |
| 244 | if (value_expected == MagickFalse) |
| 245 | continue; |
| 246 | p=value; |
| 247 | while (isalnum(c)) |
| 248 | { |
| 249 | if ((size_t) (p-value) < (MaxTextExtent-1)) |
| 250 | *p++=c; |
| 251 | c=ReadBlobByte(image); |
| 252 | count++; |
| 253 | } |
| 254 | *p='\0'; |
| 255 | /* |
| 256 | Assign a value to the specified keyword. |
| 257 | */ |
| 258 | if (LocaleCompare(keyword,"Label_RECORDS") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 259 | length=(ssize_t) StringToLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 260 | if (LocaleCompare(keyword,"LBLSIZE") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 261 | length=(ssize_t) StringToLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 262 | if (LocaleCompare(keyword,"RECORD_BYTES") == 0) |
cristy | 5131f3e | 2009-12-18 03:09:10 +0000 | [diff] [blame] | 263 | image->columns=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | if (LocaleCompare(keyword,"NS") == 0) |
cristy | 5131f3e | 2009-12-18 03:09:10 +0000 | [diff] [blame] | 265 | image->columns=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | if (LocaleCompare(keyword,"LINES") == 0) |
cristy | 5131f3e | 2009-12-18 03:09:10 +0000 | [diff] [blame] | 267 | image->rows=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 268 | if (LocaleCompare(keyword,"NL") == 0) |
cristy | 5131f3e | 2009-12-18 03:09:10 +0000 | [diff] [blame] | 269 | image->rows=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 270 | } |
| 271 | while (isspace((int) ((unsigned char) c)) != 0) |
| 272 | { |
| 273 | c=ReadBlobByte(image); |
| 274 | count++; |
| 275 | } |
| 276 | } |
| 277 | while (count < (ssize_t) length) |
| 278 | { |
| 279 | c=ReadBlobByte(image); |
| 280 | count++; |
| 281 | } |
| 282 | if ((image->columns == 0) || (image->rows == 0)) |
| 283 | ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize"); |
| 284 | image->depth=8; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 285 | if (image_info->ping != MagickFalse) |
| 286 | { |
| 287 | (void) CloseBlob(image); |
| 288 | return(GetFirstImageInList(image)); |
| 289 | } |
| 290 | /* |
| 291 | Read VICAR pixels. |
| 292 | */ |
cristy | 65bda43 | 2012-06-21 11:22:10 +0000 | [diff] [blame^] | 293 | quantum_type=GrayQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 294 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 295 | if (quantum_info == (QuantumInfo *) NULL) |
| 296 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 297 | pixels=GetQuantumPixels(quantum_info); |
cristy | 65bda43 | 2012-06-21 11:22:10 +0000 | [diff] [blame^] | 298 | length=GetQuantumExtent(image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 299 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 300 | { |
| 301 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 302 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 303 | break; |
| 304 | count=ReadBlob(image,length,pixels); |
| 305 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 306 | quantum_type,pixels,exception); |
| 307 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 308 | break; |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 309 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
cristy | 4bad316 | 2011-03-06 18:44:39 +0000 | [diff] [blame] | 310 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | if (status == MagickFalse) |
| 312 | break; |
| 313 | } |
| 314 | SetQuantumImageType(image,quantum_type); |
| 315 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 316 | if (EOFBlob(image) != MagickFalse) |
| 317 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 318 | image->filename); |
| 319 | (void) CloseBlob(image); |
| 320 | return(GetFirstImageInList(image)); |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 325 | % % |
| 326 | % % |
| 327 | % % |
| 328 | % R e g i s t e r V I C A R I m a g e % |
| 329 | % % |
| 330 | % % |
| 331 | % % |
| 332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 333 | % |
| 334 | % RegisterVICARImage() adds attributes for the VICAR image format to |
| 335 | % the list of supported formats. The attributes include the image format |
| 336 | % tag, a method to read and/or write the format, whether the format |
| 337 | % supports the saving of more than one frame to the same file or blob, |
| 338 | % whether the format supports native in-memory I/O, and a brief |
| 339 | % description of the format. |
| 340 | % |
| 341 | % The format of the RegisterVICARImage method is: |
| 342 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 343 | % size_t RegisterVICARImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | % |
| 345 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 346 | ModuleExport size_t RegisterVICARImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 347 | { |
| 348 | MagickInfo |
| 349 | *entry; |
| 350 | |
| 351 | entry=SetMagickInfo("VICAR"); |
| 352 | entry->decoder=(DecodeImageHandler *) ReadVICARImage; |
| 353 | entry->encoder=(EncodeImageHandler *) WriteVICARImage; |
| 354 | entry->magick=(IsImageFormatHandler *) IsVICAR; |
| 355 | entry->adjoin=MagickFalse; |
| 356 | entry->description=ConstantString("VICAR rasterfile format"); |
| 357 | entry->module=ConstantString("VICAR"); |
| 358 | (void) RegisterMagickInfo(entry); |
| 359 | return(MagickImageCoderSignature); |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 364 | % % |
| 365 | % % |
| 366 | % % |
| 367 | % U n r e g i s t e r V I C A R I m a g e % |
| 368 | % % |
| 369 | % % |
| 370 | % % |
| 371 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 372 | % |
| 373 | % UnregisterVICARImage() removes format registrations made by the |
| 374 | % VICAR module from the list of supported formats. |
| 375 | % |
| 376 | % The format of the UnregisterVICARImage method is: |
| 377 | % |
| 378 | % UnregisterVICARImage(void) |
| 379 | % |
| 380 | */ |
| 381 | ModuleExport void UnregisterVICARImage(void) |
| 382 | { |
| 383 | (void) UnregisterMagickInfo("VICAR"); |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 388 | % % |
| 389 | % % |
| 390 | % % |
| 391 | % W r i t e V I C A R I m a g e % |
| 392 | % % |
| 393 | % % |
| 394 | % % |
| 395 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 396 | % |
| 397 | % WriteVICARImage() writes an image in the VICAR rasterfile format. |
| 398 | % Vicar files contain a text header, followed by one or more planes of binary |
| 399 | % grayscale image data. Vicar files are designed to allow many planes to be |
| 400 | % stacked together to form image cubes. This method only writes a single |
| 401 | % grayscale plane. |
| 402 | % |
cristy | 03533f2 | 2011-03-06 23:30:17 +0000 | [diff] [blame] | 403 | % WriteVICARImage was written contributed by gorelick@esther.la.asu.edu. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | % |
| 405 | % The format of the WriteVICARImage method is: |
| 406 | % |
| 407 | % MagickBooleanType WriteVICARImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 408 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | % |
| 410 | % A description of each parameter follows. |
| 411 | % |
| 412 | % o image_info: the image info. |
| 413 | % |
| 414 | % o image: The image. |
| 415 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 416 | % o exception: return any errors or warnings in this structure. |
| 417 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | */ |
| 419 | static MagickBooleanType WriteVICARImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 420 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 421 | { |
| 422 | char |
| 423 | header[MaxTextExtent]; |
| 424 | |
| 425 | int |
| 426 | y; |
| 427 | |
| 428 | MagickBooleanType |
| 429 | status; |
| 430 | |
| 431 | QuantumInfo |
| 432 | *quantum_info; |
| 433 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 434 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 435 | *p; |
| 436 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 437 | size_t |
| 438 | length; |
| 439 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 440 | ssize_t |
| 441 | count; |
| 442 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 443 | unsigned char |
| 444 | *pixels; |
| 445 | |
| 446 | /* |
| 447 | Open output image file. |
| 448 | */ |
| 449 | assert(image_info != (const ImageInfo *) NULL); |
| 450 | assert(image_info->signature == MagickSignature); |
| 451 | assert(image != (Image *) NULL); |
| 452 | assert(image->signature == MagickSignature); |
| 453 | if (image->debug != MagickFalse) |
| 454 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 455 | assert(exception != (ExceptionInfo *) NULL); |
| 456 | assert(exception->signature == MagickSignature); |
| 457 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | if (status == MagickFalse) |
| 459 | return(status); |
cristy | d9ecd04 | 2012-06-17 18:26:12 +0000 | [diff] [blame] | 460 | if ((IssRGBColorspace(image->colorspace) == MagickFalse) && |
| 461 | (IsImageGray(image,exception) == MagickFalse)) |
cristy | 8d95109 | 2012-02-08 18:54:56 +0000 | [diff] [blame] | 462 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 463 | /* |
| 464 | Write header. |
| 465 | */ |
| 466 | (void) ResetMagickMemory(header,' ',MaxTextExtent); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 467 | (void) FormatLocaleString(header,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 468 | "LBLSIZE=%.20g FORMAT='BYTE' TYPE='IMAGE' BUFSIZE=20000 DIM=2 EOL=0 " |
| 469 | "RECSIZE=%.20g ORG='BSQ' NL=%.20g NS=%.20g NB=1 N1=0 N2=0 N3=0 N4=0 NBB=0 " |
| 470 | "NLB=0 TASK='ImageMagick'",(double) MaxTextExtent,(double) image->columns, |
| 471 | (double) image->rows,(double) image->columns); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 472 | (void) WriteBlob(image,MaxTextExtent,(unsigned char *) header); |
| 473 | /* |
| 474 | Write VICAR pixels. |
| 475 | */ |
| 476 | image->depth=8; |
| 477 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 478 | if (quantum_info == (QuantumInfo *) NULL) |
| 479 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 480 | pixels=GetQuantumPixels(quantum_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 481 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 482 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 483 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 484 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 485 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 486 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 487 | GrayQuantum,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 488 | count=WriteBlob(image,length,pixels); |
| 489 | if (count != (ssize_t) length) |
| 490 | break; |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 491 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | 84c3d05 | 2011-03-07 19:22:02 +0000 | [diff] [blame] | 492 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | if (status == MagickFalse) |
| 494 | break; |
| 495 | } |
| 496 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 497 | (void) CloseBlob(image); |
| 498 | return(MagickTrue); |
| 499 | } |