blob: ecf7819d56525db4d5183cc4872fbb961961b6fe [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
cristyebc891a2011-04-24 23:04:16 +00002%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% IIIIIIIIII PPPPPPPP LL %
7% II PP PP LL %
8% II PP PP LL %
9% II PP PP LL %
10% II PPPPPPPP LL %
11% II PP LL %
12% II PP LL %
13% IIIIIIIIII PP LLLLLLLL %
14% %
15% %
16% %
17% Read/Write Scanalytics IPLab Image Format %
18% Sean Burke %
19% 2008.05.07 %
20% v 0.9 %
21% %
cristy1454be72011-12-19 01:52:48 +000022% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristyebc891a2011-04-24 23:04:16 +000023% dedicated to making software imaging solutions freely available. %
24% %
25% You may not use this file except in compliance with the License. You may %
26% obtain a copy of the License at %
27% %
28% http://www.imagemagick.org/script/license.php %
29% %
30% Unless required by applicable law or agreed to in writing, software %
31% distributed under the License is distributed on an "AS IS" BASIS, %
32% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
33% See the License for the specific language governing permissions and %
34% limitations under the License. %
35% %
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37%
38%
39*/
cristy3ed852e2009-09-05 21:47:34 +000040
41/*
42 Include declarations.
43 */
cristy4c08aed2011-07-01 19:47:50 +000044#include "MagickCore/studio.h"
45#include "MagickCore/blob.h"
46#include "MagickCore/blob-private.h"
47#include "MagickCore/cache.h"
48#include "MagickCore/colorspace.h"
cristy510d06a2011-07-06 23:43:54 +000049#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000050#include "MagickCore/exception.h"
51#include "MagickCore/exception-private.h"
52#include "MagickCore/image.h"
53#include "MagickCore/image-private.h"
54#include "MagickCore/list.h"
55#include "MagickCore/magick.h"
56#include "MagickCore/memory_.h"
57#include "MagickCore/monitor.h"
58#include "MagickCore/monitor-private.h"
59#include "MagickCore/option.h"
60#include "MagickCore/property.h"
61#include "MagickCore/quantum-private.h"
62#include "MagickCore/static.h"
63#include "MagickCore/string_.h"
64#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000065
66/*
67Tyedef declarations
68 */
69
70typedef struct _IPLInfo
71{
cristyeaedf062010-05-29 22:36:02 +000072 unsigned int
73 tag,
74 size,
75 time,
76 z,
77 width,
78 height,
79 colors,
80 depth,
81 byteType;
cristy3ed852e2009-09-05 21:47:34 +000082} IPLInfo;
83
84static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000085 WriteIPLImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000086
87void increase (void *pixel, int byteType){
88 switch(byteType){
89 case 0:(*((unsigned char *) pixel))++; break;
90 case 1:(*((signed int *) pixel))++; break;
91 case 2:(*((unsigned int *) pixel))++; break;
92 case 3:(*((signed long *) pixel))++; break;
93 default:(*((unsigned int *) pixel))++; break;
94 }
95}
96
97/*
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 % %
100 % %
101 % %
102 % I s I P L %
103 % %
104 % %
105 % %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %
108 % IsIPL() returns MagickTrue if the image format type, identified by the
109 % magick string, is IPL.
110 %
111 % The format of the IsIPL method is:
112 %
113 % MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
114 %
115 % A description of each parameter follows:
116 %
117 % o magick: compare image format pattern against these bytes.
118 %
119 % o length: Specifies the length of the magick string.
120 %
121 */
122static MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
123{
124 if (length < 4)
125 return(MagickFalse);
126 if (LocaleNCompare((const char *) magick,"data",4) == 0)
127 return(MagickTrue);
128 return(MagickFalse);
129}
130
131/*
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % %
134 % %
135 % %
136 % R e a d I P L I m a g e %
137 % %
138 % %
139 % %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 %
142 % ReadIPLImage() reads a Scanalytics IPLab image file and returns it. It
143 % allocates the memory necessary for the new Image structure and returns a
144 % pointer to the new image.
145 %
146 % According to the IPLab spec, the data is blocked out in five dimensions:
147 % { t, z, c, y, x }. When we return the image, the latter three are folded
148 % into the standard "Image" structure. The "scenes" (image_info->scene)
149 % correspond to the order: { {t0,z0}, {t0, z1}, ..., {t1,z0}, {t1,z1}... }
150 % The number of scenes is t*z.
151 %
152 % The format of the ReadIPLImage method is:
153 %
154 % Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception)
155 %
156 % A description of each parameter follows:
157 %
158 % o image_info: The image info.
159 %
160 % o exception: return any errors or warnings in this structure.
161 %
162 */
163
164void SetHeaderFromIPL(Image *image, IPLInfo *ipl){
cristyc5de6992009-10-06 19:19:48 +0000165 image->columns = ipl->width;
166 image->rows = ipl->height;
167 image->depth = ipl->depth;
cristy2a11bef2011-10-28 18:33:11 +0000168 image->resolution.x = 1;
169 image->resolution.y = 1;
cristy3ed852e2009-09-05 21:47:34 +0000170}
171
172
173static Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception)
174{
175
176 /*
177 Declare variables
178 */
179 Image *image;
180
181 MagickBooleanType status;
cristy4c08aed2011-07-01 19:47:50 +0000182 register Quantum *q;
cristy3ed852e2009-09-05 21:47:34 +0000183 unsigned char magick[12], *pixels;
184 ssize_t count;
cristybb503372010-05-27 20:51:26 +0000185 ssize_t y;
186 size_t t_count=0;
cristy3ed852e2009-09-05 21:47:34 +0000187 size_t length;
188 IPLInfo
189 ipl_info;
190 QuantumFormatType
191 quantum_format;
192 QuantumInfo
193 *quantum_info;
194 QuantumType
195 quantum_type;
196
197 /*
198 Open Image
199 */
200
201 assert(image_info != (const ImageInfo *) NULL);
202 assert(image_info->signature == MagickSignature);
203 if ( image_info->debug != MagickFalse)
204 (void) LogMagickEvent(TraceEvent, GetMagickModule(), "%s",
205 image_info->filename);
206 assert(exception != (ExceptionInfo *) NULL);
207 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000208 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000209 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
210 if (status == MagickFalse)
211 {
212 image=DestroyImageList(image);
213 return((Image *) NULL);
214 }
215
216 /*
217 Read IPL image
218 */
219
220 /*
221 Determine endianness
222 If we get back "iiii", we have LSB,"mmmm", MSB
223 */
224 count=ReadBlob(image,4,magick);
cristyda16f162011-02-19 23:52:17 +0000225 (void) count;
cristy3ed852e2009-09-05 21:47:34 +0000226 if((LocaleNCompare((char *) magick,"iiii",4) == 0))
227 image->endian=LSBEndian;
228 else{
229 if((LocaleNCompare((char *) magick,"mmmm",4) == 0))
230 image->endian=MSBEndian;
231 else{
232 ThrowReaderException(CorruptImageError, "ImproperImageHeader");
233 }
234 }
235 /* Skip o'er the next 8 bytes (garbage) */
236 count=ReadBlob(image, 8, magick);
237 /*
238 Excellent, now we read the header unimpeded.
239 */
240 count=ReadBlob(image,4,magick);
241 if((LocaleNCompare((char *) magick,"data",4) != 0))
242 ThrowReaderException(CorruptImageError, "ImproperImageHeader");
243 ipl_info.size=ReadBlobLong(image);
244 ipl_info.width=ReadBlobLong(image);
245 ipl_info.height=ReadBlobLong(image);
246 if((ipl_info.width == 0UL) || (ipl_info.height == 0UL))
247 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
248 ipl_info.colors=ReadBlobLong(image);
cristye2c4f182012-05-12 14:11:53 +0000249 if(ipl_info.colors == 3){ SetImageColorspace(image,sRGBColorspace,exception);}
cristy3ed852e2009-09-05 21:47:34 +0000250 else { image->colorspace = GRAYColorspace; }
251 ipl_info.z=ReadBlobLong(image);
252 ipl_info.time=ReadBlobLong(image);
253
254 ipl_info.byteType=ReadBlobLong(image);
255
256
257 /* Initialize Quantum Info */
258
259 switch (ipl_info.byteType) {
260 case 0:
261 ipl_info.depth=8;
262 quantum_format = UnsignedQuantumFormat;
263 break;
264 case 1:
265 ipl_info.depth=16;
266 quantum_format = SignedQuantumFormat;
267 break;
268 case 2:
269 ipl_info.depth=16;
270 quantum_format = UnsignedQuantumFormat;
271 break;
272 case 3:
273 ipl_info.depth=32;
274 quantum_format = SignedQuantumFormat;
275 break;
276 case 4: ipl_info.depth=32;
277 quantum_format = FloatingPointQuantumFormat;
278 break;
279 case 5:
280 ipl_info.depth=8;
281 quantum_format = UnsignedQuantumFormat;
282 break;
283 case 6:
284 ipl_info.depth=16;
285 quantum_format = UnsignedQuantumFormat;
286 break;
287 case 10:
288 ipl_info.depth=64;
289 quantum_format = FloatingPointQuantumFormat;
290 break;
291 default:
292 ipl_info.depth=16;
293 quantum_format = UnsignedQuantumFormat;
294 break;
295 }
296
297 /*
298 Set number of scenes of image
299 */
300
301 SetHeaderFromIPL(image, &ipl_info);
302
303 /* Thats all we need if we are pinging. */
304 if (image_info->ping != MagickFalse)
305 {
306 (void) CloseBlob(image);
307 return(GetFirstImageInList(image));
308 }
309 length=image->columns;
310 quantum_type=GetQuantumType(image,exception);
311 do
312 {
313 SetHeaderFromIPL(image, &ipl_info);
314
315 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
316 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
317 break;
318/*
cristye8c25f92010-06-03 00:53:06 +0000319 printf("Length: %.20g, Memory size: %.20g\n", (double) length,(double)
320 image->depth);
cristy3ed852e2009-09-05 21:47:34 +0000321*/
322 quantum_info=AcquireQuantumInfo(image_info,image);
323 if (quantum_info == (QuantumInfo *) NULL)
324 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
325 status=SetQuantumFormat(image,quantum_info,quantum_format);
326 if (status == MagickFalse)
327 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
328 pixels=GetQuantumPixels(quantum_info);
329 if(image->columns != ipl_info.width){
330/*
cristye8c25f92010-06-03 00:53:06 +0000331 printf("Columns not set correctly! Wanted: %.20g, got: %.20g\n",
332 (double) ipl_info.width, (double) image->columns);
cristy3ed852e2009-09-05 21:47:34 +0000333*/
334 }
335
336 /*
337 Covert IPL binary to pixel packets
338 */
339
340 if(ipl_info.colors == 1){
cristybb503372010-05-27 20:51:26 +0000341 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000342 (void) ReadBlob(image, length*image->depth/8, pixels);
343 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000344 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000345 break;
cristyc5de6992009-10-06 19:19:48 +0000346 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3ed852e2009-09-05 21:47:34 +0000347 GrayQuantum,pixels,exception);
348 if (SyncAuthenticPixels(image,exception) == MagickFalse)
349 break;
cristyc5de6992009-10-06 19:19:48 +0000350 }
cristy3ed852e2009-09-05 21:47:34 +0000351 }
352 else{
cristybb503372010-05-27 20:51:26 +0000353 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000354 (void) ReadBlob(image, length*image->depth/8, pixels);
355 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000356 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000357 break;
cristyc5de6992009-10-06 19:19:48 +0000358 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
359 RedQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000360 if (SyncAuthenticPixels(image,exception) == MagickFalse)
361 break;
362 }
cristybb503372010-05-27 20:51:26 +0000363 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000364 (void) ReadBlob(image, length*image->depth/8, pixels);
365 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000366 if (q == (Quantum *) NULL)
cristyebc891a2011-04-24 23:04:16 +0000367 break;
cristyc5de6992009-10-06 19:19:48 +0000368 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3ed852e2009-09-05 21:47:34 +0000369 GreenQuantum,pixels,exception);
370 if (SyncAuthenticPixels(image,exception) == MagickFalse)
371 break;
372 }
cristybb503372010-05-27 20:51:26 +0000373 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000374 (void) ReadBlob(image, length*image->depth/8, pixels);
375 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000376 if (q == (Quantum *) NULL)
cristyebc891a2011-04-24 23:04:16 +0000377 break;
cristyc5de6992009-10-06 19:19:48 +0000378 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3ed852e2009-09-05 21:47:34 +0000379 BlueQuantum,pixels,exception);
380 if (SyncAuthenticPixels(image,exception) == MagickFalse)
381 break;
382 }
383 }
384 SetQuantumImageType(image,quantum_type);
385
386 t_count++;
387 quantum_info = DestroyQuantumInfo(quantum_info);
388
389 if (EOFBlob(image) != MagickFalse)
390 {
391 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
392 image->filename);
393 break;
394 }
395 if(t_count < ipl_info.z * ipl_info.time){
396 /*
397 Proceed to next image.
398 */
cristy9950d572011-10-01 18:22:35 +0000399 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000400 if (GetNextImageInList(image) == (Image *) NULL)
401 {
402 image=DestroyImageList(image);
403 return((Image *) NULL);
404 }
405 image=SyncNextImageInList(image);
406 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
407 GetBlobSize(image));
408 if (status == MagickFalse)
409 break;
410 }
411 } while (t_count < ipl_info.z*ipl_info.time);
412 CloseBlob(image);
413 return(GetFirstImageInList(image));
414}
415
416/*
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418 % %
419 % %
420 % %
421 % R e g i s t e r I P L I m a g e %
422 % %
423 % %
424 % %
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 %
427 % RegisterIPLImage() add attributes for the Scanalytics IPL image format to the
428 % list of supported formats.
429 %
430 %
431 */
cristybb503372010-05-27 20:51:26 +0000432ModuleExport size_t RegisterIPLImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000433{
434 MagickInfo
435 *entry;
436
437 entry=SetMagickInfo("IPL");
438 entry->decoder=(DecodeImageHandler *) ReadIPLImage;
439 entry->encoder=(EncodeImageHandler *) WriteIPLImage;
440 entry->magick=(IsImageFormatHandler *) IsIPL;
441 entry->adjoin=MagickTrue;
442 entry->description=ConstantString("IPL Image Sequence");
443 entry->module=ConstantString("IPL");
444 entry->endian_support=MagickTrue;
445 (void) RegisterMagickInfo(entry);
446 return(MagickImageCoderSignature);
447}
448
449/*
450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451 % %
452 % %
453 % %
454 % U n r e g i s t e r I P L I m a g e %
455 % %
456 % %
457 % %
458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 %
460 % UnregisterIPLImage() removes format registrations made by the
461 % IPL module from the list of supported formats.
462 %
463 % The format of the UnregisterIPLImage method is:
464 %
465 % UnregisterIPLImage(void)
466 %
467 */
468ModuleExport void UnregisterIPLImage(void)
469{
470 (void) UnregisterMagickInfo("IPL");
471}
472
473/*
cristy1e178e72011-08-28 19:44:34 +0000474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475% %
476% %
477% %
478% W r i t e I P L I m a g e %
479% %
480% %
481% %
482%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483%
484% WriteIPLImage() writes an image to a file in Scanalytics IPLabimage format.
485%
486% The format of the WriteIPLImage method is:
487%
488% MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image)
489% Image *image,ExceptionInfo *exception)
490%
491% A description of each parameter follows.
492%
493% o image_info: The image info.
494%
495% o image: The image.
496%
497% o exception: return any errors or warnings in this structure.
498%
499*/
500static MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image,
501 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000502{
cristyebc891a2011-04-24 23:04:16 +0000503 IPLInfo
504 ipl_info;
505
cristy3ed852e2009-09-05 21:47:34 +0000506 MagickBooleanType
507 status;
508
509 MagickOffsetType
510 scene;
511
cristy4c08aed2011-07-01 19:47:50 +0000512 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000513 *p;
514
cristy3ed852e2009-09-05 21:47:34 +0000515 QuantumInfo
516 *quantum_info;
517
cristyebc891a2011-04-24 23:04:16 +0000518 ssize_t
519 y;
520
521 unsigned char
522 *pixels;
523
cristy3ed852e2009-09-05 21:47:34 +0000524 /*
525 Open output image file.
526 */
527 assert(image_info != (const ImageInfo *) NULL);
528 assert(image_info->signature == MagickSignature);
529 assert(image != (Image *) NULL);
530 assert(image->signature == MagickSignature);
531 if (image->debug != MagickFalse)
532 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000533 assert(exception != (ExceptionInfo *) NULL);
534 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000535 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000536 if (status == MagickFalse)
537 return(status);
538 scene=0;
539
540
541 quantum_info=AcquireQuantumInfo(image_info, image);
542 if ((quantum_info->format == UndefinedQuantumFormat) &&
cristy1e178e72011-08-28 19:44:34 +0000543 (IsHighDynamicRangeImage(image,exception) != MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +0000544 SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
545 switch(quantum_info->depth){
546 case 8:
547 ipl_info.byteType = 0;
548 break;
549 case 16:
550 if(quantum_info->format == SignedQuantumFormat){
551 ipl_info.byteType = 2;
552 }
553 else{
554 ipl_info.byteType = 1;
555 }
556 break;
557 case 32:
558 if(quantum_info->format == FloatingPointQuantumFormat){
559 ipl_info.byteType = 3;
560 }
561 else{
562 ipl_info.byteType = 4;
563 }
564 break;
565 case 64:
566 ipl_info.byteType = 10;
567 break;
568 default:
569 ipl_info.byteType = 2;
570 break;
571
572 }
cristy0b29b252010-05-30 01:59:46 +0000573 ipl_info.z = (unsigned int) GetImageListLength(image);
cristy3ed852e2009-09-05 21:47:34 +0000574 /* There is no current method for detecting whether we have T or Z stacks */
575 ipl_info.time = 1;
cristy0b29b252010-05-30 01:59:46 +0000576 ipl_info.width = (unsigned int) image->columns;
577 ipl_info.height = (unsigned int) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000578
cristy501c5592012-04-18 12:45:09 +0000579 if (IssRGBColorspace(image->colorspace) == MagickFalse)
cristy8d951092012-02-08 18:54:56 +0000580 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000581
cristy501c5592012-04-18 12:45:09 +0000582 if(IssRGBColorspace(image->colorspace) == MagickTrue) { ipl_info.colors = 3; }
cristy3ed852e2009-09-05 21:47:34 +0000583 else{ ipl_info.colors = 1; }
584
cristy0b29b252010-05-30 01:59:46 +0000585 ipl_info.size = (unsigned int) (28 +
586 ((image->depth)/8)*ipl_info.height*ipl_info.width*ipl_info.colors*ipl_info.z);
cristy3ed852e2009-09-05 21:47:34 +0000587
588 /* Ok! Calculations are done. Lets write this puppy down! */
589
590 /*
591 Write IPL header.
592 */
593 /* Shockingly (maybe not if you have used IPLab), IPLab itself CANNOT read MSBEndian
594 files! The reader above can, but they cannot. For compatability reasons, I will leave
595 the code in here, but it is all but useless if you want to use IPLab. */
596
597 if(image_info->endian == MSBEndian)
598 (void) WriteBlob(image, 4, (const unsigned char *) "mmmm");
599 else{
600 image->endian = LSBEndian;
601 (void) WriteBlob(image, 4, (const unsigned char *) "iiii");
602 }
603 (void) WriteBlobLong(image, 4);
604 (void) WriteBlob(image, 4, (const unsigned char *) "100f");
605 (void) WriteBlob(image, 4, (const unsigned char *) "data");
606 (void) WriteBlobLong(image, ipl_info.size);
607 (void) WriteBlobLong(image, ipl_info.width);
608 (void) WriteBlobLong(image, ipl_info.height);
609 (void) WriteBlobLong(image, ipl_info.colors);
610 if(image_info->adjoin == MagickFalse)
611 (void) WriteBlobLong(image, 1);
612 else
613 (void) WriteBlobLong(image, ipl_info.z);
614 (void) WriteBlobLong(image, ipl_info.time);
615 (void) WriteBlobLong(image, ipl_info.byteType);
616
cristy3ed852e2009-09-05 21:47:34 +0000617 do
618 {
619 /*
620 Convert MIFF to IPL raster pixels.
621 */
622 pixels=GetQuantumPixels(quantum_info);
623 if(ipl_info.colors == 1){
624 /* Red frame */
cristybb503372010-05-27 20:51:26 +0000625 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy4c08aed2011-07-01 19:47:50 +0000626 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
627 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000628 break;
cristy4c08aed2011-07-01 19:47:50 +0000629 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000630 GrayQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000631 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
632 }
633
634}
635 if(ipl_info.colors == 3){
636 /* Red frame */
cristybb503372010-05-27 20:51:26 +0000637 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy4c08aed2011-07-01 19:47:50 +0000638 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
639 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000640 break;
cristy4c08aed2011-07-01 19:47:50 +0000641 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000642 RedQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000643 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
644 }
645
646 /* Green frame */
cristybb503372010-05-27 20:51:26 +0000647 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy1e178e72011-08-28 19:44:34 +0000648 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000649 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000650 break;
cristy4c08aed2011-07-01 19:47:50 +0000651 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000652 GreenQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000653 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
654 }
655 /* Blue frame */
cristybb503372010-05-27 20:51:26 +0000656 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy1e178e72011-08-28 19:44:34 +0000657 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000658 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000659 break;
cristy4c08aed2011-07-01 19:47:50 +0000660 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000661 BlueQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000662 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
663 if (image->previous == (Image *) NULL)
664 {
cristycee97112010-05-28 00:44:52 +0000665 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
666 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000667 if (status == MagickFalse)
668 break;
669 }
670 }
671 }
672 quantum_info=DestroyQuantumInfo(quantum_info);
673 if (GetNextImageInList(image) == (Image *) NULL)
674 break;
675 image=SyncNextImageInList(image);
676 status=SetImageProgress(image,SaveImagesTag,scene++,
677 GetImageListLength(image));
678 if (status == MagickFalse)
679 break;
680 }while (image_info->adjoin != MagickFalse);
681
682 (void) WriteBlob(image, 4, (const unsigned char *) "fini");
683 (void) WriteBlobLong(image, 0);
684
685CloseBlob(image);
686return(MagickTrue);
687}