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 "MagickCore/studio.h"
43 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
44 # if defined(__CYGWIN__)
47 /* All MinGW needs ... */
51 #include "MagickCore/blob.h"
52 #include "MagickCore/blob-private.h"
53 #include "MagickCore/cache.h"
54 #include "MagickCore/exception.h"
55 #include "MagickCore/exception-private.h"
56 #include "MagickCore/image.h"
57 #include "MagickCore/image-private.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/nt-base-private.h"
62 #include "MagickCore/pixel-accessor.h"
63 #include "MagickCore/quantum-private.h"
64 #include "MagickCore/static.h"
65 #include "MagickCore/string_.h"
66 #include "MagickCore/module.h"
71 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
72 static MagickBooleanType
73 WriteCLIPBOARDImage(const ImageInfo *,Image *,ExceptionInfo *);
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % R e a d C L I P B O A R D I m a g e %
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 % ReadCLIPBOARDImage() reads an image from the system clipboard and returns
88 % it. It allocates the memory necessary for the new Image structure and
89 % returns a pointer to the new image.
91 % The format of the ReadCLIPBOARDImage method is:
93 % Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
94 % ExceptionInfo exception)
96 % A description of each parameter follows:
98 % o image_info: the image info.
100 % o exception: return any errors or warnings in this structure.
103 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
104 static Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
105 ExceptionInfo *exception)
119 assert(image_info != (const ImageInfo *) NULL);
120 assert(image_info->signature == MagickSignature);
121 if (image_info->debug != MagickFalse)
122 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
123 image_info->filename);
124 assert(exception != (ExceptionInfo *) NULL);
125 assert(exception->signature == MagickSignature);
126 image=AcquireImage(image_info,exception);
135 bitmapH=(HBITMAP) GetClipboardData(CF_BITMAP);
136 hPal=(HPALETTE) GetClipboardData(CF_PALETTE);
138 if ( bitmapH == NULL )
139 ThrowReaderException(CoderError,"NoBitmapOnClipboard");
159 /* create an offscreen DC for the source */
160 hMemDC=CreateCompatibleDC(NULL);
161 hOldBitmap=(HBITMAP) SelectObject(hMemDC,bitmapH);
162 GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap);
163 if ((image->columns == 0) || (image->rows == 0))
165 image->rows=bitmap.bmHeight;
166 image->columns=bitmap.bmWidth;
169 Initialize the bitmap header info.
171 (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO));
172 DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
173 DIBinfo.bmiHeader.biWidth=(LONG) image->columns;
174 DIBinfo.bmiHeader.biHeight=(-1)*(LONG) image->rows;
175 DIBinfo.bmiHeader.biPlanes=1;
176 DIBinfo.bmiHeader.biBitCount=32;
177 DIBinfo.bmiHeader.biCompression=BI_RGB;
180 ThrowReaderException(CoderError,"UnableToCreateADC");
181 hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,
185 ThrowReaderException(CoderError,"UnableToCreateBitmap");
186 /* create an offscreen DC */
187 hDC=CreateCompatibleDC(NULL);
190 DeleteObject(hBitmap);
191 ThrowReaderException(CoderError,"UnableToCreateADC");
193 hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
197 DeleteObject(hBitmap);
198 ThrowReaderException(CoderError,"UnableToCreateBitmap");
202 /* Kenichi Masuko says this needed */
203 SelectPalette(hDC, hPal, FALSE);
206 /* bitblt from the memory to the DIB-based one */
207 BitBlt(hDC,0,0,(int) image->columns,(int) image->rows,hMemDC,0,0,SRCCOPY);
208 /* finally copy the pixels! */
210 for (y=0; y < (ssize_t) image->rows; y++)
212 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
213 if (q == (Quantum *) NULL)
215 for (x=0; x < (ssize_t) image->columns; x++)
217 SetPixelRed(image,ScaleCharToQuantum(pBits->rgbRed),q);
218 SetPixelGreen(image,ScaleCharToQuantum(pBits->rgbGreen),q);
219 SetPixelBlue(image,ScaleCharToQuantum(pBits->rgbBlue),q);
220 SetPixelAlpha(image,OpaqueAlpha,q);
222 q+=GetPixelChannels(image);
224 if (SyncAuthenticPixels(image,exception) == MagickFalse)
228 DeleteObject(hBitmap);
231 (void) CloseBlob(image);
232 return(GetFirstImageInList(image));
234 #endif /* MAGICKCORE_WINGDI32_DELEGATE */
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241 % R e g i s t e r C L I P B O A R D I m a g e %
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % RegisterCLIPBOARDImage() adds attributes for the clipboard "image format" to
248 % the list of supported formats. The attributes include the image format
249 % tag, a method to read and/or write the format, whether the format
250 % supports the saving of more than one frame to the same file or blob,
251 % whether the format supports native in-memory I/O, and a brief
252 % description of the format.
254 % The format of the RegisterCLIPBOARDImage method is:
256 % size_t RegisterCLIPBOARDImage(void)
259 ModuleExport size_t RegisterCLIPBOARDImage(void)
264 entry=SetMagickInfo("CLIPBOARD");
265 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
266 entry->decoder=(DecodeImageHandler *) ReadCLIPBOARDImage;
267 entry->encoder=(EncodeImageHandler *) WriteCLIPBOARDImage;
269 entry->adjoin=MagickFalse;
270 entry->format_type=ImplicitFormatType;
271 entry->description=ConstantString("The system clipboard");
272 entry->module=ConstantString("CLIPBOARD");
273 (void) RegisterMagickInfo(entry);
274 return(MagickImageCoderSignature);
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 % U n r e g i s t e r C L I P B O A R D I m a g e %
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 % UnregisterCLIPBOARDImage() removes format registrations made by the
289 % RGB module from the list of supported formats.
291 % The format of the UnregisterCLIPBOARDImage method is:
293 % UnregisterCLIPBOARDImage(void)
296 ModuleExport void UnregisterCLIPBOARDImage(void)
298 (void) UnregisterMagickInfo("CLIPBOARD");
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 % W r i t e C L I P B O A R D I m a g e %
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 % WriteCLIPBOARDImage() writes an image to the system clipboard.
314 % The format of the WriteCLIPBOARDImage method is:
316 % MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
317 % Image *image,ExceptionInfo *exception)
319 % A description of each parameter follows.
321 % o image_info: the image info.
323 % o image: The image.
325 % o exception: return any errors or warnings in this structure.
328 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
329 static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
330 Image *image,ExceptionInfo *exception)
333 Allocate memory for pixels.
335 assert(image_info != (const ImageInfo *) NULL);
336 assert(image_info->signature == MagickSignature);
337 assert(image != (Image *) NULL);
338 assert(image->signature == MagickSignature);
339 if (image->debug != MagickFalse)
340 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
347 bitmapH=(HBITMAP) ImageToHBITMAP(image);
348 SetClipboardData(CF_BITMAP,bitmapH);
353 #endif /* MAGICKCORE_WINGDI32_DELEGATE */