2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Kodak Cineon Image Format %
14 % Cineon Image Format is a subset of SMTPE CIN %
23 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
24 % dedicated to making software imaging solutions freely available. %
26 % You may not use this file except in compliance with the License. You may %
27 % obtain a copy of the License at %
29 % http://www.imagemagick.org/script/license.php %
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. %
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 % Cineon image file format draft is available at
41 % http://www.cineon.com/ff_draft.php.
49 #include "MagickCore/studio.h"
50 #include "MagickCore/blob.h"
51 #include "MagickCore/blob-private.h"
52 #include "MagickCore/cache.h"
53 #include "MagickCore/colorspace.h"
54 #include "MagickCore/exception.h"
55 #include "MagickCore/exception-private.h"
56 #include "MagickCore/image.h"
57 #include "MagickCore/image-private.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/monitor-private.h"
63 #include "MagickCore/option.h"
64 #include "MagickCore/profile.h"
65 #include "MagickCore/property.h"
66 #include "MagickCore/quantum-private.h"
67 #include "MagickCore/quantum-private.h"
68 #include "MagickCore/static.h"
69 #include "MagickCore/string_.h"
70 #include "MagickCore/string-private.h"
71 #include "MagickCore/module.h"
76 typedef struct _CINDataFormatInfo
92 typedef struct _CINFileInfo
110 typedef struct _CINFilmInfo
137 typedef struct _CINImageChannel
155 typedef struct _CINImageInfo
167 red_primary_chromaticity[2],
168 green_primary_chromaticity[2],
169 blue_primary_chromaticity[2];
176 typedef struct _CINOriginationInfo
197 } CINOriginationInfo;
199 typedef struct _CINUserInfo
205 typedef struct CINInfo
227 Forward declaractions.
229 static MagickBooleanType
230 WriteCINImage(const ImageInfo *,Image *,ExceptionInfo *);
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % IsCIN() returns MagickTrue if the image format type, identified by the magick
246 % The format of the IsCIN method is:
248 % MagickBooleanType IsCIN(const unsigned char *magick,const size_t length)
250 % A description of each parameter follows:
252 % o magick: compare image format pattern against these bytes.
254 % o length: Specifies the length of the magick string.
257 static MagickBooleanType IsCIN(const unsigned char *magick,const size_t length)
261 if (memcmp(magick,"\200\052\137\327",4) == 0)
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % R e a d C I N E O N I m a g e %
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 % ReadCINImage() reads an CIN X image file and returns it. It allocates
278 % the memory necessary for the new Image structure and returns a point to the
281 % The format of the ReadCINImage method is:
283 % Image *ReadCINImage(const ImageInfo *image_info,
284 % ExceptionInfo *exception)
286 % A description of each parameter follows:
288 % o image_info: the image info.
290 % o exception: return any errors or warnings in this structure.
294 static size_t GetBytesPerRow(size_t columns,
295 size_t samples_per_pixel,size_t bits_per_pixel,
296 MagickBooleanType pad)
301 switch (bits_per_pixel)
305 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
306 bits_per_pixel+31)/32);
312 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
313 bits_per_pixel+31)/32);
318 if (pad == MagickFalse)
320 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
321 bits_per_pixel+31)/32);
324 bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
329 if (pad == MagickFalse)
331 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
332 bits_per_pixel+31)/32);
335 bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
340 bytes_per_row=2*(((size_t) samples_per_pixel*columns*
341 bits_per_pixel+8)/16);
346 bytes_per_row=4*(((size_t) samples_per_pixel*columns*
347 bits_per_pixel+31)/32);
352 bytes_per_row=8*(((size_t) samples_per_pixel*columns*
353 bits_per_pixel+63)/64);
357 return(bytes_per_row);
360 static inline MagickBooleanType IsFloatDefined(const float value)
371 quantum.unsigned_value=0U;
372 quantum.float_value=value;
373 if (quantum.unsigned_value == 0U)
378 static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
380 #define MonoColorType 1
381 #define RGBColorType 3
421 assert(image_info != (const ImageInfo *) NULL);
422 assert(image_info->signature == MagickSignature);
423 if (image_info->debug != MagickFalse)
424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
425 image_info->filename);
426 assert(exception != (ExceptionInfo *) NULL);
427 assert(exception->signature == MagickSignature);
428 image=AcquireImage(image_info);
429 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
430 if (status == MagickFalse)
432 image=DestroyImageList(image);
433 return((Image *) NULL);
439 count=ReadBlob(image,4,magick);
442 ((LocaleNCompare((char *) magick,"\200\052\137\327",4) != 0)))
443 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
444 image->endian=(magick[0] == 0x80) && (magick[1] == 0x2a) &&
445 (magick[2] == 0x5f) && (magick[3] == 0xd7) ? MSBEndian : LSBEndian;
446 cin.file.image_offset=ReadBlobLong(image);
448 cin.file.generic_length=ReadBlobLong(image);
450 cin.file.industry_length=ReadBlobLong(image);
452 cin.file.user_length=ReadBlobLong(image);
454 cin.file.file_size=ReadBlobLong(image);
456 offset+=ReadBlob(image,sizeof(cin.file.version),(unsigned char *)
458 (void) SetImageProperty(image,"dpx:file.version",cin.file.version);
459 offset+=ReadBlob(image,sizeof(cin.file.filename),(unsigned char *)
461 (void) SetImageProperty(image,"dpx:file.filename",cin.file.filename);
462 offset+=ReadBlob(image,sizeof(cin.file.create_date),(unsigned char *)
463 cin.file.create_date);
464 (void) SetImageProperty(image,"dpx:file.create_date",cin.file.create_date);
465 offset+=ReadBlob(image,sizeof(cin.file.create_time),(unsigned char *)
466 cin.file.create_time);
467 (void) SetImageProperty(image,"dpx:file.create_time",cin.file.create_time);
468 offset+=ReadBlob(image,sizeof(cin.file.reserve),(unsigned char *)
473 cin.image.orientation=(unsigned char) ReadBlobByte(image);
475 if (cin.image.orientation != (unsigned char) (~0U))
476 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
477 cin.image.orientation);
478 switch (cin.image.orientation)
481 case 0: image->orientation=TopLeftOrientation; break;
482 case 1: image->orientation=TopRightOrientation; break;
483 case 2: image->orientation=BottomLeftOrientation; break;
484 case 3: image->orientation=BottomRightOrientation; break;
485 case 4: image->orientation=LeftTopOrientation; break;
486 case 5: image->orientation=RightTopOrientation; break;
487 case 6: image->orientation=LeftBottomOrientation; break;
488 case 7: image->orientation=RightBottomOrientation; break;
490 cin.image.number_channels=(unsigned char) ReadBlobByte(image);
492 offset+=ReadBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
494 for (i=0; i < 8; i++)
496 cin.image.channel[i].designator[0]=(unsigned char) ReadBlobByte(image);
498 cin.image.channel[i].designator[1]=(unsigned char) ReadBlobByte(image);
500 cin.image.channel[i].bits_per_pixel=(unsigned char) ReadBlobByte(image);
502 cin.image.channel[i].reserve=(unsigned char) ReadBlobByte(image);
504 cin.image.channel[i].pixels_per_line=ReadBlobLong(image);
506 cin.image.channel[i].lines_per_image=ReadBlobLong(image);
508 cin.image.channel[i].min_data=ReadBlobFloat(image);
510 cin.image.channel[i].min_quantity=ReadBlobFloat(image);
512 cin.image.channel[i].max_data=ReadBlobFloat(image);
514 cin.image.channel[i].max_quantity=ReadBlobFloat(image);
517 cin.image.white_point[0]=ReadBlobFloat(image);
519 if (IsFloatDefined(cin.image.white_point[0]) != MagickFalse)
520 image->chromaticity.white_point.x=cin.image.white_point[0];
521 cin.image.white_point[1]=ReadBlobFloat(image);
523 if (IsFloatDefined(cin.image.white_point[1]) != MagickFalse)
524 image->chromaticity.white_point.y=cin.image.white_point[1];
525 cin.image.red_primary_chromaticity[0]=ReadBlobFloat(image);
527 if (IsFloatDefined(cin.image.red_primary_chromaticity[0]) != MagickFalse)
528 image->chromaticity.red_primary.x=cin.image.red_primary_chromaticity[0];
529 cin.image.red_primary_chromaticity[1]=ReadBlobFloat(image);
531 if (IsFloatDefined(cin.image.red_primary_chromaticity[1]) != MagickFalse)
532 image->chromaticity.red_primary.y=cin.image.red_primary_chromaticity[1];
533 cin.image.green_primary_chromaticity[0]=ReadBlobFloat(image);
535 if (IsFloatDefined(cin.image.green_primary_chromaticity[0]) != MagickFalse)
536 image->chromaticity.red_primary.x=cin.image.green_primary_chromaticity[0];
537 cin.image.green_primary_chromaticity[1]=ReadBlobFloat(image);
539 if (IsFloatDefined(cin.image.green_primary_chromaticity[1]) != MagickFalse)
540 image->chromaticity.green_primary.y=cin.image.green_primary_chromaticity[1];
541 cin.image.blue_primary_chromaticity[0]=ReadBlobFloat(image);
543 if (IsFloatDefined(cin.image.blue_primary_chromaticity[0]) != MagickFalse)
544 image->chromaticity.blue_primary.x=cin.image.blue_primary_chromaticity[0];
545 cin.image.blue_primary_chromaticity[1]=ReadBlobFloat(image);
547 if (IsFloatDefined(cin.image.blue_primary_chromaticity[1]) != MagickFalse)
548 image->chromaticity.blue_primary.y=cin.image.blue_primary_chromaticity[1];
549 offset+=ReadBlob(image,sizeof(cin.image.label),(unsigned char *)
551 (void) SetImageProperty(image,"dpx:image.label",cin.image.label);
552 offset+=ReadBlob(image,sizeof(cin.image.reserve),(unsigned char *)
555 Image data format information.
557 cin.data_format.interleave=(unsigned char) ReadBlobByte(image);
559 cin.data_format.packing=(unsigned char) ReadBlobByte(image);
561 cin.data_format.sign=(unsigned char) ReadBlobByte(image);
563 cin.data_format.sense=(unsigned char) ReadBlobByte(image);
565 cin.data_format.line_pad=ReadBlobLong(image);
567 cin.data_format.channel_pad=ReadBlobLong(image);
569 offset+=ReadBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
570 cin.data_format.reserve);
572 Image origination information.
574 cin.origination.x_offset=(int) ReadBlobLong(image);
576 if ((size_t) cin.origination.x_offset != ~0UL)
577 (void) FormatImageProperty(image,"dpx:origination.x_offset","%.20g",
578 (double) cin.origination.x_offset);
579 cin.origination.y_offset=(ssize_t) ReadBlobLong(image);
581 if ((size_t) cin.origination.y_offset != ~0UL)
582 (void) FormatImageProperty(image,"dpx:origination.y_offset","%.20g",
583 (double) cin.origination.y_offset);
584 offset+=ReadBlob(image,sizeof(cin.origination.filename),(unsigned char *)
585 cin.origination.filename);
586 (void) SetImageProperty(image,"dpx:origination.filename",
587 cin.origination.filename);
588 offset+=ReadBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
589 cin.origination.create_date);
590 (void) SetImageProperty(image,"dpx:origination.create_date",
591 cin.origination.create_date);
592 offset+=ReadBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
593 cin.origination.create_time);
594 (void) SetImageProperty(image,"dpx:origination.create_time",
595 cin.origination.create_time);
596 offset+=ReadBlob(image,sizeof(cin.origination.device),(unsigned char *)
597 cin.origination.device);
598 (void) SetImageProperty(image,"dpx:origination.device",
599 cin.origination.device);
600 offset+=ReadBlob(image,sizeof(cin.origination.model),(unsigned char *)
601 cin.origination.model);
602 (void) SetImageProperty(image,"dpx:origination.model",cin.origination.model);
603 offset+=ReadBlob(image,sizeof(cin.origination.serial),(unsigned char *)
604 cin.origination.serial);
605 (void) SetImageProperty(image,"dpx:origination.serial",
606 cin.origination.serial);
607 cin.origination.x_pitch=ReadBlobFloat(image);
609 cin.origination.y_pitch=ReadBlobFloat(image);
611 cin.origination.gamma=ReadBlobFloat(image);
613 if (IsFloatDefined(cin.origination.gamma) != MagickFalse)
614 image->gamma=cin.origination.gamma;
615 offset+=ReadBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
616 cin.origination.reserve);
617 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
620 Image film information.
622 cin.film.id=ReadBlobByte(image);
624 if (((size_t) cin.film.id) != ~0UL)
625 (void) FormatImageProperty(image,"dpx:film.id","%d",cin.film.id);
626 cin.film.type=ReadBlobByte(image);
628 if (((size_t) cin.film.type) != ~0UL)
629 (void) FormatImageProperty(image,"dpx:film.type","%d",cin.film.type);
630 cin.film.offset=ReadBlobByte(image);
632 if (((size_t) cin.film.offset) != ~0UL)
633 (void) FormatImageProperty(image,"dpx:film.offset","%d",
635 cin.film.reserve1=ReadBlobByte(image);
637 cin.film.prefix=ReadBlobLong(image);
639 if (cin.film.prefix != ~0UL)
640 (void) FormatImageProperty(image,"dpx:film.prefix","%.20g",(double)
642 cin.film.count=ReadBlobLong(image);
644 offset+=ReadBlob(image,sizeof(cin.film.format),(unsigned char *)
646 (void) SetImageProperty(image,"dpx:film.format",cin.film.format);
647 cin.film.frame_position=ReadBlobLong(image);
649 if (cin.film.frame_position != ~0UL)
650 (void) FormatImageProperty(image,"dpx:film.frame_position","%.20g",
651 (double) cin.film.frame_position);
652 cin.film.frame_rate=ReadBlobFloat(image);
654 if (IsFloatDefined(cin.film.frame_rate) != MagickFalse)
655 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
656 cin.film.frame_rate);
657 offset+=ReadBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
659 (void) SetImageProperty(image,"dpx:film.frame_id",cin.film.frame_id);
660 offset+=ReadBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
661 cin.film.slate_info);
662 (void) SetImageProperty(image,"dpx:film.slate_info",cin.film.slate_info);
663 offset+=ReadBlob(image,sizeof(cin.film.reserve),(unsigned char *)
666 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
674 profile=BlobToStringInfo((const void *) NULL,cin.file.user_length);
675 if (profile == (StringInfo *) NULL)
676 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
677 offset+=ReadBlob(image,GetStringInfoLength(profile),
678 GetStringInfoDatum(profile));
679 (void) SetImageProfile(image,"dpx:user.data",profile);
680 profile=DestroyStringInfo(profile);
682 for ( ; offset < (MagickOffsetType) cin.file.image_offset; offset++)
683 (void) ReadBlobByte(image);
684 image->depth=cin.image.channel[0].bits_per_pixel;
685 image->columns=cin.image.channel[0].pixels_per_line;
686 image->rows=cin.image.channel[0].lines_per_image;
687 if (image_info->ping)
689 (void) CloseBlob(image);
693 Convert CIN raster image to pixel packets.
695 quantum_info=AcquireQuantumInfo(image_info,image);
696 if (quantum_info == (QuantumInfo *) NULL)
697 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
698 quantum_info->quantum=32;
699 quantum_info->pack=MagickFalse;
700 quantum_type=RGBQuantum;
701 pixels=GetQuantumPixels(quantum_info);
702 length=GetQuantumExtent(image,quantum_info,quantum_type);
703 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
704 if (cin.image.number_channels == 1)
706 quantum_type=GrayQuantum;
707 length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue);
709 for (y=0; y < (ssize_t) image->rows; y++)
711 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
712 if (q == (Quantum *) NULL)
714 count=ReadBlob(image,length,pixels);
715 if ((size_t) count != length)
717 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
718 quantum_type,pixels,exception);
719 if (SyncAuthenticPixels(image,exception) == MagickFalse)
721 if (image->previous == (Image *) NULL)
723 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
725 if (status == MagickFalse)
729 SetQuantumImageType(image,quantum_type);
730 quantum_info=DestroyQuantumInfo(quantum_info);
731 if (EOFBlob(image) != MagickFalse)
732 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
734 image->colorspace=LogColorspace;
735 (void) CloseBlob(image);
736 return(GetFirstImageInList(image));
740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 % R e g i s t e r C I N E O N I m a g e %
748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 % RegisterCINImage() adds attributes for the CIN image format to the list of
751 % of supported formats. The attributes include the image format tag, a method
752 % to read and/or write the format, whether the format supports the saving of
753 % more than one frame to the same file or blob, whether the format supports
754 % native in-memory I/O, and a brief description of the format.
756 % The format of the RegisterCINImage method is:
758 % size_t RegisterCINImage(void)
761 ModuleExport size_t RegisterCINImage(void)
766 entry=SetMagickInfo("CIN");
767 entry->decoder=(DecodeImageHandler *) ReadCINImage;
768 entry->encoder=(EncodeImageHandler *) WriteCINImage;
769 entry->magick=(IsImageFormatHandler *) IsCIN;
770 entry->adjoin=MagickFalse;
771 entry->description=ConstantString("Cineon Image File");
772 entry->module=ConstantString("CIN");
773 (void) RegisterMagickInfo(entry);
774 return(MagickImageCoderSignature);
778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 % U n r e g i s t e r C I N E O N I m a g e %
786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 % UnregisterCINImage() removes format registrations made by the CIN module
789 % from the list of supported formats.
791 % The format of the UnregisterCINImage method is:
793 % UnregisterCINImage(void)
796 ModuleExport void UnregisterCINImage(void)
798 (void) UnregisterMagickInfo("CINEON");
802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
806 % W r i t e C I N E O N I m a g e %
810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 % WriteCINImage() writes an image in CIN encoded image format.
814 % The format of the WriteCINImage method is:
816 % MagickBooleanType WriteCINImage(const ImageInfo *image_info,
817 % Image *image,ExceptionInfo *exception)
819 % A description of each parameter follows.
821 % o image_info: the image info.
823 % o image: The image.
825 % o exception: return any errors or warnings in this structure.
829 static inline const char *GetCINProperty(const ImageInfo *image_info,
830 const Image *image,const char *property)
835 value=GetImageOption(image_info,property);
836 if (value != (const char *) NULL)
838 return(GetImageProperty(image,property));
841 static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
842 ExceptionInfo *exception)
865 register const Quantum
888 Open output image file.
890 assert(image_info != (const ImageInfo *) NULL);
891 assert(image_info->signature == MagickSignature);
892 assert(image != (Image *) NULL);
893 assert(image->signature == MagickSignature);
894 if (image->debug != MagickFalse)
895 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
896 assert(exception != (ExceptionInfo *) NULL);
897 assert(exception->signature == MagickSignature);
898 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
899 if (status == MagickFalse)
901 if (image->colorspace != LogColorspace)
902 (void) TransformImageColorspace(image,LogColorspace);
904 Write image information.
906 (void) ResetMagickMemory(&cin,0,sizeof(cin));
908 cin.file.magic=0x802A5FD7UL;
909 offset+=WriteBlobLong(image,(unsigned int) cin.file.magic);
910 cin.file.image_offset=0x800;
911 offset+=WriteBlobLong(image,(unsigned int) cin.file.image_offset);
912 cin.file.generic_length=0x400;
913 offset+=WriteBlobLong(image,(unsigned int) cin.file.generic_length);
914 cin.file.industry_length=0x400;
915 offset+=WriteBlobLong(image,(unsigned int) cin.file.industry_length);
916 cin.file.user_length=0x00;
917 profile=GetImageProfile(image,"dpx:user.data");
918 if (profile != (StringInfo *) NULL)
920 cin.file.user_length+=(size_t) GetStringInfoLength(profile);
921 cin.file.user_length=(((cin.file.user_length+0x2000-1)/0x2000)*0x2000);
923 offset+=WriteBlobLong(image,(unsigned int) cin.file.user_length);
924 cin.file.file_size=4*image->columns*image->rows+0x2000;
925 offset+=WriteBlobLong(image,(unsigned int) cin.file.file_size);
926 (void) CopyMagickString(cin.file.version,"V4.5",sizeof(cin.file.version));
927 offset+=WriteBlob(image,sizeof(cin.file.version),(unsigned char *)
929 value=GetCINProperty(image_info,image,"dpx:file.filename");
930 if (value != (const char *) NULL)
931 (void) CopyMagickString(cin.file.filename,value,sizeof(cin.file.filename));
933 (void) CopyMagickString(cin.file.filename,image->filename,
934 sizeof(cin.file.filename));
935 offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *)
937 seconds=time((time_t *) NULL);
938 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
939 (void) localtime_r(&seconds,&local_time);
941 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
943 (void) strftime(cin.file.create_date,sizeof(cin.file.create_date),"%Y:%m:%d",
945 offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *)
946 cin.file.create_date);
947 (void) strftime(cin.file.create_time,sizeof(cin.file.create_time),
948 "%H:%M:%S%Z",&local_time);
949 offset+=WriteBlob(image,sizeof(cin.file.create_time),(unsigned char *)
950 cin.file.create_time);
951 offset+=WriteBlob(image,sizeof(cin.file.reserve),(unsigned char *)
953 cin.image.orientation=0x00;
954 offset+=WriteBlobByte(image,cin.image.orientation);
955 cin.image.number_channels=3;
956 offset+=WriteBlobByte(image,cin.image.number_channels);
957 offset+=WriteBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
959 for (i=0; i < 8; i++)
961 cin.image.channel[i].designator[0]=0; /* universal metric */
962 offset+=WriteBlobByte(image,cin.image.channel[0].designator[0]);
963 cin.image.channel[i].designator[1]=(unsigned char) (i > 3 ? 0 : i+1); /* channel color */;
964 offset+=WriteBlobByte(image,cin.image.channel[1].designator[0]);
965 cin.image.channel[i].bits_per_pixel=(unsigned char) image->depth;
966 offset+=WriteBlobByte(image,cin.image.channel[0].bits_per_pixel);
967 offset+=WriteBlobByte(image,cin.image.channel[0].reserve);
968 cin.image.channel[i].pixels_per_line=image->columns;
969 offset+=WriteBlobLong(image,(unsigned int)
970 cin.image.channel[0].pixels_per_line);
971 cin.image.channel[i].lines_per_image=image->rows;
972 offset+=WriteBlobLong(image,(unsigned int)
973 cin.image.channel[0].lines_per_image);
974 cin.image.channel[i].min_data=0;
975 offset+=WriteBlobFloat(image,cin.image.channel[0].min_data);
976 cin.image.channel[i].min_quantity=0.0;
977 offset+=WriteBlobFloat(image,cin.image.channel[0].min_quantity);
978 cin.image.channel[i].max_data=(float) ((MagickOffsetType)
979 GetQuantumRange(image->depth));
980 offset+=WriteBlobFloat(image,cin.image.channel[0].max_data);
981 cin.image.channel[i].max_quantity=2.048f;
982 offset+=WriteBlobFloat(image,cin.image.channel[0].max_quantity);
984 offset+=WriteBlobFloat(image,image->chromaticity.white_point.x);
985 offset+=WriteBlobFloat(image,image->chromaticity.white_point.y);
986 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.x);
987 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.y);
988 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.x);
989 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.y);
990 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.x);
991 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.y);
992 value=GetCINProperty(image_info,image,"dpx:image.label");
993 if (value != (const char *) NULL)
994 (void) CopyMagickString(cin.image.label,value,sizeof(cin.image.label));
995 offset+=WriteBlob(image,sizeof(cin.image.label),(unsigned char *)
997 offset+=WriteBlob(image,sizeof(cin.image.reserve),(unsigned char *)
1000 Write data format information.
1002 cin.data_format.interleave=0; /* pixel interleave (rgbrgbr...) */
1003 offset+=WriteBlobByte(image,cin.data_format.interleave);
1004 cin.data_format.packing=5; /* packing ssize_tword (32bit) boundaries */
1005 offset+=WriteBlobByte(image,cin.data_format.packing);
1006 cin.data_format.sign=0; /* unsigned data */
1007 offset+=WriteBlobByte(image,cin.data_format.sign);
1008 cin.data_format.sense=0; /* image sense: positive image */
1009 offset+=WriteBlobByte(image,cin.data_format.sense);
1010 cin.data_format.line_pad=0;
1011 offset+=WriteBlobLong(image,(unsigned int) cin.data_format.line_pad);
1012 cin.data_format.channel_pad=0;
1013 offset+=WriteBlobLong(image,(unsigned int) cin.data_format.channel_pad);
1014 offset+=WriteBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
1015 cin.data_format.reserve);
1017 Write origination information.
1019 cin.origination.x_offset=0UL;
1020 value=GetCINProperty(image_info,image,"dpx:origination.x_offset");
1021 if (value != (const char *) NULL)
1022 cin.origination.x_offset=(ssize_t) StringToLong(value);
1023 offset+=WriteBlobLong(image,(unsigned int) cin.origination.x_offset);
1024 cin.origination.y_offset=0UL;
1025 value=GetCINProperty(image_info,image,"dpx:origination.y_offset");
1026 if (value != (const char *) NULL)
1027 cin.origination.y_offset=(ssize_t) StringToLong(value);
1028 offset+=WriteBlobLong(image,(unsigned int) cin.origination.y_offset);
1029 value=GetCINProperty(image_info,image,"dpx:origination.filename");
1030 if (value != (const char *) NULL)
1031 (void) CopyMagickString(cin.origination.filename,value,
1032 sizeof(cin.origination.filename));
1034 (void) CopyMagickString(cin.origination.filename,image->filename,
1035 sizeof(cin.origination.filename));
1036 offset+=WriteBlob(image,sizeof(cin.origination.filename),(unsigned char *)
1037 cin.origination.filename);
1038 seconds=time((time_t *) NULL);
1039 (void) strftime(cin.origination.create_date,
1040 sizeof(cin.origination.create_date),"%Y:%m:%d",&local_time);
1041 offset+=WriteBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
1042 cin.origination.create_date);
1043 (void) strftime(cin.origination.create_time,
1044 sizeof(cin.origination.create_time),"%H:%M:%S%Z",&local_time);
1045 offset+=WriteBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
1046 cin.origination.create_time);
1047 value=GetCINProperty(image_info,image,"dpx:origination.device");
1048 if (value != (const char *) NULL)
1049 (void) CopyMagickString(cin.origination.device,value,
1050 sizeof(cin.origination.device));
1051 offset+=WriteBlob(image,sizeof(cin.origination.device),(unsigned char *)
1052 cin.origination.device);
1053 value=GetCINProperty(image_info,image,"dpx:origination.model");
1054 if (value != (const char *) NULL)
1055 (void) CopyMagickString(cin.origination.model,value,
1056 sizeof(cin.origination.model));
1057 offset+=WriteBlob(image,sizeof(cin.origination.model),(unsigned char *)
1058 cin.origination.model);
1059 value=GetCINProperty(image_info,image,"dpx:origination.serial");
1060 if (value != (const char *) NULL)
1061 (void) CopyMagickString(cin.origination.serial,value,
1062 sizeof(cin.origination.serial));
1063 offset+=WriteBlob(image,sizeof(cin.origination.serial),(unsigned char *)
1064 cin.origination.serial);
1065 cin.origination.x_pitch=0.0f;
1066 value=GetCINProperty(image_info,image,"dpx:origination.x_pitch");
1067 if (value != (const char *) NULL)
1068 cin.origination.x_pitch=InterpretLocaleValue(value,(char **) NULL);
1069 offset+=WriteBlobFloat(image,cin.origination.x_pitch);
1070 cin.origination.y_pitch=0.0f;
1071 value=GetCINProperty(image_info,image,"dpx:origination.y_pitch");
1072 if (value != (const char *) NULL)
1073 cin.origination.y_pitch=InterpretLocaleValue(value,(char **) NULL);
1074 offset+=WriteBlobFloat(image,cin.origination.y_pitch);
1075 cin.origination.gamma=image->gamma;
1076 offset+=WriteBlobFloat(image,cin.origination.gamma);
1077 offset+=WriteBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
1078 cin.origination.reserve);
1080 Image film information.
1083 value=GetCINProperty(image_info,image,"dpx:film.id");
1084 if (value != (const char *) NULL)
1085 cin.film.id=(char) StringToLong(value);
1086 offset+=WriteBlobByte(image,(unsigned char) cin.film.id);
1088 value=GetCINProperty(image_info,image,"dpx:film.type");
1089 if (value != (const char *) NULL)
1090 cin.film.type=(char) StringToLong(value);
1091 offset+=WriteBlobByte(image,(unsigned char) cin.film.type);
1093 value=GetCINProperty(image_info,image,"dpx:film.offset");
1094 if (value != (const char *) NULL)
1095 cin.film.offset=(char) StringToLong(value);
1096 offset+=WriteBlobByte(image,(unsigned char) cin.film.offset);
1097 offset+=WriteBlobByte(image,(unsigned char) cin.film.reserve1);
1098 cin.film.prefix=0UL;
1099 value=GetCINProperty(image_info,image,"dpx:film.prefix");
1100 if (value != (const char *) NULL)
1101 cin.film.prefix=StringToUnsignedLong(value);
1102 offset+=WriteBlobLong(image,(unsigned int) cin.film.prefix);
1104 value=GetCINProperty(image_info,image,"dpx:film.count");
1105 if (value != (const char *) NULL)
1106 cin.film.count=StringToUnsignedLong(value);
1107 offset+=WriteBlobLong(image,(unsigned int) cin.film.count);
1108 value=GetCINProperty(image_info,image,"dpx:film.format");
1109 if (value != (const char *) NULL)
1110 (void) CopyMagickString(cin.film.format,value,sizeof(cin.film.format));
1111 offset+=WriteBlob(image,sizeof(cin.film.format),(unsigned char *)
1113 cin.film.frame_position=0UL;
1114 value=GetCINProperty(image_info,image,"dpx:film.frame_position");
1115 if (value != (const char *) NULL)
1116 cin.film.frame_position=StringToUnsignedLong(value);
1117 offset+=WriteBlobLong(image,(unsigned int) cin.film.frame_position);
1118 cin.film.frame_rate=0.0f;
1119 value=GetCINProperty(image_info,image,"dpx:film.frame_rate");
1120 if (value != (const char *) NULL)
1121 cin.film.frame_rate=InterpretLocaleValue(value,(char **) NULL);
1122 offset+=WriteBlobFloat(image,cin.film.frame_rate);
1123 value=GetCINProperty(image_info,image,"dpx:film.frame_id");
1124 if (value != (const char *) NULL)
1125 (void) CopyMagickString(cin.film.frame_id,value,sizeof(cin.film.frame_id));
1126 offset+=WriteBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
1128 value=GetCINProperty(image_info,image,"dpx:film.slate_info");
1129 if (value != (const char *) NULL)
1130 (void) CopyMagickString(cin.film.slate_info,value,
1131 sizeof(cin.film.slate_info));
1132 offset+=WriteBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
1133 cin.film.slate_info);
1134 offset+=WriteBlob(image,sizeof(cin.film.reserve),(unsigned char *)
1136 if (profile != (StringInfo *) NULL)
1137 offset+=WriteBlob(image,GetStringInfoLength(profile),
1138 GetStringInfoDatum(profile));
1139 while (offset < (MagickOffsetType) cin.file.image_offset)
1140 offset+=WriteBlobByte(image,0x00);
1142 Convert pixel packets to CIN raster image.
1144 quantum_info=AcquireQuantumInfo(image_info,image);
1145 if (quantum_info == (QuantumInfo *) NULL)
1146 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1147 quantum_info->quantum=32;
1148 quantum_info->pack=MagickFalse;
1149 quantum_type=RGBQuantum;
1150 pixels=GetQuantumPixels(quantum_info);
1151 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1154 quantum_type=GrayQuantum;
1155 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1157 for (y=0; y < (ssize_t) image->rows; y++)
1159 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
1160 if (p == (const Quantum *) NULL)
1162 (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1163 quantum_type,pixels,exception);
1164 count=WriteBlob(image,length,pixels);
1165 if (count != (ssize_t) length)
1167 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1169 if (status == MagickFalse)
1172 quantum_info=DestroyQuantumInfo(quantum_info);
1173 (void) CloseBlob(image);