2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % CCCC L IIIII PPPP BBBB OOO AAA RRRR DDDD %
7 % C L I P P B B O O A A R R D D %
8 % C L I PPP BBBB O O AAAAA RRRR D D %
9 % C L I P B B O O A A R R D D %
10 % CCCC LLLLL IIIII P BBBB OOO A A R R DDDD %
13 % Read/Write Windows Clipboard. %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
44 # if defined(__CYGWIN__)
47 /* All MinGW needs ... */
51 #include "magick/blob.h"
52 #include "magick/blob-private.h"
53 #include "magick/cache.h"
54 #include "magick/exception.h"
55 #include "magick/exception-private.h"
56 #include "magick/image.h"
57 #include "magick/image-private.h"
58 #include "magick/list.h"
59 #include "magick/magick.h"
60 #include "magick/memory_.h"
61 #include "magick/nt-feature.h"
62 #include "magick/quantum-private.h"
63 #include "magick/static.h"
64 #include "magick/string_.h"
65 #include "magick/module.h"
70 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
71 static MagickBooleanType
72 WriteCLIPBOARDImage(const ImageInfo *,Image *);
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % R e a d C L I P B O A R D I m a g e %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % ReadCLIPBOARDImage() reads an image from the system clipboard and returns
87 % it. It allocates the memory necessary for the new Image structure and
88 % returns a pointer to the new image.
90 % The format of the ReadCLIPBOARDImage method is:
92 % Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
93 % ExceptionInfo exception)
95 % A description of each parameter follows:
97 % o image_info: the image info.
99 % o exception: return any errors or warnings in this structure.
102 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
103 static Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
104 ExceptionInfo *exception)
118 assert(image_info != (const ImageInfo *) NULL);
119 assert(image_info->signature == MagickSignature);
120 if (image_info->debug != MagickFalse)
121 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
122 image_info->filename);
123 assert(exception != (ExceptionInfo *) NULL);
124 assert(exception->signature == MagickSignature);
125 image=AcquireImage(image_info);
134 bitmapH=(HBITMAP) GetClipboardData(CF_BITMAP);
135 hPal=(HPALETTE) GetClipboardData(CF_PALETTE);
137 if ( bitmapH == NULL )
138 ThrowReaderException(CoderError,"NoBitmapOnClipboard");
158 /* create an offscreen DC for the source */
159 hMemDC=CreateCompatibleDC(NULL);
160 hOldBitmap=(HBITMAP) SelectObject(hMemDC,bitmapH);
161 GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap);
162 if ((image->columns == 0) || (image->rows == 0))
164 image->rows=bitmap.bmHeight;
165 image->columns=bitmap.bmWidth;
168 Initialize the bitmap header info.
170 (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO));
171 DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
172 DIBinfo.bmiHeader.biWidth=(LONG) image->columns;
173 DIBinfo.bmiHeader.biHeight=(-1)*(LONG) image->rows;
174 DIBinfo.bmiHeader.biPlanes=1;
175 DIBinfo.bmiHeader.biBitCount=32;
176 DIBinfo.bmiHeader.biCompression=BI_RGB;
179 ThrowReaderException(CoderError,"UnableToCreateADC");
180 hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,
184 ThrowReaderException(CoderError,"UnableToCreateBitmap");
185 /* create an offscreen DC */
186 hDC=CreateCompatibleDC(NULL);
189 DeleteObject(hBitmap);
190 ThrowReaderException(CoderError,"UnableToCreateADC");
192 hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
196 DeleteObject(hBitmap);
197 ThrowReaderException(CoderError,"UnableToCreateBitmap");
201 /* Kenichi Masuko says this needed */
202 SelectPalette(hDC, hPal, FALSE);
205 /* bitblt from the memory to the DIB-based one */
206 BitBlt(hDC,0,0,(int) image->columns,(int) image->rows,hMemDC,0,0,SRCCOPY);
207 /* finally copy the pixels! */
209 for (y=0; y < (ssize_t) image->rows; y++)
211 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
212 if (q == (PixelPacket *) NULL)
214 for (x=0; x < (ssize_t) image->columns; x++)
216 SetRedPixelComponent(q,ScaleCharToQuantum(pBits->rgbRed));
217 SetGreenPixelComponent(q,ScaleCharToQuantum(pBits->rgbGreen));
218 SetBluePixelComponent(q,ScaleCharToQuantum(pBits->rgbBlue));
219 SetOpacityPixelComponent(q,OpaqueOpacity);
223 if (SyncAuthenticPixels(image,exception) == MagickFalse)
227 DeleteObject(hBitmap);
230 (void) CloseBlob(image);
231 return(GetFirstImageInList(image));
233 #endif /* MAGICKCORE_WINGDI32_DELEGATE */
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % R e g i s t e r C L I P B O A R D I m a g e %
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % RegisterCLIPBOARDImage() adds attributes for the clipboard "image format" to
247 % the list of supported formats. The attributes include the image format
248 % tag, a method to read and/or write the format, whether the format
249 % supports the saving of more than one frame to the same file or blob,
250 % whether the format supports native in-memory I/O, and a brief
251 % description of the format.
253 % The format of the RegisterCLIPBOARDImage method is:
255 % size_t RegisterCLIPBOARDImage(void)
258 ModuleExport size_t RegisterCLIPBOARDImage(void)
263 entry=SetMagickInfo("CLIPBOARD");
264 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
265 entry->decoder=(DecodeImageHandler *) ReadCLIPBOARDImage;
266 entry->encoder=(EncodeImageHandler *) WriteCLIPBOARDImage;
268 entry->adjoin=MagickFalse;
269 entry->format_type=ImplicitFormatType;
270 entry->description=ConstantString("The system clipboard");
271 entry->module=ConstantString("CLIPBOARD");
272 (void) RegisterMagickInfo(entry);
273 return(MagickImageCoderSignature);
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 % U n r e g i s t e r C L I P B O A R D I m a g e %
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 % UnregisterCLIPBOARDImage() removes format registrations made by the
288 % RGB module from the list of supported formats.
290 % The format of the UnregisterCLIPBOARDImage method is:
292 % UnregisterCLIPBOARDImage(void)
295 ModuleExport void UnregisterCLIPBOARDImage(void)
297 (void) UnregisterMagickInfo("CLIPBOARD");
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 % W r i t e C L I P B O A R D I m a g e %
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % WriteCLIPBOARDImage() writes an image to the system clipboard.
313 % The format of the WriteCLIPBOARDImage method is:
315 % MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
318 % A description of each parameter follows.
320 % o image_info: the image info.
322 % o image: The image.
325 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
326 static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
330 Allocate memory for pixels.
332 assert(image_info != (const ImageInfo *) NULL);
333 assert(image_info->signature == MagickSignature);
334 assert(image != (Image *) NULL);
335 assert(image->signature == MagickSignature);
336 if (image->debug != MagickFalse)
337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
344 bitmapH=(HBITMAP) ImageToHBITMAP(image);
345 SetClipboardData(CF_BITMAP,bitmapH);
350 #endif /* MAGICKCORE_WINGDI32_DELEGATE */