| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | #include "magick/studio.h" |
|---|
| 43 | #include "magick/artifact.h" |
|---|
| 44 | #include "magick/blob.h" |
|---|
| 45 | #include "magick/blob-private.h" |
|---|
| 46 | #include "magick/draw.h" |
|---|
| 47 | #include "magick/exception.h" |
|---|
| 48 | #include "magick/exception-private.h" |
|---|
| 49 | #include "magick/image.h" |
|---|
| 50 | #include "magick/image-private.h" |
|---|
| 51 | #include "magick/list.h" |
|---|
| 52 | #include "magick/magick.h" |
|---|
| 53 | #include "magick/memory_.h" |
|---|
| 54 | #include "magick/module.h" |
|---|
| 55 | #include "magick/property.h" |
|---|
| 56 | #include "magick/quantum-private.h" |
|---|
| 57 | #include "magick/static.h" |
|---|
| 58 | #include "magick/string_.h" |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | static MagickBooleanType |
|---|
| 64 | WriteMVGImage(const ImageInfo *,Image *); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | static MagickBooleanType IsMVG(const unsigned char *magick,const size_t length) |
|---|
| 94 | { |
|---|
| 95 | if (length < 20) |
|---|
| 96 | return(MagickFalse); |
|---|
| 97 | if (LocaleNCompare((char *) magick,"push graphic-context",20) == 0) |
|---|
| 98 | return(MagickTrue); |
|---|
| 99 | return(MagickFalse); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception) |
|---|
| 130 | { |
|---|
| 131 | #define BoundingBox "viewbox" |
|---|
| 132 | |
|---|
| 133 | DrawInfo |
|---|
| 134 | *draw_info; |
|---|
| 135 | |
|---|
| 136 | Image |
|---|
| 137 | *image; |
|---|
| 138 | |
|---|
| 139 | MagickBooleanType |
|---|
| 140 | status; |
|---|
| 141 | |
|---|
| 142 | unsigned char |
|---|
| 143 | *primitive; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 149 | assert(image_info->signature == MagickSignature); |
|---|
| 150 | if (image_info->debug != MagickFalse) |
|---|
| 151 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 152 | image_info->filename); |
|---|
| 153 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 154 | assert(exception->signature == MagickSignature); |
|---|
| 155 | image=AcquireImage(image_info); |
|---|
| 156 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 157 | if (status == MagickFalse) |
|---|
| 158 | { |
|---|
| 159 | image=DestroyImageList(image); |
|---|
| 160 | return((Image *) NULL); |
|---|
| 161 | } |
|---|
| 162 | if ((image->columns == 0) || (image->rows == 0)) |
|---|
| 163 | { |
|---|
| 164 | char |
|---|
| 165 | primitive[MaxTextExtent]; |
|---|
| 166 | |
|---|
| 167 | register char |
|---|
| 168 | *p; |
|---|
| 169 | |
|---|
| 170 | SegmentInfo |
|---|
| 171 | bounds; |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | while (ReadBlobString(image,primitive) != (char *) NULL) |
|---|
| 177 | { |
|---|
| 178 | for (p=primitive; (*p == ' ') || (*p == '\t'); p++) ; |
|---|
| 179 | if (LocaleNCompare(BoundingBox,p,strlen(BoundingBox)) != 0) |
|---|
| 180 | continue; |
|---|
| 181 | (void) sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1, |
|---|
| 182 | &bounds.x2,&bounds.y2); |
|---|
| 183 | image->columns=(unsigned long) ((bounds.x2-bounds.x1)+0.5); |
|---|
| 184 | image->rows=(unsigned long) ((bounds.y2-bounds.y1)+0.5); |
|---|
| 185 | break; |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | if ((image->columns == 0) || (image->rows == 0)) |
|---|
| 189 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
|---|
| 190 | draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); |
|---|
| 191 | draw_info->affine.sx=image->x_resolution == 0.0 ? 1.0 : image->x_resolution/ |
|---|
| 192 | DefaultResolution; |
|---|
| 193 | draw_info->affine.sy=image->y_resolution == 0.0 ? 1.0 : image->y_resolution/ |
|---|
| 194 | DefaultResolution; |
|---|
| 195 | image->columns=(unsigned long) (draw_info->affine.sx*image->columns); |
|---|
| 196 | image->rows=(unsigned long) (draw_info->affine.sy*image->rows); |
|---|
| 197 | if (SetImageExtent(image,0,0) == MagickFalse) |
|---|
| 198 | { |
|---|
| 199 | InheritException(exception,&image->exception); |
|---|
| 200 | return(DestroyImageList(image)); |
|---|
| 201 | } |
|---|
| 202 | (void) SetImageBackgroundColor(image); |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | primitive=GetBlobStreamData(image); |
|---|
| 207 | if (primitive != (unsigned char *) NULL) |
|---|
| 208 | draw_info->primitive=AcquireString((char *) primitive); |
|---|
| 209 | else |
|---|
| 210 | draw_info->primitive=FileToString(image->filename,~0UL,exception); |
|---|
| 211 | if (draw_info->primitive == (char *) NULL) |
|---|
| 212 | return((Image *) NULL); |
|---|
| 213 | (void) DrawImage(image,draw_info); |
|---|
| 214 | draw_info=DestroyDrawInfo(draw_info); |
|---|
| 215 | (void) CloseBlob(image); |
|---|
| 216 | return(GetFirstImageInList(image)); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | ModuleExport unsigned long RegisterMVGImage(void) |
|---|
| 243 | { |
|---|
| 244 | MagickInfo |
|---|
| 245 | *entry; |
|---|
| 246 | |
|---|
| 247 | entry=SetMagickInfo("MVG"); |
|---|
| 248 | entry->decoder=(DecodeImageHandler *) ReadMVGImage; |
|---|
| 249 | entry->encoder=(EncodeImageHandler *) WriteMVGImage; |
|---|
| 250 | entry->magick=(IsImageFormatHandler *) IsMVG; |
|---|
| 251 | entry->adjoin=MagickFalse; |
|---|
| 252 | entry->seekable_stream=MagickTrue; |
|---|
| 253 | entry->description=ConstantString("Magick Vector Graphics"); |
|---|
| 254 | entry->module=ConstantString("MVG"); |
|---|
| 255 | (void) RegisterMagickInfo(entry); |
|---|
| 256 | return(MagickImageCoderSignature); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | ModuleExport void UnregisterMVGImage(void) |
|---|
| 279 | { |
|---|
| 280 | (void) UnregisterMagickInfo("MVG"); |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | static MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image) |
|---|
| 308 | { |
|---|
| 309 | const char |
|---|
| 310 | *value; |
|---|
| 311 | |
|---|
| 312 | MagickBooleanType |
|---|
| 313 | status; |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 319 | assert(image_info->signature == MagickSignature); |
|---|
| 320 | assert(image != (Image *) NULL); |
|---|
| 321 | assert(image->signature == MagickSignature); |
|---|
| 322 | if (image->debug != MagickFalse) |
|---|
| 323 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 324 | value=GetImageArtifact(image,"MVG"); |
|---|
| 325 | if (value == (const char *) NULL) |
|---|
| 326 | ThrowWriterException(OptionError,"NoImageVectorGraphics"); |
|---|
| 327 | status=OpenBlob(image_info,image,WriteBlobMode,&image->exception); |
|---|
| 328 | if (status == MagickFalse) |
|---|
| 329 | return(status); |
|---|
| 330 | (void) WriteBlob(image,strlen(value),(unsigned char *) value); |
|---|
| 331 | (void) CloseBlob(image); |
|---|
| 332 | return(MagickTrue); |
|---|
| 333 | } |
|---|