Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/avs.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % AAA V V SSSSS % 00007 % A A V V SS % 00008 % AAAAA V V SSS % 00009 % A A V V SS % 00010 % A A V SSSSS % 00011 % % 00012 % % 00013 % Read/Write AVS X Image Format. % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % July 1992 % 00018 % % 00019 % % 00020 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00021 % dedicated to making software imaging solutions freely available. % 00022 % % 00023 % You may not use this file except in compliance with the License. You may % 00024 % obtain a copy of the License at % 00025 % % 00026 % http://www.imagemagick.org/www/Copyright.html % 00027 % % 00028 % Unless required by applicable law or agreed to in writing, software % 00029 % distributed under the License is distributed on an "AS IS" BASIS, % 00030 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00031 % See the License for the specific language governing permissions and % 00032 % limitations under the License. % 00033 % % 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 % 00036 % 00037 */ 00038 00039 /* 00040 Include declarations. 00041 */ 00042 #include "magick/studio.h" 00043 #include "magick/blob.h" 00044 #include "magick/blob_private.h" 00045 #include "magick/colorspace.h" 00046 #include "magick/error.h" 00047 #include "magick/error_private.h" 00048 #include "magick/image.h" 00049 #include "magick/image_private.h" 00050 #include "magick/list.h" 00051 #include "magick/magick.h" 00052 #include "magick/memory_.h" 00053 #include "magick/monitor.h" 00054 #include "magick/static.h" 00055 #include "magick/string_.h" 00056 00057 /* 00058 Forward declarations. 00059 */ 00060 static MagickBooleanType 00061 WriteAVSImage(const ImageInfo *,Image *); 00062 00063 /* 00064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00065 % % 00066 % % 00067 % % 00068 % R e a d A V S I m a g e % 00069 % % 00070 % % 00071 % % 00072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00073 % 00074 % ReadAVSImage() reads an AVS X image file and returns it. It 00075 % allocates the memory necessary for the new Image structure and returns a 00076 % pointer to the new image. 00077 % 00078 % The format of the ReadAVSImage method is: 00079 % 00080 % Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) 00081 % 00082 % A description of each parameter follows: 00083 % 00084 % o image_info: The image info. 00085 % 00086 % o exception: return any errors or warnings in this structure. 00087 % 00088 % 00089 */ 00090 static Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) 00091 { 00092 Image 00093 *image; 00094 00095 long 00096 y; 00097 00098 MagickBooleanType 00099 status; 00100 00101 register long 00102 x; 00103 00104 register PixelPacket 00105 *q; 00106 00107 register unsigned char 00108 *p; 00109 00110 ssize_t 00111 count; 00112 00113 unsigned char 00114 *pixels; 00115 00116 unsigned long 00117 height, 00118 width; 00119 00120 /* 00121 Open image file. 00122 */ 00123 assert(image_info != (const ImageInfo *) NULL); 00124 assert(image_info->signature == MagickSignature); 00125 if (image_info->debug != MagickFalse) 00126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00127 assert(exception != (ExceptionInfo *) NULL); 00128 assert(exception->signature == MagickSignature); 00129 image=AllocateImage(image_info); 00130 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00131 if (status == MagickFalse) 00132 { 00133 DestroyImageList(image); 00134 return((Image *) NULL); 00135 } 00136 /* 00137 Read AVS X image. 00138 */ 00139 width=ReadBlobMSBLong(image); 00140 height=ReadBlobMSBLong(image); 00141 if ((width == (unsigned long) ~0) || (height == (unsigned long) ~0)) 00142 ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 00143 do 00144 { 00145 /* 00146 Convert AVS raster image to pixel packets. 00147 */ 00148 image->columns=width; 00149 image->rows=height; 00150 image->depth=8; 00151 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) 00152 if (image->scene >= (image_info->scene+image_info->number_scenes-1)) 00153 break; 00154 pixels=(unsigned char *) AcquireMagickMemory((size_t) (4*image->columns)); 00155 if (pixels == (unsigned char *) NULL) 00156 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 00157 for (y=0; y < (long) image->rows; y++) 00158 { 00159 count=ReadBlob(image,(size_t) (4*image->columns),pixels); 00160 if (count == 0) 00161 ThrowReaderException(CorruptImageError,"UnableToReadImageData"); 00162 p=pixels; 00163 q=SetImagePixels(image,0,y,image->columns,1); 00164 if (q == (PixelPacket *) NULL) 00165 break; 00166 for (x=0; x < (long) image->columns; x++) 00167 { 00168 q->opacity=(Quantum) (MaxRGB-ScaleCharToQuantum((unsigned long) *p++)); 00169 q->red=ScaleCharToQuantum((unsigned long) *p++); 00170 q->green=ScaleCharToQuantum((unsigned long) *p++); 00171 q->blue=ScaleCharToQuantum((unsigned long) *p++); 00172 if (q->opacity != OpaqueOpacity) 00173 image->matte=MagickTrue; 00174 q++; 00175 } 00176 if (SyncImagePixels(image) == MagickFalse) 00177 break; 00178 if (image->previous == (Image *) NULL) 00179 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00180 (QuantumTick(y,image->rows) != MagickFalse)) 00181 { 00182 status=image->progress_monitor(LoadImageTag,y,image->rows, 00183 image->client_data); 00184 if (status == MagickFalse) 00185 break; 00186 } 00187 } 00188 pixels=(unsigned char *) RelinquishMagickMemory(pixels); 00189 if (EOFBlob(image) != MagickFalse) 00190 { 00191 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", 00192 image->filename); 00193 break; 00194 } 00195 /* 00196 Proceed to next image. 00197 */ 00198 if (image_info->number_scenes != 0) 00199 if (image->scene >= (image_info->scene+image_info->number_scenes-1)) 00200 break; 00201 width=ReadBlobMSBLong(image); 00202 height=ReadBlobMSBLong(image); 00203 if ((width != (unsigned long) ~0) && (height != (unsigned long) ~0)) 00204 { 00205 /* 00206 Allocate next image structure. 00207 */ 00208 AllocateNextImage(image_info,image); 00209 if (image->next == (Image *) NULL) 00210 { 00211 DestroyImageList(image); 00212 return((Image *) NULL); 00213 } 00214 image=SyncNextImageInList(image); 00215 if (image->progress_monitor != (MagickProgressMonitor) NULL) 00216 { 00217 status=image->progress_monitor(LoadImagesTag,TellBlob(image), 00218 GetBlobSize(image),image->client_data); 00219 if (status == MagickFalse) 00220 break; 00221 } 00222 } 00223 } while ((width != (unsigned long) ~0) && (height != (unsigned long) ~0)); 00224 CloseBlob(image); 00225 return(GetFirstImageInList(image)); 00226 } 00227 00228 /* 00229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00230 % % 00231 % % 00232 % % 00233 % R e g i s t e r A V S I m a g e % 00234 % % 00235 % % 00236 % % 00237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00238 % 00239 % RegisterAVSImage() adds attributes for the AVS X image format to the list 00240 % of supported formats. The attributes include the image format tag, a 00241 % method to read and/or write the format, whether the format supports the 00242 % saving of more than one frame to the same file or blob, whether the format 00243 % supports native in-memory I/O, and a brief description of the format. 00244 % 00245 % The format of the RegisterAVSImage method is: 00246 % 00247 % RegisterAVSImage(void) 00248 % 00249 */ 00250 ModuleExport void RegisterAVSImage(void) 00251 { 00252 MagickInfo 00253 *entry; 00254 00255 entry=SetMagickInfo("AVS"); 00256 entry->decoder=(DecoderHandler *) ReadAVSImage; 00257 entry->encoder=(EncoderHandler *) WriteAVSImage; 00258 entry->description=AcquireString("AVS X image"); 00259 entry->module=AcquireString("AVS"); 00260 (void) RegisterMagickInfo(entry); 00261 } 00262 00263 /* 00264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00265 % % 00266 % % 00267 % % 00268 % U n r e g i s t e r A V S I m a g e % 00269 % % 00270 % % 00271 % % 00272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00273 % 00274 % UnregisterAVSImage() removes format registrations made by the 00275 % AVS module from the list of supported formats. 00276 % 00277 % The format of the UnregisterAVSImage method is: 00278 % 00279 % UnregisterAVSImage(void) 00280 % 00281 */ 00282 ModuleExport void UnregisterAVSImage(void) 00283 { 00284 (void) UnregisterMagickInfo("AVS"); 00285 } 00286 00287 /* 00288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00289 % % 00290 % % 00291 % % 00292 % W r i t e A V S I m a g e % 00293 % % 00294 % % 00295 % % 00296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00297 % 00298 % WriteAVSImage() writes an image to a file in AVS X image format. 00299 % 00300 % The format of the WriteAVSImage method is: 00301 % 00302 % MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image) 00303 % 00304 % A description of each parameter follows. 00305 % 00306 % o image_info: The image info. 00307 % 00308 % o image: The image. 00309 % 00310 % 00311 */ 00312 static MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image) 00313 { 00314 MagickBooleanType 00315 status; 00316 00317 MagickOffsetType 00318 scene; 00319 00320 register const PixelPacket 00321 *p; 00322 00323 register long 00324 x, 00325 y; 00326 00327 register unsigned char 00328 *q; 00329 00330 unsigned char 00331 *pixels; 00332 00333 /* 00334 Open output image file. 00335 */ 00336 assert(image_info != (const ImageInfo *) NULL); 00337 assert(image_info->signature == MagickSignature); 00338 assert(image != (Image *) NULL); 00339 assert(image->signature == MagickSignature); 00340 if (image->debug != MagickFalse) 00341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00342 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00343 if (status == MagickFalse) 00344 return(status); 00345 scene=0; 00346 do 00347 { 00348 /* 00349 Write AVS header. 00350 */ 00351 (void) SetImageColorspace(image,RGBColorspace); 00352 (void) WriteBlobMSBLong(image,image->columns); 00353 (void) WriteBlobMSBLong(image,image->rows); 00354 /* 00355 Allocate memory for pixels. 00356 */ 00357 pixels=(unsigned char *) 00358 AcquireMagickMemory((size_t) image->columns*sizeof(PixelPacket)); 00359 if (pixels == (unsigned char *) NULL) 00360 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 00361 /* 00362 Convert MIFF to AVS raster pixels. 00363 */ 00364 for (y=0; y < (long) image->rows; y++) 00365 { 00366 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception); 00367 if (p == (PixelPacket *) NULL) 00368 break; 00369 q=pixels; 00370 for (x=0; x < (long) image->columns; x++) 00371 { 00372 *q++=ScaleQuantumToChar(MaxRGB-(image->matte != MagickFalse ? 00373 p->opacity : OpaqueOpacity)); 00374 *q++=ScaleQuantumToChar(p->red); 00375 *q++=ScaleQuantumToChar(p->green); 00376 *q++=ScaleQuantumToChar(p->blue); 00377 p++; 00378 } 00379 (void) WriteBlob(image,(size_t) (q-pixels),pixels); 00380 if (image->previous == (Image *) NULL) 00381 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00382 (QuantumTick(y,image->rows) != MagickFalse)) 00383 { 00384 status=image->progress_monitor(SaveImageTag,y,image->rows, 00385 image->client_data); 00386 if (status == MagickFalse) 00387 break; 00388 } 00389 } 00390 pixels=(unsigned char *) RelinquishMagickMemory(pixels); 00391 if (image->next == (Image *) NULL) 00392 break; 00393 image=SyncNextImageInList(image); 00394 if (image->progress_monitor != (MagickProgressMonitor) NULL) 00395 { 00396 status=image->progress_monitor(SaveImagesTag,scene, 00397 GetImageListLength(image),image->client_data); 00398 if (status == MagickFalse) 00399 break; 00400 } 00401 scene++; 00402 } while (image_info->adjoin != MagickFalse); 00403 CloseBlob(image); 00404 return(MagickTrue); 00405 }

Generated on Mon Oct 25 13:40:35 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC