cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % EEEEE M M FFFFF % |
| 7 | % E MM MM F % |
| 8 | % EEE M M M FFF % |
| 9 | % E M M F % |
| 10 | % EEEEE M M F % |
| 11 | % % |
| 12 | % % |
| 13 | % Read Windows Enahanced Metafile Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % Bill Radcliffe % |
| 17 | % 2001 % |
| 18 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 19 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 20 | % dedicated to making software imaging solutions freely available. % |
| 21 | % % |
| 22 | % You may not use this file except in compliance with the License. You may % |
| 23 | % obtain a copy of the License at % |
| 24 | % % |
| 25 | % http://www.imagemagick.org/script/license.php % |
| 26 | % % |
| 27 | % Unless required by applicable law or agreed to in writing, software % |
| 28 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 29 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 30 | % See the License for the specific language governing permissions and % |
| 31 | % limitations under the License. % |
| 32 | % % |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | * Include declarations. |
| 38 | */ |
| 39 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 40 | #include "MagickCore/studio.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 41 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
| 42 | # if defined(__CYGWIN__) |
| 43 | # include <windows.h> |
| 44 | # else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 45 | # include <wingdi.h> |
| 46 | # endif |
| 47 | #endif |
| 48 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 49 | #include "MagickCore/blob.h" |
| 50 | #include "MagickCore/blob-private.h" |
| 51 | #include "MagickCore/cache.h" |
| 52 | #include "MagickCore/exception.h" |
| 53 | #include "MagickCore/exception-private.h" |
| 54 | #include "MagickCore/geometry.h" |
| 55 | #include "MagickCore/image.h" |
| 56 | #include "MagickCore/image-private.h" |
| 57 | #include "MagickCore/list.h" |
| 58 | #include "MagickCore/magick.h" |
| 59 | #include "MagickCore/memory_.h" |
| 60 | #include "MagickCore/pixel.h" |
| 61 | #include "MagickCore/quantum-private.h" |
| 62 | #include "MagickCore/static.h" |
| 63 | #include "MagickCore/string_.h" |
| 64 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 68 | % % |
| 69 | % % |
| 70 | % % |
| 71 | % I s E F M % |
| 72 | % % |
| 73 | % % |
| 74 | % % |
| 75 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 76 | % |
| 77 | % IsEMF() returns MagickTrue if the image format type, identified by the |
| 78 | % magick string, is a Microsoft Windows Enhanced MetaFile (EMF) file. |
| 79 | % |
| 80 | % The format of the ReadEMFImage method is: |
| 81 | % |
| 82 | % MagickBooleanType IsEMF(const unsigned char *magick,const size_t length) |
| 83 | % |
| 84 | % A description of each parameter follows: |
| 85 | % |
| 86 | % o magick: compare image format pattern against these bytes. |
| 87 | % |
| 88 | % o length: Specifies the length of the magick string. |
| 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 | % I s W M F % |
| 106 | % % |
| 107 | % % |
| 108 | % % |
| 109 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 110 | % |
| 111 | % IsWMF() returns MagickTrue if the image format type, identified by the |
| 112 | % magick string, is a Windows MetaFile (WMF) file. |
| 113 | % |
| 114 | % The format of the ReadEMFImage method is: |
| 115 | % |
| 116 | % MagickBooleanType IsEMF(const unsigned char *magick,const size_t length) |
| 117 | % |
| 118 | % A description of each parameter follows: |
| 119 | % |
| 120 | % o magick: compare image format pattern against these bytes. |
| 121 | % |
| 122 | % o length: Specifies the length of the magick string. |
| 123 | % |
| 124 | */ |
| 125 | static MagickBooleanType IsWMF(const unsigned char *magick,const size_t length) |
| 126 | { |
| 127 | if (length < 4) |
| 128 | return(MagickFalse); |
| 129 | if (memcmp(magick,"\327\315\306\232",4) == 0) |
| 130 | return(MagickTrue); |
| 131 | if (memcmp(magick,"\001\000\011\000",4) == 0) |
| 132 | return(MagickTrue); |
| 133 | return(MagickFalse); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 138 | % % |
| 139 | % % |
| 140 | % % |
| 141 | % R e a d E M F I m a g e % |
| 142 | % % |
| 143 | % % |
| 144 | % % |
| 145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 146 | % |
| 147 | % ReadEMFImage() reads an Microsoft Windows Enhanced MetaFile (EMF) or |
| 148 | % Windows MetaFile (WMF) file using the Windows API and returns it. It |
| 149 | % allocates the memory necessary for the new Image structure and returns a |
| 150 | % pointer to the new image. |
| 151 | % |
| 152 | % The format of the ReadEMFImage method is: |
| 153 | % |
| 154 | % Image *ReadEMFImage(const ImageInfo *image_info, |
| 155 | % ExceptionInfo *exception) |
| 156 | % |
| 157 | % A description of each parameter follows: |
| 158 | % |
| 159 | % o image_info: the image info.. |
| 160 | % |
| 161 | % o exception: return any errors or warnings in this structure. |
| 162 | % |
| 163 | */ |
| 164 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 165 | /* |
| 166 | This method reads either an enhanced metafile, a regular 16bit Windows |
| 167 | metafile, or an Aldus Placeable metafile and converts it into an enhanced |
| 168 | metafile. Width and height are returned in .01mm units. |
| 169 | */ |
| 170 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 171 | static HENHMETAFILE ReadEnhMetaFile(const char *path,ssize_t *width, |
| 172 | ssize_t *height) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | { |
cristy | 1f9e1ed | 2009-11-18 04:09:38 +0000 | [diff] [blame] | 174 | #pragma pack( push, 2 ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | typedef struct |
| 176 | { |
| 177 | DWORD dwKey; |
| 178 | WORD hmf; |
| 179 | SMALL_RECT bbox; |
| 180 | WORD wInch; |
| 181 | DWORD dwReserved; |
| 182 | WORD wCheckSum; |
| 183 | } APMHEADER, *PAPMHEADER; |
| 184 | #pragma pack( pop ) |
| 185 | |
| 186 | DWORD |
| 187 | dwSize; |
| 188 | |
| 189 | ENHMETAHEADER |
| 190 | emfh; |
| 191 | |
| 192 | HANDLE |
| 193 | hFile; |
| 194 | |
| 195 | HDC |
| 196 | hDC; |
| 197 | |
| 198 | HENHMETAFILE |
| 199 | hTemp; |
| 200 | |
| 201 | LPBYTE |
| 202 | pBits; |
| 203 | |
| 204 | METAFILEPICT |
| 205 | mp; |
| 206 | |
| 207 | HMETAFILE |
| 208 | hOld; |
| 209 | |
| 210 | *width=512; |
| 211 | *height=512; |
| 212 | hTemp=GetEnhMetaFile(path); |
| 213 | #if defined(MAGICKCORE_HAVE__WFOPEN) |
| 214 | if (hTemp == (HENHMETAFILE) NULL) |
| 215 | { |
cristy | 9d5bf45 | 2011-08-05 13:25:47 +0000 | [diff] [blame^] | 216 | int |
| 217 | count; |
| 218 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | wchar_t |
| 220 | *unicode_path; |
| 221 | |
cristy | 9d5bf45 | 2011-08-05 13:25:47 +0000 | [diff] [blame^] | 222 | count=MultiByteToWideChar(CP_ACP,0,path,-1,NULL,0); |
| 223 | unicode_path=(wchar_t *) AcquireQuantumMemory(count, |
| 224 | sizeof(*unicode_path)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 225 | if (unicode_path != (wchar_t *) NULL) |
| 226 | { |
| 227 | hTemp=GetEnhMetaFileW(unicode_path); |
| 228 | unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path); |
| 229 | } |
| 230 | } |
| 231 | #endif |
| 232 | if (hTemp != (HENHMETAFILE) NULL) |
| 233 | { |
| 234 | /* |
| 235 | Enhanced metafile. |
| 236 | */ |
| 237 | GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); |
| 238 | *width=emfh.rclFrame.right-emfh.rclFrame.left; |
| 239 | *height=emfh.rclFrame.bottom-emfh.rclFrame.top; |
| 240 | return(hTemp); |
| 241 | } |
| 242 | hOld=GetMetaFile(path); |
| 243 | if (hOld != (HMETAFILE) NULL) |
| 244 | { |
| 245 | /* |
| 246 | 16bit windows metafile. |
| 247 | */ |
| 248 | dwSize=GetMetaFileBitsEx(hOld,0,NULL); |
| 249 | if (dwSize == 0) |
| 250 | { |
| 251 | DeleteMetaFile(hOld); |
| 252 | return((HENHMETAFILE) NULL); |
| 253 | } |
| 254 | pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits)); |
| 255 | if (pBits == (LPBYTE) NULL) |
| 256 | { |
| 257 | DeleteMetaFile(hOld); |
| 258 | return((HENHMETAFILE) NULL); |
| 259 | } |
| 260 | if (GetMetaFileBitsEx(hOld,dwSize,pBits) == 0) |
| 261 | { |
| 262 | pBits=(BYTE *) DestroyString((char *) pBits); |
| 263 | DeleteMetaFile(hOld); |
| 264 | return((HENHMETAFILE) NULL); |
| 265 | } |
| 266 | /* |
| 267 | Make an enhanced metafile from the windows metafile. |
| 268 | */ |
| 269 | mp.mm=MM_ANISOTROPIC; |
| 270 | mp.xExt=1000; |
| 271 | mp.yExt=1000; |
| 272 | mp.hMF=NULL; |
| 273 | hDC=GetDC(NULL); |
| 274 | hTemp=SetWinMetaFileBits(dwSize,pBits,hDC,&mp); |
| 275 | ReleaseDC(NULL,hDC); |
| 276 | DeleteMetaFile(hOld); |
| 277 | pBits=(BYTE *) DestroyString((char *) pBits); |
| 278 | GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh); |
| 279 | *width=emfh.rclFrame.right-emfh.rclFrame.left; |
| 280 | *height=emfh.rclFrame.bottom-emfh.rclFrame.top; |
| 281 | return(hTemp); |
| 282 | } |
| 283 | /* |
| 284 | Aldus Placeable metafile. |
| 285 | */ |
| 286 | hFile=CreateFile(path,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, |
| 287 | NULL); |
| 288 | if (hFile == INVALID_HANDLE_VALUE) |
| 289 | return(NULL); |
| 290 | dwSize=GetFileSize(hFile,NULL); |
| 291 | pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits)); |
| 292 | ReadFile(hFile,pBits,dwSize,&dwSize,NULL); |
| 293 | CloseHandle(hFile); |
| 294 | if (((PAPMHEADER) pBits)->dwKey != 0x9ac6cdd7l) |
| 295 | { |
| 296 | pBits=(BYTE *) DestroyString((char *) pBits); |
| 297 | return((HENHMETAFILE) NULL); |
| 298 | } |
| 299 | /* |
| 300 | Make an enhanced metafile from the placable metafile. |
| 301 | */ |
| 302 | mp.mm=MM_ANISOTROPIC; |
| 303 | mp.xExt=((PAPMHEADER) pBits)->bbox.Right-((PAPMHEADER) pBits)->bbox.Left; |
| 304 | *width=mp.xExt; |
| 305 | mp.xExt=(mp.xExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); |
| 306 | mp.yExt=((PAPMHEADER)pBits)->bbox.Bottom-((PAPMHEADER) pBits)->bbox.Top; |
| 307 | *height=mp.yExt; |
| 308 | mp.yExt=(mp.yExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch); |
| 309 | mp.hMF=NULL; |
| 310 | hDC=GetDC(NULL); |
| 311 | hTemp=SetWinMetaFileBits(dwSize,&(pBits[sizeof(APMHEADER)]),hDC,&mp); |
| 312 | ReleaseDC(NULL,hDC); |
| 313 | pBits=(BYTE *) DestroyString((char *) pBits); |
| 314 | return(hTemp); |
| 315 | } |
| 316 | |
| 317 | #define CENTIMETERS_INCH 2.54 |
| 318 | |
| 319 | static Image *ReadEMFImage(const ImageInfo *image_info, |
| 320 | ExceptionInfo *exception) |
| 321 | { |
| 322 | BITMAPINFO |
| 323 | DIBinfo; |
| 324 | |
| 325 | HBITMAP |
| 326 | hBitmap, |
| 327 | hOldBitmap; |
| 328 | |
| 329 | HDC |
| 330 | hDC; |
| 331 | |
| 332 | HENHMETAFILE |
| 333 | hemf; |
| 334 | |
| 335 | Image |
| 336 | *image; |
| 337 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 338 | RECT |
| 339 | rect; |
| 340 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 341 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 342 | x; |
| 343 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 344 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 345 | *q; |
| 346 | |
| 347 | RGBQUAD |
| 348 | *pBits, |
| 349 | *ppBits; |
| 350 | |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 351 | ssize_t |
| 352 | height, |
| 353 | width, |
| 354 | y; |
| 355 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 356 | image=AcquireImage(image_info); |
| 357 | hemf=ReadEnhMetaFile(image_info->filename,&width,&height); |
| 358 | if (hemf == (HENHMETAFILE) NULL) |
| 359 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 360 | if ((image->columns == 0) || (image->rows == 0)) |
| 361 | { |
| 362 | double |
| 363 | y_resolution, |
| 364 | x_resolution; |
| 365 | |
| 366 | y_resolution=DefaultResolution; |
| 367 | x_resolution=DefaultResolution; |
| 368 | if (image->y_resolution > 0) |
| 369 | { |
| 370 | y_resolution=image->y_resolution; |
| 371 | if (image->units == PixelsPerCentimeterResolution) |
| 372 | y_resolution*=CENTIMETERS_INCH; |
| 373 | } |
| 374 | if (image->x_resolution > 0) |
| 375 | { |
| 376 | x_resolution=image->x_resolution; |
| 377 | if (image->units == PixelsPerCentimeterResolution) |
| 378 | x_resolution*=CENTIMETERS_INCH; |
| 379 | } |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 380 | image->rows=(size_t) ((height/1000.0/CENTIMETERS_INCH)*y_resolution+0.5); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 381 | image->columns=(size_t) ((width/1000.0/CENTIMETERS_INCH)* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 382 | x_resolution+0.5); |
| 383 | } |
| 384 | if (image_info->size != (char *) NULL) |
| 385 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 386 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 387 | x; |
| 388 | |
| 389 | image->columns=width; |
| 390 | image->rows=height; |
| 391 | x=0; |
| 392 | y=0; |
| 393 | (void) GetGeometry(image_info->size,&x,&y,&image->columns,&image->rows); |
| 394 | } |
| 395 | if (image_info->page != (char *) NULL) |
| 396 | { |
| 397 | char |
| 398 | *geometry; |
| 399 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 400 | register char |
| 401 | *p; |
| 402 | |
| 403 | MagickStatusType |
| 404 | flags; |
| 405 | |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 406 | ssize_t |
| 407 | sans; |
| 408 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | geometry=GetPageGeometry(image_info->page); |
| 410 | p=strchr(geometry,'>'); |
| 411 | if (p == (char *) NULL) |
| 412 | { |
| 413 | flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns, |
| 414 | &image->rows); |
| 415 | if (image->x_resolution != 0.0) |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 416 | image->columns=(size_t) floor((image->columns*image->x_resolution)+ |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 417 | 0.5); |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 418 | if (image->y_resolution != 0.0) |
| 419 | image->rows=(size_t) floor((image->rows*image->y_resolution)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 420 | } |
| 421 | else |
| 422 | { |
| 423 | *p='\0'; |
| 424 | flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns, |
| 425 | &image->rows); |
| 426 | if (image->x_resolution != 0.0) |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 427 | image->columns=(size_t) floor(((image->columns*image->x_resolution)/ |
| 428 | DefaultResolution)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 429 | if (image->y_resolution != 0.0) |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 430 | image->rows=(size_t) floor(((image->rows*image->y_resolution)/ |
| 431 | DefaultResolution)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 432 | } |
| 433 | geometry=DestroyString(geometry); |
| 434 | } |
| 435 | hDC=GetDC(NULL); |
| 436 | if (hDC == (HDC) NULL) |
| 437 | { |
| 438 | DeleteEnhMetaFile(hemf); |
| 439 | ThrowReaderException(ResourceLimitError,"UnableToCreateADC"); |
| 440 | } |
| 441 | /* |
| 442 | Initialize the bitmap header info. |
| 443 | */ |
| 444 | (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO)); |
| 445 | DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 446 | DIBinfo.bmiHeader.biWidth=(LONG) image->columns; |
| 447 | DIBinfo.bmiHeader.biHeight=(-1)*(LONG) image->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | DIBinfo.bmiHeader.biPlanes=1; |
| 449 | DIBinfo.bmiHeader.biBitCount=32; |
| 450 | DIBinfo.bmiHeader.biCompression=BI_RGB; |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 451 | hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,NULL, |
| 452 | 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 453 | ReleaseDC(NULL,hDC); |
| 454 | if (hBitmap == (HBITMAP) NULL) |
| 455 | { |
| 456 | DeleteEnhMetaFile(hemf); |
| 457 | ThrowReaderException(ResourceLimitError,"UnableToCreateBitmap"); |
| 458 | } |
| 459 | hDC=CreateCompatibleDC(NULL); |
| 460 | if (hDC == (HDC) NULL) |
| 461 | { |
| 462 | DeleteEnhMetaFile(hemf); |
| 463 | DeleteObject(hBitmap); |
| 464 | ThrowReaderException(ResourceLimitError,"UnableToCreateADC"); |
| 465 | } |
| 466 | hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap); |
| 467 | if (hOldBitmap == (HBITMAP) NULL) |
| 468 | { |
| 469 | DeleteEnhMetaFile(hemf); |
| 470 | DeleteDC(hDC); |
| 471 | DeleteObject(hBitmap); |
| 472 | ThrowReaderException(ResourceLimitError,"UnableToCreateBitmap"); |
| 473 | } |
| 474 | /* |
| 475 | Initialize the bitmap to the image background color. |
| 476 | */ |
| 477 | pBits=ppBits; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 478 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 479 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 480 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | { |
| 482 | pBits->rgbRed=ScaleQuantumToChar(image->background_color.red); |
| 483 | pBits->rgbGreen=ScaleQuantumToChar(image->background_color.green); |
| 484 | pBits->rgbBlue=ScaleQuantumToChar(image->background_color.blue); |
| 485 | pBits++; |
| 486 | } |
| 487 | } |
| 488 | rect.top=0; |
| 489 | rect.left=0; |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 490 | rect.right=(LONG) image->columns; |
| 491 | rect.bottom=(LONG) image->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 492 | /* |
| 493 | Convert metafile pixels. |
| 494 | */ |
| 495 | PlayEnhMetaFile(hDC,hemf,&rect); |
| 496 | pBits=ppBits; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 497 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 498 | { |
| 499 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 500 | if (q == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 501 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 502 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 503 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 504 | SetPixelRed(image,ScaleCharToQuantum(pBits->rgbRed),q); |
| 505 | SetPixelGreen(image,ScaleCharToQuantum(pBits->rgbGreen),q); |
| 506 | SetPixelBlue(image,ScaleCharToQuantum(pBits->rgbBlue),q); |
| 507 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 508 | pBits++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 509 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 510 | } |
| 511 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 512 | break; |
| 513 | } |
| 514 | DeleteEnhMetaFile(hemf); |
| 515 | SelectObject(hDC,hOldBitmap); |
| 516 | DeleteDC(hDC); |
| 517 | DeleteObject(hBitmap); |
| 518 | return(GetFirstImageInList(image)); |
| 519 | } |
| 520 | #endif /* MAGICKCORE_WINGDI32_DELEGATE */ |
| 521 | |
| 522 | /* |
| 523 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 524 | % % |
| 525 | % % |
| 526 | % % |
| 527 | % R e g i s t e r E M F I m a g e % |
| 528 | % % |
| 529 | % % |
| 530 | % % |
| 531 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 532 | % |
| 533 | % RegisterEMFImage() adds attributes for the EMF image format to |
| 534 | % the list of supported formats. The attributes include the image format |
| 535 | % tag, a method to read and/or write the format, whether the format |
| 536 | % supports the saving of more than one frame to the same file or blob, |
| 537 | % whether the format supports native in-memory I/O, and a brief |
| 538 | % description of the format. |
| 539 | % |
| 540 | % The format of the RegisterEMFImage method is: |
| 541 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 542 | % size_t RegisterEMFImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 543 | % |
| 544 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 545 | ModuleExport size_t RegisterEMFImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | { |
| 547 | MagickInfo |
| 548 | *entry; |
| 549 | |
| 550 | entry=SetMagickInfo("EMF"); |
| 551 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
| 552 | entry->decoder=ReadEMFImage; |
| 553 | #endif |
| 554 | entry->description=ConstantString( |
| 555 | "Windows WIN32 API rendered Enhanced Meta File"); |
| 556 | entry->magick=(IsImageFormatHandler *) IsEMF; |
| 557 | entry->blob_support=MagickFalse; |
| 558 | entry->module=ConstantString("WMF"); |
| 559 | (void) RegisterMagickInfo(entry); |
| 560 | entry=SetMagickInfo("WMFWIN32"); |
| 561 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
| 562 | entry->decoder=ReadEMFImage; |
| 563 | #endif |
| 564 | entry->description=ConstantString("Windows WIN32 API rendered Meta File"); |
| 565 | entry->magick=(IsImageFormatHandler *) IsWMF; |
| 566 | entry->blob_support=MagickFalse; |
| 567 | entry->module=ConstantString("WMFWIN32"); |
| 568 | (void) RegisterMagickInfo(entry); |
| 569 | return(MagickImageCoderSignature); |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 574 | % % |
| 575 | % % |
| 576 | % % |
| 577 | % U n r e g i s t e r E M F I m a g e % |
| 578 | % % |
| 579 | % % |
| 580 | % % |
| 581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 582 | % |
| 583 | % UnregisterEMFImage() removes format registrations made by the |
| 584 | % EMF module from the list of supported formats. |
| 585 | % |
| 586 | % The format of the UnregisterEMFImage method is: |
| 587 | % |
| 588 | % UnregisterEMFImage(void) |
| 589 | % |
| 590 | */ |
| 591 | ModuleExport void UnregisterEMFImage(void) |
| 592 | { |
| 593 | (void) UnregisterMagickInfo("EMF"); |
| 594 | (void) UnregisterMagickInfo("WMFWIN32"); |
| 595 | } |