00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
#include "magick/studio.h"
00038
#if defined(HasWINGDI32)
00039
# if defined(__CYGWIN__)
00040
# include <windows.h>
00041
# else
00042
00043
# include <wingdi.h>
00044
# endif
00045
#endif
00046
#include "magick/blob.h"
00047
#include "magick/blob_private.h"
00048
#include "magick/error.h"
00049
#include "magick/error_private.h"
00050
#include "magick/image.h"
00051
#include "magick/image_private.h"
00052
#include "magick/list.h"
00053
#include "magick/magick.h"
00054
#include "magick/memory_.h"
00055
#include "magick/nt_feature.h"
00056
#include "magick/static.h"
00057
#include "magick/string_.h"
00058
00059
00060
00061
00062
#if defined(HasWINGDI32)
00063
static MagickBooleanType
00064 WriteCLIPBOARDImage(
const ImageInfo *,
Image *);
00065
#endif
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
#if defined(HasWINGDI32)
00096
static Image *ReadCLIPBOARDImage(
const ImageInfo *image_info,
00097
ExceptionInfo *
exception)
00098 {
00099
Image
00100 *image;
00101
00102
long
00103 y;
00104
00105
register long
00106 x;
00107
00108
register PixelPacket
00109 *q;
00110
00111
assert(image_info != (
const ImageInfo *) NULL);
00112
assert(image_info->
signature == MagickSignature);
00113
if (image_info->
debug !=
MagickFalse)
00114 (
void)
LogMagickEvent(TraceEvent,
GetMagickModule(),image_info->
filename);
00115
assert(exception != (
ExceptionInfo *) NULL);
00116
assert(exception->
signature == MagickSignature);
00117 image=
AllocateImage(image_info);
00118 {
00119 HBITMAP
00120 bitmapH;
00121
00122 HPALETTE
00123 hPal;
00124
00125 OpenClipboard(NULL);
00126 bitmapH=GetClipboardData(CF_BITMAP);
00127 hPal = GetClipboardData(CF_PALETTE);
00128 CloseClipboard();
00129
if ( bitmapH == NULL )
00130
ThrowReaderException(CoderError,
"NoBitmapOnClipboard");
00131 {
00132 BITMAPINFO
00133 DIBinfo;
00134
00135 BITMAP
00136 bitmap;
00137
00138 HBITMAP
00139 hBitmap,
00140 hOldBitmap;
00141
00142 HDC
00143 hDC,
00144 hMemDC;
00145
00146 RGBQUAD
00147 *pBits,
00148 *ppBits;
00149
00150
00151 hMemDC=CreateCompatibleDC(NULL);
00152 hOldBitmap=SelectObject(hMemDC,bitmapH);
00153 GetObject(bitmapH,
sizeof(BITMAP),(LPSTR) &bitmap);
00154
if ((image->
columns == 0) || (image->
rows == 0))
00155 {
00156 image->
rows=bitmap.bmHeight;
00157 image->
columns=bitmap.bmWidth;
00158 }
00159
00160
00161
00162 (
void)
ResetMagickMemory(&DIBinfo,0,
sizeof(BITMAPINFO));
00163 DIBinfo.bmiHeader.biSize=
sizeof(BITMAPINFOHEADER);
00164 DIBinfo.bmiHeader.biWidth=image->
columns;
00165 DIBinfo.bmiHeader.biHeight=(-1)*image->
rows;
00166 DIBinfo.bmiHeader.biPlanes=1;
00167 DIBinfo.bmiHeader.biBitCount=32;
00168 DIBinfo.bmiHeader.biCompression=
BI_RGB;
00169 hDC=GetDC(NULL);
00170
if (hDC == 0)
00171
ThrowReaderException(CoderError,
"UnableToCreateADC");
00172 hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(
void **) &ppBits,
00173 NULL,0);
00174 ReleaseDC(NULL,hDC);
00175
if (hBitmap == 0)
00176
ThrowReaderException(CoderError,
"UnableToCreateBitmap");
00177
00178 hDC=CreateCompatibleDC(NULL);
00179
if (hDC == 0)
00180 {
00181 DeleteObject(hBitmap);
00182
ThrowReaderException(CoderError,
"UnableToCreateADC");
00183 }
00184 hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
00185
if (hOldBitmap == 0)
00186 {
00187 DeleteDC(hDC);
00188 DeleteObject(hBitmap);
00189
ThrowReaderException(CoderError,
"UnableToCreateBitmap");
00190 }
00191
if (hPal != NULL)
00192 {
00193
00194 SelectPalette(hDC, hPal, FALSE);
00195 RealizePalette(hDC);
00196 }
00197
00198 BitBlt(hDC,0,0,image->
columns,image->
rows,hMemDC,0,0,SRCCOPY);
00199
00200 pBits=ppBits;
00201
for (y=0; y < (
long) image->
rows; y++)
00202 {
00203 q=
SetImagePixels(image,0,y,image->
columns,1);
00204
if (q == (
PixelPacket *) NULL)
00205
break;
00206
for (x=0; x < (
long) image->
columns; x++)
00207 {
00208 q->
red=
ScaleCharToQuantum(pBits->rgbRed);
00209 q->
green=
ScaleCharToQuantum(pBits->rgbGreen);
00210 q->
blue=
ScaleCharToQuantum(pBits->rgbBlue);
00211 q->
opacity=
OpaqueOpacity;
00212 pBits++;
00213 q++;
00214 }
00215
if (
SyncImagePixels(image) ==
MagickFalse)
00216
break;
00217 }
00218 DeleteDC(hDC);
00219 DeleteObject(hBitmap);
00220 }
00221 }
00222
CloseBlob(image);
00223
return(
GetFirstImageInList(image));
00224 }
00225
#endif
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 ModuleExport void RegisterCLIPBOARDImage(
void)
00251 {
00252
MagickInfo
00253 *entry;
00254
00255 entry=
SetMagickInfo(
"CLIPBOARD");
00256
#if defined(HasWINGDI32)
00257
entry->
decoder=(
DecoderHandler *) ReadCLIPBOARDImage;
00258 entry->
encoder=(
EncoderHandler *) WriteCLIPBOARDImage;
00259
#endif
00260
entry->
adjoin=
MagickFalse;
00261 entry->
description=
AcquireString(
"The system clipboard");
00262 entry->
module=
AcquireString(
"CLIPBOARD");
00263 (
void)
RegisterMagickInfo(entry);
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 ModuleExport void UnregisterCLIPBOARDImage(
void)
00286 {
00287 (
void)
UnregisterMagickInfo(
"CLIPBOARD");
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
#if defined(HasWINGDI32)
00317
static MagickBooleanType WriteCLIPBOARDImage(
const ImageInfo *image_info,
00318
Image *image)
00319 {
00320
00321
00322
00323
assert(image_info != (
const ImageInfo *) NULL);
00324
assert(image_info->
signature == MagickSignature);
00325
assert(image != (
Image *) NULL);
00326
assert(image->
signature == MagickSignature);
00327
if (image->
debug !=
MagickFalse)
00328 (
void)
LogMagickEvent(TraceEvent,
GetMagickModule(),image->
filename);
00329 {
00330 HBITMAP
00331 bitmapH;
00332
00333 OpenClipboard( NULL );
00334 EmptyClipboard();
00335 bitmapH=
ImageToHBITMAP(image);
00336 SetClipboardData(CF_BITMAP,bitmapH);
00337 CloseClipboard();
00338 }
00339
return(
MagickTrue);
00340 }
00341
#endif
00342