| 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 | #include "magick/studio.h" |
|---|
| 38 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 39 | # if defined(__CYGWIN__) |
|---|
| 40 | # include <windows.h> |
|---|
| 41 | # else |
|---|
| 42 | |
|---|
| 43 | # include <wingdi.h> |
|---|
| 44 | # endif |
|---|
| 45 | #endif |
|---|
| 46 | #include "magick/blob.h" |
|---|
| 47 | #include "magick/blob-private.h" |
|---|
| 48 | #include "magick/exception.h" |
|---|
| 49 | #include "magick/exception-private.h" |
|---|
| 50 | #include "magick/image.h" |
|---|
| 51 | #include "magick/image-private.h" |
|---|
| 52 | #include "magick/list.h" |
|---|
| 53 | #include "magick/magick.h" |
|---|
| 54 | #include "magick/memory_.h" |
|---|
| 55 | #include "magick/nt-feature.h" |
|---|
| 56 | #include "magick/quantum-private.h" |
|---|
| 57 | #include "magick/static.h" |
|---|
| 58 | #include "magick/string_.h" |
|---|
| 59 | #include "magick/module.h" |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 65 | static MagickBooleanType |
|---|
| 66 | WriteCLIPBOARDImage(const ImageInfo *,Image *); |
|---|
| 67 | #endif |
|---|
| 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 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 97 | static Image *ReadCLIPBOARDImage(const ImageInfo *image_info, |
|---|
| 98 | ExceptionInfo *exception) |
|---|
| 99 | { |
|---|
| 100 | Image |
|---|
| 101 | *image; |
|---|
| 102 | |
|---|
| 103 | long |
|---|
| 104 | y; |
|---|
| 105 | |
|---|
| 106 | register long |
|---|
| 107 | x; |
|---|
| 108 | |
|---|
| 109 | register PixelPacket |
|---|
| 110 | *q; |
|---|
| 111 | |
|---|
| 112 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 113 | assert(image_info->signature == MagickSignature); |
|---|
| 114 | if (image_info->debug != MagickFalse) |
|---|
| 115 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 116 | image_info->filename); |
|---|
| 117 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 118 | assert(exception->signature == MagickSignature); |
|---|
| 119 | image=AcquireImage(image_info); |
|---|
| 120 | { |
|---|
| 121 | HBITMAP |
|---|
| 122 | bitmapH; |
|---|
| 123 | |
|---|
| 124 | HPALETTE |
|---|
| 125 | hPal; |
|---|
| 126 | |
|---|
| 127 | OpenClipboard(NULL); |
|---|
| 128 | bitmapH=(HBITMAP) GetClipboardData(CF_BITMAP); |
|---|
| 129 | hPal=(HPALETTE) GetClipboardData(CF_PALETTE); |
|---|
| 130 | CloseClipboard(); |
|---|
| 131 | if ( bitmapH == NULL ) |
|---|
| 132 | ThrowReaderException(CoderError,"NoBitmapOnClipboard"); |
|---|
| 133 | { |
|---|
| 134 | BITMAPINFO |
|---|
| 135 | DIBinfo; |
|---|
| 136 | |
|---|
| 137 | BITMAP |
|---|
| 138 | bitmap; |
|---|
| 139 | |
|---|
| 140 | HBITMAP |
|---|
| 141 | hBitmap, |
|---|
| 142 | hOldBitmap; |
|---|
| 143 | |
|---|
| 144 | HDC |
|---|
| 145 | hDC, |
|---|
| 146 | hMemDC; |
|---|
| 147 | |
|---|
| 148 | RGBQUAD |
|---|
| 149 | *pBits, |
|---|
| 150 | *ppBits; |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | hMemDC=CreateCompatibleDC(NULL); |
|---|
| 154 | hOldBitmap=(HBITMAP) SelectObject(hMemDC,bitmapH); |
|---|
| 155 | GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap); |
|---|
| 156 | if ((image->columns == 0) || (image->rows == 0)) |
|---|
| 157 | { |
|---|
| 158 | image->rows=bitmap.bmHeight; |
|---|
| 159 | image->columns=bitmap.bmWidth; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO)); |
|---|
| 165 | DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); |
|---|
| 166 | DIBinfo.bmiHeader.biWidth=image->columns; |
|---|
| 167 | DIBinfo.bmiHeader.biHeight=(-1)*image->rows; |
|---|
| 168 | DIBinfo.bmiHeader.biPlanes=1; |
|---|
| 169 | DIBinfo.bmiHeader.biBitCount=32; |
|---|
| 170 | DIBinfo.bmiHeader.biCompression=BI_RGB; |
|---|
| 171 | hDC=GetDC(NULL); |
|---|
| 172 | if (hDC == 0) |
|---|
| 173 | ThrowReaderException(CoderError,"UnableToCreateADC"); |
|---|
| 174 | hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits, |
|---|
| 175 | NULL,0); |
|---|
| 176 | ReleaseDC(NULL,hDC); |
|---|
| 177 | if (hBitmap == 0) |
|---|
| 178 | ThrowReaderException(CoderError,"UnableToCreateBitmap"); |
|---|
| 179 | |
|---|
| 180 | hDC=CreateCompatibleDC(NULL); |
|---|
| 181 | if (hDC == 0) |
|---|
| 182 | { |
|---|
| 183 | DeleteObject(hBitmap); |
|---|
| 184 | ThrowReaderException(CoderError,"UnableToCreateADC"); |
|---|
| 185 | } |
|---|
| 186 | hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap); |
|---|
| 187 | if (hOldBitmap == 0) |
|---|
| 188 | { |
|---|
| 189 | DeleteDC(hDC); |
|---|
| 190 | DeleteObject(hBitmap); |
|---|
| 191 | ThrowReaderException(CoderError,"UnableToCreateBitmap"); |
|---|
| 192 | } |
|---|
| 193 | if (hPal != NULL) |
|---|
| 194 | { |
|---|
| 195 | |
|---|
| 196 | SelectPalette(hDC, hPal, FALSE); |
|---|
| 197 | RealizePalette(hDC); |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | BitBlt(hDC,0,0,image->columns,image->rows,hMemDC,0,0,SRCCOPY); |
|---|
| 201 | |
|---|
| 202 | pBits=ppBits; |
|---|
| 203 | for (y=0; y < (long) image->rows; y++) |
|---|
| 204 | { |
|---|
| 205 | q=SetImagePixels(image,0,y,image->columns,1); |
|---|
| 206 | if (q == (PixelPacket *) NULL) |
|---|
| 207 | break; |
|---|
| 208 | for (x=0; x < (long) image->columns; x++) |
|---|
| 209 | { |
|---|
| 210 | q->red=ScaleCharToQuantum(pBits->rgbRed); |
|---|
| 211 | q->green=ScaleCharToQuantum(pBits->rgbGreen); |
|---|
| 212 | q->blue=ScaleCharToQuantum(pBits->rgbBlue); |
|---|
| 213 | q->opacity=OpaqueOpacity; |
|---|
| 214 | pBits++; |
|---|
| 215 | q++; |
|---|
| 216 | } |
|---|
| 217 | if (SyncImagePixels(image) == MagickFalse) |
|---|
| 218 | break; |
|---|
| 219 | } |
|---|
| 220 | DeleteDC(hDC); |
|---|
| 221 | DeleteObject(hBitmap); |
|---|
| 222 | } |
|---|
| 223 | } |
|---|
| 224 | (void) CloseBlob(image); |
|---|
| 225 | return(GetFirstImageInList(image)); |
|---|
| 226 | } |
|---|
| 227 | #endif |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | ModuleExport unsigned long RegisterCLIPBOARDImage(void) |
|---|
| 253 | { |
|---|
| 254 | MagickInfo |
|---|
| 255 | *entry; |
|---|
| 256 | |
|---|
| 257 | entry=SetMagickInfo("CLIPBOARD"); |
|---|
| 258 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 259 | entry->decoder=(DecodeImageHandler *) ReadCLIPBOARDImage; |
|---|
| 260 | entry->encoder=(EncodeImageHandler *) WriteCLIPBOARDImage; |
|---|
| 261 | #endif |
|---|
| 262 | entry->adjoin=MagickFalse; |
|---|
| 263 | entry->format_type=ImplicitFormatType; |
|---|
| 264 | entry->description=ConstantString("The system clipboard"); |
|---|
| 265 | entry->module=ConstantString("CLIPBOARD"); |
|---|
| 266 | (void) RegisterMagickInfo(entry); |
|---|
| 267 | return(MagickImageCoderSignature); |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | ModuleExport void UnregisterCLIPBOARDImage(void) |
|---|
| 290 | { |
|---|
| 291 | (void) UnregisterMagickInfo("CLIPBOARD"); |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | #if defined(MAGICKCORE_WINGDI32_DELEGATE) |
|---|
| 320 | static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info, |
|---|
| 321 | Image *image) |
|---|
| 322 | { |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 327 | assert(image_info->signature == MagickSignature); |
|---|
| 328 | assert(image != (Image *) NULL); |
|---|
| 329 | assert(image->signature == MagickSignature); |
|---|
| 330 | if (image->debug != MagickFalse) |
|---|
| 331 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 332 | { |
|---|
| 333 | HBITMAP |
|---|
| 334 | bitmapH; |
|---|
| 335 | |
|---|
| 336 | OpenClipboard( NULL ); |
|---|
| 337 | EmptyClipboard(); |
|---|
| 338 | bitmapH=(HBITMAP) ImageToHBITMAP(image); |
|---|
| 339 | SetClipboardData(CF_BITMAP,bitmapH); |
|---|
| 340 | CloseClipboard(); |
|---|
| 341 | } |
|---|
| 342 | return(MagickTrue); |
|---|
| 343 | } |
|---|
| 344 | #endif |
|---|