X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=coders%2Fmiff.c;h=15bcb02d2726b68cdb5b721786446d75a26001af;hb=b51dff5c0d16a4c1b69ff683e786cb3b4c467694;hp=2fe3467467a7ab32cda20747b4a18bf8a4af4db1;hpb=330af6c00116155c122d0f4d697c176bbcc31768;p=imagemagick diff --git a/coders/miff.c b/coders/miff.c index 2fe346746..15bcb02d2 100644 --- a/coders/miff.c +++ b/coders/miff.c @@ -81,6 +81,13 @@ #include "zlib.h" #endif +/* + Define declarations. +*/ +#if !defined(LZMA_OK) +#define LZMA_OK 0 +#endif + /* Forward declarations. */ @@ -281,20 +288,20 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels, quantum; p=PushCharPixel(p,&quantum); - pixel->red=ScaleCharToQuantum(quantum); + SetRedPixelComponent(pixel,ScaleCharToQuantum(quantum)); p=PushCharPixel(p,&quantum); - pixel->green=ScaleCharToQuantum(quantum); + SetGreenPixelComponent(pixel,ScaleCharToQuantum(quantum)); p=PushCharPixel(p,&quantum); - pixel->blue=ScaleCharToQuantum(quantum); + SetBluePixelComponent(pixel,ScaleCharToQuantum(quantum)); if (image->matte != MagickFalse) { p=PushCharPixel(p,&quantum); - pixel->opacity=ScaleCharToQuantum(quantum); + SetOpacityPixelComponent(pixel,ScaleCharToQuantum(quantum)); } if (image->colorspace == CMYKColorspace) { p=PushCharPixel(p,&quantum); - *index=ScaleCharToQuantum(quantum); + SetBlackPixelComponent(index,ScaleCharToQuantum(quantum)); } break; } @@ -304,23 +311,24 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels, quantum; p=PushShortPixel(MSBEndian,p,&quantum); - pixel->red=(Quantum) (quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH)); + SetRedPixelComponent(pixel,quantum >> (image->depth- + MAGICKCORE_QUANTUM_DEPTH)); p=PushShortPixel(MSBEndian,p,&quantum); - pixel->green=(Quantum) (quantum >> (image->depth- + SetGreenPixelComponent(pixel,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); p=PushShortPixel(MSBEndian,p,&quantum); - pixel->blue=(Quantum) (quantum >> (image->depth- + SetBluePixelComponent(pixel,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); if (image->matte != MagickFalse) { p=PushShortPixel(MSBEndian,p,&quantum); - pixel->opacity=(Quantum) (quantum >> (image->depth- + SetOpacityPixelComponent(pixel,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); } if (image->colorspace == CMYKColorspace) { p=PushShortPixel(MSBEndian,p,&quantum); - *index=(IndexPacket) (quantum >> (image->depth- + SetBlackPixelComponent(index,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); } break; @@ -331,23 +339,24 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels, quantum; p=PushLongPixel(MSBEndian,p,&quantum); - pixel->red=(Quantum) (quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH)); + SetRedPixelComponent(pixel,quantum >> (image->depth- + MAGICKCORE_QUANTUM_DEPTH)); p=PushLongPixel(MSBEndian,p,&quantum); - pixel->green=(Quantum) (quantum >> (image->depth- + SetGreenPixelComponent(pixel,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); p=PushLongPixel(MSBEndian,p,&quantum); - pixel->blue=(Quantum) (quantum >> (image->depth- + SetBluePixelComponent(pixel,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); if (image->matte != MagickFalse) { p=PushLongPixel(MSBEndian,p,&quantum); - pixel->opacity=(Quantum) (quantum >> (image->depth- + SetOpacityPixelComponent(pixel,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); } if (image->colorspace == CMYKColorspace) { p=PushLongPixel(MSBEndian,p,&quantum); - *index=(IndexPacket) (quantum >> (image->depth- + SetIndexPixelComponent(index,quantum >> (image->depth- MAGICKCORE_QUANTUM_DEPTH)); } break; @@ -561,8 +570,6 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, p=keyword; do { - if (isspace((int) ((unsigned char) c)) != 0) - break; if (c == (int) '=') break; if ((size_t) (p-keyword) < (MaxTextExtent-1)) @@ -645,7 +652,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t storage_class; - storage_class=ParseMagickOption(MagickClassOptions, + storage_class=ParseCommandOption(MagickClassOptions, MagickFalse,options); if (storage_class < 0) break; @@ -662,7 +669,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t colorspace; - colorspace=ParseMagickOption(MagickColorspaceOptions, + colorspace=ParseCommandOption(MagickColorspaceOptions, MagickFalse,options); if (colorspace < 0) break; @@ -674,7 +681,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t compression; - compression=ParseMagickOption(MagickCompressOptions, + compression=ParseCommandOption(MagickCompressOptions, MagickFalse,options); if (compression < 0) break; @@ -707,7 +714,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t dispose; - dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse, + dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse, options); if (dispose < 0) break; @@ -725,7 +732,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t endian; - endian=ParseMagickOption(MagickEndianOptions,MagickFalse, + endian=ParseCommandOption(MagickEndianOptions,MagickFalse, options); if (endian < 0) break; @@ -740,7 +747,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, { if (LocaleCompare(keyword,"gamma") == 0) { - image->gamma=StringToDouble(options); + image->gamma=LocaleToDouble(options,(char **) NULL); break; } if (LocaleCompare(keyword,"gravity") == 0) @@ -748,7 +755,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t gravity; - gravity=ParseMagickOption(MagickGravityOptions,MagickFalse, + gravity=ParseCommandOption(MagickGravityOptions,MagickFalse, options); if (gravity < 0) break; @@ -792,7 +799,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t matte; - matte=ParseMagickOption(MagickBooleanOptions,MagickFalse, + matte=ParseCommandOption(MagickBooleanOptions,MagickFalse, options); if (matte < 0) break; @@ -821,7 +828,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t matte; - matte=ParseMagickOption(MagickBooleanOptions,MagickFalse, + matte=ParseCommandOption(MagickBooleanOptions,MagickFalse, options); if (matte < 0) break; @@ -833,7 +840,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t orientation; - orientation=ParseMagickOption(MagickOrientationOptions, + orientation=ParseCommandOption(MagickOrientationOptions, MagickFalse,options); if (orientation < 0) break; @@ -888,7 +895,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t format; - format=ParseMagickOption(MagickQuantumFormatOptions, + format=ParseCommandOption(MagickQuantumFormatOptions, MagickFalse,options); if (format < 0) break; @@ -916,7 +923,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t rendering_intent; - rendering_intent=ParseMagickOption(MagickIntentOptions, + rendering_intent=ParseCommandOption(MagickIntentOptions, MagickFalse,options); if (rendering_intent < 0) break; @@ -974,7 +981,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t type; - type=ParseMagickOption(MagickTypeOptions,MagickFalse, + type=ParseCommandOption(MagickTypeOptions,MagickFalse, options); if (type < 0) break; @@ -992,8 +999,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, ssize_t units; - units=ParseMagickOption(MagickResolutionOptions,MagickFalse, - options); + units=ParseCommandOption(MagickResolutionOptions, + MagickFalse,options); if (units < 0) break; image->units=(ResolutionType) units; @@ -1007,7 +1014,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, { if (LocaleCompare(keyword,"version") == 0) { - version=StringToDouble(options); + version=LocaleToDouble(options,(char **) NULL); break; } (void) SetImageProperty(image,keyword,options); @@ -1103,6 +1110,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, p=GetStringInfoDatum(profile); count=ReadBlob(image,GetStringInfoLength(profile),p); + (void) count; } name=(const char *) GetNextValueInLinkedList(profiles); } @@ -1262,22 +1270,20 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, MagickFalse); if (code != BZ_OK) status=MagickFalse; - bzip_info.avail_in=0; break; } #endif #if defined(MAGICKCORE_LZMA_DELEGATE) case LZMACompression: { + (void) ResetMagickMemory(&allocator,0,sizeof(allocator)); + allocator.alloc=AcquireLZMAMemory; + allocator.free=RelinquishLZMAMemory; lzma_info=initialize_lzma; + lzma_info.allocator=(&allocator); code=lzma_auto_decoder(&lzma_info,-1,0); if (code != LZMA_OK) status=MagickFalse; - allocator.alloc=AcquireLZMAMemory; - allocator.free=RelinquishLZMAMemory; - allocator.opaque=(void *) NULL; - lzma_info.allocator=(&allocator); - lzma_info.avail_in=0; break; } #endif @@ -1292,7 +1298,6 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, code=inflateInit(&zip_info); if (code != Z_OK) status=MagickFalse; - zip_info.avail_in=0; break; } #endif @@ -1417,8 +1422,12 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, length--; if ((image->storage_class == PseudoClass) || (image->colorspace == CMYKColorspace)) - indexes[x]=index; - *q++=pixel; + SetIndexPixelComponent(indexes+x,index); + SetRedPixelComponent(q,pixel.red); + SetGreenPixelComponent(q,pixel.green); + SetBluePixelComponent(q,pixel.blue); + SetOpacityPixelComponent(q,pixel.opacity); + q++; } break; } @@ -1459,6 +1468,9 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, #if defined(MAGICKCORE_LZMA_DELEGATE) case LZMACompression: { + code=lzma_code(&lzma_info,LZMA_FINISH); + if ((code != LZMA_STREAM_END) && (code != LZMA_OK)) + status=MagickFalse; lzma_end(&lzma_info); break; } @@ -1577,6 +1589,7 @@ ModuleExport size_t RegisterMIFFImage(void) entry->decoder=(DecodeImageHandler *) ReadMIFFImage; entry->encoder=(EncodeImageHandler *) WriteMIFFImage; entry->magick=(IsImageFormatHandler *) IsMIFF; + entry->seekable_stream=MagickTrue; entry->description=ConstantString("Magick Image File Format"); if (*version != '\0') entry->version=ConstantString(version); @@ -1939,49 +1952,49 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, Write MIFF header. */ (void) WriteBlobString(image,"id=ImageMagick version=1.0\n"); - (void) FormatMagickString(buffer,MaxTextExtent, - "class=%s colors=%.20g matte=%s\n",MagickOptionToMnemonic( + (void) FormatLocaleString(buffer,MaxTextExtent, + "class=%s colors=%.20g matte=%s\n",CommandOptionToMnemonic( MagickClassOptions,image->storage_class),(double) image->colors, - MagickOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte)); + CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte)); (void) WriteBlobString(image,buffer); - (void) FormatMagickString(buffer,MaxTextExtent,"columns=%.20g rows=%.20g " + (void) FormatLocaleString(buffer,MaxTextExtent,"columns=%.20g rows=%.20g " "depth=%.20g\n",(double) image->columns,(double) image->rows,(double) image->depth); (void) WriteBlobString(image,buffer); if (image->type != UndefinedType) { - (void) FormatMagickString(buffer,MaxTextExtent,"type=%s\n", - MagickOptionToMnemonic(MagickTypeOptions,image->type)); + (void) FormatLocaleString(buffer,MaxTextExtent,"type=%s\n", + CommandOptionToMnemonic(MagickTypeOptions,image->type)); (void) WriteBlobString(image,buffer); } if (image->colorspace != UndefinedColorspace) { - (void) FormatMagickString(buffer,MaxTextExtent,"colorspace=%s\n", - MagickOptionToMnemonic(MagickColorspaceOptions,image->colorspace)); + (void) FormatLocaleString(buffer,MaxTextExtent,"colorspace=%s\n", + CommandOptionToMnemonic(MagickColorspaceOptions,image->colorspace)); (void) WriteBlobString(image,buffer); } if (compression != UndefinedCompression) { - (void) FormatMagickString(buffer,MaxTextExtent,"compression=%s " - "quality=%.20g\n",MagickOptionToMnemonic(MagickCompressOptions, + (void) FormatLocaleString(buffer,MaxTextExtent,"compression=%s " + "quality=%.20g\n",CommandOptionToMnemonic(MagickCompressOptions, compression),(double) image->quality); (void) WriteBlobString(image,buffer); } if (image->units != UndefinedResolution) { - (void) FormatMagickString(buffer,MaxTextExtent,"units=%s\n", - MagickOptionToMnemonic(MagickResolutionOptions,image->units)); + (void) FormatLocaleString(buffer,MaxTextExtent,"units=%s\n", + CommandOptionToMnemonic(MagickResolutionOptions,image->units)); (void) WriteBlobString(image,buffer); } if ((image->x_resolution != 0) || (image->y_resolution != 0)) { - (void) FormatMagickString(buffer,MaxTextExtent, + (void) FormatLocaleString(buffer,MaxTextExtent, "resolution=%gx%g\n",image->x_resolution,image->y_resolution); (void) WriteBlobString(image,buffer); } if ((image->page.width != 0) || (image->page.height != 0)) { - (void) FormatMagickString(buffer,MaxTextExtent, + (void) FormatLocaleString(buffer,MaxTextExtent, "page=%.20gx%.20g%+.20g%+.20g\n",(double) image->page.width,(double) image->page.height,(double) image->page.x,(double) image->page.y); (void) WriteBlobString(image,buffer); @@ -1989,13 +2002,13 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, else if ((image->page.x != 0) || (image->page.y != 0)) { - (void) FormatMagickString(buffer,MaxTextExtent,"page=%+ld%+ld\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"page=%+ld%+ld\n", (long) image->page.x,(long) image->page.y); (void) WriteBlobString(image,buffer); } if ((image->tile_offset.x != 0) || (image->tile_offset.y != 0)) { - (void) FormatMagickString(buffer,MaxTextExtent,"tile-offset=%+ld%+ld\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"tile-offset=%+ld%+ld\n", (long) image->tile_offset.x,(long) image->tile_offset.y); (void) WriteBlobString(image,buffer); } @@ -2003,11 +2016,11 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, (GetPreviousImageInList(image) != (Image *) NULL)) { if (image->scene == 0) - (void) FormatMagickString(buffer,MaxTextExtent,"iterations=%.20g " + (void) FormatLocaleString(buffer,MaxTextExtent,"iterations=%.20g " "delay=%.20g ticks-per-second=%.20g\n",(double) image->iterations, (double) image->delay,(double) image->ticks_per_second); else - (void) FormatMagickString(buffer,MaxTextExtent,"scene=%.20g " + (void) FormatLocaleString(buffer,MaxTextExtent,"scene=%.20g " "iterations=%.20g delay=%.20g ticks-per-second=%.20g\n",(double) image->scene,(double) image->iterations,(double) image->delay, (double) image->ticks_per_second); @@ -2017,51 +2030,51 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, { if (image->scene != 0) { - (void) FormatMagickString(buffer,MaxTextExtent,"scene=%.20g\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"scene=%.20g\n", (double) image->scene); (void) WriteBlobString(image,buffer); } if (image->iterations != 0) { - (void) FormatMagickString(buffer,MaxTextExtent,"iterations=%.20g\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"iterations=%.20g\n", (double) image->iterations); (void) WriteBlobString(image,buffer); } if (image->delay != 0) { - (void) FormatMagickString(buffer,MaxTextExtent,"delay=%.20g\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"delay=%.20g\n", (double) image->delay); (void) WriteBlobString(image,buffer); } if (image->ticks_per_second != UndefinedTicksPerSecond) { - (void) FormatMagickString(buffer,MaxTextExtent, + (void) FormatLocaleString(buffer,MaxTextExtent, "ticks-per-second=%.20g\n",(double) image->ticks_per_second); (void) WriteBlobString(image,buffer); } } if (image->gravity != UndefinedGravity) { - (void) FormatMagickString(buffer,MaxTextExtent,"gravity=%s\n", - MagickOptionToMnemonic(MagickGravityOptions,image->gravity)); + (void) FormatLocaleString(buffer,MaxTextExtent,"gravity=%s\n", + CommandOptionToMnemonic(MagickGravityOptions,image->gravity)); (void) WriteBlobString(image,buffer); } if (image->dispose != UndefinedDispose) { - (void) FormatMagickString(buffer,MaxTextExtent,"dispose=%s\n", - MagickOptionToMnemonic(MagickDisposeOptions,image->dispose)); + (void) FormatLocaleString(buffer,MaxTextExtent,"dispose=%s\n", + CommandOptionToMnemonic(MagickDisposeOptions,image->dispose)); (void) WriteBlobString(image,buffer); } if (image->rendering_intent != UndefinedIntent) { - (void) FormatMagickString(buffer,MaxTextExtent, + (void) FormatLocaleString(buffer,MaxTextExtent, "rendering-intent=%s\n", - MagickOptionToMnemonic(MagickIntentOptions,image->rendering_intent)); + CommandOptionToMnemonic(MagickIntentOptions,image->rendering_intent)); (void) WriteBlobString(image,buffer); } if (image->gamma != 0.0) { - (void) FormatMagickString(buffer,MaxTextExtent,"gamma=%g\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"gamma=%g\n", image->gamma); (void) WriteBlobString(image,buffer); } @@ -2070,7 +2083,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, /* Note chomaticity points. */ - (void) FormatMagickString(buffer,MaxTextExtent,"red-primary=%g," + (void) FormatLocaleString(buffer,MaxTextExtent,"red-primary=%g," "%g green-primary=%g,%g blue-primary=%g,%g\n", image->chromaticity.red_primary.x,image->chromaticity.red_primary.y, image->chromaticity.green_primary.x, @@ -2078,15 +2091,15 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, image->chromaticity.blue_primary.x, image->chromaticity.blue_primary.y); (void) WriteBlobString(image,buffer); - (void) FormatMagickString(buffer,MaxTextExtent, + (void) FormatLocaleString(buffer,MaxTextExtent, "white-point=%g,%g\n",image->chromaticity.white_point.x, image->chromaticity.white_point.y); (void) WriteBlobString(image,buffer); } if (image->orientation != UndefinedOrientation) { - (void) FormatMagickString(buffer,MaxTextExtent,"orientation=%s\n", - MagickOptionToMnemonic(MagickOrientationOptions,image->orientation)); + (void) FormatLocaleString(buffer,MaxTextExtent,"orientation=%s\n", + CommandOptionToMnemonic(MagickOrientationOptions,image->orientation)); (void) WriteBlobString(image,buffer); } if (image->profiles != (void *) NULL) @@ -2107,7 +2120,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, profile=GetImageProfile(image,name); if (profile != (StringInfo *) NULL) { - (void) FormatMagickString(buffer,MaxTextExtent, + (void) FormatLocaleString(buffer,MaxTextExtent, "profile:%s=%.20g\n",name,(double) GetStringInfoLength(profile)); (void) WriteBlobString(image,buffer); @@ -2117,7 +2130,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, } if (image->montage != (char *) NULL) { - (void) FormatMagickString(buffer,MaxTextExtent,"montage=%s\n", + (void) FormatLocaleString(buffer,MaxTextExtent,"montage=%s\n", image->montage); (void) WriteBlobString(image,buffer); } @@ -2127,7 +2140,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, property=GetNextImageProperty(image); while (property != (const char *) NULL) { - (void) FormatMagickString(buffer,MaxTextExtent,"%s=",property); + (void) FormatLocaleString(buffer,MaxTextExtent,"%s=",property); (void) WriteBlobString(image,buffer); value=GetImageProperty(image,property); if (value != (const char *) NULL) @@ -2271,14 +2284,14 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, #if defined(MAGICKCORE_LZMA_DELEGATE) case LZMACompression: { - lzma_info=initialize_lzma; - code=lzma_easy_encoder(&lzma_info,image->quality/10,LZMA_CHECK_SHA256); - if (code != LZMA_OK) - status=MagickTrue; (void) ResetMagickMemory(&allocator,0,sizeof(allocator)); allocator.alloc=AcquireLZMAMemory; allocator.free=RelinquishLZMAMemory; + lzma_info=initialize_lzma; lzma_info.allocator=&allocator; + code=lzma_easy_encoder(&lzma_info,image->quality/10,LZMA_CHECK_SHA256); + if (code != LZMA_OK) + status=MagickTrue; break; } #endif @@ -2407,8 +2420,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, if ((length < 255) && (x < (ssize_t) (image->columns-1)) && (IsColorEqual(p,&pixel) != MagickFalse) && ((image->matte == MagickFalse) || - (p->opacity == pixel.opacity)) && - ((indexes == (IndexPacket *) NULL) || (index == indexes[x]))) + (GetOpacityPixelComponent(p) == pixel.opacity)) && + ((indexes == (IndexPacket *) NULL) || + (index == GetIndexPixelComponent(indexes+x)))) length++; else { @@ -2418,7 +2432,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info, } pixel=(*p); if (indexes != (IndexPacket *) NULL) - index=indexes[x]; + index=GetIndexPixelComponent(indexes+x); p++; } q=PopRunlengthPacket(image,q,length,pixel,index);