static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, Image *image) { char header[129]; Image *group4_image; ImageInfo *write_info; MagickBooleanType status; register ssize_t i; size_t density, length, orient_x, orient_y; ssize_t count; unsigned char *group4; /* Open output image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); if (status == MagickFalse) return(status); /* Create standard CALS header. */ count=WriteCALSRecord(image,"srcdocid: NONE"); (void) count; count=WriteCALSRecord(image,"dstdocid: NONE"); count=WriteCALSRecord(image,"txtfilid: NONE"); count=WriteCALSRecord(image,"figid: NONE"); count=WriteCALSRecord(image,"srcgph: NONE"); count=WriteCALSRecord(image,"docls: NONE"); count=WriteCALSRecord(image,"rtype: 1"); orient_x=0; orient_y=0; switch (image->orientation) { case TopRightOrientation: { orient_x=180; orient_y=270; break; } case BottomRightOrientation: { orient_x=180; orient_y=90; break; } case BottomLeftOrientation: { orient_y=90; break; } case LeftTopOrientation: { orient_x=270; break; } case RightTopOrientation: { orient_x=270; orient_y=180; break; } case RightBottomOrientation: { orient_x=90; orient_y=180; break; } case LeftBottomOrientation: { orient_x=90; break; } default: { orient_y=270; } } (void) FormatLocaleString(header,MaxTextExtent,"rorient: %03ld,%03ld", (long) orient_x,(long) orient_y); count=WriteCALSRecord(image,header); (void) FormatLocaleString(header,MaxTextExtent,"rpelcnt: %06lu,%06lu", (unsigned long) image->columns,(unsigned long) image->rows); count=WriteCALSRecord(image,header); density=200; if (image_info->density != (char *) NULL) { GeometryInfo geometry_info; (void) ParseGeometry(image_info->density,&geometry_info); density=(size_t) floor(geometry_info.rho+0.5); } (void) FormatLocaleString(header,MaxTextExtent,"rdensty: %04lu", (unsigned long) density); count=WriteCALSRecord(image,header); count=WriteCALSRecord(image,"notes: NONE"); (void) ResetMagickMemory(header,' ',128); for (i=0; i < 5; i++) (void) WriteBlob(image,128,(unsigned char *) header); /* Write CALS pixels. */ write_info=CloneImageInfo(image_info); (void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent); (void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent); group4_image=CloneImage(image,0,0,MagickTrue,&image->exception); if (group4_image == (Image *) NULL) { (void) CloseBlob(image); return(MagickFalse); } group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length, &image->exception); group4_image=DestroyImage(group4_image); if (group4 == (unsigned char *) NULL) { (void) CloseBlob(image); return(MagickFalse); } write_info=DestroyImageInfo(write_info); if (WriteBlob(image,length,group4) != (ssize_t) length) status=MagickFalse; group4=(unsigned char *) RelinquishMagickMemory(group4); (void) CloseBlob(image); return(status); }
static MagickPassFail WriteCALSImage(const ImageInfo *image_info,Image *image) { char buffer[MaxTextExtent]; int i; long sans; unsigned long density; int orx, ory; MagickPassFail status=MagickPass; /* Validate input image */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); /* Open output image file. */ if (OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception) == MagickFail) ThrowWriterException(FileOpenError,UnableToOpenFile,image); /* Create standard header */ WriteCALSRecord(image,"srcdocid: NONE"); WriteCALSRecord(image,"dstdocid: NONE"); WriteCALSRecord(image,"txtfilid: NONE"); WriteCALSRecord(image,"figid: NONE"); WriteCALSRecord(image,"srcgph: NONE"); WriteCALSRecord(image,"docls: NONE"); WriteCALSRecord(image,"rtype: 1"); /* orientation based on input or default of upright */ switch (image->orientation) { case TopRightOrientation: orx=180; ory=270; break; case BottomRightOrientation: orx=180; ory=90; break; case BottomLeftOrientation: orx=0; ory=90; break; case LeftTopOrientation: orx=270; ory=0; break; case RightTopOrientation: orx=270; ory=180; break; case RightBottomOrientation: orx=90; ory=180; break; case LeftBottomOrientation: orx=90; ory=0; break; default: orx=0; ory=270; } FormatString(buffer,"rorient: %03d,%03d",orx,ory); WriteCALSRecord(image,buffer); /* pixel counts based on columns/rows of input */ FormatString(buffer,"rpelcnt: %06ld,%06ld",image->columns,image->rows); WriteCALSRecord(image,buffer); /* density based on input density or default of 200 */ density=200; if (image_info->density != (char *) NULL) (void) GetGeometry(image_info->density,&sans,&sans,&density,&density); FormatString(buffer,"rdensty: %04ld",density); WriteCALSRecord(image,buffer); WriteCALSRecord(image,"notes: NONE"); /* Pad header to make 16 records / 2048 bytes */ memset(buffer,' ',128); for (i = 0; i < 5; i++) if (WriteBlob(image,128,buffer) != 128) status=MagickFail; /* Encode data to Group 4 */ if (MagickFail != status) { unsigned char *blob; size_t blob_length; blob=ImageToHuffman2DBlob(image,image_info,&blob_length,&image->exception); if (blob == (unsigned char *) NULL) status=MagickFail; if (MagickFail != status) { if (WriteBlob(image,blob_length,blob) != blob_length) status=MagickFail; } MagickFreeMemory(blob); } /* Close output file and return image */ CloseBlob(image); return status; }