| 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 | #include "magick/studio.h" |
|---|
| 41 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 42 | # if defined(__CYGWIN__) |
|---|
| 43 | # include <windows.h> |
|---|
| 44 | # else |
|---|
| 45 | |
|---|
| 46 | # include <wingdi.h> |
|---|
| 47 | # endif |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | #include "magick/blob.h" |
|---|
| 51 | #include "magick/blob-private.h" |
|---|
| 52 | #include "magick/exception.h" |
|---|
| 53 | #include "magick/exception-private.h" |
|---|
| 54 | #include "magick/geometry.h" |
|---|
| 55 | #include "magick/image.h" |
|---|
| 56 | #include "magick/image-private.h" |
|---|
| 57 | #include "magick/list.h" |
|---|
| 58 | #include "magick/magick.h" |
|---|
| 59 | #include "magick/memory_.h" |
|---|
| 60 | #include "magick/quantum-private.h" |
|---|
| 61 | #include "magick/static.h" |
|---|
| 62 | #include "magick/string_.h" |
|---|
| 63 | #include "magick/module.h" |
|---|
| 64 | |
|---|
| 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 | static MagickBooleanType IsEMF(const unsigned char *magick,const size_t length) |
|---|
| 92 | { |
|---|
| 93 | if (length < 48) |
|---|
| 94 | return(MagickFalse); |
|---|
| 95 | if (memcmp(magick+40,"\040\105\115\106\000\000\001\000",8) == 0) |
|---|
| 96 | return(MagickTrue); |
|---|
| 97 | return(MagickFalse); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 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 | static MagickBooleanType IsWMF(const unsigned char *magick,const size_t length) |
|---|
| 127 | { |
|---|
| 128 | if (length < 4) |
|---|
| 129 | return(MagickFalse); |
|---|
| 130 | if (memcmp(magick,"\327\315\306\232",4) == 0) |
|---|
| 131 | return(MagickTrue); |
|---|
| 132 | if (memcmp(magick,"\001\000\011\000",4) == 0) |
|---|
| 133 | return(MagickTrue); |
|---|
| 134 | return(MagickFalse); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | #if defined(MAGICKCORE_HAVE__WFOPEN) |
|---|
| 167 | static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16) |
|---|
| 168 | { |
|---|
| 169 | register const unsigned char |
|---|
| 170 | *p; |
|---|
| 171 | |
|---|
| 172 | if (utf16 != (wchar_t *) NULL) |
|---|
| 173 | { |
|---|
| 174 | register wchar_t |
|---|
| 175 | *q; |
|---|
| 176 | |
|---|
| 177 | wchar_t |
|---|
| 178 | c; |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | q=utf16; |
|---|
| 184 | for (p=utf8; *p != '\0'; p++) |
|---|
| 185 | { |
|---|
| 186 | if ((*p & 0x80) == 0) |
|---|
| 187 | *q=(*p); |
|---|
| 188 | else |
|---|
| 189 | if ((*p & 0xE0) == 0xC0) |
|---|
| 190 | { |
|---|
| 191 | c=(*p); |
|---|
| 192 | *q=(c & 0x1F) << 6; |
|---|
| 193 | p++; |
|---|
| 194 | if ((*p & 0xC0) != 0x80) |
|---|
| 195 | return(0); |
|---|
| 196 | *q|=(*p & 0x3F); |
|---|
| 197 | } |
|---|
| 198 | else |
|---|
| 199 | if ((*p & 0xF0) == 0xE0) |
|---|
| 200 | { |
|---|
| 201 | c=(*p); |
|---|
| 202 | *q=c << 12; |
|---|
| 203 | p++; |
|---|
| 204 | if ((*p & 0xC0) != 0x80) |
|---|
| 205 | return(0); |
|---|
| 206 | c=(*p); |
|---|
| 207 | *q|=(c & 0x3F) << 6; |
|---|
| 208 | p++; |
|---|
| 209 | if ((*p & 0xC0) != 0x80) |
|---|
| 210 | return(0); |
|---|
| 211 | *q|=(*p & 0x3F); |
|---|
| 212 | } |
|---|
| 213 | else |
|---|
| 214 | return(0); |
|---|
| 215 | q++; |
|---|
| 216 | } |
|---|
| 217 | *q++='\0'; |
|---|
| 218 | return(q-utf16); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | for (p=utf8; *p != '\0'; p++) |
|---|
| 224 | { |
|---|
| 225 | if ((*p & 0x80) == 0) |
|---|
| 226 | ; |
|---|
| 227 | else |
|---|
| 228 | if ((*p & 0xE0) == 0xC0) |
|---|
| 229 | { |
|---|
| 230 | p++; |
|---|
| 231 | if ((*p & 0xC0) != 0x80) |
|---|
| 232 | return(0); |
|---|
| 233 | } |
|---|
| 234 | else |
|---|
| 235 | if ((*p & 0xF0) == 0xE0) |
|---|
| 236 | { |
|---|
| 237 | p++; |
|---|
| 238 | if ((*p & 0xC0) != 0x80) |
|---|
| 239 | return(0); |
|---|
| 240 | p++; |
|---|
| 241 | if ((*p & 0xC0) != 0x80) |
|---|
| 242 | return(0); |
|---|
| 243 | } |
|---|
| 244 | else |
|---|
| 245 | return(0); |
|---|
| 246 | } |
|---|
| 247 | return(p-utf8); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | static wchar_t *ConvertUTF8ToUTF16(const unsigned char *source) |
|---|
| 251 | { |
|---|
| 252 | size_t |
|---|
| 253 | length; |
|---|
| 254 | |
|---|
| 255 | wchar_t |
|---|
| 256 | *utf16; |
|---|
| 257 | |
|---|
| 258 | length=UTF8ToUTF16(source,(wchar_t *) NULL); |
|---|
| 259 | if (length == 0) |
|---|
| 260 | { |
|---|
| 261 | register long |
|---|
| 262 | i; |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | length=strlen(source); |
|---|
| 268 | utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16)); |
|---|
| 269 | if (utf16 == (wchar_t *) NULL) |
|---|
| 270 | return((wchar_t *) NULL); |
|---|
| 271 | for (i=0; i <= (long) length; i++) |
|---|
| 272 | utf16[i]=source[i]; |
|---|
| 273 | return(utf16); |
|---|
| 274 | } |
|---|
| 275 | utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16)); |
|---|
| 276 | if (utf16 == (wchar_t *) NULL) |
|---|
| 277 | return((wchar_t *) NULL); |
|---|
| 278 | length=UTF8ToUTF16(source,utf16); |
|---|
| 279 | return(utf16); |
|---|
| 280 | } |
|---|
| 281 | #endif |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 289 | static HENHMETAFILE ReadEnhMetaFile(const char *path,long *width, |
|---|
| 290 | long *height) |
|---|
| 291 | { |
|---|
| 292 | #pragma pack( push ) |
|---|
| 293 | #pragma pack( 2 ) |
|---|
| 294 | typedef struct |
|---|
| 295 | { |
|---|
| 296 | DWORD dwKey; |
|---|
| 297 | WORD hmf; |
|---|
| 298 | SMALL_RECT bbox; |
|---|
| 299 | WORD wInch; |
|---|
| 300 | DWORD dwReserved; |
|---|
| 301 | WORD wCheckSum; |
|---|
| 302 | } APMHEADER, *PAPMHEADER; |
|---|
| 303 | #pragma pack( pop ) |
|---|
| 304 | |
|---|
| 305 | DWORD |
|---|
| 306 | dwSize; |
|---|
| 307 | |
|---|
| 308 | ENHMETAHEADER |
|---|
| 309 | emfh; |
|---|
| 310 | |
|---|
| 311 | HANDLE |
|---|
| 312 | hFile; |
|---|
| 313 | |
|---|
| 314 | HDC |
|---|
| 315 | hDC; |
|---|
| 316 | |
|---|
| 317 | HENHMETAFILE |
|---|
| 318 | hTemp; |
|---|
| 319 | |
|---|
| 320 | LPBYTE |
|---|
| 321 | pBits; |
|---|
| 322 | |
|---|
| 323 | METAFILEPICT |
|---|
| 324 | mp; |
|---|
| 325 | |
|---|
| 326 | HMETAFILE |
|---|
| 327 | hOld; |
|---|
| 328 | |
|---|
| 329 | *width=512; |
|---|
| 330 | *height=512; |
|---|
| 331 | hTemp=GetEnhMetaFile(path); |
|---|
| 332 | #if defined(MAGICKCORE_HAVE__WFOPEN) |
|---|
| 333 | if (hTemp == (HENHMETAFILE) NULL) |
|---|
| 334 | { |
|---|
| 335 | wchar_t |
|---|
| 336 | *unicode_path; |
|---|
| 337 | |
|---|
| 338 | unicode_path=ConvertUTF8ToUTF16(path); |
|---|
| 339 | if (unicode_path != (wchar_t *) NULL) |
|---|
| 340 | { |
|---|
| 341 | hTemp=GetEnhMetaFileW(unicode_path); |
|---|
| 342 | unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path); |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | #endif |
|---|
| 346 | if (hTemp != (HENHMETAFILE) NULL) |
|---|
| 347 | { |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); |
|---|
| 352 | *width=emfh.rclFrame.right-emfh.rclFrame.left; |
|---|
| 353 | *height=emfh.rclFrame.bottom-emfh.rclFrame.top; |
|---|
| 354 | return(hTemp); |
|---|
| 355 | } |
|---|
| 356 | hOld=GetMetaFile(path); |
|---|
| 357 | if (hOld != (HMETAFILE) NULL) |
|---|
| 358 | { |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | dwSize=GetMetaFileBitsEx(hOld,0,NULL); |
|---|
| 363 | if (dwSize == 0) |
|---|
| 364 | { |
|---|
| 365 | DeleteMetaFile(hOld); |
|---|
| 366 | return((HENHMETAFILE) NULL); |
|---|
| 367 | } |
|---|
| 368 | pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits)); |
|---|
| 369 | if (pBits == (LPBYTE) NULL) |
|---|
| 370 | { |
|---|
| 371 | DeleteMetaFile(hOld); |
|---|
| 372 | return((HENHMETAFILE) NULL); |
|---|
| 373 | } |
|---|
| 374 | if (GetMetaFileBitsEx(hOld,dwSize,pBits) == 0) |
|---|
| 375 | { |
|---|
| 376 | pBits=(BYTE *) DestroyString((char *) pBits); |
|---|
| 377 | DeleteMetaFile(hOld); |
|---|
| 378 | return((HENHMETAFILE) NULL); |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | mp.mm=MM_ANISOTROPIC; |
|---|
| 384 | mp.xExt=1000; |
|---|
| 385 | mp.yExt=1000; |
|---|
| 386 | mp.hMF=NULL; |
|---|
| 387 | hDC=GetDC(NULL); |
|---|
| 388 | hTemp=SetWinMetaFileBits(dwSize,pBits,hDC,&mp); |
|---|
| 389 | ReleaseDC(NULL,hDC); |
|---|
| 390 | DeleteMetaFile(hOld); |
|---|
| 391 | pBits=(BYTE *) DestroyString((char *) pBits); |
|---|
| 392 | GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); |
|---|
| 393 | *width=emfh.rclFrame.right-emfh.rclFrame.left; |
|---|
| 394 | *height=emfh.rclFrame.bottom-emfh.rclFrame.top; |
|---|
| 395 | return(hTemp); |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | hFile=CreateFile(path,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, |
|---|
| 401 | NULL); |
|---|
| 402 | if (hFile == INVALID_HANDLE_VALUE) |
|---|
| 403 | return(NULL); |
|---|
| 404 | dwSize=GetFileSize(hFile,NULL); |
|---|
| 405 | pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits)); |
|---|
| 406 | ReadFile(hFile,pBits,dwSize,&dwSize,NULL); |
|---|
| 407 | CloseHandle(hFile); |
|---|
| 408 | if (((PAPMHEADER) pBits)->dwKey != 0x9ac6cdd7l) |
|---|
| 409 | { |
|---|
| 410 | pBits=(BYTE *) DestroyString((char *) pBits); |
|---|
| 411 | return((HENHMETAFILE) NULL); |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | mp.mm=MM_ANISOTROPIC; |
|---|
| 417 | mp.xExt=((PAPMHEADER) pBits)->bbox.Right-((PAPMHEADER) pBits)->bbox.Left; |
|---|
| 418 | *width=mp.xExt; |
|---|
| 419 | mp.xExt=(mp.xExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); |
|---|
| 420 | mp.yExt=((PAPMHEADER)pBits)->bbox.Bottom-((PAPMHEADER) pBits)->bbox.Top; |
|---|
| 421 | *height=mp.yExt; |
|---|
| 422 | mp.yExt=(mp.yExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); |
|---|
| 423 | mp.hMF=NULL; |
|---|
| 424 | hDC=GetDC(NULL); |
|---|
| 425 | hTemp=SetWinMetaFileBits(dwSize,&(pBits[sizeof(APMHEADER)]),hDC,&mp); |
|---|
| 426 | ReleaseDC(NULL,hDC); |
|---|
| 427 | pBits=(BYTE *) DestroyString((char *) pBits); |
|---|
| 428 | return(hTemp); |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | #define CENTIMETERS_INCH 2.54 |
|---|
| 432 | |
|---|
| 433 | static Image *ReadEMFImage(const ImageInfo *image_info, |
|---|
| 434 | ExceptionInfo *exception) |
|---|
| 435 | { |
|---|
| 436 | BITMAPINFO |
|---|
| 437 | DIBinfo; |
|---|
| 438 | |
|---|
| 439 | HBITMAP |
|---|
| 440 | hBitmap, |
|---|
| 441 | hOldBitmap; |
|---|
| 442 | |
|---|
| 443 | HDC |
|---|
| 444 | hDC; |
|---|
| 445 | |
|---|
| 446 | HENHMETAFILE |
|---|
| 447 | hemf; |
|---|
| 448 | |
|---|
| 449 | Image |
|---|
| 450 | *image; |
|---|
| 451 | |
|---|
| 452 | long |
|---|
| 453 | height, |
|---|
| 454 | width, |
|---|
| 455 | y; |
|---|
| 456 | |
|---|
| 457 | RECT |
|---|
| 458 | rect; |
|---|
| 459 | |
|---|
| 460 | register long |
|---|
| 461 | x; |
|---|
| 462 | |
|---|
| 463 | register PixelPacket |
|---|
| 464 | *q; |
|---|
| 465 | |
|---|
| 466 | RGBQUAD |
|---|
| 467 | *pBits, |
|---|
| 468 | *ppBits; |
|---|
| 469 | |
|---|
| 470 | image=AcquireImage(image_info); |
|---|
| 471 | hemf=ReadEnhMetaFile(image_info->filename,&width,&height); |
|---|
| 472 | if (hemf == (HENHMETAFILE) NULL) |
|---|
| 473 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 474 | if ((image->columns == 0) || (image->rows == 0)) |
|---|
| 475 | { |
|---|
| 476 | double |
|---|
| 477 | y_resolution, |
|---|
| 478 | x_resolution; |
|---|
| 479 | |
|---|
| 480 | y_resolution=DefaultResolution; |
|---|
| 481 | x_resolution=DefaultResolution; |
|---|
| 482 | if (image->y_resolution > 0) |
|---|
| 483 | { |
|---|
| 484 | y_resolution=image->y_resolution; |
|---|
| 485 | if (image->units == PixelsPerCentimeterResolution) |
|---|
| 486 | y_resolution*=CENTIMETERS_INCH; |
|---|
| 487 | } |
|---|
| 488 | if (image->x_resolution > 0) |
|---|
| 489 | { |
|---|
| 490 | x_resolution=image->x_resolution; |
|---|
| 491 | if (image->units == PixelsPerCentimeterResolution) |
|---|
| 492 | x_resolution*=CENTIMETERS_INCH; |
|---|
| 493 | } |
|---|
| 494 | image->rows=(unsigned long) ((height/1000.0/CENTIMETERS_INCH)* |
|---|
| 495 | y_resolution+0.5); |
|---|
| 496 | image->columns=(unsigned long) ((width/1000.0/CENTIMETERS_INCH)* |
|---|
| 497 | x_resolution+0.5); |
|---|
| 498 | } |
|---|
| 499 | if (image_info->size != (char *) NULL) |
|---|
| 500 | { |
|---|
| 501 | long |
|---|
| 502 | x; |
|---|
| 503 | |
|---|
| 504 | image->columns=width; |
|---|
| 505 | image->rows=height; |
|---|
| 506 | x=0; |
|---|
| 507 | y=0; |
|---|
| 508 | (void) GetGeometry(image_info->size,&x,&y,&image->columns,&image->rows); |
|---|
| 509 | } |
|---|
| 510 | if (image_info->page != (char *) NULL) |
|---|
| 511 | { |
|---|
| 512 | char |
|---|
| 513 | *geometry; |
|---|
| 514 | |
|---|
| 515 | long |
|---|
| 516 | sans; |
|---|
| 517 | |
|---|
| 518 | register char |
|---|
| 519 | *p; |
|---|
| 520 | |
|---|
| 521 | MagickStatusType |
|---|
| 522 | flags; |
|---|
| 523 | |
|---|
| 524 | geometry=GetPageGeometry(image_info->page); |
|---|
| 525 | p=strchr(geometry,'>'); |
|---|
| 526 | if (p == (char *) NULL) |
|---|
| 527 | { |
|---|
| 528 | flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns, |
|---|
| 529 | &image->rows); |
|---|
| 530 | if (image->x_resolution != 0.0) |
|---|
| 531 | image->columns=(unsigned long) ((image->columns* |
|---|
| 532 | image->x_resolution)+0.5); |
|---|
| 533 | if (image->y_resolution != 0.0) |
|---|
| 534 | image->rows=(unsigned long) ((image->rows*image->y_resolution)+0.5); |
|---|
| 535 | } |
|---|
| 536 | else |
|---|
| 537 | { |
|---|
| 538 | *p='\0'; |
|---|
| 539 | flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns, |
|---|
| 540 | &image->rows); |
|---|
| 541 | if (image->x_resolution != 0.0) |
|---|
| 542 | image->columns=(unsigned long) (((image->columns* |
|---|
| 543 | image->x_resolution)/DefaultResolution)+0.5); |
|---|
| 544 | if (image->y_resolution != 0.0) |
|---|
| 545 | image->rows=(unsigned long) (((image->rows*image->y_resolution)/ |
|---|
| 546 | DefaultResolution)+0.5); |
|---|
| 547 | } |
|---|
| 548 | geometry=DestroyString(geometry); |
|---|
| 549 | } |
|---|
| 550 | hDC=GetDC(NULL); |
|---|
| 551 | if (hDC == (HDC) NULL) |
|---|
| 552 | { |
|---|
| 553 | DeleteEnhMetaFile(hemf); |
|---|
| 554 | ThrowReaderException(ResourceLimitError,"UnableToCreateADC"); |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | if (SetImageExtent(image,0,0) == MagickFalse) |
|---|
| 560 | { |
|---|
| 561 | InheritException(exception,&image->exception); |
|---|
| 562 | return(DestroyImageList(image)); |
|---|
| 563 | } |
|---|
| 564 | (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO)); |
|---|
| 565 | DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); |
|---|
| 566 | DIBinfo.bmiHeader.biWidth=image->columns; |
|---|
| 567 | DIBinfo.bmiHeader.biHeight=(-1)*image->rows; |
|---|
| 568 | DIBinfo.bmiHeader.biPlanes=1; |
|---|
| 569 | DIBinfo.bmiHeader.biBitCount=32; |
|---|
| 570 | DIBinfo.bmiHeader.biCompression=BI_RGB; |
|---|
| 571 | hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits, |
|---|
| 572 | NULL,0); |
|---|
| 573 | ReleaseDC(NULL,hDC); |
|---|
| 574 | if (hBitmap == (HBITMAP) NULL) |
|---|
| 575 | { |
|---|
| 576 | DeleteEnhMetaFile(hemf); |
|---|
| 577 | ThrowReaderException(ResourceLimitError,"UnableToCreateBitmap"); |
|---|
| 578 | } |
|---|
| 579 | hDC=CreateCompatibleDC(NULL); |
|---|
| 580 | if (hDC == (HDC) NULL) |
|---|
| 581 | { |
|---|
| 582 | DeleteEnhMetaFile(hemf); |
|---|
| 583 | DeleteObject(hBitmap); |
|---|
| 584 | ThrowReaderException(ResourceLimitError,"UnableToCreateADC"); |
|---|
| 585 | } |
|---|
| 586 | hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap); |
|---|
| 587 | if (hOldBitmap == (HBITMAP) NULL) |
|---|
| 588 | { |
|---|
| 589 | DeleteEnhMetaFile(hemf); |
|---|
| 590 | DeleteDC(hDC); |
|---|
| 591 | DeleteObject(hBitmap); |
|---|
| 592 | ThrowReaderException(ResourceLimitError,"UnableToCreateBitmap"); |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | pBits=ppBits; |
|---|
| 598 | for (y=0; y < (long) image->rows; y++) |
|---|
| 599 | { |
|---|
| 600 | for (x=0; x < (long) image->columns; x++) |
|---|
| 601 | { |
|---|
| 602 | pBits->rgbRed=ScaleQuantumToChar(image->background_color.red); |
|---|
| 603 | pBits->rgbGreen=ScaleQuantumToChar(image->background_color.green); |
|---|
| 604 | pBits->rgbBlue=ScaleQuantumToChar(image->background_color.blue); |
|---|
| 605 | pBits++; |
|---|
| 606 | } |
|---|
| 607 | } |
|---|
| 608 | rect.top=0; |
|---|
| 609 | rect.left=0; |
|---|
| 610 | rect.right=image->columns; |
|---|
| 611 | rect.bottom=image->rows; |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | PlayEnhMetaFile(hDC,hemf,&rect); |
|---|
| 616 | pBits=ppBits; |
|---|
| 617 | for (y=0; y < (long) image->rows; y++) |
|---|
| 618 | { |
|---|
| 619 | q=SetImagePixels(image,0,y,image->columns,1); |
|---|
| 620 | if (q == (PixelPacket *) NULL) |
|---|
| 621 | break; |
|---|
| 622 | for (x=0; x < (long) image->columns; x++) |
|---|
| 623 | { |
|---|
| 624 | q->red=ScaleCharToQuantum(pBits->rgbRed); |
|---|
| 625 | q->green=ScaleCharToQuantum(pBits->rgbGreen); |
|---|
| 626 | q->blue=ScaleCharToQuantum(pBits->rgbBlue); |
|---|
| 627 | q->opacity=OpaqueOpacity; |
|---|
| 628 | pBits++; |
|---|
| 629 | q++; |
|---|
| 630 | } |
|---|
| 631 | if (SyncImagePixels(image) == MagickFalse) |
|---|
| 632 | break; |
|---|
| 633 | } |
|---|
| 634 | DeleteEnhMetaFile(hemf); |
|---|
| 635 | SelectObject(hDC,hOldBitmap); |
|---|
| 636 | DeleteDC(hDC); |
|---|
| 637 | DeleteObject(hBitmap); |
|---|
| 638 | return(GetFirstImageInList(image)); |
|---|
| 639 | } |
|---|
| 640 | #endif |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | ModuleExport unsigned long RegisterEMFImage(void) |
|---|
| 666 | { |
|---|
| 667 | MagickInfo |
|---|
| 668 | *entry; |
|---|
| 669 | |
|---|
| 670 | entry=SetMagickInfo("EMF"); |
|---|
| 671 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 672 | entry->decoder=ReadEMFImage; |
|---|
| 673 | #endif |
|---|
| 674 | entry->description=ConstantString( |
|---|
| 675 | "Windows WIN32 API rendered Enhanced Meta File"); |
|---|
| 676 | entry->magick=(IsImageFormatHandler *) IsEMF; |
|---|
| 677 | entry->blob_support=MagickFalse; |
|---|
| 678 | entry->module=ConstantString("WMF"); |
|---|
| 679 | (void) RegisterMagickInfo(entry); |
|---|
| 680 | entry=SetMagickInfo("WMFWIN32"); |
|---|
| 681 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 682 | entry->decoder=ReadEMFImage; |
|---|
| 683 | #endif |
|---|
| 684 | entry->description=ConstantString("Windows WIN32 API rendered Meta File"); |
|---|
| 685 | entry->magick=(IsImageFormatHandler *) IsWMF; |
|---|
| 686 | entry->blob_support=MagickFalse; |
|---|
| 687 | entry->module=ConstantString("WMFWIN32"); |
|---|
| 688 | (void) RegisterMagickInfo(entry); |
|---|
| 689 | return(MagickImageCoderSignature); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | ModuleExport void UnregisterEMFImage(void) |
|---|
| 712 | { |
|---|
| 713 | (void) UnregisterMagickInfo("EMF"); |
|---|
| 714 | (void) UnregisterMagickInfo("WMFWIN32"); |
|---|
| 715 | } |
|---|