blob: 49d6d06955d77882ded5df81d9112ed09f353b57 [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% %
cristyb56bb242014-11-25 17:12:48 +000022% Copyright 1999-2015 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
cristy58b6d832013-05-15 11:49:56 +000087/*
cristy41899842013-05-12 18:29:53 +000088static void increase (void *pixel, int byteType){
cristy3ed852e2009-09-05 21:47:34 +000089 switch(byteType){
90 case 0:(*((unsigned char *) pixel))++; break;
91 case 1:(*((signed int *) pixel))++; break;
92 case 2:(*((unsigned int *) pixel))++; break;
93 case 3:(*((signed long *) pixel))++; break;
94 default:(*((unsigned int *) pixel))++; break;
95 }
96}
cristy58b6d832013-05-15 11:49:56 +000097*/
cristy3ed852e2009-09-05 21:47:34 +000098
99/*
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % %
102 % %
103 % %
104 % I s I P L %
105 % %
106 % %
107 % %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %
110 % IsIPL() returns MagickTrue if the image format type, identified by the
111 % magick string, is IPL.
112 %
113 % The format of the IsIPL method is:
114 %
115 % MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
116 %
117 % A description of each parameter follows:
118 %
119 % o magick: compare image format pattern against these bytes.
120 %
121 % o length: Specifies the length of the magick string.
122 %
123 */
124static MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
125{
126 if (length < 4)
127 return(MagickFalse);
128 if (LocaleNCompare((const char *) magick,"data",4) == 0)
129 return(MagickTrue);
130 return(MagickFalse);
131}
132
133/*
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % %
136 % %
137 % %
138 % R e a d I P L I m a g e %
139 % %
140 % %
141 % %
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 %
144 % ReadIPLImage() reads a Scanalytics IPLab image file and returns it. It
145 % allocates the memory necessary for the new Image structure and returns a
146 % pointer to the new image.
147 %
148 % According to the IPLab spec, the data is blocked out in five dimensions:
149 % { t, z, c, y, x }. When we return the image, the latter three are folded
150 % into the standard "Image" structure. The "scenes" (image_info->scene)
151 % correspond to the order: { {t0,z0}, {t0, z1}, ..., {t1,z0}, {t1,z1}... }
152 % The number of scenes is t*z.
153 %
154 % The format of the ReadIPLImage method is:
155 %
156 % Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception)
157 %
158 % A description of each parameter follows:
159 %
160 % o image_info: The image info.
161 %
162 % o exception: return any errors or warnings in this structure.
163 %
164 */
165
cristy41899842013-05-12 18:29:53 +0000166static void SetHeaderFromIPL(Image *image, IPLInfo *ipl){
cristyc5de6992009-10-06 19:19:48 +0000167 image->columns = ipl->width;
168 image->rows = ipl->height;
169 image->depth = ipl->depth;
cristy2a11bef2011-10-28 18:33:11 +0000170 image->resolution.x = 1;
171 image->resolution.y = 1;
cristy3ed852e2009-09-05 21:47:34 +0000172}
173
174
175static Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception)
176{
177
178 /*
179 Declare variables
180 */
181 Image *image;
182
183 MagickBooleanType status;
cristy4c08aed2011-07-01 19:47:50 +0000184 register Quantum *q;
cristy3ed852e2009-09-05 21:47:34 +0000185 unsigned char magick[12], *pixels;
186 ssize_t count;
cristybb503372010-05-27 20:51:26 +0000187 ssize_t y;
188 size_t t_count=0;
cristy3ed852e2009-09-05 21:47:34 +0000189 size_t length;
190 IPLInfo
191 ipl_info;
192 QuantumFormatType
193 quantum_format;
194 QuantumInfo
195 *quantum_info;
196 QuantumType
197 quantum_type;
198
199 /*
200 Open Image
201 */
202
203 assert(image_info != (const ImageInfo *) NULL);
204 assert(image_info->signature == MagickSignature);
205 if ( image_info->debug != MagickFalse)
206 (void) LogMagickEvent(TraceEvent, GetMagickModule(), "%s",
207 image_info->filename);
208 assert(exception != (ExceptionInfo *) NULL);
209 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000210 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000211 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
212 if (status == MagickFalse)
213 {
214 image=DestroyImageList(image);
215 return((Image *) NULL);
216 }
217
218 /*
219 Read IPL image
220 */
221
222 /*
223 Determine endianness
224 If we get back "iiii", we have LSB,"mmmm", MSB
225 */
226 count=ReadBlob(image,4,magick);
cristyda16f162011-02-19 23:52:17 +0000227 (void) count;
cristy3ed852e2009-09-05 21:47:34 +0000228 if((LocaleNCompare((char *) magick,"iiii",4) == 0))
229 image->endian=LSBEndian;
230 else{
231 if((LocaleNCompare((char *) magick,"mmmm",4) == 0))
232 image->endian=MSBEndian;
233 else{
234 ThrowReaderException(CorruptImageError, "ImproperImageHeader");
235 }
236 }
237 /* Skip o'er the next 8 bytes (garbage) */
238 count=ReadBlob(image, 8, magick);
239 /*
240 Excellent, now we read the header unimpeded.
241 */
242 count=ReadBlob(image,4,magick);
243 if((LocaleNCompare((char *) magick,"data",4) != 0))
244 ThrowReaderException(CorruptImageError, "ImproperImageHeader");
245 ipl_info.size=ReadBlobLong(image);
246 ipl_info.width=ReadBlobLong(image);
247 ipl_info.height=ReadBlobLong(image);
248 if((ipl_info.width == 0UL) || (ipl_info.height == 0UL))
249 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
250 ipl_info.colors=ReadBlobLong(image);
cristye2c4f182012-05-12 14:11:53 +0000251 if(ipl_info.colors == 3){ SetImageColorspace(image,sRGBColorspace,exception);}
cristy3ed852e2009-09-05 21:47:34 +0000252 else { image->colorspace = GRAYColorspace; }
253 ipl_info.z=ReadBlobLong(image);
254 ipl_info.time=ReadBlobLong(image);
255
256 ipl_info.byteType=ReadBlobLong(image);
257
258
259 /* Initialize Quantum Info */
260
261 switch (ipl_info.byteType) {
262 case 0:
263 ipl_info.depth=8;
264 quantum_format = UnsignedQuantumFormat;
265 break;
266 case 1:
267 ipl_info.depth=16;
268 quantum_format = SignedQuantumFormat;
269 break;
270 case 2:
271 ipl_info.depth=16;
272 quantum_format = UnsignedQuantumFormat;
273 break;
274 case 3:
275 ipl_info.depth=32;
276 quantum_format = SignedQuantumFormat;
277 break;
278 case 4: ipl_info.depth=32;
279 quantum_format = FloatingPointQuantumFormat;
280 break;
281 case 5:
282 ipl_info.depth=8;
283 quantum_format = UnsignedQuantumFormat;
284 break;
285 case 6:
286 ipl_info.depth=16;
287 quantum_format = UnsignedQuantumFormat;
288 break;
289 case 10:
290 ipl_info.depth=64;
291 quantum_format = FloatingPointQuantumFormat;
292 break;
293 default:
294 ipl_info.depth=16;
295 quantum_format = UnsignedQuantumFormat;
296 break;
297 }
298
299 /*
300 Set number of scenes of image
301 */
302
303 SetHeaderFromIPL(image, &ipl_info);
304
305 /* Thats all we need if we are pinging. */
306 if (image_info->ping != MagickFalse)
307 {
308 (void) CloseBlob(image);
309 return(GetFirstImageInList(image));
310 }
311 length=image->columns;
312 quantum_type=GetQuantumType(image,exception);
313 do
314 {
315 SetHeaderFromIPL(image, &ipl_info);
316
317 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
318 if (image->scene >= (image_info->scene+image_info->number_scenes-1))
319 break;
320/*
cristye8c25f92010-06-03 00:53:06 +0000321 printf("Length: %.20g, Memory size: %.20g\n", (double) length,(double)
322 image->depth);
cristy3ed852e2009-09-05 21:47:34 +0000323*/
324 quantum_info=AcquireQuantumInfo(image_info,image);
325 if (quantum_info == (QuantumInfo *) NULL)
326 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
327 status=SetQuantumFormat(image,quantum_info,quantum_format);
328 if (status == MagickFalse)
329 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
330 pixels=GetQuantumPixels(quantum_info);
331 if(image->columns != ipl_info.width){
332/*
cristye8c25f92010-06-03 00:53:06 +0000333 printf("Columns not set correctly! Wanted: %.20g, got: %.20g\n",
334 (double) ipl_info.width, (double) image->columns);
cristy3ed852e2009-09-05 21:47:34 +0000335*/
336 }
337
338 /*
339 Covert IPL binary to pixel packets
340 */
341
342 if(ipl_info.colors == 1){
cristybb503372010-05-27 20:51:26 +0000343 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000344 (void) ReadBlob(image, length*image->depth/8, pixels);
345 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000346 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000347 break;
cristyc5de6992009-10-06 19:19:48 +0000348 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3ed852e2009-09-05 21:47:34 +0000349 GrayQuantum,pixels,exception);
350 if (SyncAuthenticPixels(image,exception) == MagickFalse)
351 break;
cristyc5de6992009-10-06 19:19:48 +0000352 }
cristy3ed852e2009-09-05 21:47:34 +0000353 }
354 else{
cristybb503372010-05-27 20:51:26 +0000355 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000356 (void) ReadBlob(image, length*image->depth/8, pixels);
357 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000358 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000359 break;
cristyc5de6992009-10-06 19:19:48 +0000360 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
361 RedQuantum,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000362 if (SyncAuthenticPixels(image,exception) == MagickFalse)
363 break;
364 }
cristybb503372010-05-27 20:51:26 +0000365 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000366 (void) ReadBlob(image, length*image->depth/8, pixels);
367 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000368 if (q == (Quantum *) NULL)
cristyebc891a2011-04-24 23:04:16 +0000369 break;
cristyc5de6992009-10-06 19:19:48 +0000370 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3ed852e2009-09-05 21:47:34 +0000371 GreenQuantum,pixels,exception);
372 if (SyncAuthenticPixels(image,exception) == MagickFalse)
373 break;
374 }
cristybb503372010-05-27 20:51:26 +0000375 for(y = 0; y < (ssize_t) image->rows; y++){
cristy3ed852e2009-09-05 21:47:34 +0000376 (void) ReadBlob(image, length*image->depth/8, pixels);
377 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000378 if (q == (Quantum *) NULL)
cristyebc891a2011-04-24 23:04:16 +0000379 break;
cristyc5de6992009-10-06 19:19:48 +0000380 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy3ed852e2009-09-05 21:47:34 +0000381 BlueQuantum,pixels,exception);
382 if (SyncAuthenticPixels(image,exception) == MagickFalse)
383 break;
384 }
385 }
386 SetQuantumImageType(image,quantum_type);
387
388 t_count++;
389 quantum_info = DestroyQuantumInfo(quantum_info);
390
391 if (EOFBlob(image) != MagickFalse)
392 {
393 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
394 image->filename);
395 break;
396 }
397 if(t_count < ipl_info.z * ipl_info.time){
398 /*
399 Proceed to next image.
400 */
cristy9950d572011-10-01 18:22:35 +0000401 AcquireNextImage(image_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000402 if (GetNextImageInList(image) == (Image *) NULL)
403 {
404 image=DestroyImageList(image);
405 return((Image *) NULL);
406 }
407 image=SyncNextImageInList(image);
408 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
409 GetBlobSize(image));
410 if (status == MagickFalse)
411 break;
412 }
413 } while (t_count < ipl_info.z*ipl_info.time);
414 CloseBlob(image);
415 return(GetFirstImageInList(image));
416}
417
418/*
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 % %
421 % %
422 % %
423 % R e g i s t e r I P L I m a g e %
424 % %
425 % %
426 % %
427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 %
429 % RegisterIPLImage() add attributes for the Scanalytics IPL image format to the
430 % list of supported formats.
431 %
432 %
433 */
cristybb503372010-05-27 20:51:26 +0000434ModuleExport size_t RegisterIPLImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000435{
436 MagickInfo
437 *entry;
438
439 entry=SetMagickInfo("IPL");
440 entry->decoder=(DecodeImageHandler *) ReadIPLImage;
441 entry->encoder=(EncodeImageHandler *) WriteIPLImage;
442 entry->magick=(IsImageFormatHandler *) IsIPL;
443 entry->adjoin=MagickTrue;
444 entry->description=ConstantString("IPL Image Sequence");
445 entry->module=ConstantString("IPL");
446 entry->endian_support=MagickTrue;
447 (void) RegisterMagickInfo(entry);
448 return(MagickImageCoderSignature);
449}
450
451/*
452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
453 % %
454 % %
455 % %
456 % U n r e g i s t e r I P L I m a g e %
457 % %
458 % %
459 % %
460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461 %
462 % UnregisterIPLImage() removes format registrations made by the
463 % IPL module from the list of supported formats.
464 %
465 % The format of the UnregisterIPLImage method is:
466 %
467 % UnregisterIPLImage(void)
468 %
469 */
470ModuleExport void UnregisterIPLImage(void)
471{
472 (void) UnregisterMagickInfo("IPL");
473}
474
475/*
cristy1e178e72011-08-28 19:44:34 +0000476%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477% %
478% %
479% %
480% W r i t e I P L I m a g e %
481% %
482% %
483% %
484%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485%
486% WriteIPLImage() writes an image to a file in Scanalytics IPLabimage format.
487%
488% The format of the WriteIPLImage method is:
489%
490% MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image)
491% Image *image,ExceptionInfo *exception)
492%
493% A description of each parameter follows.
494%
495% o image_info: The image info.
496%
497% o image: The image.
498%
499% o exception: return any errors or warnings in this structure.
500%
501*/
502static MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image,
503 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000504{
cristyebc891a2011-04-24 23:04:16 +0000505 IPLInfo
506 ipl_info;
507
cristy3ed852e2009-09-05 21:47:34 +0000508 MagickBooleanType
509 status;
510
511 MagickOffsetType
512 scene;
513
cristy4c08aed2011-07-01 19:47:50 +0000514 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000515 *p;
516
cristy3ed852e2009-09-05 21:47:34 +0000517 QuantumInfo
518 *quantum_info;
519
cristyebc891a2011-04-24 23:04:16 +0000520 ssize_t
521 y;
522
523 unsigned char
524 *pixels;
525
cristy3ed852e2009-09-05 21:47:34 +0000526 /*
527 Open output image file.
528 */
529 assert(image_info != (const ImageInfo *) NULL);
530 assert(image_info->signature == MagickSignature);
531 assert(image != (Image *) NULL);
532 assert(image->signature == MagickSignature);
533 if (image->debug != MagickFalse)
534 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000535 assert(exception != (ExceptionInfo *) NULL);
536 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000537 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000538 if (status == MagickFalse)
539 return(status);
540 scene=0;
541
542
543 quantum_info=AcquireQuantumInfo(image_info, image);
544 if ((quantum_info->format == UndefinedQuantumFormat) &&
cristy1e178e72011-08-28 19:44:34 +0000545 (IsHighDynamicRangeImage(image,exception) != MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +0000546 SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
547 switch(quantum_info->depth){
548 case 8:
549 ipl_info.byteType = 0;
550 break;
551 case 16:
552 if(quantum_info->format == SignedQuantumFormat){
553 ipl_info.byteType = 2;
554 }
555 else{
556 ipl_info.byteType = 1;
557 }
558 break;
559 case 32:
560 if(quantum_info->format == FloatingPointQuantumFormat){
561 ipl_info.byteType = 3;
562 }
563 else{
564 ipl_info.byteType = 4;
565 }
566 break;
567 case 64:
568 ipl_info.byteType = 10;
569 break;
570 default:
571 ipl_info.byteType = 2;
572 break;
573
574 }
cristy0b29b252010-05-30 01:59:46 +0000575 ipl_info.z = (unsigned int) GetImageListLength(image);
cristy3ed852e2009-09-05 21:47:34 +0000576 /* There is no current method for detecting whether we have T or Z stacks */
577 ipl_info.time = 1;
cristy0b29b252010-05-30 01:59:46 +0000578 ipl_info.width = (unsigned int) image->columns;
579 ipl_info.height = (unsigned int) image->rows;
cristyaf8d3912014-02-21 14:50:33 +0000580 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristycd8b3312013-12-22 01:51:11 +0000581 if(IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) { ipl_info.colors = 3; }
cristy3ed852e2009-09-05 21:47:34 +0000582 else{ ipl_info.colors = 1; }
583
cristy0b29b252010-05-30 01:59:46 +0000584 ipl_info.size = (unsigned int) (28 +
585 ((image->depth)/8)*ipl_info.height*ipl_info.width*ipl_info.colors*ipl_info.z);
cristy3ed852e2009-09-05 21:47:34 +0000586
587 /* Ok! Calculations are done. Lets write this puppy down! */
588
589 /*
590 Write IPL header.
591 */
592 /* Shockingly (maybe not if you have used IPLab), IPLab itself CANNOT read MSBEndian
593 files! The reader above can, but they cannot. For compatability reasons, I will leave
594 the code in here, but it is all but useless if you want to use IPLab. */
595
596 if(image_info->endian == MSBEndian)
597 (void) WriteBlob(image, 4, (const unsigned char *) "mmmm");
598 else{
599 image->endian = LSBEndian;
600 (void) WriteBlob(image, 4, (const unsigned char *) "iiii");
601 }
602 (void) WriteBlobLong(image, 4);
603 (void) WriteBlob(image, 4, (const unsigned char *) "100f");
604 (void) WriteBlob(image, 4, (const unsigned char *) "data");
605 (void) WriteBlobLong(image, ipl_info.size);
606 (void) WriteBlobLong(image, ipl_info.width);
607 (void) WriteBlobLong(image, ipl_info.height);
608 (void) WriteBlobLong(image, ipl_info.colors);
609 if(image_info->adjoin == MagickFalse)
610 (void) WriteBlobLong(image, 1);
611 else
612 (void) WriteBlobLong(image, ipl_info.z);
613 (void) WriteBlobLong(image, ipl_info.time);
614 (void) WriteBlobLong(image, ipl_info.byteType);
615
cristy3ed852e2009-09-05 21:47:34 +0000616 do
617 {
618 /*
619 Convert MIFF to IPL raster pixels.
620 */
621 pixels=GetQuantumPixels(quantum_info);
622 if(ipl_info.colors == 1){
623 /* Red frame */
cristybb503372010-05-27 20:51:26 +0000624 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy4c08aed2011-07-01 19:47:50 +0000625 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
626 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000627 break;
cristy4c08aed2011-07-01 19:47:50 +0000628 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000629 GrayQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000630 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
631 }
632
633}
634 if(ipl_info.colors == 3){
635 /* Red frame */
cristybb503372010-05-27 20:51:26 +0000636 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy4c08aed2011-07-01 19:47:50 +0000637 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
638 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000639 break;
cristy4c08aed2011-07-01 19:47:50 +0000640 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000641 RedQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000642 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
643 }
644
645 /* Green frame */
cristybb503372010-05-27 20:51:26 +0000646 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy1e178e72011-08-28 19:44:34 +0000647 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000648 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000649 break;
cristy4c08aed2011-07-01 19:47:50 +0000650 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000651 GreenQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000652 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
653 }
654 /* Blue frame */
cristybb503372010-05-27 20:51:26 +0000655 for(y = 0; y < (ssize_t) ipl_info.height; y++){
cristy1e178e72011-08-28 19:44:34 +0000656 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000657 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000658 break;
cristy4c08aed2011-07-01 19:47:50 +0000659 (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info,
cristy1e178e72011-08-28 19:44:34 +0000660 BlueQuantum, pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +0000661 (void) WriteBlob(image, image->columns*image->depth/8, pixels);
662 if (image->previous == (Image *) NULL)
663 {
cristycee97112010-05-28 00:44:52 +0000664 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
665 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000666 if (status == MagickFalse)
667 break;
668 }
669 }
670 }
671 quantum_info=DestroyQuantumInfo(quantum_info);
672 if (GetNextImageInList(image) == (Image *) NULL)
673 break;
674 image=SyncNextImageInList(image);
675 status=SetImageProgress(image,SaveImagesTag,scene++,
676 GetImageListLength(image));
677 if (status == MagickFalse)
678 break;
679 }while (image_info->adjoin != MagickFalse);
680
681 (void) WriteBlob(image, 4, (const unsigned char *) "fini");
682 (void) WriteBlobLong(image, 0);
683
684CloseBlob(image);
685return(MagickTrue);
686}