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

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % M M V V GGGG % 00007 % MM MM V V G % 00008 % M M M V V G GG % 00009 % M M V V G G % 00010 % M M V GGG % 00011 % % 00012 % % 00013 % Read/Write Magick Vector Graphics Metafiles. % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % April 2000 % 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/attribute.h" 00044 #include "magick/blob.h" 00045 #include "magick/blob_private.h" 00046 #include "magick/draw.h" 00047 #include "magick/error.h" 00048 #include "magick/error_private.h" 00049 #include "magick/image.h" 00050 #include "magick/image_private.h" 00051 #include "magick/list.h" 00052 #include "magick/magick.h" 00053 #include "magick/memory_.h" 00054 #include "magick/static.h" 00055 #include "magick/string_.h" 00056 00057 /* 00058 Forward declarations. 00059 */ 00060 static MagickBooleanType 00061 WriteMVGImage(const ImageInfo *,Image *); 00062 00063 /* 00064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00065 % % 00066 % % 00067 % % 00068 % I s M V G % 00069 % % 00070 % % 00071 % % 00072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00073 % 00074 % IsMVG() returns MagickTrue if the image format type, identified by the 00075 % magick string, is MVG. 00076 % 00077 % The format of the IsMVG method is: 00078 % 00079 % MagickBooleanType IsMVG(const unsigned char *magick,const size_t length) 00080 % 00081 % A description of each parameter follows: 00082 % 00083 % o magick: This string is generally the first few bytes of an image file 00084 % or blob. 00085 % 00086 % o length: Specifies the length of the magick string. 00087 % 00088 % 00089 */ 00090 static MagickBooleanType IsMVG(const unsigned char *magick,const size_t length) 00091 { 00092 if (length < 20) 00093 return(MagickFalse); 00094 if (LocaleNCompare((char *) magick,"push graphic-context",20) == 0) 00095 return(MagickTrue); 00096 return(MagickFalse); 00097 } 00098 00099 /* 00100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00101 % % 00102 % % 00103 % % 00104 % R e a d M V G I m a g e % 00105 % % 00106 % % 00107 % % 00108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00109 % 00110 % ReadMVGImage creates a gradient image and initializes it to 00111 % the X server color range as specified by the filename. It allocates the 00112 % memory necessary for the new Image structure and returns a pointer to the 00113 % new image. 00114 % 00115 % The format of the ReadMVGImage method is: 00116 % 00117 % Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception) 00118 % 00119 % A description of each parameter follows: 00120 % 00121 % o image_info: The image info. 00122 % 00123 % o exception: return any errors or warnings in this structure. 00124 % 00125 % 00126 */ 00127 static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception) 00128 { 00129 #define BoundingBox "viewbox" 00130 00131 DrawInfo 00132 *draw_info; 00133 00134 Image 00135 *image; 00136 00137 MagickBooleanType 00138 status; 00139 00140 size_t 00141 length; 00142 00143 unsigned char 00144 *primitive; 00145 00146 /* 00147 Open image. 00148 */ 00149 assert(image_info != (const ImageInfo *) NULL); 00150 assert(image_info->signature == MagickSignature); 00151 if (image_info->debug != MagickFalse) 00152 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00153 assert(exception != (ExceptionInfo *) NULL); 00154 assert(exception->signature == MagickSignature); 00155 image=AllocateImage(image_info); 00156 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00157 if (status == MagickFalse) 00158 { 00159 DestroyImageList(image); 00160 return((Image *) NULL); 00161 } 00162 if ((image->columns == 0) || (image->rows == 0)) 00163 { 00164 char 00165 primitive[MaxTextExtent]; 00166 00167 register char 00168 *p; 00169 00170 SegmentInfo 00171 bounds; 00172 00173 /* 00174 Determine size of image canvas. 00175 */ 00176 while (ReadBlobString(image,primitive) != (char *) NULL) 00177 { 00178 for (p=primitive; (*p == ' ') || (*p == '\t'); p++); 00179 if (LocaleNCompare(BoundingBox,p,strlen(BoundingBox)) != 0) 00180 continue; 00181 (void) sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1, 00182 &bounds.x2,&bounds.y2); 00183 image->columns=(unsigned long) ((bounds.x2-bounds.x1)+0.5); 00184 image->rows=(unsigned long) ((bounds.y2-bounds.y1)+0.5); 00185 break; 00186 } 00187 } 00188 if ((image->columns == 0) || (image->rows == 0)) 00189 ThrowReaderException(OptionError,"MustSpecifyImageSize"); 00190 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); 00191 draw_info->affine.sx= 00192 image->x_resolution == 0.0 ? 1.0 : image->x_resolution/72.0; 00193 draw_info->affine.sy= 00194 image->y_resolution == 0.0 ? 1.0 : image->y_resolution/72.0; 00195 image->columns=(unsigned long) (draw_info->affine.sx*image->columns); 00196 image->rows=(unsigned long) (draw_info->affine.sy*image->rows); 00197 SetImage(image,OpaqueOpacity); 00198 /* 00199 Render drawing. 00200 */ 00201 draw_info->fill=image_info->pen; 00202 primitive=GetBlobStreamData(image); 00203 if (primitive != (unsigned char) NULL) 00204 draw_info->primitive=AcquireString((char *) primitive); 00205 else 00206 draw_info->primitive=(char *) FileToBlob(image->filename,&length,exception); 00207 if (draw_info->primitive == (char *) NULL) 00208 return((Image *) NULL); 00209 (void) DrawImage(image,draw_info); 00210 draw_info=DestroyDrawInfo(draw_info); 00211 CloseBlob(image); 00212 return(GetFirstImageInList(image)); 00213 } 00214 00215 /* 00216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00217 % % 00218 % % 00219 % % 00220 % R e g i s t e r M V G I m a g e % 00221 % % 00222 % % 00223 % % 00224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00225 % 00226 % RegisterMVGImage() adds attributes for the MVG image format 00227 % to the list of supported formats. The attributes include the image format 00228 % tag, a method to read and/or write the format, whether the format 00229 % supports the saving of more than one frame to the same file or blob, 00230 % whether the format supports native in-memory I/O, and a brief 00231 % description of the format. 00232 % 00233 % The format of the RegisterMVGImage method is: 00234 % 00235 % RegisterMVGImage(void) 00236 % 00237 */ 00238 ModuleExport void RegisterMVGImage(void) 00239 { 00240 MagickInfo 00241 *entry; 00242 00243 entry=SetMagickInfo("MVG"); 00244 entry->decoder=(DecoderHandler *) ReadMVGImage; 00245 entry->encoder=(EncoderHandler *) WriteMVGImage; 00246 entry->magick=(MagickHandler *) IsMVG; 00247 entry->adjoin=MagickFalse; 00248 entry->seekable_stream=MagickTrue; 00249 entry->description=AcquireString("Magick Vector Graphics"); 00250 entry->module=AcquireString("MVG"); 00251 (void) RegisterMagickInfo(entry); 00252 } 00253 00254 /* 00255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00256 % % 00257 % % 00258 % % 00259 % U n r e g i s t e r M V G I m a g e % 00260 % % 00261 % % 00262 % % 00263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00264 % 00265 % UnregisterMVGImage() removes format registrations made by the 00266 % MVG module from the list of supported formats. 00267 % 00268 % The format of the UnregisterMVGImage method is: 00269 % 00270 % UnregisterMVGImage(void) 00271 % 00272 */ 00273 ModuleExport void UnregisterMVGImage(void) 00274 { 00275 (void) UnregisterMagickInfo("MVG"); 00276 } 00277 00278 /* 00279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00280 % % 00281 % % 00282 % % 00283 % W r i t e M V G I m a g e % 00284 % % 00285 % % 00286 % % 00287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00288 % 00289 % WriteMVGImage() writes an image to a file in MVG image format. 00290 % 00291 % The format of the WriteMVGImage method is: 00292 % 00293 % MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image) 00294 % 00295 % A description of each parameter follows. 00296 % 00297 % o image_info: The image info. 00298 % 00299 % o image: The image. 00300 % 00301 % 00302 */ 00303 static MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image) 00304 { 00305 const ImageAttribute 00306 *attribute; 00307 00308 MagickBooleanType 00309 status; 00310 00311 /* 00312 Open output image file. 00313 */ 00314 assert(image_info != (const ImageInfo *) NULL); 00315 assert(image_info->signature == MagickSignature); 00316 assert(image != (Image *) NULL); 00317 assert(image->signature == MagickSignature); 00318 if (image->debug != MagickFalse) 00319 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00320 attribute=GetImageAttribute(image,"[MVG]"); 00321 if (attribute == (ImageAttribute *) NULL) 00322 ThrowWriterException(OptionError,"NoImageVectorGraphics"); 00323 status=OpenBlob(image_info,image,WriteBlobMode,&image->exception); 00324 if (status == MagickFalse) 00325 return(status); 00326 (void) WriteBlob(image,strlen(attribute->value),(unsigned char *) 00327 attribute->value); 00328 CloseBlob(image); 00329 return(MagickTrue); 00330 }

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