2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Kodak Cineon Image Format %
14 % Cineon Image Format is a subset of SMTPE CIN %
23 % Copyright 1999-2010 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(unsigned long columns,
295 unsigned long samples_per_pixel,unsigned long 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=0UL;
372 quantum.float_value=value;
373 if (quantum.unsigned_value == 0UL)
378 static Image *ReadCINImage(const ImageInfo *image_info,
379 ExceptionInfo *exception)
381 #define MonoColorType 1
382 #define RGBColorType 3
429 assert(image_info != (const ImageInfo *) NULL);
430 assert(image_info->signature == MagickSignature);
431 if (image_info->debug != MagickFalse)
432 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
433 image_info->filename);
434 assert(exception != (ExceptionInfo *) NULL);
435 assert(exception->signature == MagickSignature);
436 image=AcquireImage(image_info);
437 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
438 if (status == MagickFalse)
440 image=DestroyImageList(image);
441 return((Image *) NULL);
447 count=ReadBlob(image,4,(unsigned char *) magick);
450 ((LocaleNCompare((char *) magick,"\200\052\137\327",4) != 0)))
451 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
452 image->endian=LSBEndian;
454 if ((int) (*(char *) &lsb_first) != 0)
455 image->endian=MSBEndian;
456 cin.file.image_offset=ReadBlobLong(image);
458 cin.file.generic_length=ReadBlobLong(image);
460 cin.file.industry_length=ReadBlobLong(image);
462 cin.file.user_length=ReadBlobLong(image);
464 cin.file.file_size=ReadBlobLong(image);
466 offset+=ReadBlob(image,sizeof(cin.file.version),(unsigned char *)
468 (void) SetImageProperty(image,"cin:file.version",cin.file.version);
469 offset+=ReadBlob(image,sizeof(cin.file.filename),(unsigned char *)
471 (void) SetImageProperty(image,"cin:file.filename",cin.file.filename);
472 offset+=ReadBlob(image,sizeof(cin.file.create_date),(unsigned char *)
473 cin.file.create_date);
474 (void) SetImageProperty(image,"cin:file.create_date",cin.file.create_date);
475 offset+=ReadBlob(image,sizeof(cin.file.create_time),(unsigned char *)
476 cin.file.create_time);
477 (void) SetImageProperty(image,"cin:file.create_time",cin.file.create_time);
478 offset+=ReadBlob(image,sizeof(cin.file.reserve),(unsigned char *)
483 cin.image.orientation=(unsigned char) ReadBlobByte(image);
485 if (cin.image.orientation != (unsigned char) (~0U))
486 (void) FormatImageProperty(image,"cin:image.orientation","%d",
487 cin.image.orientation);
488 switch (cin.image.orientation)
491 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;
500 cin.image.number_channels=(unsigned char) ReadBlobByte(image);
502 offset+=ReadBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
504 for (i=0; i < 8; i++)
506 cin.image.channel[i].designator[0]=(unsigned char) ReadBlobByte(image);
508 cin.image.channel[i].designator[1]=(unsigned char) ReadBlobByte(image);
510 cin.image.channel[i].bits_per_pixel=(unsigned char) ReadBlobByte(image);
512 cin.image.channel[i].reserve=(unsigned char) ReadBlobByte(image);
514 cin.image.channel[i].pixels_per_line=ReadBlobLong(image);
516 cin.image.channel[i].lines_per_image=ReadBlobLong(image);
518 cin.image.channel[i].min_data=ReadBlobFloat(image);
520 cin.image.channel[i].min_quantity=ReadBlobFloat(image);
522 cin.image.channel[i].max_data=ReadBlobFloat(image);
524 cin.image.channel[i].max_quantity=ReadBlobFloat(image);
527 cin.image.white_point[0]=ReadBlobFloat(image);
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);
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);
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);
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);
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);
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);
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);
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 *)
561 (void) SetImageProperty(image,"cin:image.label",cin.image.label);
562 offset+=ReadBlob(image,sizeof(cin.image.reserve),(unsigned char *)
565 Image data format information.
567 cin.data_format.interleave=(unsigned char) ReadBlobByte(image);
569 cin.data_format.packing=(unsigned char) ReadBlobByte(image);
571 cin.data_format.sign=(unsigned char) ReadBlobByte(image);
573 cin.data_format.sense=(unsigned char) ReadBlobByte(image);
575 cin.data_format.line_pad=ReadBlobLong(image);
577 cin.data_format.channel_pad=ReadBlobLong(image);
579 offset+=ReadBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
580 cin.data_format.reserve);
582 Image origination information.
584 cin.origination.x_offset=(long) ReadBlobLong(image);
586 if ((unsigned long) cin.origination.x_offset != ~0UL)
587 (void) FormatImageProperty(image,"cin:origination.x_offset","%ld",
588 cin.origination.x_offset);
589 cin.origination.y_offset=(long) ReadBlobLong(image);
591 if ((unsigned long) cin.origination.y_offset != ~0UL)
592 (void) FormatImageProperty(image,"cin:origination.y_offset","%ld",
593 cin.origination.y_offset);
594 offset+=ReadBlob(image,sizeof(cin.origination.filename),(unsigned char *)
595 cin.origination.filename);
596 (void) SetImageProperty(image,"cin:origination.filename",
597 cin.origination.filename);
598 offset+=ReadBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
599 cin.origination.create_date);
600 (void) SetImageProperty(image,"cin:origination.create_date",
601 cin.origination.create_date);
602 offset+=ReadBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
603 cin.origination.create_time);
604 (void) SetImageProperty(image,"cin:origination.create_time",
605 cin.origination.create_time);
606 offset+=ReadBlob(image,sizeof(cin.origination.device),(unsigned char *)
607 cin.origination.device);
608 (void) SetImageProperty(image,"cin:origination.device",
609 cin.origination.device);
610 offset+=ReadBlob(image,sizeof(cin.origination.model),(unsigned char *)
611 cin.origination.model);
612 (void) SetImageProperty(image,"cin:origination.model",cin.origination.model);
613 offset+=ReadBlob(image,sizeof(cin.origination.serial),(unsigned char *)
614 cin.origination.serial);
615 (void) SetImageProperty(image,"cin:origination.serial",
616 cin.origination.serial);
617 cin.origination.x_pitch=ReadBlobFloat(image);
619 cin.origination.y_pitch=ReadBlobFloat(image);
621 cin.origination.gamma=ReadBlobFloat(image);
623 if (IsFloatDefined(cin.origination.gamma) != MagickFalse)
624 image->gamma=cin.origination.gamma;
625 offset+=ReadBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
626 cin.origination.reserve);
627 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
630 Image film information.
632 cin.film.id=ReadBlobByte(image);
634 if ((unsigned long) cin.film.id != ~0UL)
635 (void) FormatImageProperty(image,"cin:film.id","%d",cin.film.id);
636 cin.film.type=ReadBlobByte(image);
638 if ((unsigned long) cin.film.type != ~0UL)
639 (void) FormatImageProperty(image,"cin:film.type","%d",cin.film.type);
640 cin.film.offset=ReadBlobByte(image);
642 if ((unsigned long) cin.film.offset != ~0UL)
643 (void) FormatImageProperty(image,"cin:film.offset","%d",
645 cin.film.reserve1=ReadBlobByte(image);
647 cin.film.prefix=ReadBlobLong(image);
649 if (cin.film.prefix != ~0UL)
650 (void) FormatImageProperty(image,"cin:film.prefix","%lu",
652 cin.film.count=ReadBlobLong(image);
654 offset+=ReadBlob(image,sizeof(cin.film.format),(unsigned char *)
656 (void) SetImageProperty(image,"cin:film.format",cin.film.format);
657 cin.film.frame_position=ReadBlobLong(image);
659 if (cin.film.frame_position != ~0UL)
660 (void) FormatImageProperty(image,"cin:film.frame_position","%lu",
661 cin.film.frame_position);
662 cin.film.frame_rate=ReadBlobFloat(image);
664 if (IsFloatDefined(cin.film.frame_rate) != MagickFalse)
665 (void) FormatImageProperty(image,"cin:film.frame_rate","%g",
666 cin.film.frame_rate);
667 offset+=ReadBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
669 (void) SetImageProperty(image,"cin:film.frame_id",cin.film.frame_id);
670 offset+=ReadBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
671 cin.film.slate_info);
672 (void) SetImageProperty(image,"cin:film.slate_info",cin.film.slate_info);
673 offset+=ReadBlob(image,sizeof(cin.film.reserve),(unsigned char *)
676 if ((cin.file.image_offset > 2048) && (cin.file.user_length != 0))
684 profile=AcquireStringInfo(cin.file.user_length);
685 offset+=ReadBlob(image,GetStringInfoLength(profile),
686 GetStringInfoDatum(profile));
687 (void) SetImageProfile(image,"cin:user.data",profile);
688 profile=DestroyStringInfo(profile);
690 for ( ; offset < (long) cin.file.image_offset; offset++)
691 (void) ReadBlobByte(image);
692 image->depth=cin.image.channel[0].bits_per_pixel;
693 image->columns=cin.image.channel[0].pixels_per_line;
694 image->rows=cin.image.channel[0].lines_per_image;
695 if (image_info->ping)
697 (void) CloseBlob(image);
701 Convert CIN raster image to pixel packets.
703 quantum_info=AcquireQuantumInfo(image_info,image);
704 if (quantum_info == (QuantumInfo *) NULL)
705 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
706 quantum_info->quantum=32;
707 quantum_info->pack=MagickFalse;
708 quantum_type=RGBQuantum;
709 pixels=GetQuantumPixels(quantum_info);
710 length=GetQuantumExtent(image,quantum_info,quantum_type);
711 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
712 if (cin.image.number_channels == 1)
714 quantum_type=GrayQuantum;
715 length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue);
717 for (y=0; y < (long) image->rows; y++)
719 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
720 if (q == (PixelPacket *) NULL)
722 count=ReadBlob(image,length,pixels);
723 if ((size_t) count != length)
725 (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
726 quantum_type,pixels,exception);
727 if (SyncAuthenticPixels(image,exception) == MagickFalse)
729 if (image->previous == (Image *) NULL)
731 status=SetImageProgress(image,LoadImageTag,y,image->rows);
732 if (status == MagickFalse)
736 SetQuantumImageType(image,quantum_type);
737 quantum_info=DestroyQuantumInfo(quantum_info);
738 if (EOFBlob(image) != MagickFalse)
739 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
741 image->colorspace=LogColorspace;
742 (void) CloseBlob(image);
743 return(GetFirstImageInList(image));
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % R e g i s t e r C I N E O N I m a g e %
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % RegisterCINImage() adds attributes for the CIN image format to the list of
758 % of supported formats. The attributes include the image format tag, a method
759 % to read and/or write the format, whether the format supports the saving of
760 % more than one frame to the same file or blob, whether the format supports
761 % native in-memory I/O, and a brief description of the format.
763 % The format of the RegisterCINImage method is:
765 % unsigned long RegisterCINImage(void)
768 ModuleExport unsigned long RegisterCINImage(void)
773 entry=SetMagickInfo("CIN");
774 entry->decoder=(DecodeImageHandler *) ReadCINImage;
775 entry->encoder=(EncodeImageHandler *) WriteCINImage;
776 entry->magick=(IsImageFormatHandler *) IsCIN;
777 entry->description=ConstantString("Cineon Image File");
778 entry->module=ConstantString("CIN");
779 (void) RegisterMagickInfo(entry);
780 return(MagickImageCoderSignature);
784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 % U n r e g i s t e r C I N E O N I m a g e %
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
794 % UnregisterCINImage() removes format registrations made by the CIN module
795 % from the list of supported formats.
797 % The format of the UnregisterCINImage method is:
799 % UnregisterCINImage(void)
802 ModuleExport void UnregisterCINImage(void)
804 (void) UnregisterMagickInfo("CINEON");
808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 % W r i t e C I N E O N I m a g e %
816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
818 % WriteCINImage() writes an image in CIN encoded image format.
820 % The format of the WriteCINImage method is:
822 % MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image)
824 % A description of each parameter follows.
826 % o image_info: the image info.
828 % o image: The image.
832 static inline const char *GetCINProperty(const ImageInfo *image_info,
833 const Image *image,const char *property)
838 value=GetImageOption(image_info,property);
839 if (value != (const char *) NULL)
841 return(GetImageProperty(image,property));
844 static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image)
870 register const PixelPacket
892 Open output image file.
894 assert(image_info != (const ImageInfo *) NULL);
895 assert(image_info->signature == MagickSignature);
896 assert(image != (Image *) NULL);
897 assert(image->signature == MagickSignature);
898 if (image->debug != MagickFalse)
899 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
900 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
901 if (status == MagickFalse)
903 if (image->colorspace != LogColorspace)
904 (void) TransformImageColorspace(image,LogColorspace);
906 Write image information.
908 (void) ResetMagickMemory(&cin,0,sizeof(cin));
910 cin.file.magic=0x802A5FD7UL;
911 offset+=WriteBlobLong(image,cin.file.magic);
912 cin.file.image_offset=0x800;
913 profile=GetImageProfile(image,"cin:user.data");
914 if (profile != (StringInfo *) NULL)
916 cin.file.image_offset+=(unsigned long) GetStringInfoLength(profile);
917 cin.file.image_offset=(((cin.file.image_offset+0x2000-1)/0x2000)*0x2000);
919 offset+=WriteBlobLong(image,cin.file.image_offset);
920 cin.file.generic_length=0x400;
921 offset+=WriteBlobLong(image,cin.file.generic_length);
922 cin.file.industry_length=0x400;
923 offset+=WriteBlobLong(image,cin.file.industry_length);
924 cin.file.user_length=0x00;
925 if (profile != (StringInfo *) NULL)
927 cin.file.user_length+=(unsigned long) GetStringInfoLength(profile);
928 cin.file.user_length=(((cin.file.user_length+0x2000-1)/0x2000)*0x2000);
930 offset+=WriteBlobLong(image,cin.file.user_length);
931 cin.file.file_size=4*image->columns*image->rows+0x2000;
932 offset+=WriteBlobLong(image,cin.file.file_size);
933 (void) CopyMagickString(cin.file.version,"V4.5",sizeof(cin.file.version));
934 offset+=WriteBlob(image,sizeof(cin.file.version),(unsigned char *)
936 value=GetCINProperty(image_info,image,"cin:file.filename");
937 if (value != (const char *) NULL)
938 (void) CopyMagickString(cin.file.filename,value,sizeof(cin.file.filename));
940 (void) CopyMagickString(cin.file.filename,image->filename,
941 sizeof(cin.file.filename));
942 offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *)
944 seconds=time((time_t *) NULL);
945 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
946 (void) localtime_r(&seconds,&local_time);
948 (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
950 (void) strftime(cin.file.create_date,sizeof(cin.file.create_date),"%Y:%m:%d",
952 offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *)
953 cin.file.create_date);
954 (void) strftime(cin.file.create_time,sizeof(cin.file.create_time),
955 "%H:%M:%S%Z",&local_time);
956 offset+=WriteBlob(image,sizeof(cin.file.create_time),(unsigned char *)
957 cin.file.create_time);
958 offset+=WriteBlob(image,sizeof(cin.file.reserve),(unsigned char *)
960 cin.image.orientation=0x00;
961 offset+=WriteBlobByte(image,cin.image.orientation);
962 cin.image.number_channels=3;
963 offset+=WriteBlobByte(image,cin.image.number_channels);
964 offset+=WriteBlob(image,sizeof(cin.image.reserve1),(unsigned char *)
966 for (i=0; i < 8; i++)
968 cin.image.channel[i].designator[0]=0; /* universal metric */
969 offset+=WriteBlobByte(image,cin.image.channel[0].designator[0]);
970 cin.image.channel[i].designator[1]=(unsigned char) (i > 3 ? 0 : i+1); /* channel color */;
971 offset+=WriteBlobByte(image,cin.image.channel[1].designator[0]);
972 cin.image.channel[i].bits_per_pixel=(unsigned char) image->depth;
973 offset+=WriteBlobByte(image,cin.image.channel[0].bits_per_pixel);
974 offset+=WriteBlobByte(image,cin.image.channel[0].reserve);
975 cin.image.channel[i].pixels_per_line=image->columns;
976 offset+=WriteBlobLong(image,cin.image.channel[0].pixels_per_line);
977 cin.image.channel[i].lines_per_image=image->rows;
978 offset+=WriteBlobLong(image,cin.image.channel[0].lines_per_image);
979 cin.image.channel[i].min_data=0;
980 offset+=WriteBlobFloat(image,cin.image.channel[0].min_data);
981 cin.image.channel[i].min_quantity=0.0;
982 offset+=WriteBlobFloat(image,cin.image.channel[0].min_quantity);
983 cin.image.channel[i].max_data=(float) ((MagickOffsetType)
984 GetQuantumRange(image->depth));
985 offset+=WriteBlobFloat(image,cin.image.channel[0].max_data);
986 cin.image.channel[i].max_quantity=2.048f;
987 offset+=WriteBlobFloat(image,cin.image.channel[0].max_quantity);
989 offset+=WriteBlobFloat(image,image->chromaticity.white_point.x);
990 offset+=WriteBlobFloat(image,image->chromaticity.white_point.y);
991 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.x);
992 offset+=WriteBlobFloat(image,image->chromaticity.red_primary.y);
993 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.x);
994 offset+=WriteBlobFloat(image,image->chromaticity.green_primary.y);
995 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.x);
996 offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.y);
997 value=GetCINProperty(image_info,image,"cin:image.label");
998 if (value != (const char *) NULL)
999 (void) CopyMagickString(cin.image.label,value,sizeof(cin.image.label));
1000 offset+=WriteBlob(image,sizeof(cin.image.label),(unsigned char *)
1002 offset+=WriteBlob(image,sizeof(cin.image.reserve),(unsigned char *)
1005 Write data format information.
1007 cin.data_format.interleave=0; /* pixel interleave (rgbrgbr...) */
1008 offset+=WriteBlobByte(image,cin.data_format.interleave);
1009 cin.data_format.packing=5; /* packing longword (32bit) boundaries */
1010 offset+=WriteBlobByte(image,cin.data_format.packing);
1011 cin.data_format.sign=0; /* unsigned data */
1012 offset+=WriteBlobByte(image,cin.data_format.sign);
1013 cin.data_format.sense=0; /* image sense: positive image */
1014 offset+=WriteBlobByte(image,cin.data_format.sense);
1015 cin.data_format.line_pad=0;
1016 offset+=WriteBlobLong(image,cin.data_format.line_pad);
1017 cin.data_format.channel_pad=0;
1018 offset+=WriteBlobLong(image,cin.data_format.channel_pad);
1019 offset+=WriteBlob(image,sizeof(cin.data_format.reserve),(unsigned char *)
1020 cin.data_format.reserve);
1022 Write origination information.
1024 cin.origination.x_offset=0UL;
1025 value=GetCINProperty(image_info,image,"cin:origination.x_offset");
1026 if (value != (const char *) NULL)
1027 cin.origination.x_offset=StringToLong(value);
1028 offset+=WriteBlobLong(image,(unsigned long) cin.origination.x_offset);
1029 cin.origination.y_offset=0UL;
1030 value=GetCINProperty(image_info,image,"cin:origination.y_offset");
1031 if (value != (const char *) NULL)
1032 cin.origination.y_offset=StringToLong(value);
1033 offset+=WriteBlobLong(image,(unsigned long) cin.origination.y_offset);
1034 value=GetCINProperty(image_info,image,"cin:origination.filename");
1035 if (value != (const char *) NULL)
1036 (void) CopyMagickString(cin.origination.filename,value,
1037 sizeof(cin.origination.filename));
1039 (void) CopyMagickString(cin.origination.filename,image->filename,
1040 sizeof(cin.origination.filename));
1041 offset+=WriteBlob(image,sizeof(cin.origination.filename),(unsigned char *)
1042 cin.origination.filename);
1043 seconds=time((time_t *) NULL);
1044 (void) strftime(cin.origination.create_date,
1045 sizeof(cin.origination.create_date),"%Y:%m:%d",&local_time);
1046 offset+=WriteBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
1047 cin.origination.create_date);
1048 (void) strftime(cin.origination.create_time,
1049 sizeof(cin.origination.create_time),"%H:%M:%S%Z",&local_time);
1050 offset+=WriteBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
1051 cin.origination.create_time);
1052 value=GetCINProperty(image_info,image,"cin:origination.device");
1053 if (value != (const char *) NULL)
1054 (void) CopyMagickString(cin.origination.device,value,
1055 sizeof(cin.origination.device));
1056 offset+=WriteBlob(image,sizeof(cin.origination.device),(unsigned char *)
1057 cin.origination.device);
1058 value=GetCINProperty(image_info,image,"cin:origination.model");
1059 if (value != (const char *) NULL)
1060 (void) CopyMagickString(cin.origination.model,value,
1061 sizeof(cin.origination.model));
1062 offset+=WriteBlob(image,sizeof(cin.origination.model),(unsigned char *)
1063 cin.origination.model);
1064 value=GetCINProperty(image_info,image,"cin:origination.serial");
1065 if (value != (const char *) NULL)
1066 (void) CopyMagickString(cin.origination.serial,value,
1067 sizeof(cin.origination.serial));
1068 offset+=WriteBlob(image,sizeof(cin.origination.serial),(unsigned char *)
1069 cin.origination.serial);
1070 cin.origination.x_pitch=0.0f;
1071 value=GetCINProperty(image_info,image,"cin:origination.x_pitch");
1072 if (value != (const char *) NULL)
1073 cin.origination.x_pitch=StringToDouble(value);
1074 offset+=WriteBlobFloat(image,cin.origination.x_pitch);
1075 cin.origination.y_pitch=0.0f;
1076 value=GetCINProperty(image_info,image,"cin:origination.y_pitch");
1077 if (value != (const char *) NULL)
1078 cin.origination.y_pitch=StringToDouble(value);
1079 offset+=WriteBlobFloat(image,cin.origination.y_pitch);
1080 cin.origination.gamma=image->gamma;
1081 offset+=WriteBlobFloat(image,cin.origination.gamma);
1082 offset+=WriteBlob(image,sizeof(cin.origination.reserve),(unsigned char *)
1083 cin.origination.reserve);
1085 Image film information.
1088 value=GetCINProperty(image_info,image,"cin:film.id");
1089 if (value != (const char *) NULL)
1090 cin.film.id=(char) StringToLong(value);
1091 offset+=WriteBlobByte(image,(unsigned char) cin.film.id);
1093 value=GetCINProperty(image_info,image,"cin:film.type");
1094 if (value != (const char *) NULL)
1095 cin.film.type=(char) StringToLong(value);
1096 offset+=WriteBlobByte(image,(unsigned char) cin.film.type);
1098 value=GetCINProperty(image_info,image,"cin:film.offset");
1099 if (value != (const char *) NULL)
1100 cin.film.offset=(char) StringToLong(value);
1101 offset+=WriteBlobByte(image,(unsigned char) cin.film.offset);
1102 offset+=WriteBlobByte(image,(unsigned char) cin.film.reserve1);
1103 cin.film.prefix=0UL;
1104 value=GetCINProperty(image_info,image,"cin:film.prefix");
1105 if (value != (const char *) NULL)
1106 cin.film.prefix=(unsigned long) StringToLong(value);
1107 offset+=WriteBlobLong(image,cin.film.prefix);
1109 value=GetCINProperty(image_info,image,"cin:film.count");
1110 if (value != (const char *) NULL)
1111 cin.film.count=(unsigned long) StringToLong(value);
1112 offset+=WriteBlobLong(image,cin.film.count);
1113 value=GetCINProperty(image_info,image,"cin:film.format");
1114 if (value != (const char *) NULL)
1115 (void) CopyMagickString(cin.film.format,value,sizeof(cin.film.format));
1116 offset+=WriteBlob(image,sizeof(cin.film.format),(unsigned char *)
1118 cin.film.frame_position=0UL;
1119 value=GetCINProperty(image_info,image,"cin:film.frame_position");
1120 if (value != (const char *) NULL)
1121 cin.film.frame_position=(unsigned long) StringToLong(value);
1122 offset+=WriteBlobLong(image,cin.film.frame_position);
1123 cin.film.frame_rate=0.0f;
1124 value=GetCINProperty(image_info,image,"cin:film.frame_rate");
1125 if (value != (const char *) NULL)
1126 cin.film.frame_rate=StringToDouble(value);
1127 offset+=WriteBlobFloat(image,cin.film.frame_rate);
1128 value=GetCINProperty(image_info,image,"cin:film.frame_id");
1129 if (value != (const char *) NULL)
1130 (void) CopyMagickString(cin.film.frame_id,value,sizeof(cin.film.frame_id));
1131 offset+=WriteBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
1133 value=GetCINProperty(image_info,image,"cin:film.slate_info");
1134 if (value != (const char *) NULL)
1135 (void) CopyMagickString(cin.film.slate_info,value,
1136 sizeof(cin.film.slate_info));
1137 offset+=WriteBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
1138 cin.film.slate_info);
1139 offset+=WriteBlob(image,sizeof(cin.film.reserve),(unsigned char *)
1141 if (profile != (StringInfo *) NULL)
1142 offset+=WriteBlob(image,GetStringInfoLength(profile),
1143 GetStringInfoDatum(profile));
1144 while (offset < (MagickOffsetType) cin.file.image_offset)
1145 offset+=WriteBlobByte(image,0x00);
1147 Convert pixel packets to CIN raster image.
1149 quantum_info=AcquireQuantumInfo(image_info,image);
1150 if (quantum_info == (QuantumInfo *) NULL)
1151 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1152 quantum_info->quantum=32;
1153 quantum_info->pack=MagickFalse;
1154 quantum_type=RGBQuantum;
1155 pixels=GetQuantumPixels(quantum_info);
1156 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1159 quantum_type=GrayQuantum;
1160 length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1162 for (y=0; y < (long) image->rows; y++)
1164 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1165 if (p == (const PixelPacket *) NULL)
1167 (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
1168 quantum_type,pixels,&image->exception);
1169 count=WriteBlob(image,length,pixels);
1170 if (count != (ssize_t) length)
1172 status=SetImageProgress(image,SaveImageTag,y,image->rows);
1173 if (status == MagickFalse)
1176 quantum_info=DestroyQuantumInfo(quantum_info);
1177 (void) CloseBlob(image);