From: cristy Date: Fri, 25 Sep 2009 03:18:25 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~10641 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d6ccc32baf7e3e71a566f4c55ac9342ccc9b5e0;p=imagemagick --- diff --git a/Makefile.in b/Makefile.in index ffd008bf2..4b5bfa384 100644 --- a/Makefile.in +++ b/Makefile.in @@ -421,9 +421,7 @@ coders_braille_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_CFLAGS) $(CFLAGS) $(coders_braille_la_LDFLAGS) $(LDFLAGS) \ -o $@ @WITH_MODULES_TRUE@am_coders_braille_la_rpath = -rpath $(codersdir) -coders_cals_la_DEPENDENCIES = $(MAGICKCORE_LIBS) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) +coders_cals_la_DEPENDENCIES = $(MAGICKCORE_LIBS) am_coders_cals_la_OBJECTS = coders/coders_cals_la-cals.lo coders_cals_la_OBJECTS = $(am_coders_cals_la_OBJECTS) coders_cals_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ @@ -3035,7 +3033,7 @@ coders_braille_la_LIBADD = $(MAGICKCORE_LIBS) coders_cals_la_SOURCES = coders/cals.c coders_cals_la_CPPFLAGS = $(MODULE_EXTRA_CPPFLAGS) coders_cals_la_LDFLAGS = $(MODULECOMMONFLAGS) -coders_cals_la_LIBADD = $(MAGICKCORE_LIBS) $(TIFF_LIBS) $(JBIG_LIBS) $(JPEG_LIBS) $(MATH_LIBS) +coders_cals_la_LIBADD = $(MAGICKCORE_LIBS) # CAPTION coder module coders_caption_la_SOURCES = coders/caption.c diff --git a/coders/Makefile.am b/coders/Makefile.am index 30f5bc103..6ce099941 100644 --- a/coders/Makefile.am +++ b/coders/Makefile.am @@ -337,7 +337,7 @@ coders_braille_la_LIBADD = $(MAGICKCORE_LIBS) coders_cals_la_SOURCES = coders/cals.c coders_cals_la_CPPFLAGS = $(MODULE_EXTRA_CPPFLAGS) coders_cals_la_LDFLAGS = $(MODULECOMMONFLAGS) -coders_cals_la_LIBADD = $(MAGICKCORE_LIBS) $(TIFF_LIBS) $(JBIG_LIBS) $(JPEG_LIBS) $(MATH_LIBS) +coders_cals_la_LIBADD = $(MAGICKCORE_LIBS) # CAPTION coder module coders_caption_la_SOURCES = coders/caption.c diff --git a/coders/cals.c b/coders/cals.c index 90d156bc2..a4f46f4d9 100644 --- a/coders/cals.c +++ b/coders/cals.c @@ -65,15 +65,6 @@ #include "magick/static.h" #include "magick/string_.h" #include "magick/module.h" -#if defined(MAGICKCORE_TIFF_DELEGATE) -#if defined(MAGICKCORE_HAVE_TIFFCONF_H) -#include "tiffconf.h" -#endif -#include "tiffio.h" -#define CCITTParam "-1" -#else -#define CCITTParam "0" -#endif /* Forward declarations. @@ -146,31 +137,19 @@ static MagickBooleanType IsCALS(const unsigned char *magick,const size_t length) % o exception: return any errors or warnings in this structure. % */ - -static inline size_t WriteCALSLSBLong(FILE *file,const unsigned int value) -{ - unsigned char - buffer[4]; - - buffer[0]=(unsigned char) value; - buffer[1]=(unsigned char) (value >> 8); - buffer[2]=(unsigned char) (value >> 16); - buffer[3]=(unsigned char) (value >> 24); - return(fwrite(buffer,1,4,file)); -} - -#if defined(MAGICKCORE_TIFF_DELEGATE) -static Image *Huffman2DDecodeImage(const ImageInfo *image_info,Image *image, +static Image *ReadCALSImage(const ImageInfo *image_info, ExceptionInfo *exception) { char - filename[MaxTextExtent]; + filename[MaxTextExtent], + header[129], + message[MaxTextExtent]; FILE *file; Image - *huffman_image; + *image; ImageInfo *read_info; @@ -179,97 +158,6 @@ static Image *Huffman2DDecodeImage(const ImageInfo *image_info,Image *image, c, unique_file; - size_t - length; - - ssize_t - offset, - strip_offset; - - /* - Write CALS facsimile document wrapped as a TIFF image file. - */ - file=(FILE *) NULL; - unique_file=AcquireUniqueFileResource(filename); - if (unique_file != -1) - file=fdopen(unique_file,"wb"); - if ((unique_file == -1) || (file == (FILE *) NULL)) - ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile"); - length=fwrite("\111\111\052\000\010\000\000\000\016\000",1,10,file); - length=fwrite("\376\000\003\000\001\000\000\000\000\000\000\000",1,12,file); - length=fwrite("\000\001\004\000\001\000\000\000",1,8,file); - length=WriteCALSLSBLong(file,image->columns); - length=fwrite("\001\001\004\000\001\000\000\000",1,8,file); - length=WriteCALSLSBLong(file,image->rows); - length=fwrite("\002\001\003\000\001\000\000\000\001\000\000\000",1,12,file); - length=fwrite("\003\001\003\000\001\000\000\000\004\000\000\000",1,12,file); - length=fwrite("\006\001\003\000\001\000\000\000\000\000\000\000",1,12,file); - length=fwrite("\021\001\003\000\001\000\000\000",1,8,file); - strip_offset=10+(12*14)+4+8; - length=WriteCALSLSBLong(file,(unsigned long) strip_offset); - length=fwrite("\022\001\003\000\001\000\000\000",1,8,file); - length=WriteCALSLSBLong(file,(unsigned long) image->orientation); - length=fwrite("\025\001\003\000\001\000\000\000\001\000\000\000",1,12,file); - length=fwrite("\026\001\004\000\001\000\000\000",1,8,file); - length=WriteCALSLSBLong(file,image->columns); - length=fwrite("\027\001\004\000\001\000\000\000\000\000\000\000",1,12,file); - offset=(ssize_t) ftell(file)-4; - length=fwrite("\032\001\005\000\001\000\000\000",1,8,file); - length=WriteCALSLSBLong(file,(unsigned long) (strip_offset-8)); - length=fwrite("\033\001\005\000\001\000\000\000",1,8,file); - length=WriteCALSLSBLong(file,(unsigned long) (strip_offset-8)); - length=fwrite("\050\001\003\000\001\000\000\000\002\000\000\000",1,12,file); - length=fwrite("\000\000\000\000",1,4,file); - length=WriteCALSLSBLong(file,image->x_resolution); - length=WriteCALSLSBLong(file,1); - for (length=0; (c=ReadBlobByte(image)) != EOF; length++) - (void) fputc(c,file); - (void) CloseBlob(image); - offset=(ssize_t) fseek(file,(long) offset,SEEK_SET); - length=WriteCALSLSBLong(file,(unsigned int) length); - (void) fclose(file); - /* - Read TIFF image. - */ - read_info=CloneImageInfo(image_info); - SetImageInfoBlob(read_info,(void *) NULL,0); - (void) FormatMagickString(read_info->filename,MaxTextExtent,"tiff:%.1024s", - filename); - huffman_image=ReadImage(read_info,exception); - if (huffman_image != (Image *) NULL) - { - (void) CopyMagickString(huffman_image->filename,image_info->filename, - MaxTextExtent); - (void) CopyMagickString(huffman_image->magick_filename, - image_info->filename,MaxTextExtent); - (void) CopyMagickString(huffman_image->magick,"CALS",MaxTextExtent); - } - read_info=DestroyImageInfo(read_info); - (void) RelinquishUniqueFileResource(filename); - return(huffman_image); -} -#else -static Image *Huffman2DDecodeImage(const ImageInfo *magick_unused(image_info), - Image *image,ExceptionInfo *exception) -{ - assert(image != (Image *) NULL); - assert(image->signature == MagickSignature); - (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError, - "DelegateLibrarySupportNotBuiltIn","`%s' (TIFF)",image->filename); - return((Image *) NULL); -} -#endif - -static Image *ReadCALSImage(const ImageInfo *image_info, - ExceptionInfo *exception) -{ - char - header[129]; - - Image - *huffman_image, - *image; - MagickBooleanType status; @@ -356,19 +244,41 @@ static Image *ReadCALSImage(const ImageInfo *image_info, } } } - if ((width == 0) || (height == 0) || (type == 0)) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); - image->columns=width; - image->rows=height; - image->x_resolution=(double) density; - image->y_resolution=(double) density; - image->orientation=(OrientationType) orientation; - huffman_image=Huffman2DDecodeImage(image_info,image,exception); + /* + Read CALS pixels. + */ + file=(FILE *) NULL; + unique_file=AcquireUniqueFileResource(filename); + if (unique_file != -1) + file=fdopen(unique_file,"wb"); + if ((unique_file == -1) || (file == (FILE *) NULL)) + ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile"); + while ((c=ReadBlobByte(image)) != EOF) + (void) fputc(c,file); + (void) fclose(file); + (void) CloseBlob(image); image=DestroyImage(image); - (void) CloseBlob(huffman_image); - if (huffman_image == (Image *) NULL) - return(huffman_image); - return(GetFirstImageInList(huffman_image)); + read_info=CloneImageInfo(image_info); + SetImageInfoBlob(read_info,(void *) NULL,0); + (void) FormatMagickString(read_info->filename,MaxTextExtent,"group4:%.1024s", + filename); + (void) FormatMagickString(message,MaxTextExtent,"%lux%lu",width,height); + read_info->size=ConstantString(message); + (void) FormatMagickString(message,MaxTextExtent,"%lu",density); + read_info->density=ConstantString(message); + read_info->orientation=(OrientationType) orientation; + image=ReadImage(read_info,exception); + if (image != (Image *) NULL) + { + (void) CopyMagickString(image->filename,image_info->filename, + MaxTextExtent); + (void) CopyMagickString(image->magick_filename,image_info->filename, + MaxTextExtent); + (void) CopyMagickString(image->magick,"CALS",MaxTextExtent); + } + read_info=DestroyImageInfo(read_info); + (void) RelinquishUniqueFileResource(filename); + return(image); } /* @@ -486,155 +396,6 @@ ModuleExport void UnregisterCALSImage(void) % */ -#if defined(MAGICKCORE_TIFF_DELEGATE) -static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info, - Image *image,Image *inject_image) -{ - char - filename[MaxTextExtent]; - - FILE - *file; - - Image - *huffman_image; - - ImageInfo - *write_info; - - int - unique_file; - - MagickBooleanType - status; - - register long - i; - - ssize_t - count; - - TIFF - *tiff; - - uint16 - fillorder; - - uint32 - *byte_count, - strip_size; - - unsigned char - *buffer; - - /* - Write image as CCITTFax4 TIFF image to a temporary 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); - assert(inject_image != (Image *) NULL); - assert(inject_image->signature == MagickSignature); - huffman_image=CloneImage(inject_image,0,0,MagickTrue,&image->exception); - if (huffman_image == (Image *) NULL) - return(MagickFalse); - file=(FILE *) NULL; - unique_file=AcquireUniqueFileResource(filename); - if (unique_file != -1) - file=fdopen(unique_file,"wb"); - if ((unique_file == -1) || (file == (FILE *) NULL)) - { - ThrowFileException(&image->exception,FileOpenError, - "UnableToCreateTemporaryFile",filename); - return(MagickFalse); - } - (void) FormatMagickString(huffman_image->filename,MaxTextExtent,"tiff:%s", - filename); - write_info=CloneImageInfo(image_info); - SetImageInfoFile(write_info,file); - write_info->compression=Group4Compression; - write_info->type=BilevelType; - (void) SetImageOption(write_info,"quantum:polarity","min-is-white"); - status=WriteImage(write_info,huffman_image); - (void) fflush(file); - write_info=DestroyImageInfo(write_info); - if (status == MagickFalse) - { - (void) RelinquishUniqueFileResource(filename); - return(MagickFalse); - } - tiff=TIFFOpen(filename,"rb"); - if (tiff == (TIFF *) NULL) - { - huffman_image=DestroyImage(huffman_image); - (void) fclose(file); - (void) RelinquishUniqueFileResource(filename); - ThrowFileException(&image->exception,FileOpenError,"UnableToOpenFile", - image_info->filename); - return(MagickFalse); - } - /* - Allocate raw strip buffer. - */ - byte_count=0; - (void) TIFFGetField(tiff,TIFFTAG_STRIPBYTECOUNTS,&byte_count); - strip_size=byte_count[0]; - for (i=1; i < (long) TIFFNumberOfStrips(tiff); i++) - if (byte_count[i] > strip_size) - strip_size=byte_count[i]; - buffer=(unsigned char *) AcquireQuantumMemory((size_t) strip_size, - sizeof(*buffer)); - if (buffer == (unsigned char *) NULL) - { - TIFFClose(tiff); - huffman_image=DestroyImage(huffman_image); - (void) fclose(file); - (void) RelinquishUniqueFileResource(filename); - ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", - image_info->filename); - } - /* - Compress runlength encoded to 2D Huffman pixels. - */ - fillorder=FILLORDER_LSB2MSB; - (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_FILLORDER,&fillorder); - for (i=0; i < (long) TIFFNumberOfStrips(tiff); i++) - { - count=(ssize_t) TIFFReadRawStrip(tiff,(uint32) i,buffer,(long) - byte_count[i]); - if (fillorder == FILLORDER_LSB2MSB) - TIFFReverseBits(buffer,(unsigned long) count); - (void) WriteBlob(image,(size_t) count,buffer); - } - buffer=(unsigned char *) RelinquishMagickMemory(buffer); - TIFFClose(tiff); - huffman_image=DestroyImage(huffman_image); - (void) fclose(file); - (void) RelinquishUniqueFileResource(filename); - return(MagickTrue); -} -#else -static MagickBooleanType Huffman2DEncodeImage(const ImageInfo *image_info, - Image *image,Image *inject_image) -{ - 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); - assert(inject_image != (Image *) NULL); - assert(inject_image->signature == MagickSignature); - (void) ThrowMagickException(&image->exception,GetMagickModule(), - MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","`%s' (TIFF)", - image->filename); - return(MagickFalse); -} -#endif - static ssize_t WriteCALSRecord(Image *image,const char *data) { char @@ -669,7 +430,13 @@ static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, Image *image) { char - buffer[129]; + header[129]; + + Image + *group4_image; + + ImageInfo + *write_info; MagickBooleanType status; @@ -680,6 +447,12 @@ static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, ssize_t count; + size_t + length; + + unsigned char + *group4; + unsigned long density, orient_x, @@ -755,12 +528,12 @@ static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, orient_y=270; } } - (void) FormatMagickString(buffer,MaxTextExtent,"rorient: %03ld,%03ld", + (void) FormatMagickString(header,MaxTextExtent,"rorient: %03ld,%03ld", orient_x,orient_y); - count=WriteCALSRecord(image,buffer); - (void) FormatMagickString(buffer,MaxTextExtent,"rpelcnt: %06lu,%06lu", + count=WriteCALSRecord(image,header); + (void) FormatMagickString(header,MaxTextExtent,"rpelcnt: %06lu,%06lu", image->columns,image->rows); - count=WriteCALSRecord(image,buffer); + count=WriteCALSRecord(image,header); density=200; if (image_info->density != (char *) NULL) { @@ -770,13 +543,36 @@ static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, (void) ParseGeometry(image_info->density,&geometry_info); density=(unsigned long) (geometry_info.rho+0.5); } - (void) FormatMagickString(buffer,MaxTextExtent,"rdensty: %04lu",density); - count=WriteCALSRecord(image,buffer); + (void) FormatMagickString(header,MaxTextExtent,"rdensty: %04lu",density); + count=WriteCALSRecord(image,header); count=WriteCALSRecord(image,"notes: NONE"); - (void) ResetMagickMemory(buffer,' ',128); + (void) ResetMagickMemory(header,' ',128); for (i=0; i < 5; i++) - (void) WriteBlob(image,128,(unsigned char *) buffer); - status=Huffman2DEncodeImage(image_info,image,image); + (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); } diff --git a/coders/ept.c b/coders/ept.c index b6e7456c3..af97f0898 100644 --- a/coders/ept.c +++ b/coders/ept.c @@ -351,6 +351,9 @@ ModuleExport void UnregisterEPTImage(void) */ static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image) { + char + filename[MaxTextExtent]; + EPTInfo ept_info; @@ -397,8 +400,9 @@ static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image) return(MagickFalse); write_info=CloneImageInfo(image_info); (void) CopyMagickString(write_info->magick,"TIFF",MaxTextExtent); - (void) FormatMagickString(write_info->filename,MaxTextExtent,"tiff:%.1024s", + (void) FormatMagickString(filename,MaxTextExtent,"tiff:%.1024s", write_info->filename); + (void) CopyMagickString(write_info->filename,filename,MaxTextExtent); (void) TransformImage(&write_image,(char *) NULL,"512x512>"); if ((write_image->storage_class == DirectClass) || (write_image->colors > 256)) @@ -428,13 +432,13 @@ static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image) /* Write EPT image. */ - (void) WriteBlobLSBLong(image,ept_info.magick); + (void) WriteBlobLSBLong(image,(unsigned int) ept_info.magick); (void) WriteBlobLSBLong(image,30); - (void) WriteBlobLSBLong(image,(unsigned long) ept_info.postscript_length); + (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length); (void) WriteBlobLSBLong(image,0); (void) WriteBlobLSBLong(image,0); - (void) WriteBlobLSBLong(image,(unsigned long) ept_info.postscript_length+30); - (void) WriteBlobLSBLong(image,(unsigned long) ept_info.tiff_length); + (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length+30); + (void) WriteBlobLSBLong(image,(unsigned int) ept_info.tiff_length); (void) WriteBlobLSBShort(image,0xffff); (void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript); (void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff); diff --git a/coders/tiff.c b/coders/tiff.c index 61a86dfe3..f6e8546ac 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -341,7 +341,7 @@ static Image *ReadGROUP4Image(const ImageInfo *image_info, strip_offset=10+(12*14)+4+8; length=WriteLSBLong(file,(unsigned long) strip_offset); length=fwrite("\022\001\003\000\001\000\000\000",1,8,file); - length=WriteLSBLong(file,(unsigned long) image->orientation); + length=WriteLSBLong(file,(unsigned long) image_info->orientation); length=fwrite("\025\001\003\000\001\000\000\000\001\000\000\000",1,12,file); length=fwrite("\026\001\004\000\001\000\000\000",1,8,file); length=WriteLSBLong(file,image->columns); @@ -1694,6 +1694,7 @@ ModuleExport unsigned long RegisterTIFFImage(void) #endif entry->raw=MagickTrue; entry->endian_support=MagickTrue; + entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->thread_support=NoThreadSupport; entry->description=ConstantString("Raw CCITT Group4"); @@ -1888,6 +1889,7 @@ static MagickBooleanType WriteGROUP4Image(const ImageInfo *image_info, filename); (void) SetImageType(huffman_image,BilevelType); write_info=CloneImageInfo(image_info); + SetImageInfoBlob(write_info,(void *) NULL,0); SetImageInfoFile(write_info,file); write_info->compression=Group4Compression; write_info->type=BilevelType;