int main(int argc, char *argv[]) { VMVALUE lineNumber = 0; HandlerData data; ImageHdr *image; System *sys; VM_printf("ebasic 0.003\n"); VM_sysinit(argc, argv); sys = InitSystem(space, sizeof(space)); sys->getLine = TermGetLine; sys->getLineCookie = &lineNumber; if (!(image = AllocateImage(sys, IMAGESIZE))) return 1; sys->freeMark = sys->freeNext; data.sys = sys; data.image = image; EditWorkspace(sys, userCmds, (Handler *)CompileAndExecute, &data); return 0; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d F A X I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadFAXImage() reads a Group 3 FAX image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadFAXImage method is: % % Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; MagickBooleanType status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Initialize image structure. */ image->storage_class=PseudoClass; if (image->columns == 0) image->columns=2592; if (image->rows == 0) image->rows=3508; image->depth=8; if (AllocateImageColormap(image,2) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Monochrome colormap. */ image->colormap[0].red=QuantumRange; image->colormap[0].green=QuantumRange; image->colormap[0].blue=QuantumRange; image->colormap[1].red=0; image->colormap[1].green=0; image->colormap[1].blue=0; if (image_info->ping != MagickFalse) { CloseBlob(image); return(GetFirstImageInList(image)); } status=HuffmanDecodeImage(image); if (status == MagickFalse) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d D O T I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadDOTImage() reads a Graphviz image file and returns it. It allocates % the memory necessary for the new Image structure and returns a pointer to % the new image. % % The format of the ReadDOTImage method is: % % Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception) { char command[MaxTextExtent]; const char *option; graph_t *graph; Image *image; ImageInfo *read_info; MagickBooleanType status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) return((Image *) NULL); read_info=CloneImageInfo(image_info); (void) CopyMagickString(read_info->magick,"PS",MaxTextExtent); (void) AcquireUniqueFilename(read_info->filename); (void) FormatMagickString(command,MaxTextExtent,"-Tps2 -o%s %s", read_info->filename,image_info->filename); graph=agread(GetBlobFileHandle(image)); if (graph == (graph_t *) NULL) return ((Image *) NULL); option=GetImageOption(image_info,"dot:layout-engine"); if (option == (const char *) NULL) gvLayout(graphic_context,graph,"dot"); else gvLayout(graphic_context,graph,(char *) option); gvRenderFilename(graphic_context,graph,"ps2",read_info->filename); gvFreeLayout(graphic_context,graph); /* Read Postscript graph. */ image=ReadImage(read_info,exception); (void) RelinquishUniqueFileResource(read_info->filename); read_info=DestroyImageInfo(read_info); if (image == (Image *) NULL) return((Image *) NULL); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d F A X I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadFAXImage reads a Group 3 FAX image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadFAXImage method is: % % Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadFAXImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or % if the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; unsigned int status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); /* Initialize image structure. */ image->storage_class=PseudoClass; if (image->columns == 0) image->columns=2592; if (image->rows == 0) image->rows=3508; image->depth=8; if (!AllocateImageColormap(image,2)) ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); /* Monochrome colormap. */ image->colormap[0].red=MaxRGB; image->colormap[0].green=MaxRGB; image->colormap[0].blue=MaxRGB; image->colormap[1].red=0; image->colormap[1].green=0; image->colormap[1].blue=0; if (image_info->ping) { CloseBlob(image); return(image); } if (CheckImagePixelLimits(image, exception) != MagickPass) ThrowReaderException(ResourceLimitError,ImagePixelLimitExceeded,image); status=HuffmanDecodeImage(image); if (status == False) ThrowReaderException(CorruptImageError,UnableToReadImageData,image); if (EOFBlob(image)) ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, image->filename); CloseBlob(image); return(image); }
Image *get_blue_channe_image(Image *img) { unsigned int i = 0; unsigned int j = 0; PixelPacket *px_original; PixelPacket *px_new; Image *new_img; ExceptionInfo exception; ImageInfo *new_img_info; GetExceptionInfo(&exception); if ((new_img_info = CloneImageInfo((ImageInfo *)NULL)) == NULL) { CatchException(&exception); DestroyImageInfo(new_img_info); return (NULL); } new_img_info->colorspace = RGBColorspace; new_img = AllocateImage(new_img_info); new_img->rows = img->rows; new_img->columns = img->columns; if ((px_original = GetImagePixelsEx(img, 0, 0, img->columns, img->rows, &exception)) == NULL) { DestroyImage(new_img); CatchException(&exception); return (NULL); } if ((px_new = SetImagePixelsEx(new_img, 0, 0, new_img->columns, new_img->rows, &exception)) == NULL) { DestroyImage(new_img); CatchException(&exception); return (NULL); } while (i < img->rows) { j = 0; while (j < img->columns) { px_new[(new_img->columns * i) + j].red = 0; px_new[(new_img->columns * i) + j].blue = px_original[(img->columns * i) + j].blue; px_new[(new_img->columns * i) + j].green = 0; j++; } i++; } SyncImagePixels(new_img); DestroyImageInfo(new_img_info); return (new_img); }
// // LoadAEArtFile // Purpose: Loads a .AEArt file and places it into the table of image files // IMAGE *LoadAEArtFile( const char *folder, const char *fileName ) { FILE *fp; IMAGE *image = NULL; // Allocate space to concatenate the folder and the fileName together int size = strlen( folder ) + strlen( fileName ) + 2; char *pathName = (char *)malloc( size ); // Copy the folder and fileName into the pathName array strcpy_s( pathName, size, folder ); strcat_s( pathName, size, fileName ); fopen_s( &fp, pathName, "r" ); if(fp) // read image contents in file { int x, y; CHAR *thisChar; COL *thisColor; AE_COORD bottomRight = { 0 }; fscanf_s( fp, "%d", &bottomRight.x_ ); fscanf_s( fp, "%d", &bottomRight.y_ ); image = AllocateImage( fileName, bottomRight.x_, bottomRight.y_ ); for(y = 0; y < bottomRight.y_; ++y) { for(x = 0; x < bottomRight.x_; ++x) { int copy = 0; thisChar = CharAt( image, x, y ); fscanf_s( fp, "%d", © ); *thisChar = (char)copy; } } for(y = 0; y < bottomRight.y_; ++y) { for(x = 0; x < bottomRight.x_; ++x) { int copy = 0; thisColor = ColorAt( image, x, y ); fscanf_s( fp, "%d", © ); *thisColor = (char)copy; } } fclose( fp ); } return image; }
// Default constructor Magick::ImageRef::ImageRef ( void ) : _image(0), _options(new Options), _id(-1), _refCount(1), _mutexLock() { // Allocate default image _image = AllocateImage( _options->imageInfo() ); // Test for error and throw exception (like throwImageException()) throwException(_image->exception); }
AtlasTextureInfo TextureCache::LoadGlyphTexture(uint32 image, uint8 * palette) { rct_drawpixelinfo dpi = GetGlyphAsDPI(image, palette); auto cacheInfo = AllocateImage(dpi.width, dpi.height); cacheInfo.image = image; glBindTexture(GL_TEXTURE_2D_ARRAY, _atlasesTexture); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, cacheInfo.bounds.x, cacheInfo.bounds.y, cacheInfo.index, dpi.width, dpi.height, 1, GL_RED_INTEGER, GL_UNSIGNED_BYTE, dpi.bits); DeleteDPI(dpi); return cacheInfo; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d T I L E I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadTILEImage tiles a texture on an image. It allocates the % memory necessary for the new Image structure and returns a pointer to the % new image. % % The format of the ReadTILEImage method is: % % Image *ReadTILEImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadTILEImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image, *tile_image; ImageInfo *read_info; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); read_info=CloneImageInfo(image_info); SetImageInfoBlob(read_info,(void *) NULL,0); *read_info->magick='\0'; tile_image=ReadImage(read_info,exception); read_info=DestroyImageInfo(read_info); if (tile_image == (Image *) NULL) return((Image *) NULL); image=AllocateImage(image_info); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,"MustSpecifyImageSize"); if (*image_info->filename == '\0') ThrowReaderException(OptionError,"MustSpecifyAnImageName"); (void) SetImageBackgroundColor(image); image->matte=tile_image->matte; (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); if (LocaleCompare(tile_image->magick,"PATTERN") == 0) { tile_image->tile_offset.x=0; tile_image->tile_offset.y=0; } (void) TextureImage(image,tile_image); tile_image=DestroyImage(tile_image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d G R A D I E N T I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadGRADIENTImage creates a gradient image and initializes it to % the color range as specified by the filename. It allocates the memory % necessary for the new Image structure and returns a pointer to the new % image. % % The format of the ReadGRADIENTImage method is: % % Image *ReadGRADIENTImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadGRADIENTImage returns a pointer to the image after % creating it. A null image is returned if there is a memory shortage % or if the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadGRADIENTImage(const ImageInfo *image_info, ExceptionInfo *exception) { char colorname[MaxTextExtent]; PixelPacket start_color, stop_color; Image *image; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,MustSpecifyImageSize,image); (void) SetImage(image,OpaqueOpacity); (void) strlcpy(image->filename,image_info->filename,MaxTextExtent); (void) strlcpy(colorname,image_info->filename,MaxTextExtent); (void) sscanf(image_info->filename,"%[^-]",colorname); if (!QueryColorDatabase(colorname,&start_color,exception)) { DestroyImage(image); return((Image *) NULL); } (void) strcpy(colorname,"white"); if (PixelIntensityToQuantum(&start_color) > (0.5*MaxRGB)) (void) strcpy(colorname,"black"); (void) sscanf(image_info->filename,"%*[^-]-%s",colorname); if (!QueryColorDatabase(colorname,&stop_color,exception)) { DestroyImage(image); return((Image *) NULL); } (void) GradientImage(image,&start_color,&stop_color); return(image); }
static Image *ReadSFWImage(const ImageInfo *image_info,ExceptionInfo *exception) { static unsigned char HuffmanTable[] = { 0xFF, 0xC4, 0x01, 0xA2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA }; FILE *file; Image *flipped_image, *image; ImageInfo *clone_info; register unsigned char *header, *data; size_t count; unsigned char *buffer, *offset; unsigned int status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); /* Read image into a buffer. */ buffer=MagickAllocateMemory(unsigned char *,(size_t) GetBlobSize(image)); if (buffer == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); count=ReadBlob(image,(size_t) GetBlobSize(image),(char *) buffer); if ((count == 0) || (LocaleNCompare((char *) buffer,"SFW",3) != 0)) ThrowReaderException(CorruptImageError,ImproperImageHeader,image); CloseBlob(image); DestroyImage(image); /* Find the start of the JFIF data */ header=SFWScan(buffer,buffer+GetBlobSize(image)-1,(unsigned char *) "\377\310\377\320",4); if (header == (unsigned char *) NULL) { MagickFreeMemory(buffer); ThrowReaderException(CorruptImageError,ImproperImageHeader,image) }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d J B I G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadJBIGImage() reads a JBIG image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadJBIGImage method is: % % Image *ReadJBIGImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadJBIGImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; IndexPacket index; long length, y; MagickBooleanType status; register IndexPacket *indexes; register long x; register PixelPacket *q; register unsigned char *p; ssize_t count; struct jbg_dec_state jbig_info; unsigned char bit, *buffer, byte; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Initialize JBIG toolkit. */ jbg_dec_init(&jbig_info); jbg_dec_maxsize(&jbig_info,(unsigned long) image->columns,(unsigned long) image->rows); image->columns=jbg_dec_getwidth(&jbig_info); image->rows=jbg_dec_getheight(&jbig_info); image->depth=8; image->storage_class=PseudoClass; image->colors=2; /* Read JBIG file. */ buffer=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferSize, sizeof(*buffer)); if (buffer == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); status=JBG_EAGAIN; do { length=(long) ReadBlob(image,MagickMaxBufferSize,buffer); if (length == 0) break; p=buffer; count=0; while ((length > 0) && ((status == JBG_EAGAIN) || (status == JBG_EOK))) { size_t count; status=jbg_dec_in(&jbig_info,p,length,&count); p+=count; length-=(long) count; } } while ((status == JBG_EAGAIN) || (status == JBG_EOK)); /* Create colormap. */ image->columns=jbg_dec_getwidth(&jbig_info); image->rows=jbg_dec_getheight(&jbig_info); if (AllocateImageColormap(image,2) == MagickFalse) { buffer=(unsigned char *) RelinquishMagickMemory(buffer); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } image->colormap[0].red=0; image->colormap[0].green=0; image->colormap[0].blue=0; image->colormap[1].red=QuantumRange; image->colormap[1].green=QuantumRange; image->colormap[1].blue=QuantumRange; image->x_resolution=300; image->y_resolution=300; if (image_info->ping != MagickFalse) { (void) CloseBlob(image); return(GetFirstImageInList(image)); } /* Convert X bitmap image to pixel packets. */ if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } p=jbg_dec_getimage(&jbig_info,0); for (y=0; y < (long) image->rows; y++) { q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; indexes=GetIndexes(image); bit=0; byte=0; for (x=0; x < (long) image->columns; x++) { if (bit == 0) byte=(*p++); index=(byte & 0x80) ? 0 : 1; bit++; byte<<=1; if (bit == 8) bit=0; indexes[x]=index; *q++=image->colormap[(long) index]; } if (SyncImagePixels(image) == MagickFalse) break; if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } /* Free scale resource. */ jbg_dec_free(&jbig_info); buffer=(unsigned char *) RelinquishMagickMemory(buffer); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d R G B I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadRGBImage() reads an image of raw red, green, and blue samples and % returns it. It allocates the memory necessary for the new Image structure % and returns a pointer to the new image. % % The format of the ReadRGBImage method is: % % Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; long y; MagickBooleanType status; MagickOffsetType offset; QuantumInfo quantum_info; register long i; register PixelPacket *q; ssize_t count; size_t packet_size; unsigned char *pixels; unsigned long width; assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,"MustSpecifyImageSize"); if (image_info->interlace != PartitionInterlace) { /* Open image file. */ status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } for (i=0; i < image->offset; i++) if (ReadBlobByte(image) == EOF) { ThrowFileException(exception,CorruptImageError, "UnexpectedEndOfFile",image->filename); break; } } /* Allocate memory for a pixels. */ packet_size=(size_t) ((3*image->depth+7)/8); if ((LocaleCompare(image_info->magick,"RGBA") == 0) || (LocaleCompare(image_info->magick,"RGBO") == 0)) { packet_size+=(image->depth+7)/8; image->matte=MagickTrue; } pixels=(unsigned char *) AcquireQuantumMemory(image->extract_info.width, packet_size*sizeof(*pixels)); if (pixels == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); if (image_info->number_scenes != 0) while (image->scene < image_info->scene) { /* Skip to next image. */ image->scene++; for (y=0; y < (long) image->rows; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } } offset=(MagickOffsetType) (packet_size*image->extract_info.x); do { /* Convert raster image to pixel packets. */ GetQuantumInfo(image_info,&quantum_info); if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } switch (image_info->interlace) { case NoInterlace: default: { /* No interlacing: RGBRGBRGBRGBRGBRGB... */ for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL)) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; if (image->matte == MagickFalse) (void) ExportQuantumPixels(image,&quantum_info,RGBQuantum, pixels+offset); else if (LocaleCompare(image_info->magick,"RGBA") == 0) (void) ExportQuantumPixels(image,&quantum_info,RGBAQuantum, pixels+offset); else (void) ExportQuantumPixels(image,&quantum_info,RGBOQuantum, pixels+offset); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } width=image->extract_info.height-image->rows-image->extract_info.y; for (i=0; i < (long) width; i++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } break; } case LineInterlace: { /* Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB... */ packet_size=(size_t) ((image->depth+7)/8); for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL)) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ExportQuantumPixels(image,&quantum_info,RedQuantum, pixels+offset); count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; (void) ExportQuantumPixels(image,&quantum_info,GreenQuantum, pixels+offset); count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; (void) ExportQuantumPixels(image,&quantum_info,BlueQuantum, pixels+offset); if (image->matte != MagickFalse) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; if (LocaleCompare(image_info->magick,"RGBA") == 0) (void) ExportQuantumPixels(image,&quantum_info,AlphaQuantum, pixels+offset); else (void) ExportQuantumPixels(image,&quantum_info,OpacityQuantum, pixels+offset); } if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } width=image->extract_info.height-image->rows-image->extract_info.y; for (i=0; i < (long) width; i++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } break; } case PlaneInterlace: case PartitionInterlace: { unsigned long span; /* Plane interlacing: RRRRRR...GGGGGG...BBBBBB... */ if (image_info->interlace == PartitionInterlace) { AppendImageFormat("R",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } } packet_size=(size_t) ((image->depth+7)/8); for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } i=0; span=image->rows*(image->matte != MagickFalse ? 4 : 3); for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL)) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ExportQuantumPixels(image,&quantum_info,RedQuantum, pixels+offset); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(i,span) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,i,span, image->client_data); if (status == MagickFalse) break; } i++; } width=image->extract_info.height-image->rows-image->extract_info.y; for (i=0; i < (long) width; i++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("G",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } } for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } for (y=0; y < (long) image->rows; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ExportQuantumPixels(image,&quantum_info,GreenQuantum, pixels+offset); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(i,span) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,i,span, image->client_data); if (status == MagickFalse) break; } i++; } width=image->extract_info.height-image->rows-image->extract_info.y; for (i=0; i < (long) width; i++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("B",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } } for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } for (y=0; y < (long) image->rows; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ExportQuantumPixels(image,&quantum_info,BlueQuantum, pixels+offset); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(i,span) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,i,span, image->client_data); if (status == MagickFalse) break; } i++; } width=image->extract_info.height-image->rows-image->extract_info.y; for (i=0; i < (long) width; i++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } if (image->matte != MagickFalse) { /* Read matte channel. */ if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("A",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } } for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } for (y=0; y < (long) image->rows; y++) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; if (LocaleCompare(image_info->magick,"RGBA") == 0) (void) ExportQuantumPixels(image,&quantum_info,AlphaQuantum, pixels+offset); else (void) ExportQuantumPixels(image,&quantum_info,OpacityQuantum, pixels+offset); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(i,span) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,i,span, image->client_data); if (status == MagickFalse) break; } i++; } width=image->extract_info.height-image->rows-image->extract_info.y; for (i=0; i < (long) width; i++) { count=ReadBlob(image,packet_size*image->extract_info.width, pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } } if (image_info->interlace == PartitionInterlace) (void) CopyMagickString(image->filename,image_info->filename, MaxTextExtent); break; } } if (y < (long) image->rows) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Proceed to next image. */ if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (image_info->interlace == PartitionInterlace) break; count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count == (ssize_t) (packet_size*image->extract_info.width)) { /* Allocate next image structure. */ AllocateNextImage(image_info,image); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); if (image->progress_monitor != (MagickProgressMonitor) NULL) { status=image->progress_monitor(LoadImagesTag,TellBlob(image), GetBlobSize(image),image->client_data); if (status == MagickFalse) break; } } } while ((size_t) count == (packet_size*image->extract_info.width)); pixels=(unsigned char *) RelinquishMagickMemory(pixels); CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d P W P I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadPWPImage reads a Seattle Film Works multi-image file and returns % it. It allocates the memory necessary for the new Image structure and % returns a pointer to the new image. % % The format of the ReadPWPImage method is: % % Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadPWPImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or % if the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception) { FILE *file; Image *image, *next_image, *pwp_image; ImageInfo *clone_info; int c; MonitorHandler handler; register Image *p; register unsigned long i; size_t count; unsigned char magick[MaxTextExtent]; unsigned int status; unsigned long filesize; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=(Image *) NULL; pwp_image=AllocateImage(image_info); status=OpenBlob(image_info,pwp_image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,pwp_image); count=ReadBlob(pwp_image,5,(char *) magick); if ((count == 0) || (LocaleNCompare((char *) magick,"SFW95",5) != 0)) ThrowReaderException(CorruptImageError,ImproperImageHeader,pwp_image); clone_info=CloneImageInfo(image_info); clone_info->blob=(void *) NULL; clone_info->length=0; for ( ; ; ) { for (c=ReadBlobByte(pwp_image); c != EOF; c=ReadBlobByte(pwp_image)) { for (i=0; i < 17; i++) magick[i]=magick[i+1]; magick[17]=(unsigned char) c; if (LocaleNCompare((char *) (magick+12),"SFW94A",6) == 0) break; } if (c == EOF) break; if (LocaleNCompare((char *) (magick+12),"SFW94A",6) != 0) { ThrowReaderException(CorruptImageError,ImproperImageHeader,pwp_image); } /* Dump SFW image to a temporary file. */ file=AcquireTemporaryFileStream(clone_info->filename,BinaryFileIOMode); if (file == (FILE *) NULL) { char filename[MaxTextExtent]; (void) strcpy(filename,clone_info->filename); DestroyImageInfo(clone_info); ThrowReaderTemporaryFileException(filename); } (void) fwrite("SFW94A",1,6,file); filesize=(65535L*magick[2]+256L*magick[1]+magick[0]) & 0xFFFFFFFF; for (i=0; i < filesize; i++) { if ((c=ReadBlobByte(pwp_image)) == EOF) break; (void) fputc(c,file); } (void) fclose(file); if (c == EOF) break; handler=SetMonitorHandler((MonitorHandler) NULL); next_image=ReadImage(clone_info,exception); (void) LiberateTemporaryFile(clone_info->filename); (void) SetMonitorHandler(handler); if (next_image == (Image *) NULL) break; FormatString(next_image->filename,"slide_%02ld.sfw",next_image->scene); if (image == (Image *) NULL) image=next_image; else { /* Link image into image list. */ for (p=image; p->next != (Image *) NULL; p=p->next); next_image->previous=p; next_image->scene=p->scene+1; p->next=next_image; } if (image_info->subrange != 0) if (next_image->scene >= (image_info->subimage+image_info->subrange-1)) break; if (!MagickMonitorFormatted(TellBlob(pwp_image),GetBlobSize(image), &image->exception,LoadImagesText, image->filename)) break; } DestroyImageInfo(clone_info); CloseBlob(pwp_image); DestroyImage(pwp_image); if (EOFBlob(image)) ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, image->filename); CloseBlob(image); return(image); }
void apitextotex(apitexture * apitex, texture * tex) { switch(apitex->texturefunc) { case 0: tex->texfunc=(color(*)(void *, void *, void *))(standard_texture); break; case 1: tex->texfunc=(color(*)(void *, void *, void *))(checker_texture); break; case 2: tex->texfunc=(color(*)(void *, void *, void *))(grit_texture); break; case 3: tex->texfunc=(color(*)(void *, void *, void *))(marble_texture); break; case 4: tex->texfunc=(color(*)(void *, void *, void *))(wood_texture); break; case 5: tex->texfunc=(color(*)(void *, void *, void *))(gnoise_texture); break; case 6: tex->texfunc=(color(*)(void *, void *, void *))(cyl_checker_texture); break; case 7: tex->texfunc=(color(*)(void *, void *, void *))(image_sphere_texture); tex->img=AllocateImage((char *)apitex->imap); break; case 8: tex->texfunc=(color(*)(void *, void *, void *))(image_cyl_texture); tex->img=AllocateImage((char *)apitex->imap); break; case 9: tex->texfunc=(color(*)(void *, void *, void *))(image_plane_texture); tex->img=AllocateImage((char *)apitex->imap); break; default: tex->texfunc=(color(*)(void *, void *, void *))(standard_texture); break; } tex->ctr = apitex->ctr; tex->rot = apitex->rot; tex->scale = apitex->scale; tex->uaxs = apitex->uaxs; tex->vaxs = apitex->vaxs; tex->ambient = apitex->ambient; tex->diffuse = apitex->diffuse; tex->specular = apitex->specular; tex->opacity = apitex->opacity; tex->col = apitex->col; tex->islight = 0; tex->shadowcast = 1; tex->phong = 0.0; tex->phongexp = 0.0; tex->phongtype = 0; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d C M Y K I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadCMYKImage reads an image of raw cyan, magenta, yellow, and black % samples and returns it. It allocates the memory necessary for the new % Image structure and returns a pointer to the new image. % % The format of the ReadCMYKImage method is: % % Image *ReadCMYKImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadCMYKImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or % if the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadCMYKImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; long y; register long i, x; register PixelPacket *q; size_t count; unsigned char *scanline; unsigned int status; unsigned int packet_size, quantum_size; ImportPixelAreaOptions import_options; assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,MustSpecifyImageSize,image); if (image_info->interlace != PartitionInterlace) { /* Open image file. */ status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); for (i=0; i < image->offset; i++) { if (EOF == ReadBlobByte(image)) ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, image->filename); } } if (image->logging) (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Tile %lux%lu%+ld%+ld", image->tile_info.width,image->tile_info.height, image->tile_info.x,image->tile_info.y); /* Allocate memory for a scanline. */ if (image->depth <= 8) quantum_size=8; else if (image->depth <= 16) quantum_size=16; else quantum_size=32; packet_size=(quantum_size*4)/8; if (LocaleCompare(image_info->magick,"CMYKA") == 0) { image->matte=True; packet_size=(quantum_size*5)/8; } scanline=MagickAllocateArray(unsigned char *, packet_size,image->tile_info.width); if (scanline == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); /* Initialize import options. */ ImportPixelAreaOptionsInit(&import_options); if (image_info->endian != UndefinedEndian) import_options.endian=image_info->endian; if (image->logging) (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Depth %u bits, Endian %s, Interlace %s", quantum_size, EndianTypeToString(import_options.endian), InterlaceTypeToString(image_info->interlace)); /* Support starting at intermediate image frame. */ if (image_info->subrange != 0) while (image->scene < image_info->subimage) { /* Skip to next image. */ image->scene++; for (y=0; y < (long) image->rows; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); } x=(long) (packet_size*image->tile_info.x); do { /* Convert raster image to pixel packets. */ image->colorspace=CMYKColorspace; if (image_info->ping && (image_info->subrange != 0)) if (image->scene >= (image_info->subimage+image_info->subrange-1)) break; switch (image_info->interlace) { case NoInterlace: default: { /* No interlacing: CMYKCMYKCMYKCMYKCMYKCMYK... */ for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (image->previous == (Image *) NULL)) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; if (!image->matte) (void) ImportImagePixelArea(image,CMYKQuantum,quantum_size,scanline+x, &import_options,0); else (void) ImportImagePixelArea(image,CMYKAQuantum,quantum_size,scanline+x, &import_options,0); if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(y,image->rows)) if (!MagickMonitorFormatted(y,image->rows,exception, LoadImageText,image->filename, image->columns,image->rows)) break; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); break; } case LineInterlace: { /* Line interlacing: CCC...MMM...YYY...KKK...CCC...MMM...YYY...KKK... */ packet_size=(quantum_size)/8; for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (image->previous == (Image *) NULL)) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ImportImagePixelArea(image,CyanQuantum,quantum_size,scanline+x, &import_options,0); (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); (void) ImportImagePixelArea(image,MagentaQuantum,quantum_size,scanline+x, &import_options,0); (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); (void) ImportImagePixelArea(image,YellowQuantum,quantum_size,scanline+x, &import_options,0); (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); (void) ImportImagePixelArea(image,BlackQuantum,quantum_size,scanline+x, &import_options,0); if (image->matte) { (void) ReadBlob(image,packet_size*image->tile_info.width, scanline); (void) ImportImagePixelArea(image,AlphaQuantum,quantum_size,scanline+x, &import_options,0); } if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(y,image->rows)) if (!MagickMonitorFormatted(y,image->rows,exception, LoadImageText,image->filename, image->columns,image->rows)) break; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); break; } case PlaneInterlace: case PartitionInterlace: { unsigned long span; /* Plane interlacing: CCCCCC...MMMMMM...YYYYYY...KKKKKK... */ if (image_info->interlace == PartitionInterlace) { AppendImageFormat("C",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); } packet_size=(quantum_size)/8; for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); i=0; span=image->rows*(image->matte ? 5 : 4); for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (image->previous == (Image *) NULL)) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ImportImagePixelArea(image,CyanQuantum,quantum_size,scanline+x, &import_options,0); if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(i,span)) if (!MagickMonitorFormatted(i,span,&image->exception, LoadImageText,image->filename, image->columns,image->rows)) break; i++; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("M",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); } for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); for (y=0; y < (long) image->rows; y++) { (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ImportImagePixelArea(image,MagentaQuantum,quantum_size,scanline+x, &import_options,0); if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(i,span)) if (!MagickMonitorFormatted(i,span,&image->exception, LoadImageText,image->filename, image->columns,image->rows)) break; i++; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("Y",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); } for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); for (y=0; y < (long) image->rows; y++) { (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ImportImagePixelArea(image,YellowQuantum,quantum_size,scanline+x, &import_options,0); if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(i,span)) if (!MagickMonitorFormatted(i,span,&image->exception, LoadImageText,image->filename, image->columns,image->rows)) break; i++; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("K",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); } for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); for (y=0; y < (long) image->rows; y++) { (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ImportImagePixelArea(image,BlackQuantum,quantum_size,scanline+x, &import_options,0); if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(i,span)) if (!MagickMonitorFormatted(i,span,&image->exception, LoadImageText,image->filename, image->columns,image->rows)) break; i++; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width,scanline); if (image->matte) { /* Read matte channel. */ if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("A",image->filename); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); } for (y=0; y < image->tile_info.y; y++) (void) ReadBlob(image,packet_size*image->tile_info.width, scanline); for (y=0; y < (long) image->rows; y++) { (void) ReadBlob(image,packet_size*image->tile_info.width, scanline); q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ImportImagePixelArea(image,AlphaQuantum,quantum_size,scanline+x, &import_options,0); if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(i,span)) if (!MagickMonitorFormatted(i,span,&image->exception, LoadImageText,image->filename, image->columns,image->rows)) break; i++; } count=image->tile_info.height-image->rows-image->tile_info.y; for (i=0; i < (long) count; i++) (void) ReadBlob(image,packet_size*image->tile_info.width, scanline); } if (image_info->interlace == PartitionInterlace) (void) strlcpy(image->filename,image_info->filename,MaxTextExtent); break; } } if (EOFBlob(image)) { ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, image->filename); break; } /* Proceed to next image. */ if (image_info->subrange != 0) if (image->scene >= (image_info->subimage+image_info->subrange-1)) break; if (image_info->interlace == PartitionInterlace) break; count=ReadBlob(image,packet_size*image->tile_info.width,scanline); if (count != 0) { /* Allocate next image structure. */ AllocateNextImage(image_info,image); if (image->next == (Image *) NULL) { DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); status=MagickMonitorFormatted(TellBlob(image),GetBlobSize(image), exception,LoadImagesText, image->filename); if (status == False) break; } } while (count != 0); MagickFreeMemory(scanline); while (image->previous != (Image *) NULL) image=image->previous; CloseBlob(image); return(image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d Y U V I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadYUVImage reads an image with digital YUV (CCIR 601 4:1:1) bytes % and returns it. It allocates the memory necessary for the new Image % structure and returns a pointer to the new image. % % The format of the ReadYUVImage method is: % % Image *ReadYUVImage(const ImageInfo *image_info) % % A description of each parameter follows: % % o image: Method ReadYUVImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or % if the image cannot be read. % % o image_info: Specifies a pointer to an ImageInfo structure. % % */ Export Image *ReadYUVImage(const ImageInfo *image_info) { Image *chroma_image, *image, *zoom_image; int count, y; register int i, x; register PixelPacket *q, *r; register unsigned char *p; unsigned char *scanline; unsigned int status; /* Allocate image structure. */ image=AllocateImage(image_info); if (image == (Image *) NULL) return((Image *) NULL); if ((image->columns == 0) || (image->rows == 0)) ReaderExit(OptionWarning,"Must specify image size",image); image->depth=8; if (image_info->interlace != PartitionInterlace) { /* Open image file. */ status=OpenBlob(image_info,image,ReadBinaryType); if (status == False) ReaderExit(FileOpenWarning,"Unable to open file",image); for (i=0; i < image->offset; i++) (void) ReadByte(image); } /* Allocate memory for a scanline. */ scanline=(unsigned char *) AllocateMemory(image->columns*sizeof(unsigned char)); if (scanline == (unsigned char *) NULL) ReaderExit(ResourceLimitWarning,"Memory allocation failed",image); do { /* Convert raster image to pixel packets. */ if (image_info->interlace == PartitionInterlace) { AppendImageFormat("Y",image->filename); status=OpenBlob(image_info,image,ReadBinaryType); if (status == False) ReaderExit(FileOpenWarning,"Unable to open file",image); } for (y=0; y < (int) image->rows; y++) { if ((y > 0) || (image->previous == (Image *) NULL)) (void) ReadBlob(image,image->columns,scanline); p=scanline; q=SetPixelCache(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; for (x=0; x < (int) image->columns; x++) { q->red=UpScale(*p++); q->green=0; q->blue=0; q++; } if (!SyncPixelCache(image)) break; if (image->previous == (Image *) NULL) ProgressMonitor(LoadImageText,y,image->rows); } if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("U",image->filename); status=OpenBlob(image_info,image,ReadBinaryType); if (status == False) ReaderExit(FileOpenWarning,"Unable to open file",image); } chroma_image=CloneImage(image,image->columns/2,image->rows/2,True); if (chroma_image == (Image *) NULL) ReaderExit(ResourceLimitWarning,"Memory allocation failed",image); for (y=0; y < (int) chroma_image->rows; y++) { (void) ReadBlob(image,chroma_image->columns,scanline); p=scanline; q=SetPixelCache(chroma_image,0,y,chroma_image->columns,1); if (q == (PixelPacket *) NULL) break; for (x=0; x < (int) chroma_image->columns; x++) { q->red=0; q->green=UpScale(*p++); q->blue=0; q++; } if (!SyncPixelCache(chroma_image)) break; } if (image_info->interlace == PartitionInterlace) { CloseBlob(image); AppendImageFormat("V",image->filename); status=OpenBlob(image_info,image,ReadBinaryType); if (status == False) ReaderExit(FileOpenWarning,"Unable to open file",image); } for (y=0; y < (int) chroma_image->rows; y++) { (void) ReadBlob(image,chroma_image->columns,scanline); p=scanline; q=GetPixelCache(chroma_image,0,y,chroma_image->columns,1); if (q == (PixelPacket *) NULL) break; for (x=0; x < (int) chroma_image->columns; x++) { q->blue=UpScale(*p++); q++; } if (!SyncPixelCache(chroma_image)) break; } /* Scale image. */ chroma_image->orphan=True; zoom_image=SampleImage(chroma_image,image->columns,image->rows); DestroyImage(chroma_image); if (zoom_image == (Image *) NULL) ReaderExit(ResourceLimitWarning,"Memory allocation failed",image); for (y=0; y < (int) image->rows; y++) { q=GetPixelCache(image,0,y,image->columns,1); r=GetPixelCache(zoom_image,0,y,zoom_image->columns,1); if ((q == (PixelPacket *) NULL) || (r == (PixelPacket *) NULL)) break; for (x=0; x < (int) image->columns; x++) { q->green=r->green; q->blue=r->blue; r++; q++; } if (!SyncPixelCache(image)) break; } DestroyImage(zoom_image); TransformRGBImage(image,YCbCrColorspace); if (image_info->interlace == PartitionInterlace) (void) strcpy(image->filename,image_info->filename); /* Proceed to next image. */ if (image_info->subrange != 0) if (image->scene >= (image_info->subimage+image_info->subrange-1)) break; count=ReadBlob(image,image->columns,(char *) scanline); if (count > 0) { /* Allocate next image structure. */ AllocateNextImage(image_info,image); if (image->next == (Image *) NULL) { DestroyImages(image); return((Image *) NULL); } image=image->next; ProgressMonitor(LoadImagesText,TellBlob(image),image->filesize); } } while (count > 0); FreeMemory(scanline); while (image->previous != (Image *) NULL) image=image->previous; CloseBlob(image); return(image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d L A B E L I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadLABELImage() reads a LABEL image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadLABELImage method is: % % Image *ReadLABELImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadLABELImage(const ImageInfo *image_info, ExceptionInfo *exception) { char geometry[MaxTextExtent], *property; const char *label; DrawInfo *draw_info; Image *image; MagickBooleanType status; TypeMetric metrics; unsigned long height, width; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); (void) ResetImagePage(image,"0x0+0+0"); property=InterpretImageProperties(image_info,image,image_info->filename); (void) SetImageProperty(image,"label",property); property=DestroyString(property); label=GetImageProperty(image,"label"); draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); draw_info->text=ConstantString(label); if ((image->columns != 0) || (image->rows != 0)) { /* Fit label to canvas size. */ status=GetMultilineTypeMetrics(image,draw_info,&metrics); for ( ; status != MagickFalse; draw_info->pointsize*=2.0) { width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); if (((image->columns != 0) && (width > (image->columns+1))) || ((image->rows != 0) && (height > (image->rows+1)))) break; status=GetMultilineTypeMetrics(image,draw_info,&metrics); } for ( ; status != MagickFalse; draw_info->pointsize--) { width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); if ((image->columns != 0) && (width <= (image->columns+1)) && ((image->rows == 0) || (height <= (image->rows+1)))) break; if ((image->rows != 0) && (height <= (image->rows+1)) && ((image->columns == 0) || (width <= (image->columns+1)))) break; if (draw_info->pointsize < 2.0) break; status=GetMultilineTypeMetrics(image,draw_info,&metrics); } } status=GetMultilineTypeMetrics(image,draw_info,&metrics); if (status == MagickFalse) { InheritException(exception,&image->exception); image=DestroyImageList(image); return((Image *) NULL); } if (image->columns == 0) image->columns=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); if (image->columns == 0) image->columns=(unsigned long) (draw_info->pointsize+ draw_info->stroke_width+0.5); if (draw_info->gravity == UndefinedGravity) { (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+ draw_info->stroke_width/2.0); draw_info->geometry=AcquireString(geometry); } if (image->rows == 0) image->rows=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); if (image->rows == 0) image->rows=(unsigned long) (draw_info->pointsize+draw_info->stroke_width+ 0.5); if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } (void) SetImageBackgroundColor(image); (void) AnnotateImage(image,draw_info); draw_info=DestroyDrawInfo(draw_info); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d V I F F I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadVIFFImage() reads a Khoros Visualization image file and returns % it. It allocates the memory necessary for the new Image structure and % returns a pointer to the new image. % % The format of the ReadVIFFImage method is: % % Image *ReadVIFFImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadVIFFImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or if % the image cannot be read. % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadVIFFImage(const ImageInfo *image_info, ExceptionInfo *exception) { #define VFF_CM_genericRGB 15 #define VFF_CM_ntscRGB 1 #define VFF_CM_NONE 0 #define VFF_DEP_DECORDER 0x4 #define VFF_DEP_NSORDER 0x8 #define VFF_DES_RAW 0 #define VFF_LOC_IMPLICIT 1 #define VFF_MAPTYP_NONE 0 #define VFF_MAPTYP_1_BYTE 1 #define VFF_MAPTYP_2_BYTE 2 #define VFF_MAPTYP_4_BYTE 4 #define VFF_MAPTYP_FLOAT 5 #define VFF_MAPTYP_DOUBLE 7 #define VFF_MS_NONE 0 #define VFF_MS_ONEPERBAND 1 #define VFF_MS_SHARED 3 #define VFF_TYP_BIT 0 #define VFF_TYP_1_BYTE 1 #define VFF_TYP_2_BYTE 2 #define VFF_TYP_4_BYTE 4 #define VFF_TYP_FLOAT 5 #define VFF_TYP_DOUBLE 9 typedef struct _ViffInfo { unsigned char identifier, file_type, release, version, machine_dependency, reserve[3]; char comment[512]; unsigned long rows, columns, subrows; long x_offset, y_offset; float x_bits_per_pixel, y_bits_per_pixel; unsigned long location_type, location_dimension, number_of_images, number_data_bands, data_storage_type, data_encode_scheme, map_scheme, map_storage_type, map_rows, map_columns, map_subrows, map_enable, maps_per_cycle, color_space_model; } ViffInfo; double min_value, scale_factor, value; Image *image; int bit; long y; MagickBooleanType status; MagickSizeType number_pixels; register IndexPacket *indexes; register long x; register PixelPacket *q; register long i; register unsigned char *p; ssize_t count; unsigned char buffer[7], *viff_pixels; unsigned long bytes_per_pixel, lsb_first, max_packets, quantum; ViffInfo viff_info; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read VIFF header (1024 bytes). */ count=ReadBlob(image,1,&viff_info.identifier); do { /* Verify VIFF identifier. */ if ((count == 0) || ((unsigned char) viff_info.identifier != 0xab)) ThrowReaderException(CorruptImageError,"NotAVIFFImage"); /* Initialize VIFF image. */ count=ReadBlob(image,7,buffer); viff_info.file_type=buffer[0]; viff_info.release=buffer[1]; viff_info.version=buffer[2]; viff_info.machine_dependency=buffer[3]; count=ReadBlob(image,512,(unsigned char *) viff_info.comment); viff_info.comment[511]='\0'; if (strlen(viff_info.comment) > 4) (void) SetImageProperty(image,"comment",viff_info.comment); if ((viff_info.machine_dependency == VFF_DEP_DECORDER) || (viff_info.machine_dependency == VFF_DEP_NSORDER)) { viff_info.rows=ReadBlobLSBLong(image); viff_info.columns=ReadBlobLSBLong(image); viff_info.subrows=ReadBlobLSBLong(image); viff_info.x_offset=(long) ReadBlobLSBLong(image); viff_info.y_offset=(long) ReadBlobLSBLong(image); viff_info.x_bits_per_pixel=(float) ReadBlobLSBLong(image); viff_info.y_bits_per_pixel=(float) ReadBlobLSBLong(image); viff_info.location_type=ReadBlobLSBLong(image); viff_info.location_dimension=ReadBlobLSBLong(image); viff_info.number_of_images=ReadBlobLSBLong(image); viff_info.number_data_bands=ReadBlobLSBLong(image); viff_info.data_storage_type=ReadBlobLSBLong(image); viff_info.data_encode_scheme=ReadBlobLSBLong(image); viff_info.map_scheme=ReadBlobLSBLong(image); viff_info.map_storage_type=ReadBlobLSBLong(image); viff_info.map_rows=ReadBlobLSBLong(image); viff_info.map_columns=ReadBlobLSBLong(image); viff_info.map_subrows=ReadBlobLSBLong(image); viff_info.map_enable=ReadBlobLSBLong(image); viff_info.maps_per_cycle=ReadBlobLSBLong(image); viff_info.color_space_model=ReadBlobLSBLong(image); } else { viff_info.rows=ReadBlobMSBLong(image); viff_info.columns=ReadBlobMSBLong(image); viff_info.subrows=ReadBlobMSBLong(image); viff_info.x_offset=(long) ReadBlobMSBLong(image); viff_info.y_offset=(long) ReadBlobMSBLong(image); viff_info.x_bits_per_pixel=(float) ReadBlobMSBLong(image); viff_info.y_bits_per_pixel=(float) ReadBlobMSBLong(image); viff_info.location_type=ReadBlobMSBLong(image); viff_info.location_dimension=ReadBlobMSBLong(image); viff_info.number_of_images=ReadBlobMSBLong(image); viff_info.number_data_bands=ReadBlobMSBLong(image); viff_info.data_storage_type=ReadBlobMSBLong(image); viff_info.data_encode_scheme=ReadBlobMSBLong(image); viff_info.map_scheme=ReadBlobMSBLong(image); viff_info.map_storage_type=ReadBlobMSBLong(image); viff_info.map_rows=ReadBlobMSBLong(image); viff_info.map_columns=ReadBlobMSBLong(image); viff_info.map_subrows=ReadBlobMSBLong(image); viff_info.map_enable=ReadBlobMSBLong(image); viff_info.maps_per_cycle=ReadBlobMSBLong(image); viff_info.color_space_model=ReadBlobMSBLong(image); } for (i=0; i < 420; i++) (void) ReadBlobByte(image); image->columns=viff_info.rows; image->rows=viff_info.columns; image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL : MAGICKCORE_QUANTUM_DEPTH; /* Verify that we can read this VIFF image. */ number_pixels=(MagickSizeType) viff_info.columns*viff_info.rows; if (number_pixels != (size_t) number_pixels) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); if (number_pixels == 0) ThrowReaderException(CoderError,"ImageColumnOrRowSizeIsNotSupported"); if ((viff_info.number_data_bands < 1) || (viff_info.number_data_bands > 4)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if ((viff_info.data_storage_type != VFF_TYP_BIT) && (viff_info.data_storage_type != VFF_TYP_1_BYTE) && (viff_info.data_storage_type != VFF_TYP_2_BYTE) && (viff_info.data_storage_type != VFF_TYP_4_BYTE) && (viff_info.data_storage_type != VFF_TYP_FLOAT) && (viff_info.data_storage_type != VFF_TYP_DOUBLE)) ThrowReaderException(CoderError,"DataStorageTypeIsNotSupported"); if (viff_info.data_encode_scheme != VFF_DES_RAW) ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported"); if ((viff_info.map_storage_type != VFF_MAPTYP_NONE) && (viff_info.map_storage_type != VFF_MAPTYP_1_BYTE) && (viff_info.map_storage_type != VFF_MAPTYP_2_BYTE) && (viff_info.map_storage_type != VFF_MAPTYP_4_BYTE) && (viff_info.map_storage_type != VFF_MAPTYP_FLOAT) && (viff_info.map_storage_type != VFF_MAPTYP_DOUBLE)) ThrowReaderException(CoderError,"MapStorageTypeIsNotSupported"); if ((viff_info.color_space_model != VFF_CM_NONE) && (viff_info.color_space_model != VFF_CM_ntscRGB) && (viff_info.color_space_model != VFF_CM_genericRGB)) ThrowReaderException(CoderError,"ColorspaceModelIsNotSupported"); if (viff_info.location_type != VFF_LOC_IMPLICIT) ThrowReaderException(CoderError,"LocationTypeIsNotSupported"); if (viff_info.number_of_images != 1) ThrowReaderException(CoderError,"NumberOfImagesIsNotSupported"); if (viff_info.map_rows == 0) viff_info.map_scheme=VFF_MS_NONE; switch ((int) viff_info.map_scheme) { case VFF_MS_NONE: { if (viff_info.number_data_bands < 3) { /* Create linear color ramp. */ image->colors=image->depth <= 8 ? 256UL : 65536UL; if (viff_info.data_storage_type == VFF_TYP_BIT) image->colors=2; if (AllocateImageColormap(image,image->colors) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } break; } case VFF_MS_ONEPERBAND: case VFF_MS_SHARED: { unsigned char *viff_colormap; /* Allocate VIFF colormap. */ switch ((int) viff_info.map_storage_type) { case VFF_MAPTYP_1_BYTE: bytes_per_pixel=1; break; case VFF_MAPTYP_2_BYTE: bytes_per_pixel=2; break; case VFF_MAPTYP_4_BYTE: bytes_per_pixel=4; break; case VFF_MAPTYP_FLOAT: bytes_per_pixel=4; break; case VFF_MAPTYP_DOUBLE: bytes_per_pixel=8; break; default: bytes_per_pixel=1; break; } image->colors=viff_info.map_columns; if (AllocateImageColormap(image,image->colors) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors, viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap)); if (viff_colormap == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Read VIFF raster colormap. */ count=ReadBlob(image,bytes_per_pixel*image->colors*viff_info.map_rows, viff_colormap); lsb_first=1; if (*(char *) &lsb_first && ((viff_info.machine_dependency != VFF_DEP_DECORDER) && (viff_info.machine_dependency != VFF_DEP_NSORDER))) switch ((int) viff_info.map_storage_type) { case VFF_MAPTYP_2_BYTE: { MSBOrderShort(viff_colormap,(bytes_per_pixel*image->colors* viff_info.map_rows)); break; } case VFF_MAPTYP_4_BYTE: case VFF_MAPTYP_FLOAT: { MSBOrderLong(viff_colormap,(bytes_per_pixel*image->colors* viff_info.map_rows)); break; } default: break; } for (i=0; i < (long) (viff_info.map_rows*image->colors); i++) { switch ((int) viff_info.map_storage_type) { case VFF_MAPTYP_2_BYTE: value=1.0*((short *) viff_colormap)[i]; break; case VFF_MAPTYP_4_BYTE: value=1.0*((int *) viff_colormap)[i]; break; case VFF_MAPTYP_FLOAT: value=((float *) viff_colormap)[i]; break; case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break; default: value=1.0*viff_colormap[i]; break; } if (i < (long) image->colors) { image->colormap[i].red=ScaleCharToQuantum((unsigned char) value); image->colormap[i].green= ScaleCharToQuantum((unsigned char) value); image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value); } else if (i < (long) (2*image->colors)) image->colormap[i % image->colors].green= ScaleCharToQuantum((unsigned char) value); else if (i < (long) (3*image->colors)) image->colormap[i % image->colors].blue= ScaleCharToQuantum((unsigned char) value); } viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap); break; } default: ThrowReaderException(CoderError,"ColormapTypeNotSupported"); } /* Initialize image structure. */ image->matte=viff_info.number_data_bands == 4 ? MagickTrue : MagickFalse; image->storage_class= (viff_info.number_data_bands < 3 ? PseudoClass : DirectClass); image->columns=viff_info.rows; image->rows=viff_info.columns; if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } /* Allocate VIFF pixels. */ switch ((int) viff_info.data_storage_type) { case VFF_TYP_2_BYTE: bytes_per_pixel=2; break; case VFF_TYP_4_BYTE: bytes_per_pixel=4; break; case VFF_TYP_FLOAT: bytes_per_pixel=4; break; case VFF_TYP_DOUBLE: bytes_per_pixel=8; break; default: bytes_per_pixel=1; break; } if (viff_info.data_storage_type == VFF_TYP_BIT) max_packets=((image->columns+7UL) >> 3UL)*image->rows; else max_packets=(unsigned long) (number_pixels*viff_info.number_data_bands); viff_pixels=(unsigned char *) AcquireQuantumMemory(max_packets, bytes_per_pixel*sizeof(*viff_pixels)); if (viff_pixels == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); count=ReadBlob(image,bytes_per_pixel*max_packets,viff_pixels); lsb_first=1; if (*(char *) &lsb_first && ((viff_info.machine_dependency != VFF_DEP_DECORDER) && (viff_info.machine_dependency != VFF_DEP_NSORDER))) switch ((int) viff_info.data_storage_type) { case VFF_TYP_2_BYTE: { MSBOrderShort(viff_pixels,bytes_per_pixel*max_packets); break; } case VFF_TYP_4_BYTE: case VFF_TYP_FLOAT: { MSBOrderLong(viff_pixels,bytes_per_pixel*max_packets); break; } default: break; } min_value=0.0; scale_factor=1.0; if ((viff_info.data_storage_type != VFF_TYP_1_BYTE) && (viff_info.map_scheme == VFF_MS_NONE)) { double max_value; /* Determine scale factor. */ switch ((int) viff_info.data_storage_type) { case VFF_TYP_2_BYTE: value=1.0*((short *) viff_pixels)[0]; break; case VFF_TYP_4_BYTE: value=1.0*((int *) viff_pixels)[0]; break; case VFF_TYP_FLOAT: value=((float *) viff_pixels)[0]; break; case VFF_TYP_DOUBLE: value=((double *) viff_pixels)[0]; break; default: value=1.0*viff_pixels[0]; break; } max_value=value; min_value=value; for (i=0; i < (long) max_packets; i++) { switch ((int) viff_info.data_storage_type) { case VFF_TYP_2_BYTE: value=1.0*((short *) viff_pixels)[i]; break; case VFF_TYP_4_BYTE: value=1.0*((int *) viff_pixels)[i]; break; case VFF_TYP_FLOAT: value=((float *) viff_pixels)[i]; break; case VFF_TYP_DOUBLE: value=((double *) viff_pixels)[i]; break; default: value=1.0*viff_pixels[i]; break; } if (value > max_value) max_value=value; else if (value < min_value) min_value=value; } if ((min_value == 0) && (max_value == 0)) scale_factor=0; else if (min_value == max_value) { scale_factor=(MagickRealType) QuantumRange/min_value; min_value=0; } else scale_factor=(MagickRealType) QuantumRange/(max_value-min_value); } /* Convert pixels to Quantum size. */ p=(unsigned char *) viff_pixels; for (i=0; i < (long) max_packets; i++) { switch ((int) viff_info.data_storage_type) { case VFF_TYP_2_BYTE: value=1.0*((short *) viff_pixels)[i]; break; case VFF_TYP_4_BYTE: value=1.0*((int *) viff_pixels)[i]; break; case VFF_TYP_FLOAT: value=((float *) viff_pixels)[i]; break; case VFF_TYP_DOUBLE: value=((double *) viff_pixels)[i]; break; default: value=1.0*viff_pixels[i]; break; } if (viff_info.map_scheme == VFF_MS_NONE) { value=(value-min_value)*scale_factor; if (value > QuantumRange) value=QuantumRange; else if (value < 0) value=0; } *p=(unsigned char) value; p++; } /* Convert VIFF raster image to pixel packets. */ p=(unsigned char *) viff_pixels; if (viff_info.data_storage_type == VFF_TYP_BIT) { /* Convert bitmap scanline. */ (void) SetImageType(image,BilevelType); (void) SetImageType(image,PaletteType); for (y=0; y < (long) image->rows; y++) { q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; indexes=GetIndexes(image); for (x=0; x < (long) (image->columns-7); x+=8) { for (bit=0; bit < 8; bit++) if (PixelIntensity(q) < ((MagickRealType) QuantumRange/2.0)) { quantum=(unsigned long) indexes[x+bit]; quantum|=0x01; indexes[x+bit]=(IndexPacket) quantum; } p++; } if ((image->columns % 8) != 0) { for (bit=0; bit < (long) (image->columns % 8); bit++) if (PixelIntensity(q) < ((MagickRealType) QuantumRange/2.0)) { quantum=(unsigned long) indexes[x+bit]; quantum|=0x01; indexes[x+bit]=(IndexPacket) quantum; } p++; } if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } } else if (image->storage_class == PseudoClass) for (y=0; y < (long) image->rows; y++) { q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; indexes=GetIndexes(image); for (x=0; x < (long) image->columns; x++) indexes[x]=(IndexPacket) (*p++); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } else { /* Convert DirectColor scanline. */ number_pixels=(MagickSizeType) image->columns*image->rows; for (y=0; y < (long) image->rows; y++) { q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; for (x=0; x < (long) image->columns; x++) { q->red=ScaleCharToQuantum(*p); q->green=ScaleCharToQuantum(*(p+number_pixels)); q->blue=ScaleCharToQuantum(*(p+2*number_pixels)); if (image->colors != 0) { q->red=image->colormap[(long) q->red].red; q->green=image->colormap[(long) q->green].green; q->blue=image->colormap[(long) q->blue].blue; } q->opacity=(Quantum) (image->matte ? QuantumRange- ScaleCharToQuantum(*(p+number_pixels*3)) : OpaqueOpacity); p++; q++; } if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } } viff_pixels=(unsigned char *) RelinquishMagickMemory(viff_pixels); if (image->storage_class == PseudoClass) (void) SyncImage(image); if (EOFBlob(image) != MagickFalse) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Proceed to next image. */ if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; count=ReadBlob(image,1,&viff_info.identifier); if ((count != 0) && (viff_info.identifier == 0xab)) { /* Allocate next image structure. */ AllocateNextImage(image_info,image); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); if (image->progress_monitor != (MagickProgressMonitor) NULL) { status=image->progress_monitor(LoadImagesTag,TellBlob(image), GetBlobSize(image),image->client_data); if (status == MagickFalse) break; } } } while ((count != 0) && (viff_info.identifier == 0xab));
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d O T B I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadOTBImage() reads a on-the-air (level 0) bitmap and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadOTBImage method is: % % Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception) { #define GetBit(a,i) (((a) >> (i)) & 1L) Image *image; int byte; long y; MagickBooleanType status; register IndexPacket *indexes; register long x; register PixelPacket *q; unsigned char bit, info, depth; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Initialize image structure. */ info=(unsigned char) ReadBlobByte(image); if (GetBit(info,4) == 0) { image->columns=(unsigned long) ReadBlobByte(image); image->rows=(unsigned long) ReadBlobByte(image); } else { image->columns=(unsigned long) ReadBlobMSBShort(image); image->rows=(unsigned long) ReadBlobMSBShort(image); } if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); depth=(unsigned char) ReadBlobByte(image); if (depth != 1) ThrowReaderException(CoderError,"OnlyLevelZerofilesSupported"); if (AllocateImageColormap(image,2) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); if (image_info->ping != MagickFalse) { CloseBlob(image); return(GetFirstImageInList(image)); } if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } /* Convert bi-level image to pixel packets. */ for (y=0; y < (long) image->rows; y++) { q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; indexes=GetIndexes(image); bit=0; byte=0; for (x=0; x < (long) image->columns; x++) { if (bit == 0) { byte=ReadBlobByte(image); if (byte == EOF) ThrowReaderException(CorruptImageError,"CorruptImage"); } indexes[x]=(IndexPacket) ((byte & (0x01 << (7-bit))) ? 0x00 : 0x01); bit++; if (bit == 8) bit=0; } if (SyncImagePixels(image) == MagickFalse) break; if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } (void) SyncImage(image); if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d M P E G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadMPEGImage() reads an binary file in the MPEG video stream format % and returns it. It allocates the memory necessary for the new Image % structure and returns a pointer to the new image. This method differs from % the other decoder methods in that only the Photoshop resource (MPEG) % information is useful in the returned image. % % The format of the ReadMPEGImage method is: % % Image *ReadMPEGImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadMPEGImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image, *images; ImageInfo *read_info; MagickBooleanType status; register long i; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } CloseBlob(image); DestroyImageList(image); /* Convert MPEG to PPM with delegate. */ image=AllocateImage(image_info); read_info=CloneImageInfo(image_info); (void) InvokeDelegate(read_info,image,"mpeg-decode",(char *) NULL,exception); image=DestroyImage(image); /* Read PPM files. */ images=NewImageList(); for (i=(long) read_info->scene; ; i++) { (void) FormatMagickString(read_info->filename,MaxTextExtent, "%s%ld.ppm",read_info->unique,i); if (IsAccessible(read_info->filename) == MagickFalse) break; image=ReadImage(read_info,exception); if (image == (Image *) NULL) break; (void) strcpy(image->magick,image_info->magick); image->scene=(unsigned long) i; AppendImageToList(&images,image); if (read_info->number_scenes != 0) if (i >= (long) (read_info->scene+read_info->number_scenes-1)) break; } /* Free resources. */ for (i=0; ; i++) { (void) FormatMagickString(read_info->filename,MaxTextExtent, "%s%ld.ppm",read_info->unique,i); if (IsAccessible(read_info->filename) == MagickFalse) break; (void) remove(read_info->filename); } read_info=DestroyImageInfo(read_info); return(images); }
static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception) { char key[MaxTextExtent], target[MaxTextExtent], *xpm_buffer; Image *image; long j, y; MagickBooleanType active, status; register char *p, *q, *next; register IndexPacket *indexes; register long i, x; register PixelPacket *r; size_t length; SplayTreeInfo *xpm_colors; ssize_t count; unsigned long width; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read XPM file. */ length=MaxTextExtent; xpm_buffer=(char *) AcquireQuantumMemory((size_t) length,sizeof(*xpm_buffer)); p=xpm_buffer; if (xpm_buffer != (char *) NULL) while (ReadBlobString(image,p) != (char *) NULL) { if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n'))) continue; if ((*p == '}') && (*(p+1) == ';')) break; p+=strlen(p); if ((size_t) (p-xpm_buffer+MaxTextExtent) < length) continue; length<<=1; xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MaxTextExtent, sizeof(*xpm_buffer)); if (xpm_buffer == (char *) NULL) break; p=xpm_buffer+strlen(xpm_buffer); } if (xpm_buffer == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Remove comments. */ count=0; for (p=xpm_buffer; *p != '\0'; p++) { if (*p != '"') continue; count=(ssize_t) sscanf(p+1,"%lu %lu %lu %lu",&image->columns,&image->rows, &image->colors,&width); if (count == 4) break; } if ((count != 4) || (width > 10) || (image->columns == 0) || (image->rows == 0) || (image->colors == 0)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); image->depth=16; /* Remove unquoted characters. */ i=0; active=MagickFalse; q=xpm_buffer; while (*p != '\0') { if (*p++ == '"') { if (active != MagickFalse) *q++='\n'; active=active != MagickFalse ? MagickFalse : MagickTrue; } if (active != MagickFalse) *q++=(*p); } *q='\0'; /* Initialize image structure. */ xpm_colors=NewSplayTree(CompareXPMColor,RelinquishMagickMemory, (void *(*)(void *)) NULL); if (AllocateImageColormap(image,image->colors) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Read image colormap. */ i=1; next=NextXPMLine(xpm_buffer); for (j=0; (j < (long) image->colors) && (next != (char*) NULL); j++) { p=next; next=NextXPMLine(p); (void) CopyXPMColor(key,p,MagickMin((size_t) width,MaxTextExtent)); status=AddValueToSplayTree(xpm_colors,ConstantString(key),(void *) j); /* Parse color. */ (void) CopyMagickString(target,"gray",MaxTextExtent); q=ParseXPMColor(p+width); if (q != (char *) NULL) { while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0')) q++; if (next != (char *) NULL) (void) CopyXPMColor(target,q,MagickMin((size_t) (next-q), MaxTextExtent)); else (void) CopyMagickString(target,q,MaxTextExtent); q=ParseXPMColor(target); if (q != (char *) NULL) *q='\0'; } StripString(target); if (LocaleCompare(target,"none") == 0) { image->storage_class=DirectClass; image->matte=MagickTrue; } if (QueryColorDatabase(target,&image->colormap[j],exception) == MagickFalse) break; } if (j < (long) image->colors) ThrowReaderException(CorruptImageError,"CorruptImage"); j=0; if (image_info->ping == MagickFalse) { /* Read image pixels. */ if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } for (y=0; y < (long) image->rows; y++) { p=NextXPMLine(p); if (p == (char *) NULL) break; r=SetImagePixels(image,0,y,image->columns,1); if (r == (PixelPacket *) NULL) break; indexes=GetIndexes(image); for (x=0; x < (long) image->columns; x++) { (void) CopyXPMColor(key,p,(size_t) width); j=(long) GetValueFromSplayTree(xpm_colors,key); if (image->storage_class == PseudoClass) indexes[x]=(IndexPacket) j; *r=image->colormap[j]; r++; p+=width; } if (SyncImagePixels(image) == MagickFalse) break; } if (y < (long) image->rows) ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); } /* Relinquish resources. */ xpm_colors=DestroySplayTree(xpm_colors); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d A V S I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadAVSImage() reads an AVS X image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadAVSImage method is: % % Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; long y; MagickBooleanType status; register long x; register PixelPacket *q; register unsigned char *p; ssize_t count; size_t length; unsigned char *pixels; unsigned long height, width; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read AVS X image. */ width=ReadBlobMSBLong(image); height=ReadBlobMSBLong(image); if ((width == ~0UL) || (height == ~0UL)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); do { /* Convert AVS raster image to pixel packets. */ image->columns=width; image->rows=height; image->depth=8; if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } length=(size_t) image->columns; pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels)); if (pixels == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); length*=4*sizeof(*pixels); for (y=0; y < (long) image->rows; y++) { count=ReadBlob(image,length,pixels); if ((size_t) count != length) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); p=pixels; q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; for (x=0; x < (long) image->columns; x++) { q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++)); q->red=ScaleCharToQuantum(*p++); q->green=ScaleCharToQuantum(*p++); q->blue=ScaleCharToQuantum(*p++); if (q->opacity != OpaqueOpacity) image->matte=MagickTrue; q++; } if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } pixels=(unsigned char *) RelinquishMagickMemory(pixels); if (EOFBlob(image) != MagickFalse) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Proceed to next image. */ if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; width=ReadBlobMSBLong(image); height=ReadBlobMSBLong(image); if ((width != ~0UL) && (height != ~0UL)) { /* Allocate next image structure. */ AllocateNextImage(image_info,image); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); if (image->progress_monitor != (MagickProgressMonitor) NULL) { status=image->progress_monitor(LoadImagesTag,TellBlob(image), GetBlobSize(image),image->client_data); if (status == MagickFalse) break; } } } while ((width != ~0UL) && (height != ~0UL)); CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d A R T I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadARTImage reads an ART X image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadARTImage method is: % % Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadARTImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or if % the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; int i; unsigned width,height,dummy; long ldblk; unsigned char *BImgBuff=NULL; unsigned char Padding; unsigned int status; const PixelPacket *q; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); /* Read ART image. */ dummy=ReadBlobLSBShort(image); width=ReadBlobLSBShort(image); dummy=ReadBlobLSBShort(image); height=ReadBlobLSBShort(image); ldblk=(long) ((width+7) / 8); Padding=(unsigned char) ((-ldblk) & 0x01); if(GetBlobSize(image)!=(8+((long)ldblk+Padding)*height)) ThrowReaderException(CorruptImageError,ImproperImageHeader,image); image->columns=width; image->rows=height; image->depth=1; image->colors=1l << image->depth; /* printf("ART header checked OK %d,%d\n",image->colors,image->depth); */ if (!AllocateImageColormap(image,image->colors)) goto NoMemory; /* If ping is true, then only set image size and colors without reading any image data. */ if (image_info->ping) goto DONE_READING; /* ----- Load RLE compressed raster ----- */ BImgBuff=MagickAllocateMemory(unsigned char *,((size_t) ldblk)); /*Ldblk was set in the check phase*/ if(BImgBuff==NULL) NoMemory: ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); for(i=0; i<(int)height; i++) { (void) ReadBlob(image,(size_t)ldblk,(char *)BImgBuff); (void) ReadBlob(image,Padding,(char *)&dummy); q=SetImagePixels(image,0,i,image->columns,1); if (q == (PixelPacket *)NULL) break; (void)ImportImagePixelArea(image,GrayQuantum,1,BImgBuff,NULL,0); if (!SyncImagePixels(image)) break; } if(BImgBuff!=NULL) MagickFreeMemory(BImgBuff); if (EOFBlob(image)) ThrowException(exception,CorruptImageError,UnexpectedEndOfFile, image->filename); DONE_READING: CloseBlob(image); return(image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d G R A Y I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadGRAYImage() reads an image of raw grayscale samples and returns % it. It allocates the memory necessary for the new Image structure and % returns a pointer to the new image. % % The format of the ReadGRAYImage method is: % % Image *ReadGRAYImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: The image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadGRAYImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; long j, y; MagickBooleanType status; MagickOffsetType offset; QuantumInfo quantum_info; register long i; register PixelPacket *q; ssize_t count; size_t packet_size; unsigned char *pixels; unsigned long width; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,"MustSpecifyImageSize"); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } for (i=0; i < image->offset; i++) if (ReadBlobByte(image) == EOF) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Allocate memory for a pixels. */ packet_size=(size_t) (image->depth+7)/8; pixels=(unsigned char *) AcquireQuantumMemory(image->extract_info.width, packet_size*sizeof(*pixels)); if (pixels == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); if (image_info->number_scenes != 0) while (image->scene < image_info->scene) { /* Skip to next image. */ image->scene++; for (y=0; y < (long) image->rows; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } } offset=(MagickOffsetType) (packet_size*image->extract_info.x); do { /* Convert raster image to pixel packets. */ GetQuantumInfo(image_info,&quantum_info); if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } for (y=0; y < image->extract_info.y; y++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } for (y=0; y < (long) image->rows; y++) { if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL)) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; (void) ExportQuantumPixels(image,&quantum_info,GrayQuantum,pixels+offset); if (SyncImagePixels(image) == MagickFalse) break; if (image->previous == (Image *) NULL) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } width=image->extract_info.height-image->rows-image->extract_info.y; for (j=0; j < (long) width; j++) { count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count != (ssize_t) (packet_size*image->extract_info.width)) break; } if (y < (long) image->rows) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Proceed to next image. */ if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; count=ReadBlob(image,packet_size*image->extract_info.width,pixels); if (count == (ssize_t) (packet_size*image->extract_info.width)) { /* Allocate next image structure. */ AllocateNextImage(image_info,image); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); if (image->progress_monitor != (MagickProgressMonitor) NULL) { status=image->progress_monitor(LoadImagesTag,TellBlob(image), GetBlobSize(image),image->client_data); if (status == MagickFalse) break; } } } while (count == (ssize_t) (packet_size*image->extract_info.width)); pixels=(unsigned char *) RelinquishMagickMemory(pixels); CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d V I C A R I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadVICARImage() reads a VICAR image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadVICARImage method is: % % Image *ReadVICARImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadVICARImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or if % the image cannot be read. % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadVICARImage(const ImageInfo *image_info, ExceptionInfo *exception) { char keyword[MaxTextExtent], value[MaxTextExtent]; Image *image; int c; long y; MagickBooleanType status, value_expected; QuantumInfo quantum_info; register PixelPacket *q; ssize_t count; ssize_t length; unsigned char *scanline; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Decode image header. */ c=ReadBlobByte(image); count=1; if (c == EOF) { image=DestroyImage(image); return((Image *) NULL); } length=0; image->columns=0; image->rows=0; while (isgraph(c) && ((image->columns == 0) || (image->rows == 0))) { if (isalnum(c) == MagickFalse) { c=ReadBlobByte(image); count++; } else { register char *p; /* Determine a keyword and its value. */ p=keyword; do { if ((size_t) (p-keyword) < MaxTextExtent) *p++=c; c=ReadBlobByte(image); count++; } while (isalnum(c) || (c == '_')); *p='\0'; value_expected=MagickFalse; while ((isspace((int) ((unsigned char) c)) != 0) || (c == '=')) { if (c == '=') value_expected=MagickTrue; c=ReadBlobByte(image); count++; } if (value_expected == MagickFalse) continue; p=value; while (isalnum(c)) { if ((size_t) (p-value) < MaxTextExtent) *p++=c; c=ReadBlobByte(image); count++; } *p='\0'; /* Assign a value to the specified keyword. */ if (LocaleCompare(keyword,"Label_RECORDS") == 0) length=(ssize_t) atol(value); if (LocaleCompare(keyword,"LBLSIZE") == 0) length=(ssize_t) atol(value); if (LocaleCompare(keyword,"RECORD_BYTES") == 0) image->columns=1UL*atol(value); if (LocaleCompare(keyword,"NS") == 0) image->columns=1UL*atol(value); if (LocaleCompare(keyword,"LINES") == 0) image->rows=1UL*atol(value); if (LocaleCompare(keyword,"NL") == 0) image->rows=1UL*atol(value); } while (isspace((int) ((unsigned char) c)) != 0) { c=ReadBlobByte(image); count++; } } while (count < (ssize_t) length) { c=ReadBlobByte(image); count++; } if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize"); image->depth=8; if (AllocateImageColormap(image,256) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); if (image_info->ping != MagickFalse) { (void) CloseBlob(image); return(GetFirstImageInList(image)); } /* Read VICAR pixels. */ if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } GetQuantumInfo(image_info,&quantum_info); scanline=(unsigned char *) AcquireQuantumMemory(image->columns, sizeof(*scanline)); if (scanline == (unsigned char *) NULL) ThrowReaderException(CorruptImageError,"UnableToReadImageData"); for (y=0; y < (long) image->rows; y++) { q=SetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; count=ReadBlob(image,image->columns,scanline); (void) ExportQuantumPixels(image,&quantum_info,GrayQuantum,scanline); if (SyncImagePixels(image) == MagickFalse) break; if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,image->rows) != MagickFalse)) { status=image->progress_monitor(LoadImageTag,y,image->rows, image->client_data); if (status == MagickFalse) break; } } scanline=(unsigned char *) RelinquishMagickMemory(scanline); if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d M A C I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadMACImage reads an MAC image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadMACImage method is: % % Image *ReadMACImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadMACImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or if % the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadMACImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; unsigned int y; unsigned char x8, rep, b; long ldblk; unsigned char *BImgBuff = NULL; unsigned char *DataPtr; unsigned int status; const PixelPacket *q; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image = AllocateImage(image_info); status = OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if(status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); /* Read MAC image. */ ldblk = ReadBlobLSBShort(image); if((ldblk & 0xFF)!=0) ThrowReaderException(CorruptImageError,ImproperImageHeader,image); if(ldblk==0) /* ???? don't know why */ SeekBlob(image,0x200,SEEK_SET); else SeekBlob(image,0x280,SEEK_SET); image->columns = 576; image->rows = 720; image->depth = 1; image->colors = 1l << image->depth; if (!AllocateImageColormap(image,image->colors)) goto NoMemory; /* If ping is true, then only set image size and colors without reading any image data. */ if (image_info->ping) goto DONE_READING; /* ----- Load RLE compressed raster ----- */ ldblk = (image->depth*image->columns) /8; BImgBuff = MagickAllocateMemory(unsigned char *, ((size_t)ldblk)); if(BImgBuff==NULL) NoMemory: ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); DataPtr = BImgBuff; x8=0; y=0; while(y<image->rows) { rep = ReadBlobByte(image); if(EOFBlob(image)) break; if( rep>=128 || rep<=0) { b = ~ReadBlobByte(image);; rep = ~rep + 2; while(rep>0) { *DataPtr++ = b; x8++; rep--; if(x8>=ldblk) { x8=0; q = SetImagePixels(image,0,y,image->columns,1); if(q == (PixelPacket *)NULL) break; (void)ImportImagePixelArea(image,GrayQuantum,1,BImgBuff,NULL,0); if(!SyncImagePixels(image)) break; DataPtr = BImgBuff; y++; if(y>=image->rows) { break; } } } } else { rep++; while(rep>0) { b = ~ReadBlobByte(image); *DataPtr++ = b; x8++; rep--; if(x8>=ldblk) { x8=0; q = SetImagePixels(image,0,y,image->columns,1); if(q == (PixelPacket *)NULL) break; (void)ImportImagePixelArea(image,GrayQuantum,1,BImgBuff,NULL,0); if (!SyncImagePixels(image)) break; DataPtr = BImgBuff; y++; if(y>=image->rows) { break; } } } } } if(BImgBuff!=NULL) MagickFreeMemory(BImgBuff); if(EOFBlob(image)) ThrowException(exception,CorruptImageError,UnexpectedEndOfFile,image->filename); DONE_READING: CloseBlob(image); return(image); }
static Image *ReadJP2Image(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; long y; jas_image_t *jp2_image; jas_matrix_t *pixels; jas_stream_t *jp2_stream; register long x; register PixelPacket *q; int component, components[4], number_components; Quantum *channel_lut[4]; unsigned int status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); /* Obtain a JP2 Stream. */ jp2_stream=JP2StreamManager(image); if (jp2_stream == (jas_stream_t *) NULL) ThrowReaderException(DelegateError,UnableToManageJP2Stream,image); jp2_image=jas_image_decode(jp2_stream,-1,0); if (jp2_image == (jas_image_t *) NULL) { (void) jas_stream_close(jp2_stream); ThrowReaderException(DelegateError,UnableToDecodeImageFile,image); } /* Validate that we can handle the image and obtain component indexes. */ switch (jas_clrspc_fam(jas_image_clrspc(jp2_image))) { case JAS_CLRSPC_FAM_RGB: { if (((components[0]= jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R))) < 0) || ((components[1]= jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G))) < 0) || ((components[2]= jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B))) < 0)) { (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); ThrowReaderException(CorruptImageError,MissingImageChannel,image); } number_components=3; (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Image is in RGB colorspace family"); (void) LogMagickEvent(CoderEvent,GetMagickModule(), "RED is in channel %d, GREEN is in channel %d, BLUE is in channel %d", components[0],components[1],components[2]); if((components[3]=jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_OPACITY))) > 0) { image->matte=MagickTrue; (void) LogMagickEvent(CoderEvent,GetMagickModule(), "OPACITY is in channel %d",components[3]); number_components++; } break; } case JAS_CLRSPC_FAM_GRAY: { if ((components[0]= jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y))) < 0) { (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); ThrowReaderException(CorruptImageError,MissingImageChannel,image); } (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Image is in GRAY colorspace family"); (void) LogMagickEvent(CoderEvent,GetMagickModule(), "GRAY is in channel %d",components[0]); number_components=1; break; } case JAS_CLRSPC_FAM_YCBCR: { components[0]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_YCBCR_Y); components[1]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_YCBCR_CB); components[2]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_YCBCR_CR); if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) { (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); ThrowReaderException(CorruptImageError,MissingImageChannel,image); } number_components=3; components[3]=jas_image_getcmptbytype(jp2_image,JAS_IMAGE_CT_OPACITY); if (components[3] > 0) { image->matte=True; number_components++; } image->colorspace=YCbCrColorspace; (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Image is in YCBCR colorspace family"); break; } default: { (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); ThrowReaderException(CoderError,ColorspaceModelIsNotSupported,image); } } image->columns=jas_image_width(jp2_image); image->rows=jas_image_height(jp2_image); (void) LogMagickEvent(CoderEvent,GetMagickModule(), "columns=%lu rows=%lu components=%d",image->columns,image->rows, number_components); for (component=0; component < number_components; component++) { if(((unsigned long) jas_image_cmptwidth(jp2_image,components[component]) != image->columns) || ((unsigned long) jas_image_cmptheight(jp2_image,components[component]) != image->rows) || (jas_image_cmpttlx(jp2_image, components[component]) != 0) || (jas_image_cmpttly(jp2_image, components[component]) != 0) || (jas_image_cmpthstep(jp2_image, components[component]) != 1) || (jas_image_cmptvstep(jp2_image, components[component]) != 1) || (jas_image_cmptsgnd(jp2_image, components[component]) != false)) { (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); ThrowReaderException(CoderError,IrregularChannelGeometryNotSupported,image); } } image->matte=number_components > 3; for (component=0; component < number_components; component++) { unsigned int component_depth; component_depth=jas_image_cmptprec(jp2_image,components[component]); (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Component[%d] depth is %u",component,component_depth); if (0 == component) image->depth=component_depth; else image->depth=Max(image->depth,component_depth); } (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Image depth is %u",image->depth); if (image_info->ping) { (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); return(image); } /* Allocate Jasper pixels. */ pixels=jas_matrix_create(1,(unsigned int) image->columns); if (pixels == (jas_matrix_t *) NULL) { jas_image_destroy(jp2_image); ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); } /* Allocate and populate channel LUTs */ for (component=0; component < (long) number_components; component++) { unsigned long component_depth, i, max_value; double scale_to_quantum; component_depth=jas_image_cmptprec(jp2_image,components[component]); max_value=MaxValueGivenBits(component_depth); scale_to_quantum=MaxRGBDouble/max_value; (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Channel %d scale is %g", component, scale_to_quantum); channel_lut[component]=MagickAllocateArray(Quantum *,max_value+1,sizeof(Quantum)); if (channel_lut[component] == (Quantum *) NULL) { for ( --component; component >= 0; --component) MagickFreeMemory(channel_lut[component]); jas_matrix_destroy(pixels); jas_image_destroy(jp2_image); ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image); } for(i=0; i <= max_value; i++) (channel_lut[component])[i]=scale_to_quantum*i+0.5; } /* Convert JPEG 2000 pixels. */ for (y=0; y < (long) image->rows; y++) { q=GetImagePixels(image,0,y,image->columns,1); if (q == (PixelPacket *) NULL) break; if (1 == number_components) { /* Grayscale */ (void) jas_image_readcmpt(jp2_image,(short) components[0],0, (unsigned int) y, (unsigned int) image->columns,1,pixels); for (x=0; x < (long) image->columns; x++) { q->red=q->green=q->blue=(channel_lut[0])[jas_matrix_getv(pixels,x)]; q->opacity=OpaqueOpacity; q++; } } else { /* Red */ (void) jas_image_readcmpt(jp2_image,(short) components[0],0, (unsigned int) y, (unsigned int) image->columns,1,pixels); for (x=0; x < (long) image->columns; x++) q[x].red=(channel_lut[0])[jas_matrix_getv(pixels,x)]; /* Green */ (void) jas_image_readcmpt(jp2_image,(short) components[1],0, (unsigned int) y, (unsigned int) image->columns,1,pixels); for (x=0; x < (long) image->columns; x++) q[x].green=(channel_lut[1])[jas_matrix_getv(pixels,x)]; /* Blue */ (void) jas_image_readcmpt(jp2_image,(short) components[2],0, (unsigned int) y, (unsigned int) image->columns,1,pixels); for (x=0; x < (long) image->columns; x++) q[x].blue=(channel_lut[2])[jas_matrix_getv(pixels,x)]; /* Opacity */ if (number_components > 3) { (void) jas_image_readcmpt(jp2_image,(short) components[3],0, (unsigned int) y, (unsigned int) image->columns,1,pixels); for (x=0; x < (long) image->columns; x++) q[x].opacity=MaxRGB-(channel_lut[3])[jas_matrix_getv(pixels,x)]; } else { for (x=0; x < (long) image->columns; x++) q[x].opacity=OpaqueOpacity; } } if (!SyncImagePixels(image)) break; if (image->previous == (Image *) NULL) if (QuantumTick(y,image->rows)) if (!MagickMonitorFormatted(y,image->rows,exception,LoadImageText, image->filename, image->columns,image->rows)) break; } if (number_components == 1) image->is_grayscale=MagickTrue; { /* Obtain ICC ICM color profile */ jas_cmprof_t *cm_profile; /* Obtain a pointer to the existing jas_cmprof_t profile handle. */ cm_profile=jas_image_cmprof(jp2_image); if (cm_profile != (jas_cmprof_t *) NULL) { jas_iccprof_t *icc_profile; /* Obtain a copy of the jas_iccprof_t ICC profile handle */ icc_profile=jas_iccprof_createfromcmprof(cm_profile); /* or maybe just icc_profile=cm_profile->iccprof */ if (icc_profile != (jas_iccprof_t *) NULL) { jas_stream_t *icc_stream; icc_stream=jas_stream_memopen(NULL,0); if ((icc_stream != (jas_stream_t *) NULL) && (jas_iccprof_save(icc_profile,icc_stream) == 0) && (jas_stream_flush(icc_stream) == 0)) { jas_stream_memobj_t *blob; blob=(jas_stream_memobj_t *) icc_stream->obj_; if (image->logging) (void) LogMagickEvent(CoderEvent,GetMagickModule(), "ICC profile: %lu bytes",(unsigned long) blob->len_); SetImageProfile(image,"ICM",blob->buf_,blob->len_); (void) jas_stream_close(icc_stream); jas_iccprof_destroy(icc_profile); } } } } for (component=0; component < (long) number_components; component++) MagickFreeMemory(channel_lut[component]); jas_matrix_destroy(pixels); (void) jas_stream_close(jp2_stream); jas_image_destroy(jp2_image); return(image); }
Export Image *ReadSFWImage(const ImageInfo *image_info) { static unsigned char HuffmanTable[] = { 0xFF, 0xC4, 0x01, 0xA2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA }; FILE *file; Image *flipped_image, *image; ImageInfo *local_info; register unsigned char *header, *data; unsigned char *buffer, *offset; unsigned int status; /* Allocate image structure. */ image=AllocateImage(image_info); if (image == (Image *) NULL) return((Image *) NULL); /* Open image file. */ status=OpenBlob(image_info,image,ReadBinaryType); if (status == False) ReaderExit(FileOpenWarning,"Unable to open file",image); /* Read image into a buffer. */ buffer=(unsigned char *) AllocateMemory(image->filesize*sizeof(unsigned char)); if (buffer == (unsigned char *) NULL) ReaderExit(ResourceLimitWarning,"Memory allocation failed",image); status=ReadBlob(image,image->filesize,(char *) buffer); if ((status == False) || (strncmp((char *) buffer,"SFW",3) != 0)) ReaderExit(CorruptImageWarning,"Not a SFW image file",image); CloseBlob(image); DestroyImage(image); /* Find the start of the JFIF data */ header=SFWScan(buffer,buffer+image->filesize-1,(unsigned char *) "\377\310\377\320",4); if (header == (unsigned char *) NULL) { FreeMemory(buffer); ReaderExit(CorruptImageWarning,"Not a SFW image file",image); } TranslateSFWMarker(header); /* translate soi and app tags */ TranslateSFWMarker(header+2); (void) memcpy((char *) header+6,"JFIF\0\001\0",7); /* JFIF magic */ /* Translate remaining markers. */ offset=header+2; offset+=(offset[2] << 8)+offset[3]+2; for ( ; ; ) { TranslateSFWMarker(offset); if (offset[1] == 0xda) break; offset+=(offset[2] << 8)+offset[3]+2; } offset--; data=SFWScan(offset,buffer+image->filesize-1,(unsigned char *) "\377\311",2); if (data == (unsigned char *) NULL) { FreeMemory(buffer); ReaderExit(CorruptImageWarning,"Not a SFW image file",image); } TranslateSFWMarker(data++); /* translate eoi marker */ /* Write JFIF file. */ local_info=CloneImageInfo(image_info); TemporaryFilename(local_info->filename); file=fopen(local_info->filename,WriteBinaryType); if (file == (FILE *) NULL) { FreeMemory(buffer); DestroyImageInfo(local_info); ReaderExit(FileOpenWarning,"Unable to write file",image); } (void) fwrite(header,offset-header+1,1,file); (void) fwrite(HuffmanTable,1,sizeof(HuffmanTable)/sizeof(*HuffmanTable),file); (void) fwrite(offset+1,data-offset,1,file); status=ferror(file); (void) fclose(file); FreeMemory(buffer); if (status) { (void) remove(local_info->filename); DestroyImageInfo(local_info); ReaderExit(FileOpenWarning,"Unable to write file",image); } /* Read JPEG image. */ image=ReadImage(local_info); (void) remove(local_info->filename); DestroyImageInfo(local_info); if (image == (Image *) NULL) return(image); /* Correct image orientation. */ flipped_image=FlipImage(image); if (flipped_image == (Image *) NULL) return(image); DestroyImage(image); return(flipped_image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d M V G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadMVGImage creates a gradient image and initializes it to % the X server color range as specified by the filename. It allocates the % memory necessary for the new Image structure and returns a pointer to the % new image. % % The format of the ReadMVGImage method is: % % Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadMVGImage returns a pointer to the image after % creating it. A null image is returned if there is a memory shortage % or if the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception) { #define BoundingBox "viewbox" DrawInfo *draw_info; Image *image; size_t length; unsigned int status; /* Open image. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == False) ThrowReaderException(FileOpenError,UnableToOpenFile,image); if ((image->columns == 0) || (image->rows == 0)) { char primitive[MaxTextExtent]; register char *p; SegmentInfo bounds; /* Determine size of image canvas. */ while (ReadBlobString(image,primitive) != (char *) NULL) { for (p=primitive; (*p == ' ') || (*p == '\t'); p++); if (LocaleNCompare(BoundingBox,p,strlen(BoundingBox)) != 0) continue; (void) sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1, &bounds.x2,&bounds.y2); image->columns=(unsigned long) (bounds.x2-bounds.x1+0.5); image->rows=(unsigned long) (bounds.y2-bounds.y1+0.5); break; } } if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,MustSpecifyImageSize,image); if (CheckImagePixelLimits(image, exception) != MagickPass) ThrowReaderException(ResourceLimitError,ImagePixelLimitExceeded,image); /* Render drawing. */ (void) SetImage(image,OpaqueOpacity); draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); draw_info->fill=image_info->pen; if (GetBlobStreamData(image)) draw_info->primitive=AllocateString((char *) GetBlobStreamData(image)); else draw_info->primitive=(char *) FileToBlob(image->filename,&length,exception); if (draw_info->primitive == (char *) NULL) { DestroyDrawInfo(draw_info); CloseBlob(image); return (Image *) NULL; } (void) DrawImage(image,draw_info); DestroyDrawInfo(draw_info); CloseBlob(image); return(image); }