blob: ed2db8bbdb54f237dba1b91588c79398604b52ff [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC IIIII N N %
7% C I NN N %
8% C I N N N %
9% C I N NN %
10% CCCC IIIII N N %
11% %
12% %
13% Read/Write Kodak Cineon Image Format %
14% Cineon Image Format is a subset of SMTPE CIN %
15% %
16% %
17% Software Design %
cristyde984cd2013-12-01 14:49:27 +000018% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000019% Kelly Bergougnoux %
20% October 2003 %
21% %
22% %
cristyfe676ee2013-11-18 13:03:38 +000023% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000024% dedicated to making software imaging solutions freely available. %
25% %
26% You may not use this file except in compliance with the License. You may %
27% obtain a copy of the License at %
28% %
29% http://www.imagemagick.org/script/license.php %
30% %
31% Unless required by applicable law or agreed to in writing, software %
32% distributed under the License is distributed on an "AS IS" BASIS, %
33% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
34% See the License for the specific language governing permissions and %
35% limitations under the License. %
36% %
37% %
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39%
40% Cineon image file format draft is available at
41% http://www.cineon.com/ff_draft.php.
42%
43%
44*/
45
46/*
47 Include declarations.
48*/
cristy4c08aed2011-07-01 19:47:50 +000049#include "MagickCore/studio.h"
cristy76ce6e12013-04-05 14:33:38 +000050#include "MagickCore/artifact.h"
cristy4c08aed2011-07-01 19:47:50 +000051#include "MagickCore/blob.h"
52#include "MagickCore/blob-private.h"
53#include "MagickCore/cache.h"
54#include "MagickCore/colorspace.h"
55#include "MagickCore/exception.h"
56#include "MagickCore/exception-private.h"
57#include "MagickCore/image.h"
58#include "MagickCore/image-private.h"
59#include "MagickCore/list.h"
60#include "MagickCore/magick.h"
61#include "MagickCore/memory_.h"
62#include "MagickCore/monitor.h"
63#include "MagickCore/monitor-private.h"
64#include "MagickCore/option.h"
65#include "MagickCore/profile.h"
66#include "MagickCore/property.h"
67#include "MagickCore/quantum-private.h"
68#include "MagickCore/quantum-private.h"
69#include "MagickCore/static.h"
70#include "MagickCore/string_.h"
71#include "MagickCore/string-private.h"
72#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000073
74/*
75 Typedef declaration.
76*/
77typedef struct _CINDataFormatInfo
78{
79 unsigned char
80 interleave,
81 packing,
82 sign,
83 sense;
84
cristyf6fe0a12010-05-30 00:44:47 +000085 size_t
cristy3ed852e2009-09-05 21:47:34 +000086 line_pad,
87 channel_pad;
88
89 unsigned char
90 reserve[20];
91} CINDataFormatInfo;
92
93typedef struct _CINFileInfo
94{
cristyf6fe0a12010-05-30 00:44:47 +000095 size_t
cristy3ed852e2009-09-05 21:47:34 +000096 magic,
97 image_offset,
98 generic_length,
99 industry_length,
100 user_length,
101 file_size;
102
103 char
104 version[8],
105 filename[100],
106 create_date[12],
107 create_time[12],
108 reserve[36];
109} CINFileInfo;
110
111typedef struct _CINFilmInfo
112{
113 char
114 id,
115 type,
116 offset,
117 reserve1;
118
cristyf6fe0a12010-05-30 00:44:47 +0000119 size_t
cristy3ed852e2009-09-05 21:47:34 +0000120 prefix,
121 count;
122
123 char
124 format[32];
125
cristyf6fe0a12010-05-30 00:44:47 +0000126 size_t
cristy3ed852e2009-09-05 21:47:34 +0000127 frame_position;
128
129 float
130 frame_rate;
131
132 char
133 frame_id[32],
134 slate_info[200],
135 reserve[740];
136} CINFilmInfo;
137
138typedef struct _CINImageChannel
139{
140 unsigned char
141 designator[2],
142 bits_per_pixel,
143 reserve;
144
cristyf6fe0a12010-05-30 00:44:47 +0000145 size_t
cristy3ed852e2009-09-05 21:47:34 +0000146 pixels_per_line,
147 lines_per_image;
148
149 float
150 min_data,
151 min_quantity,
152 max_data,
153 max_quantity;
154} CINImageChannel;
155
156typedef struct _CINImageInfo
157{
158 unsigned char
159 orientation,
160 number_channels,
161 reserve1[2];
162
163 CINImageChannel
164 channel[8];
165
166 float
167 white_point[2],
168 red_primary_chromaticity[2],
169 green_primary_chromaticity[2],
170 blue_primary_chromaticity[2];
171
172 char
173 label[200],
174 reserve[28];
175} CINImageInfo;
176
177typedef struct _CINOriginationInfo
178{
cristyf6fe0a12010-05-30 00:44:47 +0000179 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000180 x_offset,
181 y_offset;
182
183 char
184 filename[100],
185 create_date[12],
186 create_time[12],
187 device[64],
188 model[32],
189 serial[32];
190
191 float
192 x_pitch,
193 y_pitch,
194 gamma;
195
196 char
197 reserve[40];
198} CINOriginationInfo;
199
200typedef struct _CINUserInfo
201{
202 char
203 id[32];
204} CINUserInfo;
205
206typedef struct CINInfo
207{
208 CINFileInfo
209 file;
210
211 CINImageInfo
212 image;
213
214 CINDataFormatInfo
215 data_format;
216
217 CINOriginationInfo
218 origination;
219
220 CINFilmInfo
221 film;
222
223 CINUserInfo
224 user;
225} CINInfo;
226
227/*
228 Forward declaractions.
229*/
230static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +0000231 WriteCINImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000232
233/*
234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235% %
236% %
237% %
238% I s C I N E O N %
239% %
240% %
241% %
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243%
244% IsCIN() returns MagickTrue if the image format type, identified by the magick
245% string, is CIN.
246%
247% The format of the IsCIN method is:
248%
249% MagickBooleanType IsCIN(const unsigned char *magick,const size_t length)
250%
251% A description of each parameter follows:
252%
253% o magick: compare image format pattern against these bytes.
254%
255% o length: Specifies the length of the magick string.
256%
257*/
258static MagickBooleanType IsCIN(const unsigned char *magick,const size_t length)
259{
260 if (length < 4)
261 return(MagickFalse);
262 if (memcmp(magick,"\200\052\137\327",4) == 0)
263 return(MagickTrue);
264 return(MagickFalse);
265}
266
267/*
268%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269% %
270% %
271% %
272% R e a d C I N E O N I m a g e %
273% %
274% %
275% %
276%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277%
278% ReadCINImage() reads an CIN X image file and returns it. It allocates
279% the memory necessary for the new Image structure and returns a point to the
280% new image.
281%
282% The format of the ReadCINImage method is:
283%
284% Image *ReadCINImage(const ImageInfo *image_info,
285% ExceptionInfo *exception)
286%
287% A description of each parameter follows:
288%
289% o image_info: the image info.
290%
291% o exception: return any errors or warnings in this structure.
292%
293*/
294
cristybb503372010-05-27 20:51:26 +0000295static size_t GetBytesPerRow(size_t columns,
296 size_t samples_per_pixel,size_t bits_per_pixel,
cristy3ed852e2009-09-05 21:47:34 +0000297 MagickBooleanType pad)
298{
299 size_t
300 bytes_per_row;
301
302 switch (bits_per_pixel)
303 {
304 case 1:
305 {
306 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
307 bits_per_pixel+31)/32);
308 break;
309 }
310 case 8:
311 default:
312 {
313 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
314 bits_per_pixel+31)/32);
315 break;
316 }
317 case 10:
318 {
319 if (pad == MagickFalse)
320 {
321 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
322 bits_per_pixel+31)/32);
323 break;
324 }
325 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
326 break;
327 }
328 case 12:
329 {
330 if (pad == MagickFalse)
331 {
332 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
333 bits_per_pixel+31)/32);
334 break;
335 }
336 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
337 break;
338 }
339 case 16:
340 {
341 bytes_per_row=2*(((size_t) samples_per_pixel*columns*
342 bits_per_pixel+8)/16);
343 break;
344 }
345 case 32:
346 {
347 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
348 bits_per_pixel+31)/32);
349 break;
350 }
351 case 64:
352 {
353 bytes_per_row=8*(((size_t) samples_per_pixel*columns*
354 bits_per_pixel+63)/64);
355 break;
356 }
357 }
358 return(bytes_per_row);
359}
360
361static inline MagickBooleanType IsFloatDefined(const float value)
362{
363 union
364 {
cristy97450ff2010-12-29 17:29:17 +0000365 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000366 unsigned_value;
367
368 double
369 float_value;
370 } quantum;
371
cristy97450ff2010-12-29 17:29:17 +0000372 quantum.unsigned_value=0U;
cristy3ed852e2009-09-05 21:47:34 +0000373 quantum.float_value=value;
cristy97450ff2010-12-29 17:29:17 +0000374 if (quantum.unsigned_value == 0U)
cristy3ed852e2009-09-05 21:47:34 +0000375 return(MagickFalse);
376 return(MagickTrue);
377}
378
cristy4e82e512011-04-24 01:33:42 +0000379static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000380{
381#define MonoColorType 1
382#define RGBColorType 3
383
cristye6f04802014-05-04 01:41:20 +0000384 char
385 property[MaxTextExtent];
386
cristy3ed852e2009-09-05 21:47:34 +0000387 CINInfo
388 cin;
389
390 Image
391 *image;
392
cristy3ed852e2009-09-05 21:47:34 +0000393 MagickBooleanType
394 status;
395
396 MagickOffsetType
397 offset;
398
399 QuantumInfo
400 *quantum_info;
401
402 QuantumType
403 quantum_type;
404
cristybb503372010-05-27 20:51:26 +0000405 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000406 i;
407
cristy4c08aed2011-07-01 19:47:50 +0000408 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000409 *q;
410
411 size_t
cristy5a128302011-05-17 12:42:40 +0000412 length;
cristy3ed852e2009-09-05 21:47:34 +0000413
414 ssize_t
cristy4e82e512011-04-24 01:33:42 +0000415 count,
416 y;
cristy3ed852e2009-09-05 21:47:34 +0000417
418 unsigned char
cristya9c6cd62011-05-18 21:11:35 +0000419 magick[4],
cristy3ed852e2009-09-05 21:47:34 +0000420 *pixels;
421
cristy3ed852e2009-09-05 21:47:34 +0000422 /*
423 Open image file.
424 */
425 assert(image_info != (const ImageInfo *) NULL);
426 assert(image_info->signature == MagickSignature);
427 if (image_info->debug != MagickFalse)
428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
429 image_info->filename);
430 assert(exception != (ExceptionInfo *) NULL);
431 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000432 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000433 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
434 if (status == MagickFalse)
435 {
436 image=DestroyImageList(image);
437 return((Image *) NULL);
438 }
439 /*
440 File information.
441 */
442 offset=0;
cristya9c6cd62011-05-18 21:11:35 +0000443 count=ReadBlob(image,4,magick);
cristy3ed852e2009-09-05 21:47:34 +0000444 offset+=count;
445 if ((count != 4) ||
446 ((LocaleNCompare((char *) magick,"\200\052\137\327",4) != 0)))
447 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
cristya9c6cd62011-05-18 21:11:35 +0000448 image->endian=(magick[0] == 0x80) && (magick[1] == 0x2a) &&
449 (magick[2] == 0x5f) && (magick[3] == 0xd7) ? MSBEndian : LSBEndian;
cristy3ed852e2009-09-05 21:47:34 +0000450 cin.file.image_offset=ReadBlobLong(image);
451 offset+=4;
452 cin.file.generic_length=ReadBlobLong(image);
453 offset+=4;
454 cin.file.industry_length=ReadBlobLong(image);
455 offset+=4;
456 cin.file.user_length=ReadBlobLong(image);
457 offset+=4;
458 cin.file.file_size=ReadBlobLong(image);
459 offset+=4;
460 offset+=ReadBlob(image,sizeof(cin.file.version),(unsigned char *)
461 cin.file.version);
cristye6f04802014-05-04 01:41:20 +0000462 (void) CopyMagickString(property,cin.file.version,sizeof(cin.file.version));
463 (void) SetImageProperty(image,"dpx:file.version",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000464 offset+=ReadBlob(image,sizeof(cin.file.filename),(unsigned char *)
465 cin.file.filename);
cristye6f04802014-05-04 01:41:20 +0000466 (void) CopyMagickString(property,cin.file.filename,sizeof(cin.file.filename));
467 (void) SetImageProperty(image,"dpx:file.filename",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000468 offset+=ReadBlob(image,sizeof(cin.file.create_date),(unsigned char *)
469 cin.file.create_date);
cristye6f04802014-05-04 01:41:20 +0000470 (void) CopyMagickString(property,cin.file.create_date,
471 sizeof(cin.file.create_date));
472 (void) SetImageProperty(image,"dpx:file.create_date",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000473 offset+=ReadBlob(image,sizeof(cin.file.create_time),(unsigned char *)
474 cin.file.create_time);
cristye6f04802014-05-04 01:41:20 +0000475 (void) CopyMagickString(property,cin.file.create_time,
476 sizeof(cin.file.create_time));
477 (void) SetImageProperty(image,"dpx:file.create_time",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000478 offset+=ReadBlob(image,sizeof(cin.file.reserve),(unsigned char *)
479 cin.file.reserve);
480 /*
481 Image information.
482 */
483 cin.image.orientation=(unsigned char) ReadBlobByte(image);
484 offset++;
dirk93b02b72013-11-16 16:03:36 +0000485 if (cin.image.orientation != (unsigned char) (~0))
cristy97450ff2010-12-29 17:29:17 +0000486 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
cristy3ed852e2009-09-05 21:47:34 +0000487 cin.image.orientation);
488 switch (cin.image.orientation)
489 {
490 default:
cristy4e82e512011-04-24 01:33:42 +0000491 case 0: image->orientation=TopLeftOrientation; break;
492 case 1: image->orientation=TopRightOrientation; break;
493 case 2: image->orientation=BottomLeftOrientation; break;
494 case 3: image->orientation=BottomRightOrientation; break;
495 case 4: image->orientation=LeftTopOrientation; break;
496 case 5: image->orientation=RightTopOrientation; break;
497 case 6: image->orientation=LeftBottomOrientation; break;
498 case 7: image->orientation=RightBottomOrientation; break;
cristy3ed852e2009-09-05 21:47:34 +0000499 }
500 cin.image.number_channels=(unsigned char) ReadBlobByte(image);
501 offset++;
502 offset+=ReadBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
503 cin.image.reserve1);
504 for (i=0; i < 8; i++)
505 {
506 cin.image.channel[i].designator[0]=(unsigned char) ReadBlobByte(image);
507 offset++;
508 cin.image.channel[i].designator[1]=(unsigned char) ReadBlobByte(image);
509 offset++;
510 cin.image.channel[i].bits_per_pixel=(unsigned char) ReadBlobByte(image);
511 offset++;
512 cin.image.channel[i].reserve=(unsigned char) ReadBlobByte(image);
513 offset++;
514 cin.image.channel[i].pixels_per_line=ReadBlobLong(image);
515 offset+=4;
516 cin.image.channel[i].lines_per_image=ReadBlobLong(image);
517 offset+=4;
518 cin.image.channel[i].min_data=ReadBlobFloat(image);
519 offset+=4;
520 cin.image.channel[i].min_quantity=ReadBlobFloat(image);
521 offset+=4;
522 cin.image.channel[i].max_data=ReadBlobFloat(image);
523 offset+=4;
524 cin.image.channel[i].max_quantity=ReadBlobFloat(image);
525 offset+=4;
526 }
527 cin.image.white_point[0]=ReadBlobFloat(image);
528 offset+=4;
529 if (IsFloatDefined(cin.image.white_point[0]) != MagickFalse)
530 image->chromaticity.white_point.x=cin.image.white_point[0];
531 cin.image.white_point[1]=ReadBlobFloat(image);
532 offset+=4;
533 if (IsFloatDefined(cin.image.white_point[1]) != MagickFalse)
534 image->chromaticity.white_point.y=cin.image.white_point[1];
535 cin.image.red_primary_chromaticity[0]=ReadBlobFloat(image);
536 offset+=4;
537 if (IsFloatDefined(cin.image.red_primary_chromaticity[0]) != MagickFalse)
538 image->chromaticity.red_primary.x=cin.image.red_primary_chromaticity[0];
539 cin.image.red_primary_chromaticity[1]=ReadBlobFloat(image);
540 offset+=4;
541 if (IsFloatDefined(cin.image.red_primary_chromaticity[1]) != MagickFalse)
542 image->chromaticity.red_primary.y=cin.image.red_primary_chromaticity[1];
543 cin.image.green_primary_chromaticity[0]=ReadBlobFloat(image);
544 offset+=4;
545 if (IsFloatDefined(cin.image.green_primary_chromaticity[0]) != MagickFalse)
546 image->chromaticity.red_primary.x=cin.image.green_primary_chromaticity[0];
547 cin.image.green_primary_chromaticity[1]=ReadBlobFloat(image);
548 offset+=4;
549 if (IsFloatDefined(cin.image.green_primary_chromaticity[1]) != MagickFalse)
550 image->chromaticity.green_primary.y=cin.image.green_primary_chromaticity[1];
551 cin.image.blue_primary_chromaticity[0]=ReadBlobFloat(image);
552 offset+=4;
553 if (IsFloatDefined(cin.image.blue_primary_chromaticity[0]) != MagickFalse)
554 image->chromaticity.blue_primary.x=cin.image.blue_primary_chromaticity[0];
555 cin.image.blue_primary_chromaticity[1]=ReadBlobFloat(image);
556 offset+=4;
557 if (IsFloatDefined(cin.image.blue_primary_chromaticity[1]) != MagickFalse)
558 image->chromaticity.blue_primary.y=cin.image.blue_primary_chromaticity[1];
559 offset+=ReadBlob(image,sizeof(cin.image.label),(unsigned char *)
560 cin.image.label);
cristye6f04802014-05-04 01:41:20 +0000561 (void) CopyMagickString(property,cin.image.label,sizeof(cin.image.label));
562 (void) SetImageProperty(image,"dpx:image.label",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000563 offset+=ReadBlob(image,sizeof(cin.image.reserve),(unsigned char *)
564 cin.image.reserve);
565 /*
566 Image data format information.
567 */
568 cin.data_format.interleave=(unsigned char) ReadBlobByte(image);
569 offset++;
570 cin.data_format.packing=(unsigned char) ReadBlobByte(image);
571 offset++;
572 cin.data_format.sign=(unsigned char) ReadBlobByte(image);
573 offset++;
574 cin.data_format.sense=(unsigned char) ReadBlobByte(image);
575 offset++;
576 cin.data_format.line_pad=ReadBlobLong(image);
577 offset+=4;
578 cin.data_format.channel_pad=ReadBlobLong(image);
579 offset+=4;
580 offset+=ReadBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
581 cin.data_format.reserve);
582 /*
583 Image origination information.
584 */
cristy6cff05d2010-09-02 11:22:46 +0000585 cin.origination.x_offset=(int) ReadBlobLong(image);
cristy3ed852e2009-09-05 21:47:34 +0000586 offset+=4;
cristybb503372010-05-27 20:51:26 +0000587 if ((size_t) cin.origination.x_offset != ~0UL)
cristy97450ff2010-12-29 17:29:17 +0000588 (void) FormatImageProperty(image,"dpx:origination.x_offset","%.20g",
cristye8c25f92010-06-03 00:53:06 +0000589 (double) cin.origination.x_offset);
cristy811f5172010-12-29 17:38:08 +0000590 cin.origination.y_offset=(ssize_t) ReadBlobLong(image);
cristy3ed852e2009-09-05 21:47:34 +0000591 offset+=4;
cristybb503372010-05-27 20:51:26 +0000592 if ((size_t) cin.origination.y_offset != ~0UL)
cristy97450ff2010-12-29 17:29:17 +0000593 (void) FormatImageProperty(image,"dpx:origination.y_offset","%.20g",
cristye8c25f92010-06-03 00:53:06 +0000594 (double) cin.origination.y_offset);
cristy3ed852e2009-09-05 21:47:34 +0000595 offset+=ReadBlob(image,sizeof(cin.origination.filename),(unsigned char *)
596 cin.origination.filename);
cristye6f04802014-05-04 01:41:20 +0000597 (void) CopyMagickString(property,cin.origination.filename,
598 sizeof(cin.origination.filename));
599 (void) SetImageProperty(image,"dpx:origination.filename",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000600 offset+=ReadBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
601 cin.origination.create_date);
cristye6f04802014-05-04 01:41:20 +0000602 (void) CopyMagickString(property,cin.origination.create_date,
603 sizeof(cin.origination.create_date));
604 (void) SetImageProperty(image,"dpx:origination.create_date",property,
605 exception);
cristy3ed852e2009-09-05 21:47:34 +0000606 offset+=ReadBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
607 cin.origination.create_time);
cristye6f04802014-05-04 01:41:20 +0000608 (void) CopyMagickString(property,cin.origination.create_time,
609 sizeof(cin.origination.create_time));
610 (void) SetImageProperty(image,"dpx:origination.create_time",property,
611 exception);
cristy3ed852e2009-09-05 21:47:34 +0000612 offset+=ReadBlob(image,sizeof(cin.origination.device),(unsigned char *)
613 cin.origination.device);
cristye6f04802014-05-04 01:41:20 +0000614 (void) CopyMagickString(property,cin.origination.device,
615 sizeof(cin.origination.device));
616 (void) SetImageProperty(image,"dpx:origination.device",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000617 offset+=ReadBlob(image,sizeof(cin.origination.model),(unsigned char *)
618 cin.origination.model);
cristye6f04802014-05-04 01:41:20 +0000619 (void) CopyMagickString(property,cin.origination.model,
620 sizeof(cin.origination.model));
621 (void) SetImageProperty(image,"dpx:origination.model",property,exception);
cristy100a0562014-04-18 01:27:37 +0000622 (void) ResetMagickMemory(cin.origination.serial,0,
623 sizeof(cin.origination.serial));
cristy3ed852e2009-09-05 21:47:34 +0000624 offset+=ReadBlob(image,sizeof(cin.origination.serial),(unsigned char *)
625 cin.origination.serial);
cristye6f04802014-05-04 01:41:20 +0000626 (void) CopyMagickString(property,cin.origination.serial,
627 sizeof(cin.origination.serial));
628 (void) SetImageProperty(image,"dpx:origination.serial",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000629 cin.origination.x_pitch=ReadBlobFloat(image);
630 offset+=4;
631 cin.origination.y_pitch=ReadBlobFloat(image);
632 offset+=4;
633 cin.origination.gamma=ReadBlobFloat(image);
634 offset+=4;
635 if (IsFloatDefined(cin.origination.gamma) != MagickFalse)
636 image->gamma=cin.origination.gamma;
637 offset+=ReadBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
638 cin.origination.reserve);
639 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
640 {
cristyf0605892011-09-06 14:56:46 +0000641 int
642 c;
643
cristy3ed852e2009-09-05 21:47:34 +0000644 /*
645 Image film information.
646 */
647 cin.film.id=ReadBlobByte(image);
648 offset++;
cristyf0605892011-09-06 14:56:46 +0000649 c=cin.film.id;
cristy94b11832011-09-08 19:46:03 +0000650 if (c != ~0)
cristy97450ff2010-12-29 17:29:17 +0000651 (void) FormatImageProperty(image,"dpx:film.id","%d",cin.film.id);
cristy3ed852e2009-09-05 21:47:34 +0000652 cin.film.type=ReadBlobByte(image);
653 offset++;
cristyf0605892011-09-06 14:56:46 +0000654 c=cin.film.type;
cristy94b11832011-09-08 19:46:03 +0000655 if (c != ~0)
cristy97450ff2010-12-29 17:29:17 +0000656 (void) FormatImageProperty(image,"dpx:film.type","%d",cin.film.type);
cristy3ed852e2009-09-05 21:47:34 +0000657 cin.film.offset=ReadBlobByte(image);
658 offset++;
cristyf0605892011-09-06 14:56:46 +0000659 c=cin.film.offset;
cristy94b11832011-09-08 19:46:03 +0000660 if (c != ~0)
cristy97450ff2010-12-29 17:29:17 +0000661 (void) FormatImageProperty(image,"dpx:film.offset","%d",
cristy3ed852e2009-09-05 21:47:34 +0000662 cin.film.offset);
663 cin.film.reserve1=ReadBlobByte(image);
664 offset++;
665 cin.film.prefix=ReadBlobLong(image);
666 offset+=4;
667 if (cin.film.prefix != ~0UL)
cristy97450ff2010-12-29 17:29:17 +0000668 (void) FormatImageProperty(image,"dpx:film.prefix","%.20g",(double)
cristy3ed852e2009-09-05 21:47:34 +0000669 cin.film.prefix);
670 cin.film.count=ReadBlobLong(image);
671 offset+=4;
672 offset+=ReadBlob(image,sizeof(cin.film.format),(unsigned char *)
673 cin.film.format);
cristye6f04802014-05-04 01:41:20 +0000674 (void) CopyMagickString(property,cin.film.format,sizeof(cin.film.format));
675 (void) SetImageProperty(image,"dpx:film.format",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000676 cin.film.frame_position=ReadBlobLong(image);
677 offset+=4;
678 if (cin.film.frame_position != ~0UL)
cristy97450ff2010-12-29 17:29:17 +0000679 (void) FormatImageProperty(image,"dpx:film.frame_position","%.20g",
cristye8c25f92010-06-03 00:53:06 +0000680 (double) cin.film.frame_position);
cristy3ed852e2009-09-05 21:47:34 +0000681 cin.film.frame_rate=ReadBlobFloat(image);
682 offset+=4;
683 if (IsFloatDefined(cin.film.frame_rate) != MagickFalse)
cristy97450ff2010-12-29 17:29:17 +0000684 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
cristy3ed852e2009-09-05 21:47:34 +0000685 cin.film.frame_rate);
686 offset+=ReadBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
687 cin.film.frame_id);
cristye6f04802014-05-04 01:41:20 +0000688 (void) CopyMagickString(property,cin.film.frame_id,
689 sizeof(cin.film.frame_id));
690 (void) SetImageProperty(image,"dpx:film.frame_id",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000691 offset+=ReadBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
692 cin.film.slate_info);
cristye6f04802014-05-04 01:41:20 +0000693 (void) CopyMagickString(property,cin.film.slate_info,
694 sizeof(cin.film.slate_info));
695 (void) SetImageProperty(image,"dpx:film.slate_info",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000696 offset+=ReadBlob(image,sizeof(cin.film.reserve),(unsigned char *)
697 cin.film.reserve);
698 }
699 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
700 {
701 StringInfo
702 *profile;
703
704 /*
705 User defined data.
706 */
cristy60395292011-09-01 13:25:56 +0000707 profile=BlobToStringInfo((const void *) NULL,cin.file.user_length);
708 if (profile == (StringInfo *) NULL)
709 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
cristy3ed852e2009-09-05 21:47:34 +0000710 offset+=ReadBlob(image,GetStringInfoLength(profile),
711 GetStringInfoDatum(profile));
cristyd15e6592011-10-15 00:13:06 +0000712 (void) SetImageProfile(image,"dpx:user.data",profile,exception);
cristy3ed852e2009-09-05 21:47:34 +0000713 profile=DestroyStringInfo(profile);
714 }
cristy811f5172010-12-29 17:38:08 +0000715 for ( ; offset < (MagickOffsetType) cin.file.image_offset; offset++)
cristy3ed852e2009-09-05 21:47:34 +0000716 (void) ReadBlobByte(image);
717 image->depth=cin.image.channel[0].bits_per_pixel;
718 image->columns=cin.image.channel[0].pixels_per_line;
719 image->rows=cin.image.channel[0].lines_per_image;
720 if (image_info->ping)
721 {
722 (void) CloseBlob(image);
723 return(image);
724 }
725 /*
726 Convert CIN raster image to pixel packets.
727 */
728 quantum_info=AcquireQuantumInfo(image_info,image);
729 if (quantum_info == (QuantumInfo *) NULL)
730 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
731 quantum_info->quantum=32;
732 quantum_info->pack=MagickFalse;
733 quantum_type=RGBQuantum;
734 pixels=GetQuantumPixels(quantum_info);
735 length=GetQuantumExtent(image,quantum_info,quantum_type);
736 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
737 if (cin.image.number_channels == 1)
738 {
739 quantum_type=GrayQuantum;
740 length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue);
741 }
cristybb503372010-05-27 20:51:26 +0000742 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000743 {
744 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000745 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000746 break;
747 count=ReadBlob(image,length,pixels);
748 if ((size_t) count != length)
749 break;
750 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
751 quantum_type,pixels,exception);
752 if (SyncAuthenticPixels(image,exception) == MagickFalse)
753 break;
754 if (image->previous == (Image *) NULL)
755 {
cristycee97112010-05-28 00:44:52 +0000756 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
cristy97450ff2010-12-29 17:29:17 +0000757 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000758 if (status == MagickFalse)
759 break;
760 }
761 }
762 SetQuantumImageType(image,quantum_type);
763 quantum_info=DestroyQuantumInfo(quantum_info);
764 if (EOFBlob(image) != MagickFalse)
765 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
766 image->filename);
cristye2c4f182012-05-12 14:11:53 +0000767 SetImageColorspace(image,LogColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000768 (void) CloseBlob(image);
769 return(GetFirstImageInList(image));
770}
771
772/*
773%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
774% %
775% %
776% %
777% R e g i s t e r C I N E O N I m a g e %
778% %
779% %
780% %
781%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782%
783% RegisterCINImage() adds attributes for the CIN image format to the list of
784% of supported formats. The attributes include the image format tag, a method
785% to read and/or write the format, whether the format supports the saving of
786% more than one frame to the same file or blob, whether the format supports
787% native in-memory I/O, and a brief description of the format.
788%
789% The format of the RegisterCINImage method is:
790%
cristybb503372010-05-27 20:51:26 +0000791% size_t RegisterCINImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000792%
793*/
cristybb503372010-05-27 20:51:26 +0000794ModuleExport size_t RegisterCINImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000795{
796 MagickInfo
797 *entry;
798
799 entry=SetMagickInfo("CIN");
800 entry->decoder=(DecodeImageHandler *) ReadCINImage;
801 entry->encoder=(EncodeImageHandler *) WriteCINImage;
802 entry->magick=(IsImageFormatHandler *) IsCIN;
cristybc4eb112011-02-03 01:05:23 +0000803 entry->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000804 entry->description=ConstantString("Cineon Image File");
805 entry->module=ConstantString("CIN");
806 (void) RegisterMagickInfo(entry);
807 return(MagickImageCoderSignature);
808}
809
810/*
811%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812% %
813% %
814% %
815% U n r e g i s t e r C I N E O N I m a g e %
816% %
817% %
818% %
819%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820%
821% UnregisterCINImage() removes format registrations made by the CIN module
822% from the list of supported formats.
823%
824% The format of the UnregisterCINImage method is:
825%
826% UnregisterCINImage(void)
827%
828*/
829ModuleExport void UnregisterCINImage(void)
830{
831 (void) UnregisterMagickInfo("CINEON");
832}
833
834/*
835%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
836% %
837% %
838% %
839% W r i t e C I N E O N I m a g e %
840% %
841% %
842% %
843%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844%
845% WriteCINImage() writes an image in CIN encoded image format.
846%
847% The format of the WriteCINImage method is:
848%
cristy1e178e72011-08-28 19:44:34 +0000849% MagickBooleanType WriteCINImage(const ImageInfo *image_info,
850% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000851%
852% A description of each parameter follows.
853%
854% o image_info: the image info.
855%
856% o image: The image.
857%
cristy1e178e72011-08-28 19:44:34 +0000858% o exception: return any errors or warnings in this structure.
859%
cristy3ed852e2009-09-05 21:47:34 +0000860*/
861
862static inline const char *GetCINProperty(const ImageInfo *image_info,
cristyd15e6592011-10-15 00:13:06 +0000863 const Image *image,const char *property,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000864{
865 const char
866 *value;
867
cristy092ec8d2013-04-26 13:46:22 +0000868 value=GetImageOption(image_info,property);
cristy3ed852e2009-09-05 21:47:34 +0000869 if (value != (const char *) NULL)
870 return(value);
cristyd15e6592011-10-15 00:13:06 +0000871 return(GetImageProperty(image,property,exception));
cristy3ed852e2009-09-05 21:47:34 +0000872}
873
cristy1e178e72011-08-28 19:44:34 +0000874static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
875 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000876{
cristyc50489c2014-05-16 17:43:56 +0000877 char
878 timestamp[MaxTextExtent];
879
cristy3ed852e2009-09-05 21:47:34 +0000880 const char
881 *value;
882
883 CINInfo
884 cin;
885
886 const StringInfo
887 *profile;
888
cristy3ed852e2009-09-05 21:47:34 +0000889 MagickBooleanType
890 status;
891
892 MagickOffsetType
893 offset;
894
895 QuantumInfo
896 *quantum_info;
897
898 QuantumType
899 quantum_type;
900
cristy4c08aed2011-07-01 19:47:50 +0000901 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000902 *p;
903
cristybb503372010-05-27 20:51:26 +0000904 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000905 i;
906
907 size_t
908 length;
909
910 ssize_t
cristy4e82e512011-04-24 01:33:42 +0000911 count,
912 y;
cristy3ed852e2009-09-05 21:47:34 +0000913
914 struct tm
915 local_time;
916
917 time_t
918 seconds;
919
920 unsigned char
921 *pixels;
922
923 /*
924 Open output image file.
925 */
926 assert(image_info != (const ImageInfo *) NULL);
927 assert(image_info->signature == MagickSignature);
928 assert(image != (Image *) NULL);
929 assert(image->signature == MagickSignature);
930 if (image->debug != MagickFalse)
931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000932 assert(exception != (ExceptionInfo *) NULL);
933 assert(exception->signature == MagickSignature);
cristy1e178e72011-08-28 19:44:34 +0000934 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000935 if (status == MagickFalse)
936 return(status);
937 if (image->colorspace != LogColorspace)
cristye941a752011-10-15 01:52:48 +0000938 (void) TransformImageColorspace(image,LogColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000939 /*
940 Write image information.
941 */
942 (void) ResetMagickMemory(&cin,0,sizeof(cin));
943 offset=0;
944 cin.file.magic=0x802A5FD7UL;
cristyf6fe0a12010-05-30 00:44:47 +0000945 offset+=WriteBlobLong(image,(unsigned int) cin.file.magic);
cristy3ed852e2009-09-05 21:47:34 +0000946 cin.file.image_offset=0x800;
cristyf6fe0a12010-05-30 00:44:47 +0000947 offset+=WriteBlobLong(image,(unsigned int) cin.file.image_offset);
cristy3ed852e2009-09-05 21:47:34 +0000948 cin.file.generic_length=0x400;
cristyf6fe0a12010-05-30 00:44:47 +0000949 offset+=WriteBlobLong(image,(unsigned int) cin.file.generic_length);
cristy3ed852e2009-09-05 21:47:34 +0000950 cin.file.industry_length=0x400;
cristyf6fe0a12010-05-30 00:44:47 +0000951 offset+=WriteBlobLong(image,(unsigned int) cin.file.industry_length);
cristy3ed852e2009-09-05 21:47:34 +0000952 cin.file.user_length=0x00;
cristy97450ff2010-12-29 17:29:17 +0000953 profile=GetImageProfile(image,"dpx:user.data");
cristy3ed852e2009-09-05 21:47:34 +0000954 if (profile != (StringInfo *) NULL)
955 {
cristybb503372010-05-27 20:51:26 +0000956 cin.file.user_length+=(size_t) GetStringInfoLength(profile);
cristy3ed852e2009-09-05 21:47:34 +0000957 cin.file.user_length=(((cin.file.user_length+0x2000-1)/0x2000)*0x2000);
958 }
cristyf6fe0a12010-05-30 00:44:47 +0000959 offset+=WriteBlobLong(image,(unsigned int) cin.file.user_length);
cristy3ed852e2009-09-05 21:47:34 +0000960 cin.file.file_size=4*image->columns*image->rows+0x2000;
cristyf6fe0a12010-05-30 00:44:47 +0000961 offset+=WriteBlobLong(image,(unsigned int) cin.file.file_size);
cristy3ed852e2009-09-05 21:47:34 +0000962 (void) CopyMagickString(cin.file.version,"V4.5",sizeof(cin.file.version));
963 offset+=WriteBlob(image,sizeof(cin.file.version),(unsigned char *)
964 cin.file.version);
cristyd15e6592011-10-15 00:13:06 +0000965 value=GetCINProperty(image_info,image,"dpx:file.filename",exception);
cristy3ed852e2009-09-05 21:47:34 +0000966 if (value != (const char *) NULL)
967 (void) CopyMagickString(cin.file.filename,value,sizeof(cin.file.filename));
968 else
969 (void) CopyMagickString(cin.file.filename,image->filename,
970 sizeof(cin.file.filename));
971 offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *)
972 cin.file.filename);
973 seconds=time((time_t *) NULL);
974#if defined(MAGICKCORE_HAVE_LOCALTIME_R)
975 (void) localtime_r(&seconds,&local_time);
976#else
977 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
978#endif
cristyc50489c2014-05-16 17:43:56 +0000979 (void) memset(timestamp,0,sizeof(timestamp));
980 (void) strftime(timestamp,MaxTextExtent,"%Y:%m:%d:%H:%M:%S%Z",&local_time);
981 (void) memset(cin.file.create_date,0,sizeof(cin.file.create_date));
982 (void) CopyMagickString(cin.file.create_date,timestamp,11);
cristy3ed852e2009-09-05 21:47:34 +0000983 offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *)
984 cin.file.create_date);
cristyc50489c2014-05-16 17:43:56 +0000985 (void) memset(cin.file.create_time,0,sizeof(cin.file.create_time));
986 (void) CopyMagickString(cin.file.create_time,timestamp+11,15);
cristy3ed852e2009-09-05 21:47:34 +0000987 offset+=WriteBlob(image,sizeof(cin.file.create_time),(unsigned char *)
988 cin.file.create_time);
989 offset+=WriteBlob(image,sizeof(cin.file.reserve),(unsigned char *)
990 cin.file.reserve);
991 cin.image.orientation=0x00;
992 offset+=WriteBlobByte(image,cin.image.orientation);
993 cin.image.number_channels=3;
994 offset+=WriteBlobByte(image,cin.image.number_channels);
995 offset+=WriteBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
996 cin.image.reserve1);
997 for (i=0; i < 8; i++)
998 {
999 cin.image.channel[i].designator[0]=0; /* universal metric */
1000 offset+=WriteBlobByte(image,cin.image.channel[0].designator[0]);
1001 cin.image.channel[i].designator[1]=(unsigned char) (i > 3 ? 0 : i+1); /* channel color */;
1002 offset+=WriteBlobByte(image,cin.image.channel[1].designator[0]);
1003 cin.image.channel[i].bits_per_pixel=(unsigned char) image->depth;
1004 offset+=WriteBlobByte(image,cin.image.channel[0].bits_per_pixel);
1005 offset+=WriteBlobByte(image,cin.image.channel[0].reserve);
1006 cin.image.channel[i].pixels_per_line=image->columns;
cristyf6fe0a12010-05-30 00:44:47 +00001007 offset+=WriteBlobLong(image,(unsigned int)
1008 cin.image.channel[0].pixels_per_line);
cristy3ed852e2009-09-05 21:47:34 +00001009 cin.image.channel[i].lines_per_image=image->rows;
cristyf6fe0a12010-05-30 00:44:47 +00001010 offset+=WriteBlobLong(image,(unsigned int)
1011 cin.image.channel[0].lines_per_image);
cristy3ed852e2009-09-05 21:47:34 +00001012 cin.image.channel[i].min_data=0;
1013 offset+=WriteBlobFloat(image,cin.image.channel[0].min_data);
1014 cin.image.channel[i].min_quantity=0.0;
1015 offset+=WriteBlobFloat(image,cin.image.channel[0].min_quantity);
1016 cin.image.channel[i].max_data=(float) ((MagickOffsetType)
1017 GetQuantumRange(image->depth));
1018 offset+=WriteBlobFloat(image,cin.image.channel[0].max_data);
1019 cin.image.channel[i].max_quantity=2.048f;
1020 offset+=WriteBlobFloat(image,cin.image.channel[0].max_quantity);
1021 }
1022 offset+=WriteBlobFloat(image,image->chromaticity.white_point.x);
1023 offset+=WriteBlobFloat(image,image->chromaticity.white_point.y);
1024 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.x);
1025 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.y);
1026 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.x);
1027 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.y);
1028 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.x);
1029 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.y);
cristyd15e6592011-10-15 00:13:06 +00001030 value=GetCINProperty(image_info,image,"dpx:image.label",exception);
cristy3ed852e2009-09-05 21:47:34 +00001031 if (value != (const char *) NULL)
1032 (void) CopyMagickString(cin.image.label,value,sizeof(cin.image.label));
1033 offset+=WriteBlob(image,sizeof(cin.image.label),(unsigned char *)
1034 cin.image.label);
1035 offset+=WriteBlob(image,sizeof(cin.image.reserve),(unsigned char *)
1036 cin.image.reserve);
1037 /*
1038 Write data format information.
1039 */
1040 cin.data_format.interleave=0; /* pixel interleave (rgbrgbr...) */
1041 offset+=WriteBlobByte(image,cin.data_format.interleave);
cristybb503372010-05-27 20:51:26 +00001042 cin.data_format.packing=5; /* packing ssize_tword (32bit) boundaries */
cristy3ed852e2009-09-05 21:47:34 +00001043 offset+=WriteBlobByte(image,cin.data_format.packing);
1044 cin.data_format.sign=0; /* unsigned data */
1045 offset+=WriteBlobByte(image,cin.data_format.sign);
1046 cin.data_format.sense=0; /* image sense: positive image */
1047 offset+=WriteBlobByte(image,cin.data_format.sense);
1048 cin.data_format.line_pad=0;
cristyf6fe0a12010-05-30 00:44:47 +00001049 offset+=WriteBlobLong(image,(unsigned int) cin.data_format.line_pad);
cristy3ed852e2009-09-05 21:47:34 +00001050 cin.data_format.channel_pad=0;
cristyf6fe0a12010-05-30 00:44:47 +00001051 offset+=WriteBlobLong(image,(unsigned int) cin.data_format.channel_pad);
cristy3ed852e2009-09-05 21:47:34 +00001052 offset+=WriteBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
1053 cin.data_format.reserve);
1054 /*
1055 Write origination information.
1056 */
1057 cin.origination.x_offset=0UL;
cristyd15e6592011-10-15 00:13:06 +00001058 value=GetCINProperty(image_info,image,"dpx:origination.x_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001059 if (value != (const char *) NULL)
cristy811f5172010-12-29 17:38:08 +00001060 cin.origination.x_offset=(ssize_t) StringToLong(value);
cristyf9cca6a2010-06-04 23:49:28 +00001061 offset+=WriteBlobLong(image,(unsigned int) cin.origination.x_offset);
cristy3ed852e2009-09-05 21:47:34 +00001062 cin.origination.y_offset=0UL;
cristyd15e6592011-10-15 00:13:06 +00001063 value=GetCINProperty(image_info,image,"dpx:origination.y_offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001064 if (value != (const char *) NULL)
cristy811f5172010-12-29 17:38:08 +00001065 cin.origination.y_offset=(ssize_t) StringToLong(value);
cristyf9cca6a2010-06-04 23:49:28 +00001066 offset+=WriteBlobLong(image,(unsigned int) cin.origination.y_offset);
cristyd15e6592011-10-15 00:13:06 +00001067 value=GetCINProperty(image_info,image,"dpx:origination.filename",exception);
cristy3ed852e2009-09-05 21:47:34 +00001068 if (value != (const char *) NULL)
1069 (void) CopyMagickString(cin.origination.filename,value,
1070 sizeof(cin.origination.filename));
1071 else
1072 (void) CopyMagickString(cin.origination.filename,image->filename,
1073 sizeof(cin.origination.filename));
1074 offset+=WriteBlob(image,sizeof(cin.origination.filename),(unsigned char *)
1075 cin.origination.filename);
1076 seconds=time((time_t *) NULL);
cristyc50489c2014-05-16 17:43:56 +00001077 (void) memset(timestamp,0,sizeof(timestamp));
1078 (void) strftime(timestamp,MaxTextExtent,"%Y:%m:%d:%H:%M:%S%Z",&local_time);
cristy69c1a6e2014-05-16 17:46:12 +00001079 (void) memset(cin.origination.create_date,0,
1080 sizeof(cin.origination.create_date));
1081 (void) CopyMagickString(cin.origination.create_date,timestamp,11);
cristy3ed852e2009-09-05 21:47:34 +00001082 offset+=WriteBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
1083 cin.origination.create_date);
cristyc50489c2014-05-16 17:43:56 +00001084 (void) memset(cin.origination.create_time,0,
1085 sizeof(cin.origination.create_time));
1086 (void) CopyMagickString(cin.origination.create_time,timestamp+11,15);
cristy3ed852e2009-09-05 21:47:34 +00001087 offset+=WriteBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
cristy69c1a6e2014-05-16 17:46:12 +00001088 cin.origination.create_time);
cristyd15e6592011-10-15 00:13:06 +00001089 value=GetCINProperty(image_info,image,"dpx:origination.device",exception);
cristy3ed852e2009-09-05 21:47:34 +00001090 if (value != (const char *) NULL)
1091 (void) CopyMagickString(cin.origination.device,value,
1092 sizeof(cin.origination.device));
1093 offset+=WriteBlob(image,sizeof(cin.origination.device),(unsigned char *)
1094 cin.origination.device);
cristyd15e6592011-10-15 00:13:06 +00001095 value=GetCINProperty(image_info,image,"dpx:origination.model",exception);
cristy3ed852e2009-09-05 21:47:34 +00001096 if (value != (const char *) NULL)
1097 (void) CopyMagickString(cin.origination.model,value,
1098 sizeof(cin.origination.model));
1099 offset+=WriteBlob(image,sizeof(cin.origination.model),(unsigned char *)
1100 cin.origination.model);
cristyd15e6592011-10-15 00:13:06 +00001101 value=GetCINProperty(image_info,image,"dpx:origination.serial",exception);
cristy3ed852e2009-09-05 21:47:34 +00001102 if (value != (const char *) NULL)
1103 (void) CopyMagickString(cin.origination.serial,value,
1104 sizeof(cin.origination.serial));
1105 offset+=WriteBlob(image,sizeof(cin.origination.serial),(unsigned char *)
1106 cin.origination.serial);
1107 cin.origination.x_pitch=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001108 value=GetCINProperty(image_info,image,"dpx:origination.x_pitch",exception);
cristy3ed852e2009-09-05 21:47:34 +00001109 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001110 cin.origination.x_pitch=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001111 offset+=WriteBlobFloat(image,cin.origination.x_pitch);
1112 cin.origination.y_pitch=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001113 value=GetCINProperty(image_info,image,"dpx:origination.y_pitch",exception);
cristy3ed852e2009-09-05 21:47:34 +00001114 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001115 cin.origination.y_pitch=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001116 offset+=WriteBlobFloat(image,cin.origination.y_pitch);
1117 cin.origination.gamma=image->gamma;
1118 offset+=WriteBlobFloat(image,cin.origination.gamma);
1119 offset+=WriteBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
1120 cin.origination.reserve);
1121 /*
1122 Image film information.
1123 */
1124 cin.film.id=0;
cristyd15e6592011-10-15 00:13:06 +00001125 value=GetCINProperty(image_info,image,"dpx:film.id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001126 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001127 cin.film.id=(char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001128 offset+=WriteBlobByte(image,(unsigned char) cin.film.id);
1129 cin.film.type=0;
cristyd15e6592011-10-15 00:13:06 +00001130 value=GetCINProperty(image_info,image,"dpx:film.type",exception);
cristy3ed852e2009-09-05 21:47:34 +00001131 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001132 cin.film.type=(char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001133 offset+=WriteBlobByte(image,(unsigned char) cin.film.type);
1134 cin.film.offset=0;
cristyd15e6592011-10-15 00:13:06 +00001135 value=GetCINProperty(image_info,image,"dpx:film.offset",exception);
cristy3ed852e2009-09-05 21:47:34 +00001136 if (value != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00001137 cin.film.offset=(char) StringToLong(value);
cristy3ed852e2009-09-05 21:47:34 +00001138 offset+=WriteBlobByte(image,(unsigned char) cin.film.offset);
1139 offset+=WriteBlobByte(image,(unsigned char) cin.film.reserve1);
1140 cin.film.prefix=0UL;
cristyd15e6592011-10-15 00:13:06 +00001141 value=GetCINProperty(image_info,image,"dpx:film.prefix",exception);
cristy3ed852e2009-09-05 21:47:34 +00001142 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001143 cin.film.prefix=StringToUnsignedLong(value);
cristyf6fe0a12010-05-30 00:44:47 +00001144 offset+=WriteBlobLong(image,(unsigned int) cin.film.prefix);
cristy3ed852e2009-09-05 21:47:34 +00001145 cin.film.count=0UL;
cristyd15e6592011-10-15 00:13:06 +00001146 value=GetCINProperty(image_info,image,"dpx:film.count",exception);
cristy3ed852e2009-09-05 21:47:34 +00001147 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001148 cin.film.count=StringToUnsignedLong(value);
cristyf6fe0a12010-05-30 00:44:47 +00001149 offset+=WriteBlobLong(image,(unsigned int) cin.film.count);
cristyd15e6592011-10-15 00:13:06 +00001150 value=GetCINProperty(image_info,image,"dpx:film.format",exception);
cristy3ed852e2009-09-05 21:47:34 +00001151 if (value != (const char *) NULL)
1152 (void) CopyMagickString(cin.film.format,value,sizeof(cin.film.format));
1153 offset+=WriteBlob(image,sizeof(cin.film.format),(unsigned char *)
1154 cin.film.format);
1155 cin.film.frame_position=0UL;
cristyd15e6592011-10-15 00:13:06 +00001156 value=GetCINProperty(image_info,image,"dpx:film.frame_position",exception);
cristy3ed852e2009-09-05 21:47:34 +00001157 if (value != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00001158 cin.film.frame_position=StringToUnsignedLong(value);
cristyf6fe0a12010-05-30 00:44:47 +00001159 offset+=WriteBlobLong(image,(unsigned int) cin.film.frame_position);
cristy3ed852e2009-09-05 21:47:34 +00001160 cin.film.frame_rate=0.0f;
cristyd15e6592011-10-15 00:13:06 +00001161 value=GetCINProperty(image_info,image,"dpx:film.frame_rate",exception);
cristy3ed852e2009-09-05 21:47:34 +00001162 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001163 cin.film.frame_rate=StringToDouble(value,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001164 offset+=WriteBlobFloat(image,cin.film.frame_rate);
cristyd15e6592011-10-15 00:13:06 +00001165 value=GetCINProperty(image_info,image,"dpx:film.frame_id",exception);
cristy3ed852e2009-09-05 21:47:34 +00001166 if (value != (const char *) NULL)
1167 (void) CopyMagickString(cin.film.frame_id,value,sizeof(cin.film.frame_id));
1168 offset+=WriteBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
1169 cin.film.frame_id);
cristyd15e6592011-10-15 00:13:06 +00001170 value=GetCINProperty(image_info,image,"dpx:film.slate_info",exception);
cristy3ed852e2009-09-05 21:47:34 +00001171 if (value != (const char *) NULL)
1172 (void) CopyMagickString(cin.film.slate_info,value,
1173 sizeof(cin.film.slate_info));
1174 offset+=WriteBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
1175 cin.film.slate_info);
1176 offset+=WriteBlob(image,sizeof(cin.film.reserve),(unsigned char *)
1177 cin.film.reserve);
1178 if (profile != (StringInfo *) NULL)
1179 offset+=WriteBlob(image,GetStringInfoLength(profile),
1180 GetStringInfoDatum(profile));
1181 while (offset < (MagickOffsetType) cin.file.image_offset)
1182 offset+=WriteBlobByte(image,0x00);
1183 /*
1184 Convert pixel packets to CIN raster image.
1185 */
1186 quantum_info=AcquireQuantumInfo(image_info,image);
1187 if (quantum_info == (QuantumInfo *) NULL)
1188 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1189 quantum_info->quantum=32;
1190 quantum_info->pack=MagickFalse;
1191 quantum_type=RGBQuantum;
1192 pixels=GetQuantumPixels(quantum_info);
1193 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
dirk93b02b72013-11-16 16:03:36 +00001194DisableMSCWarning(4127)
cristy3ed852e2009-09-05 21:47:34 +00001195 if (0)
dirk93b02b72013-11-16 16:03:36 +00001196RestoreMSCWarning
cristy3ed852e2009-09-05 21:47:34 +00001197 {
1198 quantum_type=GrayQuantum;
cristybccc4f42011-11-24 17:57:52 +00001199 length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00001200 }
cristybb503372010-05-27 20:51:26 +00001201 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001202 {
cristy1e178e72011-08-28 19:44:34 +00001203 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001204 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001205 break;
cristy4c08aed2011-07-01 19:47:50 +00001206 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
cristy1e178e72011-08-28 19:44:34 +00001207 quantum_type,pixels,exception);
cristy3ed852e2009-09-05 21:47:34 +00001208 count=WriteBlob(image,length,pixels);
1209 if (count != (ssize_t) length)
1210 break;
cristycee97112010-05-28 00:44:52 +00001211 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy97450ff2010-12-29 17:29:17 +00001212 image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001213 if (status == MagickFalse)
1214 break;
1215 }
1216 quantum_info=DestroyQuantumInfo(quantum_info);
1217 (void) CloseBlob(image);
1218 return(status);
1219}