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 "magick/studio.h"
50 #include "magick/blob.h"
51 #include "magick/blob-private.h"
52 #include "magick/cache.h"
53 #include "magick/colorspace.h"
54 #include "magick/exception.h"
55 #include "magick/exception-private.h"
56 #include "magick/image.h"
57 #include "magick/image-private.h"
58 #include "magick/list.h"
59 #include "magick/magick.h"
60 #include "magick/memory_.h"
61 #include "magick/monitor.h"
62 #include "magick/monitor-private.h"
63 #include "magick/option.h"
64 #include "magick/profile.h"
65 #include "magick/property.h"
66 #include "magick/quantum-private.h"
67 #include "magick/quantum-private.h"
68 #include "magick/static.h"
69 #include "magick/string_.h"
70 #include "magick/string-private.h"
71 #include "magick/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 *);
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
424 assert(image_info != (const ImageInfo *) NULL);
425 assert(image_info->signature == MagickSignature);
426 if (image_info->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
428 image_info->filename);
429 assert(exception != (ExceptionInfo *) NULL);
430 assert(exception->signature == MagickSignature);
431 image=AcquireImage(image_info);
432 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
433 if (status == MagickFalse)
435 image=DestroyImageList(image);
436 return((Image *) NULL);
442 count=ReadBlob(image,4,(unsigned char *) magick);
445 ((LocaleNCompare((char *) magick,"\200\052\137\327",4) != 0)))
446 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
447 image->endian=LSBEndian;
449 if ((int) (*(char *) &lsb_first) != 0)
450 image->endian=MSBEndian;
451 cin.file.image_offset=ReadBlobLong(image);
453 cin.file.generic_length=ReadBlobLong(image);
455 cin.file.industry_length=ReadBlobLong(image);
457 cin.file.user_length=ReadBlobLong(image);
459 cin.file.file_size=ReadBlobLong(image);
461 offset+=ReadBlob(image,sizeof(cin.file.version),(unsigned char *)
463 (void) SetImageProperty(image,"dpx:file.version",cin.file.version);
464 offset+=ReadBlob(image,sizeof(cin.file.filename),(unsigned char *)
466 (void) SetImageProperty(image,"dpx:file.filename",cin.file.filename);
467 offset+=ReadBlob(image,sizeof(cin.file.create_date),(unsigned char *)
468 cin.file.create_date);
469 (void) SetImageProperty(image,"dpx:file.create_date",cin.file.create_date);
470 offset+=ReadBlob(image,sizeof(cin.file.create_time),(unsigned char *)
471 cin.file.create_time);
472 (void) SetImageProperty(image,"dpx:file.create_time",cin.file.create_time);
473 offset+=ReadBlob(image,sizeof(cin.file.reserve),(unsigned char *)
478 cin.image.orientation=(unsigned char) ReadBlobByte(image);
480 if (cin.image.orientation != (unsigned char) (~0U))
481 (void) FormatImageProperty(image,"dpx:image.orientation","%d",
482 cin.image.orientation);
483 switch (cin.image.orientation)
486 case 0: image->orientation=TopLeftOrientation; break;
487 case 1: image->orientation=TopRightOrientation; break;
488 case 2: image->orientation=BottomLeftOrientation; break;
489 case 3: image->orientation=BottomRightOrientation; break;
490 case 4: image->orientation=LeftTopOrientation; break;
491 case 5: image->orientation=RightTopOrientation; break;
492 case 6: image->orientation=LeftBottomOrientation; break;
493 case 7: image->orientation=RightBottomOrientation; break;
495 cin.image.number_channels=(unsigned char) ReadBlobByte(image);
497 offset+=ReadBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
499 for (i=0; i < 8; i++)
501 cin.image.channel[i].designator[0]=(unsigned char) ReadBlobByte(image);
503 cin.image.channel[i].designator[1]=(unsigned char) ReadBlobByte(image);
505 cin.image.channel[i].bits_per_pixel=(unsigned char) ReadBlobByte(image);
507 cin.image.channel[i].reserve=(unsigned char) ReadBlobByte(image);
509 cin.image.channel[i].pixels_per_line=ReadBlobLong(image);
511 cin.image.channel[i].lines_per_image=ReadBlobLong(image);
513 cin.image.channel[i].min_data=ReadBlobFloat(image);
515 cin.image.channel[i].min_quantity=ReadBlobFloat(image);
517 cin.image.channel[i].max_data=ReadBlobFloat(image);
519 cin.image.channel[i].max_quantity=ReadBlobFloat(image);
522 cin.image.white_point[0]=ReadBlobFloat(image);
524 if (IsFloatDefined(cin.image.white_point[0]) != MagickFalse)
525 image->chromaticity.white_point.x=cin.image.white_point[0];
526 cin.image.white_point[1]=ReadBlobFloat(image);
528 if (IsFloatDefined(cin.image.white_point[1]) != MagickFalse)
529 image->chromaticity.white_point.y=cin.image.white_point[1];
530 cin.image.red_primary_chromaticity[0]=ReadBlobFloat(image);
532 if (IsFloatDefined(cin.image.red_primary_chromaticity[0]) != MagickFalse)
533 image->chromaticity.red_primary.x=cin.image.red_primary_chromaticity[0];
534 cin.image.red_primary_chromaticity[1]=ReadBlobFloat(image);
536 if (IsFloatDefined(cin.image.red_primary_chromaticity[1]) != MagickFalse)
537 image->chromaticity.red_primary.y=cin.image.red_primary_chromaticity[1];
538 cin.image.green_primary_chromaticity[0]=ReadBlobFloat(image);
540 if (IsFloatDefined(cin.image.green_primary_chromaticity[0]) != MagickFalse)
541 image->chromaticity.red_primary.x=cin.image.green_primary_chromaticity[0];
542 cin.image.green_primary_chromaticity[1]=ReadBlobFloat(image);
544 if (IsFloatDefined(cin.image.green_primary_chromaticity[1]) != MagickFalse)
545 image->chromaticity.green_primary.y=cin.image.green_primary_chromaticity[1];
546 cin.image.blue_primary_chromaticity[0]=ReadBlobFloat(image);
548 if (IsFloatDefined(cin.image.blue_primary_chromaticity[0]) != MagickFalse)
549 image->chromaticity.blue_primary.x=cin.image.blue_primary_chromaticity[0];
550 cin.image.blue_primary_chromaticity[1]=ReadBlobFloat(image);
552 if (IsFloatDefined(cin.image.blue_primary_chromaticity[1]) != MagickFalse)
553 image->chromaticity.blue_primary.y=cin.image.blue_primary_chromaticity[1];
554 offset+=ReadBlob(image,sizeof(cin.image.label),(unsigned char *)
556 (void) SetImageProperty(image,"dpx:image.label",cin.image.label);
557 offset+=ReadBlob(image,sizeof(cin.image.reserve),(unsigned char *)
560 Image data format information.
562 cin.data_format.interleave=(unsigned char) ReadBlobByte(image);
564 cin.data_format.packing=(unsigned char) ReadBlobByte(image);
566 cin.data_format.sign=(unsigned char) ReadBlobByte(image);
568 cin.data_format.sense=(unsigned char) ReadBlobByte(image);
570 cin.data_format.line_pad=ReadBlobLong(image);
572 cin.data_format.channel_pad=ReadBlobLong(image);
574 offset+=ReadBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
575 cin.data_format.reserve);
577 Image origination information.
579 cin.origination.x_offset=(int) ReadBlobLong(image);
581 if ((size_t) cin.origination.x_offset != ~0UL)
582 (void) FormatImageProperty(image,"dpx:origination.x_offset","%.20g",
583 (double) cin.origination.x_offset);
584 cin.origination.y_offset=(ssize_t) ReadBlobLong(image);
586 if ((size_t) cin.origination.y_offset != ~0UL)
587 (void) FormatImageProperty(image,"dpx:origination.y_offset","%.20g",
588 (double) cin.origination.y_offset);
589 offset+=ReadBlob(image,sizeof(cin.origination.filename),(unsigned char *)
590 cin.origination.filename);
591 (void) SetImageProperty(image,"dpx:origination.filename",
592 cin.origination.filename);
593 offset+=ReadBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
594 cin.origination.create_date);
595 (void) SetImageProperty(image,"dpx:origination.create_date",
596 cin.origination.create_date);
597 offset+=ReadBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
598 cin.origination.create_time);
599 (void) SetImageProperty(image,"dpx:origination.create_time",
600 cin.origination.create_time);
601 offset+=ReadBlob(image,sizeof(cin.origination.device),(unsigned char *)
602 cin.origination.device);
603 (void) SetImageProperty(image,"dpx:origination.device",
604 cin.origination.device);
605 offset+=ReadBlob(image,sizeof(cin.origination.model),(unsigned char *)
606 cin.origination.model);
607 (void) SetImageProperty(image,"dpx:origination.model",cin.origination.model);
608 offset+=ReadBlob(image,sizeof(cin.origination.serial),(unsigned char *)
609 cin.origination.serial);
610 (void) SetImageProperty(image,"dpx:origination.serial",
611 cin.origination.serial);
612 cin.origination.x_pitch=ReadBlobFloat(image);
614 cin.origination.y_pitch=ReadBlobFloat(image);
616 cin.origination.gamma=ReadBlobFloat(image);
618 if (IsFloatDefined(cin.origination.gamma) != MagickFalse)
619 image->gamma=cin.origination.gamma;
620 offset+=ReadBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
621 cin.origination.reserve);
622 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
625 Image film information.
627 cin.film.id=ReadBlobByte(image);
629 if (((size_t) cin.film.id) != ~0UL)
630 (void) FormatImageProperty(image,"dpx:film.id","%d",cin.film.id);
631 cin.film.type=ReadBlobByte(image);
633 if (((size_t) cin.film.type) != ~0UL)
634 (void) FormatImageProperty(image,"dpx:film.type","%d",cin.film.type);
635 cin.film.offset=ReadBlobByte(image);
637 if (((size_t) cin.film.offset) != ~0UL)
638 (void) FormatImageProperty(image,"dpx:film.offset","%d",
640 cin.film.reserve1=ReadBlobByte(image);
642 cin.film.prefix=ReadBlobLong(image);
644 if (cin.film.prefix != ~0UL)
645 (void) FormatImageProperty(image,"dpx:film.prefix","%.20g",(double)
647 cin.film.count=ReadBlobLong(image);
649 offset+=ReadBlob(image,sizeof(cin.film.format),(unsigned char *)
651 (void) SetImageProperty(image,"dpx:film.format",cin.film.format);
652 cin.film.frame_position=ReadBlobLong(image);
654 if (cin.film.frame_position != ~0UL)
655 (void) FormatImageProperty(image,"dpx:film.frame_position","%.20g",
656 (double) cin.film.frame_position);
657 cin.film.frame_rate=ReadBlobFloat(image);
659 if (IsFloatDefined(cin.film.frame_rate) != MagickFalse)
660 (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
661 cin.film.frame_rate);
662 offset+=ReadBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
664 (void) SetImageProperty(image,"dpx:film.frame_id",cin.film.frame_id);
665 offset+=ReadBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
666 cin.film.slate_info);
667 (void) SetImageProperty(image,"dpx:film.slate_info",cin.film.slate_info);
668 offset+=ReadBlob(image,sizeof(cin.film.reserve),(unsigned char *)
671 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
679 profile=AcquireStringInfo(cin.file.user_length);
680 offset+=ReadBlob(image,GetStringInfoLength(profile),
681 GetStringInfoDatum(profile));
682 (void) SetImageProfile(image,"dpx:user.data",profile);
683 profile=DestroyStringInfo(profile);
685 for ( ; offset < (MagickOffsetType) cin.file.image_offset; offset++)
686 (void) ReadBlobByte(image);
687 image->depth=cin.image.channel[0].bits_per_pixel;
688 image->columns=cin.image.channel[0].pixels_per_line;
689 image->rows=cin.image.channel[0].lines_per_image;
690 if (image_info->ping)
692 (void) CloseBlob(image);
696 Convert CIN raster image to pixel packets.
698 quantum_info=AcquireQuantumInfo(image_info,image);
699 if (quantum_info == (QuantumInfo *) NULL)
700 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
701 quantum_info->quantum=32;
702 quantum_info->pack=MagickFalse;
703 quantum_type=RGBQuantum;
704 pixels=GetQuantumPixels(quantum_info);
705 length=GetQuantumExtent(image,quantum_info,quantum_type);
706 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
707 if (cin.image.number_channels == 1)
709 quantum_type=GrayQuantum;
710 length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue);
712 for (y=0; y < (ssize_t) image->rows; y++)
714 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
715 if (q == (PixelPacket *) NULL)
717 count=ReadBlob(image,length,pixels);
718 if ((size_t) count != length)
720 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
721 quantum_type,pixels,exception);
722 if (SyncAuthenticPixels(image,exception) == MagickFalse)
724 if (image->previous == (Image *) NULL)
726 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
728 if (status == MagickFalse)
732 SetQuantumImageType(image,quantum_type);
733 quantum_info=DestroyQuantumInfo(quantum_info);
734 if (EOFBlob(image) != MagickFalse)
735 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
737 image->colorspace=LogColorspace;
738 (void) CloseBlob(image);
739 return(GetFirstImageInList(image));
743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747 % R e g i s t e r C I N E O N I m a g e %
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 % RegisterCINImage() adds attributes for the CIN image format to the list of
754 % of supported formats. The attributes include the image format tag, a method
755 % to read and/or write the format, whether the format supports the saving of
756 % more than one frame to the same file or blob, whether the format supports
757 % native in-memory I/O, and a brief description of the format.
759 % The format of the RegisterCINImage method is:
761 % size_t RegisterCINImage(void)
764 ModuleExport size_t RegisterCINImage(void)
769 entry=SetMagickInfo("CIN");
770 entry->decoder=(DecodeImageHandler *) ReadCINImage;
771 entry->encoder=(EncodeImageHandler *) WriteCINImage;
772 entry->magick=(IsImageFormatHandler *) IsCIN;
773 entry->adjoin=MagickFalse;
774 entry->description=ConstantString("Cineon Image File");
775 entry->module=ConstantString("CIN");
776 (void) RegisterMagickInfo(entry);
777 return(MagickImageCoderSignature);
781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
785 % U n r e g i s t e r C I N E O N I m a g e %
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 % UnregisterCINImage() removes format registrations made by the CIN module
792 % from the list of supported formats.
794 % The format of the UnregisterCINImage method is:
796 % UnregisterCINImage(void)
799 ModuleExport void UnregisterCINImage(void)
801 (void) UnregisterMagickInfo("CINEON");
805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
809 % W r i t e C I N E O N I m a g e %
813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
815 % WriteCINImage() writes an image in CIN encoded image format.
817 % The format of the WriteCINImage method is:
819 % MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image)
821 % A description of each parameter follows.
823 % o image_info: the image info.
825 % o image: The image.
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)
864 register const PixelPacket
887 Open output image file.
889 assert(image_info != (const ImageInfo *) NULL);
890 assert(image_info->signature == MagickSignature);
891 assert(image != (Image *) NULL);
892 assert(image->signature == MagickSignature);
893 if (image->debug != MagickFalse)
894 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
895 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
896 if (status == MagickFalse)
898 if (image->colorspace != LogColorspace)
899 (void) TransformImageColorspace(image,LogColorspace);
901 Write image information.
903 (void) ResetMagickMemory(&cin,0,sizeof(cin));
905 cin.file.magic=0x802A5FD7UL;
906 offset+=WriteBlobLong(image,(unsigned int) cin.file.magic);
907 cin.file.image_offset=0x800;
908 offset+=WriteBlobLong(image,(unsigned int) cin.file.image_offset);
909 cin.file.generic_length=0x400;
910 offset+=WriteBlobLong(image,(unsigned int) cin.file.generic_length);
911 cin.file.industry_length=0x400;
912 offset+=WriteBlobLong(image,(unsigned int) cin.file.industry_length);
913 cin.file.user_length=0x00;
914 profile=GetImageProfile(image,"dpx:user.data");
915 if (profile != (StringInfo *) NULL)
917 cin.file.user_length+=(size_t) GetStringInfoLength(profile);
918 cin.file.user_length=(((cin.file.user_length+0x2000-1)/0x2000)*0x2000);
920 offset+=WriteBlobLong(image,(unsigned int) cin.file.user_length);
921 cin.file.file_size=4*image->columns*image->rows+0x2000;
922 offset+=WriteBlobLong(image,(unsigned int) cin.file.file_size);
923 (void) CopyMagickString(cin.file.version,"V4.5",sizeof(cin.file.version));
924 offset+=WriteBlob(image,sizeof(cin.file.version),(unsigned char *)
926 value=GetCINProperty(image_info,image,"dpx:file.filename");
927 if (value != (const char *) NULL)
928 (void) CopyMagickString(cin.file.filename,value,sizeof(cin.file.filename));
930 (void) CopyMagickString(cin.file.filename,image->filename,
931 sizeof(cin.file.filename));
932 offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *)
934 seconds=time((time_t *) NULL);
935 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
936 (void) localtime_r(&seconds,&local_time);
938 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
940 (void) strftime(cin.file.create_date,sizeof(cin.file.create_date),"%Y:%m:%d",
942 offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *)
943 cin.file.create_date);
944 (void) strftime(cin.file.create_time,sizeof(cin.file.create_time),
945 "%H:%M:%S%Z",&local_time);
946 offset+=WriteBlob(image,sizeof(cin.file.create_time),(unsigned char *)
947 cin.file.create_time);
948 offset+=WriteBlob(image,sizeof(cin.file.reserve),(unsigned char *)
950 cin.image.orientation=0x00;
951 offset+=WriteBlobByte(image,cin.image.orientation);
952 cin.image.number_channels=3;
953 offset+=WriteBlobByte(image,cin.image.number_channels);
954 offset+=WriteBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
956 for (i=0; i < 8; i++)
958 cin.image.channel[i].designator[0]=0; /* universal metric */
959 offset+=WriteBlobByte(image,cin.image.channel[0].designator[0]);
960 cin.image.channel[i].designator[1]=(unsigned char) (i > 3 ? 0 : i+1); /* channel color */;
961 offset+=WriteBlobByte(image,cin.image.channel[1].designator[0]);
962 cin.image.channel[i].bits_per_pixel=(unsigned char) image->depth;
963 offset+=WriteBlobByte(image,cin.image.channel[0].bits_per_pixel);
964 offset+=WriteBlobByte(image,cin.image.channel[0].reserve);
965 cin.image.channel[i].pixels_per_line=image->columns;
966 offset+=WriteBlobLong(image,(unsigned int)
967 cin.image.channel[0].pixels_per_line);
968 cin.image.channel[i].lines_per_image=image->rows;
969 offset+=WriteBlobLong(image,(unsigned int)
970 cin.image.channel[0].lines_per_image);
971 cin.image.channel[i].min_data=0;
972 offset+=WriteBlobFloat(image,cin.image.channel[0].min_data);
973 cin.image.channel[i].min_quantity=0.0;
974 offset+=WriteBlobFloat(image,cin.image.channel[0].min_quantity);
975 cin.image.channel[i].max_data=(float) ((MagickOffsetType)
976 GetQuantumRange(image->depth));
977 offset+=WriteBlobFloat(image,cin.image.channel[0].max_data);
978 cin.image.channel[i].max_quantity=2.048f;
979 offset+=WriteBlobFloat(image,cin.image.channel[0].max_quantity);
981 offset+=WriteBlobFloat(image,image->chromaticity.white_point.x);
982 offset+=WriteBlobFloat(image,image->chromaticity.white_point.y);
983 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.x);
984 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.y);
985 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.x);
986 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.y);
987 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.x);
988 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.y);
989 value=GetCINProperty(image_info,image,"dpx:image.label");
990 if (value != (const char *) NULL)
991 (void) CopyMagickString(cin.image.label,value,sizeof(cin.image.label));
992 offset+=WriteBlob(image,sizeof(cin.image.label),(unsigned char *)
994 offset+=WriteBlob(image,sizeof(cin.image.reserve),(unsigned char *)
997 Write data format information.
999 cin.data_format.interleave=0; /* pixel interleave (rgbrgbr...) */
1000 offset+=WriteBlobByte(image,cin.data_format.interleave);
1001 cin.data_format.packing=5; /* packing ssize_tword (32bit) boundaries */
1002 offset+=WriteBlobByte(image,cin.data_format.packing);
1003 cin.data_format.sign=0; /* unsigned data */
1004 offset+=WriteBlobByte(image,cin.data_format.sign);
1005 cin.data_format.sense=0; /* image sense: positive image */
1006 offset+=WriteBlobByte(image,cin.data_format.sense);
1007 cin.data_format.line_pad=0;
1008 offset+=WriteBlobLong(image,(unsigned int) cin.data_format.line_pad);
1009 cin.data_format.channel_pad=0;
1010 offset+=WriteBlobLong(image,(unsigned int) cin.data_format.channel_pad);
1011 offset+=WriteBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
1012 cin.data_format.reserve);
1014 Write origination information.
1016 cin.origination.x_offset=0UL;
1017 value=GetCINProperty(image_info,image,"dpx:origination.x_offset");
1018 if (value != (const char *) NULL)
1019 cin.origination.x_offset=(ssize_t) StringToLong(value);
1020 offset+=WriteBlobLong(image,(unsigned int) cin.origination.x_offset);
1021 cin.origination.y_offset=0UL;
1022 value=GetCINProperty(image_info,image,"dpx:origination.y_offset");
1023 if (value != (const char *) NULL)
1024 cin.origination.y_offset=(ssize_t) StringToLong(value);
1025 offset+=WriteBlobLong(image,(unsigned int) cin.origination.y_offset);
1026 value=GetCINProperty(image_info,image,"dpx:origination.filename");
1027 if (value != (const char *) NULL)
1028 (void) CopyMagickString(cin.origination.filename,value,
1029 sizeof(cin.origination.filename));
1031 (void) CopyMagickString(cin.origination.filename,image->filename,
1032 sizeof(cin.origination.filename));
1033 offset+=WriteBlob(image,sizeof(cin.origination.filename),(unsigned char *)
1034 cin.origination.filename);
1035 seconds=time((time_t *) NULL);
1036 (void) strftime(cin.origination.create_date,
1037 sizeof(cin.origination.create_date),"%Y:%m:%d",&local_time);
1038 offset+=WriteBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
1039 cin.origination.create_date);
1040 (void) strftime(cin.origination.create_time,
1041 sizeof(cin.origination.create_time),"%H:%M:%S%Z",&local_time);
1042 offset+=WriteBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
1043 cin.origination.create_time);
1044 value=GetCINProperty(image_info,image,"dpx:origination.device");
1045 if (value != (const char *) NULL)
1046 (void) CopyMagickString(cin.origination.device,value,
1047 sizeof(cin.origination.device));
1048 offset+=WriteBlob(image,sizeof(cin.origination.device),(unsigned char *)
1049 cin.origination.device);
1050 value=GetCINProperty(image_info,image,"dpx:origination.model");
1051 if (value != (const char *) NULL)
1052 (void) CopyMagickString(cin.origination.model,value,
1053 sizeof(cin.origination.model));
1054 offset+=WriteBlob(image,sizeof(cin.origination.model),(unsigned char *)
1055 cin.origination.model);
1056 value=GetCINProperty(image_info,image,"dpx:origination.serial");
1057 if (value != (const char *) NULL)
1058 (void) CopyMagickString(cin.origination.serial,value,
1059 sizeof(cin.origination.serial));
1060 offset+=WriteBlob(image,sizeof(cin.origination.serial),(unsigned char *)
1061 cin.origination.serial);
1062 cin.origination.x_pitch=0.0f;
1063 value=GetCINProperty(image_info,image,"dpx:origination.x_pitch");
1064 if (value != (const char *) NULL)
1065 cin.origination.x_pitch=StringToDouble(value);
1066 offset+=WriteBlobFloat(image,cin.origination.x_pitch);
1067 cin.origination.y_pitch=0.0f;
1068 value=GetCINProperty(image_info,image,"dpx:origination.y_pitch");
1069 if (value != (const char *) NULL)
1070 cin.origination.y_pitch=StringToDouble(value);
1071 offset+=WriteBlobFloat(image,cin.origination.y_pitch);
1072 cin.origination.gamma=image->gamma;
1073 offset+=WriteBlobFloat(image,cin.origination.gamma);
1074 offset+=WriteBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
1075 cin.origination.reserve);
1077 Image film information.
1080 value=GetCINProperty(image_info,image,"dpx:film.id");
1081 if (value != (const char *) NULL)
1082 cin.film.id=(char) StringToLong(value);
1083 offset+=WriteBlobByte(image,(unsigned char) cin.film.id);
1085 value=GetCINProperty(image_info,image,"dpx:film.type");
1086 if (value != (const char *) NULL)
1087 cin.film.type=(char) StringToLong(value);
1088 offset+=WriteBlobByte(image,(unsigned char) cin.film.type);
1090 value=GetCINProperty(image_info,image,"dpx:film.offset");
1091 if (value != (const char *) NULL)
1092 cin.film.offset=(char) StringToLong(value);
1093 offset+=WriteBlobByte(image,(unsigned char) cin.film.offset);
1094 offset+=WriteBlobByte(image,(unsigned char) cin.film.reserve1);
1095 cin.film.prefix=0UL;
1096 value=GetCINProperty(image_info,image,"dpx:film.prefix");
1097 if (value != (const char *) NULL)
1098 cin.film.prefix=StringToUnsignedLong(value);
1099 offset+=WriteBlobLong(image,(unsigned int) cin.film.prefix);
1101 value=GetCINProperty(image_info,image,"dpx:film.count");
1102 if (value != (const char *) NULL)
1103 cin.film.count=StringToUnsignedLong(value);
1104 offset+=WriteBlobLong(image,(unsigned int) cin.film.count);
1105 value=GetCINProperty(image_info,image,"dpx:film.format");
1106 if (value != (const char *) NULL)
1107 (void) CopyMagickString(cin.film.format,value,sizeof(cin.film.format));
1108 offset+=WriteBlob(image,sizeof(cin.film.format),(unsigned char *)
1110 cin.film.frame_position=0UL;
1111 value=GetCINProperty(image_info,image,"dpx:film.frame_position");
1112 if (value != (const char *) NULL)
1113 cin.film.frame_position=StringToUnsignedLong(value);
1114 offset+=WriteBlobLong(image,(unsigned int) cin.film.frame_position);
1115 cin.film.frame_rate=0.0f;
1116 value=GetCINProperty(image_info,image,"dpx:film.frame_rate");
1117 if (value != (const char *) NULL)
1118 cin.film.frame_rate=StringToDouble(value);
1119 offset+=WriteBlobFloat(image,cin.film.frame_rate);
1120 value=GetCINProperty(image_info,image,"dpx:film.frame_id");
1121 if (value != (const char *) NULL)
1122 (void) CopyMagickString(cin.film.frame_id,value,sizeof(cin.film.frame_id));
1123 offset+=WriteBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
1125 value=GetCINProperty(image_info,image,"dpx:film.slate_info");
1126 if (value != (const char *) NULL)
1127 (void) CopyMagickString(cin.film.slate_info,value,
1128 sizeof(cin.film.slate_info));
1129 offset+=WriteBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
1130 cin.film.slate_info);
1131 offset+=WriteBlob(image,sizeof(cin.film.reserve),(unsigned char *)
1133 if (profile != (StringInfo *) NULL)
1134 offset+=WriteBlob(image,GetStringInfoLength(profile),
1135 GetStringInfoDatum(profile));
1136 while (offset < (MagickOffsetType) cin.file.image_offset)
1137 offset+=WriteBlobByte(image,0x00);
1139 Convert pixel packets to CIN raster image.
1141 quantum_info=AcquireQuantumInfo(image_info,image);
1142 if (quantum_info == (QuantumInfo *) NULL)
1143 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1144 quantum_info->quantum=32;
1145 quantum_info->pack=MagickFalse;
1146 quantum_type=RGBQuantum;
1147 pixels=GetQuantumPixels(quantum_info);
1148 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1151 quantum_type=GrayQuantum;
1152 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1154 for (y=0; y < (ssize_t) image->rows; y++)
1156 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1157 if (p == (const PixelPacket *) NULL)
1159 (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
1160 quantum_type,pixels,&image->exception);
1161 count=WriteBlob(image,length,pixels);
1162 if (count != (ssize_t) length)
1164 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
1166 if (status == MagickFalse)
1169 quantum_info=DestroyQuantumInfo(quantum_info);
1170 (void) CloseBlob(image);