2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 % Read/Write Windows Clipboard. %
15 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
16 % dedicated to making software imaging solutions freely available. %
18 % You may not use this file except in compliance with the License. You may %
19 % obtain a copy of the License at %
21 % http://www.imagemagick.org/script/license.php %
23 % Unless required by applicable law or agreed to in writing, software %
24 % distributed under the License is distributed on an "AS IS" BASIS, %
25 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
26 % See the License for the specific language governing permissions and %
27 % limitations under the License. %
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 #include "magick/studio.h"
38 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
39 # if defined(__CYGWIN__)
42 /* All MinGW needs ... */
46 #include "magick/blob.h"
47 #include "magick/blob-private.h"
48 #include "magick/cache.h"
49 #include "magick/exception.h"
50 #include "magick/exception-private.h"
51 #include "magick/image.h"
52 #include "magick/image-private.h"
53 #include "magick/list.h"
54 #include "magick/magick.h"
55 #include "magick/memory_.h"
56 #include "magick/nt-feature.h"
57 #include "magick/quantum-private.h"
58 #include "magick/static.h"
59 #include "magick/string_.h"
60 #include "magick/module.h"
65 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
66 static MagickBooleanType
67 WriteCLIPBOARDImage(const ImageInfo *,Image *);
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % R e a d C L I P B O A R D I m a g e %
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % ReadCLIPBOARDImage() reads an image from the system clipboard and returns
82 % it. It allocates the memory necessary for the new Image structure and
83 % returns a pointer to the new image.
85 % The format of the ReadCLIPBOARDImage method is:
87 % Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
88 % ExceptionInfo exception)
90 % A description of each parameter follows:
92 % o image_info: the image info.
94 % o exception: return any errors or warnings in this structure.
97 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
98 static Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
99 ExceptionInfo *exception)
113 assert(image_info != (const ImageInfo *) NULL);
114 assert(image_info->signature == MagickSignature);
115 if (image_info->debug != MagickFalse)
116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
117 image_info->filename);
118 assert(exception != (ExceptionInfo *) NULL);
119 assert(exception->signature == MagickSignature);
120 image=AcquireImage(image_info);
129 bitmapH=(HBITMAP) GetClipboardData(CF_BITMAP);
130 hPal=(HPALETTE) GetClipboardData(CF_PALETTE);
132 if ( bitmapH == NULL )
133 ThrowReaderException(CoderError,"NoBitmapOnClipboard");
153 /* create an offscreen DC for the source */
154 hMemDC=CreateCompatibleDC(NULL);
155 hOldBitmap=(HBITMAP) SelectObject(hMemDC,bitmapH);
156 GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap);
157 if ((image->columns == 0) || (image->rows == 0))
159 image->rows=bitmap.bmHeight;
160 image->columns=bitmap.bmWidth;
163 Initialize the bitmap header info.
165 (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO));
166 DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
167 DIBinfo.bmiHeader.biWidth=image->columns;
168 DIBinfo.bmiHeader.biHeight=(-1)*image->rows;
169 DIBinfo.bmiHeader.biPlanes=1;
170 DIBinfo.bmiHeader.biBitCount=32;
171 DIBinfo.bmiHeader.biCompression=BI_RGB;
174 ThrowReaderException(CoderError,"UnableToCreateADC");
175 hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,
179 ThrowReaderException(CoderError,"UnableToCreateBitmap");
180 /* create an offscreen DC */
181 hDC=CreateCompatibleDC(NULL);
184 DeleteObject(hBitmap);
185 ThrowReaderException(CoderError,"UnableToCreateADC");
187 hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
191 DeleteObject(hBitmap);
192 ThrowReaderException(CoderError,"UnableToCreateBitmap");
196 /* Kenichi Masuko says this needed */
197 SelectPalette(hDC, hPal, FALSE);
200 /* bitblt from the memory to the DIB-based one */
201 BitBlt(hDC,0,0,image->columns,image->rows,hMemDC,0,0,SRCCOPY);
202 /* finally copy the pixels! */
204 for (y=0; y < (long) image->rows; y++)
206 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
207 if (q == (PixelPacket *) NULL)
209 for (x=0; x < (long) image->columns; x++)
211 q->red=ScaleCharToQuantum(pBits->rgbRed);
212 q->green=ScaleCharToQuantum(pBits->rgbGreen);
213 q->blue=ScaleCharToQuantum(pBits->rgbBlue);
214 SetOpacityPixelComponent(q,OpaqueOpacity);
218 if (SyncAuthenticPixels(image,exception) == MagickFalse)
222 DeleteObject(hBitmap);
225 (void) CloseBlob(image);
226 return(GetFirstImageInList(image));
228 #endif /* MAGICKCORE_WINGDI32_DELEGATE */
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 % R e g i s t e r C L I P B O A R D I m a g e %
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 % RegisterCLIPBOARDImage() adds attributes for the clipboard "image format" to
242 % the list of supported formats. The attributes include the image format
243 % tag, a method to read and/or write the format, whether the format
244 % supports the saving of more than one frame to the same file or blob,
245 % whether the format supports native in-memory I/O, and a brief
246 % description of the format.
248 % The format of the RegisterCLIPBOARDImage method is:
250 % unsigned long RegisterCLIPBOARDImage(void)
253 ModuleExport unsigned long RegisterCLIPBOARDImage(void)
258 entry=SetMagickInfo("CLIPBOARD");
259 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
260 entry->decoder=(DecodeImageHandler *) ReadCLIPBOARDImage;
261 entry->encoder=(EncodeImageHandler *) WriteCLIPBOARDImage;
263 entry->adjoin=MagickFalse;
264 entry->format_type=ExplicitFormatType;
265 entry->description=ConstantString("The system clipboard");
266 entry->module=ConstantString("CLIPBOARD");
267 (void) RegisterMagickInfo(entry);
268 return(MagickImageCoderSignature);
272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 % U n r e g i s t e r C L I P B O A R D I m a g e %
280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 % UnregisterCLIPBOARDImage() removes format registrations made by the
283 % RGB module from the list of supported formats.
285 % The format of the UnregisterCLIPBOARDImage method is:
287 % UnregisterCLIPBOARDImage(void)
290 ModuleExport void UnregisterCLIPBOARDImage(void)
292 (void) UnregisterMagickInfo("CLIPBOARD");
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % W r i t e C L I P B O A R D I m a g e %
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 % WriteCLIPBOARDImage() writes an image to the system clipboard.
308 % The format of the WriteCLIPBOARDImage method is:
310 % MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
313 % A description of each parameter follows.
315 % o image_info: the image info.
317 % o image: The image.
320 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
321 static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
325 Allocate memory for pixels.
327 assert(image_info != (const ImageInfo *) NULL);
328 assert(image_info->signature == MagickSignature);
329 assert(image != (Image *) NULL);
330 assert(image->signature == MagickSignature);
331 if (image->debug != MagickFalse)
332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
337 OpenClipboard( NULL );
339 bitmapH=(HBITMAP) ImageToHBITMAP(image);
340 SetClipboardData(CF_BITMAP,bitmapH);
345 #endif /* MAGICKCORE_WINGDI32_DELEGATE */