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/mtv.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % M M TTTTT V V % 00007 % MM MM T V V % 00008 % M M M T V V % 00009 % M M T V V % 00010 % M M T V % 00011 % % 00012 % % 00013 % Read/Write MTV Raytracer 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 WriteMTVImage(const ImageInfo *,Image *); 00062 00063 /* 00064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00065 % % 00066 % % 00067 % % 00068 % R e a d M T V I m a g e % 00069 % % 00070 % % 00071 % % 00072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00073 % 00074 % ReadMTVImage() reads a MTV image file and returns it. It allocates 00075 % the memory necessary for the new Image structure and returns a pointer to 00076 % the new image. 00077 % 00078 % The format of the ReadMTVImage method is: 00079 % 00080 % Image *ReadMTVImage(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 *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception) 00091 { 00092 char 00093 buffer[MaxTextExtent]; 00094 00095 Image 00096 *image; 00097 00098 long 00099 y; 00100 00101 MagickBooleanType 00102 status; 00103 00104 register long 00105 x; 00106 00107 register PixelPacket 00108 *q; 00109 00110 register unsigned char 00111 *p; 00112 00113 ssize_t 00114 count; 00115 00116 unsigned char 00117 *pixels; 00118 00119 unsigned long 00120 columns, 00121 rows; 00122 00123 /* 00124 Open image file. 00125 */ 00126 assert(image_info != (const ImageInfo *) NULL); 00127 assert(image_info->signature == MagickSignature); 00128 if (image_info->debug != MagickFalse) 00129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00130 assert(exception != (ExceptionInfo *) NULL); 00131 assert(exception->signature == MagickSignature); 00132 image=AllocateImage(image_info); 00133 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00134 if (status == MagickFalse) 00135 { 00136 DestroyImageList(image); 00137 return((Image *) NULL); 00138 } 00139 /* 00140 Read MTV image. 00141 */ 00142 (void) ReadBlobString(image,buffer); 00143 count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows); 00144 if (count <= 0) 00145 ThrowReaderException(CorruptImageError,"ImproperImageHeader"); 00146 do 00147 { 00148 /* 00149 Initialize image structure. 00150 */ 00151 image->columns=columns; 00152 image->rows=rows; 00153 image->depth=8; 00154 if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) 00155 if (image->scene >= (image_info->scene+image_info->number_scenes-1)) 00156 break; 00157 /* 00158 Convert MTV raster image to pixel packets. 00159 */ 00160 pixels=(unsigned char *) AcquireMagickMemory((size_t) (3*image->columns)); 00161 if (pixels == (unsigned char *) NULL) 00162 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 00163 for (y=0; y < (long) image->rows; y++) 00164 { 00165 count=(ssize_t) ReadBlob(image,(size_t) (3*image->columns),pixels); 00166 if (count == 0) 00167 ThrowReaderException(CorruptImageError,"UnableToReadImageData"); 00168 p=pixels; 00169 q=SetImagePixels(image,0,y,image->columns,1); 00170 if (q == (PixelPacket *) NULL) 00171 break; 00172 for (x=0; x < (long) image->columns; x++) 00173 { 00174 q->red=ScaleCharToQuantum(*p++); 00175 q->green=ScaleCharToQuantum(*p++); 00176 q->blue=ScaleCharToQuantum(*p++); 00177 q++; 00178 } 00179 if (SyncImagePixels(image) == MagickFalse) 00180 break; 00181 if (image->previous == (Image *) NULL) 00182 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00183 (QuantumTick(y,image->rows) != MagickFalse)) 00184 { 00185 status=image->progress_monitor(LoadImageTag,y,image->rows, 00186 image->client_data); 00187 if (status == MagickFalse) 00188 break; 00189 } 00190 } 00191 pixels=(unsigned char *) RelinquishMagickMemory(pixels); 00192 if (EOFBlob(image) != MagickFalse) 00193 { 00194 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", 00195 image->filename); 00196 break; 00197 } 00198 /* 00199 Proceed to next image. 00200 */ 00201 if (image_info->number_scenes != 0) 00202 if (image->scene >= (image_info->scene+image_info->number_scenes-1)) 00203 break; 00204 *buffer='\0'; 00205 (void) ReadBlobString(image,buffer); 00206 count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows); 00207 if (count > 0) 00208 { 00209 /* 00210 Allocate next image structure. 00211 */ 00212 AllocateNextImage(image_info,image); 00213 if (image->next == (Image *) NULL) 00214 { 00215 DestroyImageList(image); 00216 return((Image *) NULL); 00217 } 00218 image=SyncNextImageInList(image); 00219 if (image->progress_monitor != (MagickProgressMonitor) NULL) 00220 { 00221 status=image->progress_monitor(LoadImagesTag,TellBlob(image), 00222 GetBlobSize(image),image->client_data); 00223 if (status == MagickFalse) 00224 break; 00225 } 00226 } 00227 } while (count > 0); 00228 CloseBlob(image); 00229 return(GetFirstImageInList(image)); 00230 } 00231 00232 /* 00233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00234 % % 00235 % % 00236 % % 00237 % R e g i s t e r M T V I m a g e % 00238 % % 00239 % % 00240 % % 00241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00242 % 00243 % RegisterMTVImage() adds attributes for the MTV image format to 00244 % the list of supported formats. The attributes include the image format 00245 % tag, a method to read and/or write the format, whether the format 00246 % supports the saving of more than one frame to the same file or blob, 00247 % whether the format supports native in-memory I/O, and a brief 00248 % description of the format. 00249 % 00250 % The format of the RegisterMTVImage method is: 00251 % 00252 % RegisterMTVImage(void) 00253 % 00254 */ 00255 ModuleExport void RegisterMTVImage(void) 00256 { 00257 MagickInfo 00258 *entry; 00259 00260 entry=SetMagickInfo("MTV"); 00261 entry->decoder=(DecoderHandler *) ReadMTVImage; 00262 entry->encoder=(EncoderHandler *) WriteMTVImage; 00263 entry->description=AcquireString("MTV Raytracing image format"); 00264 entry->module=AcquireString("MTV"); 00265 (void) RegisterMagickInfo(entry); 00266 } 00267 00268 /* 00269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00270 % % 00271 % % 00272 % % 00273 % U n r e g i s t e r M T V I m a g e % 00274 % % 00275 % % 00276 % % 00277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00278 % 00279 % UnregisterMTVImage() removes format registrations made by the 00280 % MTV module from the list of supported formats. 00281 % 00282 % The format of the UnregisterMTVImage method is: 00283 % 00284 % UnregisterMTVImage(void) 00285 % 00286 */ 00287 ModuleExport void UnregisterMTVImage(void) 00288 { 00289 (void) UnregisterMagickInfo("MTV"); 00290 } 00291 00292 /* 00293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00294 % % 00295 % % 00296 % % 00297 % W r i t e M T V I m a g e % 00298 % % 00299 % % 00300 % % 00301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00302 % 00303 % WriteMTVImage() writes an image to a file in red, green, and blue 00304 % MTV rasterfile format. 00305 % 00306 % The format of the WriteMTVImage method is: 00307 % 00308 % MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image) 00309 % 00310 % A description of each parameter follows. 00311 % 00312 % o image_info: The image info. 00313 % 00314 % o image: The image. 00315 % 00316 % 00317 */ 00318 static MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image) 00319 { 00320 char 00321 buffer[MaxTextExtent]; 00322 00323 long 00324 y; 00325 00326 MagickBooleanType 00327 status; 00328 00329 MagickOffsetType 00330 scene; 00331 00332 register const PixelPacket 00333 *p; 00334 00335 register long 00336 x; 00337 00338 register unsigned char 00339 *q; 00340 00341 unsigned char 00342 *pixels; 00343 00344 /* 00345 Open output image file. 00346 */ 00347 assert(image_info != (const ImageInfo *) NULL); 00348 assert(image_info->signature == MagickSignature); 00349 assert(image != (Image *) NULL); 00350 assert(image->signature == MagickSignature); 00351 if (image->debug != MagickFalse) 00352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00353 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); 00354 if (status == MagickFalse) 00355 return(status); 00356 scene=0; 00357 do 00358 { 00359 /* 00360 Allocate memory for pixels. 00361 */ 00362 (void) SetImageColorspace(image,RGBColorspace); 00363 pixels=(unsigned char *) 00364 AcquireMagickMemory((size_t) image->columns*sizeof(PixelPacket)); 00365 if (pixels == (unsigned char *) NULL) 00366 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); 00367 /* 00368 Initialize raster file header. 00369 */ 00370 (void) FormatMagickString(buffer,MaxTextExtent,"%lu %lu\n", 00371 image->columns,image->rows); 00372 (void) WriteBlobString(image,buffer); 00373 for (y=0; y < (long) image->rows; y++) 00374 { 00375 p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception); 00376 if (p == (const PixelPacket *) NULL) 00377 break; 00378 q=pixels; 00379 for (x=0; x < (long) image->columns; x++) 00380 { 00381 *q++=ScaleQuantumToChar(p->red); 00382 *q++=ScaleQuantumToChar(p->green); 00383 *q++=ScaleQuantumToChar(p->blue); 00384 p++; 00385 } 00386 (void) WriteBlob(image,(size_t) (q-pixels),pixels); 00387 if (image->previous == (Image *) NULL) 00388 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00389 (QuantumTick(y,image->rows) != MagickFalse)) 00390 { 00391 status=image->progress_monitor(SaveImageTag,y,image->rows, 00392 image->client_data); 00393 if (status == MagickFalse) 00394 break; 00395 } 00396 } 00397 pixels=(unsigned char *) RelinquishMagickMemory(pixels); 00398 if (image->next == (Image *) NULL) 00399 break; 00400 image=SyncNextImageInList(image); 00401 if (image->progress_monitor != (MagickProgressMonitor) NULL) 00402 { 00403 status=image->progress_monitor(SaveImagesTag,scene, 00404 GetImageListLength(image),image->client_data); 00405 if (status == MagickFalse) 00406 break; 00407 } 00408 scene++; 00409 } while (image_info->adjoin != MagickFalse); 00410 CloseBlob(image); 00411 return(MagickTrue); 00412 }

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