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-2017 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 ... */
48 # include "MagickCore/nt-base-private.h"
52 #include "MagickCore/blob.h"
53 #include "MagickCore/blob-private.h"
54 #include "MagickCore/cache.h"
55 #include "MagickCore/exception.h"
56 #include "MagickCore/exception-private.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/image-private.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/magick.h"
61 #include "MagickCore/memory_.h"
62 #include "MagickCore/nt-feature.h"
63 #include "MagickCore/pixel-accessor.h"
64 #include "MagickCore/quantum-private.h"
65 #include "MagickCore/static.h"
66 #include "MagickCore/string_.h"
67 #include "MagickCore/module.h"
72 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
73 static MagickBooleanType
74 WriteCLIPBOARDImage(const ImageInfo *,Image *,ExceptionInfo *);
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % R e a d C L I P B O A R D I m a g e %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % ReadCLIPBOARDImage() reads an image from the system clipboard and returns
89 % it. It allocates the memory necessary for the new Image structure and
90 % returns a pointer to the new image.
92 % The format of the ReadCLIPBOARDImage method is:
94 % Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
95 % ExceptionInfo exception)
97 % A description of each parameter follows:
99 % o image_info: the image info.
101 % o exception: return any errors or warnings in this structure.
104 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
105 static Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
106 ExceptionInfo *exception)
123 assert(image_info != (const ImageInfo *) NULL);
124 assert(image_info->signature == MagickCoreSignature);
125 if (image_info->debug != MagickFalse)
126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
127 image_info->filename);
128 assert(exception != (ExceptionInfo *) NULL);
129 assert(exception->signature == MagickCoreSignature);
130 image=AcquireImage(image_info,exception);
139 bitmapH=(HBITMAP) GetClipboardData(CF_BITMAP);
140 hPal=(HPALETTE) GetClipboardData(CF_PALETTE);
142 if ( bitmapH == NULL )
143 ThrowReaderException(CoderError,"NoBitmapOnClipboard");
163 /* create an offscreen DC for the source */
164 hMemDC=CreateCompatibleDC(NULL);
165 hOldBitmap=(HBITMAP) SelectObject(hMemDC,bitmapH);
166 GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap);
167 if ((image->columns == 0) || (image->rows == 0))
169 image->columns=bitmap.bmWidth;
170 image->rows=bitmap.bmHeight;
172 status=SetImageExtent(image,image->columns,image->rows,exception);
173 if (status == MagickFalse)
174 return(DestroyImageList(image));
176 Initialize the bitmap header info.
178 (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO));
179 DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
180 DIBinfo.bmiHeader.biWidth=(LONG) image->columns;
181 DIBinfo.bmiHeader.biHeight=(-1)*(LONG) image->rows;
182 DIBinfo.bmiHeader.biPlanes=1;
183 DIBinfo.bmiHeader.biBitCount=32;
184 DIBinfo.bmiHeader.biCompression=BI_RGB;
187 ThrowReaderException(CoderError,"UnableToCreateADC");
188 hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,
192 ThrowReaderException(CoderError,"UnableToCreateBitmap");
193 /* create an offscreen DC */
194 hDC=CreateCompatibleDC(NULL);
197 DeleteObject(hBitmap);
198 ThrowReaderException(CoderError,"UnableToCreateADC");
200 hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
204 DeleteObject(hBitmap);
205 ThrowReaderException(CoderError,"UnableToCreateBitmap");
209 /* Kenichi Masuko says this needed */
210 SelectPalette(hDC, hPal, FALSE);
213 /* bitblt from the memory to the DIB-based one */
214 BitBlt(hDC,0,0,(int) image->columns,(int) image->rows,hMemDC,0,0,SRCCOPY);
215 /* finally copy the pixels! */
217 for (y=0; y < (ssize_t) image->rows; y++)
219 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
220 if (q == (Quantum *) NULL)
222 for (x=0; x < (ssize_t) image->columns; x++)
224 SetPixelRed(image,ScaleCharToQuantum(pBits->rgbRed),q);
225 SetPixelGreen(image,ScaleCharToQuantum(pBits->rgbGreen),q);
226 SetPixelBlue(image,ScaleCharToQuantum(pBits->rgbBlue),q);
227 SetPixelAlpha(image,OpaqueAlpha,q);
229 q+=GetPixelChannels(image);
231 if (SyncAuthenticPixels(image,exception) == MagickFalse)
235 DeleteObject(hBitmap);
238 (void) CloseBlob(image);
239 return(GetFirstImageInList(image));
241 #endif /* MAGICKCORE_WINGDI32_DELEGATE */
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 % R e g i s t e r C L I P B O A R D I m a g e %
252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 % RegisterCLIPBOARDImage() adds attributes for the clipboard "image format" to
255 % the list of supported formats. The attributes include the image format
256 % tag, a method to read and/or write the format, whether the format
257 % supports the saving of more than one frame to the same file or blob,
258 % whether the format supports native in-memory I/O, and a brief
259 % description of the format.
261 % The format of the RegisterCLIPBOARDImage method is:
263 % size_t RegisterCLIPBOARDImage(void)
266 ModuleExport size_t RegisterCLIPBOARDImage(void)
271 entry=AcquireMagickInfo("CLIPBOARD","CLIPBOARD","The system clipboard");
272 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
273 entry->decoder=(DecodeImageHandler *) ReadCLIPBOARDImage;
274 entry->encoder=(EncodeImageHandler *) WriteCLIPBOARDImage;
276 entry->flags^=CoderAdjoinFlag;
277 entry->format_type=ImplicitFormatType;
278 (void) RegisterMagickInfo(entry);
279 return(MagickImageCoderSignature);
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 % U n r e g i s t e r C L I P B O A R D I m a g e %
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 % UnregisterCLIPBOARDImage() removes format registrations made by the
294 % RGB module from the list of supported formats.
296 % The format of the UnregisterCLIPBOARDImage method is:
298 % UnregisterCLIPBOARDImage(void)
301 ModuleExport void UnregisterCLIPBOARDImage(void)
303 (void) UnregisterMagickInfo("CLIPBOARD");
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % W r i t e C L I P B O A R D I m a g e %
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 % WriteCLIPBOARDImage() writes an image to the system clipboard.
319 % The format of the WriteCLIPBOARDImage method is:
321 % MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
322 % Image *image,ExceptionInfo *exception)
324 % A description of each parameter follows.
326 % o image_info: the image info.
328 % o image: The image.
330 % o exception: return any errors or warnings in this structure.
333 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
334 static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
335 Image *image,ExceptionInfo *exception)
338 Allocate memory for pixels.
340 assert(image_info != (const ImageInfo *) NULL);
341 assert(image_info->signature == MagickCoreSignature);
342 assert(image != (Image *) NULL);
343 assert(image->signature == MagickCoreSignature);
344 if (image->debug != MagickFalse)
345 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
352 bitmapH=(HBITMAP) ImageToHBITMAP(image,exception);
353 SetClipboardData(CF_BITMAP,bitmapH);
358 #endif /* MAGICKCORE_WINGDI32_DELEGATE */