2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % SSSSS CCCC RRRR EEEEE EEEEE N N SSSSS H H OOO TTTTT %
7 % SS C R R E E NN N SS H H O O T %
8 % SSS C RRRR EEE EEE N N N SSS HHHHH O O T %
9 % SS C R R E E N NN SS H H O O T %
10 % SSSSS CCCC R R EEEEE EEEEE N N SSSSS H H OOO T %
13 % Takes a screenshot from the monitor(s). %
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 % https://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"
50 # ifndef DISPLAY_DEVICE_ACTIVE
51 # define DISPLAY_DEVICE_ACTIVE 0x00000001
55 #include "MagickCore/blob.h"
56 #include "MagickCore/blob-private.h"
57 #include "MagickCore/cache.h"
58 #include "MagickCore/exception.h"
59 #include "MagickCore/exception-private.h"
60 #include "MagickCore/image.h"
61 #include "MagickCore/image-private.h"
62 #include "MagickCore/list.h"
63 #include "MagickCore/magick.h"
64 #include "MagickCore/memory_.h"
65 #include "MagickCore/module.h"
66 #include "MagickCore/nt-feature.h"
67 #include "MagickCore/option.h"
68 #include "MagickCore/pixel-accessor.h"
69 #include "MagickCore/quantum-private.h"
70 #include "MagickCore/static.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/token.h"
73 #include "MagickCore/utility.h"
74 #include "MagickCore/xwindow.h"
75 #include "MagickCore/xwindow-private.h"
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % R e a d S C R E E N S H O T I m a g e %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % ReadSCREENSHOTImage() Takes a screenshot from the monitor(s).
90 % The format of the ReadSCREENSHOTImage method is:
92 % Image *ReadXImage(const ImageInfo *image_info,ExceptionInfo *exception)
94 % A description of each parameter follows:
96 % o image_info: the image info.
98 % o exception: return any errors or warnings in this structure.
101 static Image *ReadSCREENSHOTImage(const ImageInfo *image_info,
102 ExceptionInfo *exception)
107 assert(image_info->signature == MagickCoreSignature);
108 if (image_info->debug != MagickFalse)
109 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
110 image_info->filename);
111 assert(exception != (ExceptionInfo *) NULL);
112 assert(exception->signature == MagickCoreSignature);
113 image=(Image *) NULL;
114 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
151 assert(image_info != (const ImageInfo *) NULL);
153 device.cb = sizeof(device);
154 image=(Image *) NULL;
155 while(EnumDisplayDevices(NULL,i,&device,0) && ++i)
157 if ((device.StateFlags & DISPLAY_DEVICE_ACTIVE) != DISPLAY_DEVICE_ACTIVE)
160 hDC=CreateDC(device.DeviceName,device.DeviceName,NULL,NULL);
161 if (hDC == (HDC) NULL)
162 ThrowReaderException(CoderError,"UnableToCreateDC");
164 screen=AcquireImage(image_info,exception);
165 screen->columns=(size_t) GetDeviceCaps(hDC,HORZRES);
166 screen->rows=(size_t) GetDeviceCaps(hDC,VERTRES);
167 screen->storage_class=DirectClass;
168 if (image == (Image *) NULL)
171 AppendImageToList(&image,screen);
172 status=SetImageExtent(screen,screen->columns,screen->rows,exception);
173 if (status == MagickFalse)
174 return(DestroyImageList(image));
176 bitmapDC=CreateCompatibleDC(hDC);
177 if (bitmapDC == (HDC) NULL)
180 ThrowReaderException(CoderError,"UnableToCreateDC");
182 (void) ResetMagickMemory(&bmi,0,sizeof(BITMAPINFO));
183 bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
184 bmi.bmiHeader.biWidth=(LONG) screen->columns;
185 bmi.bmiHeader.biHeight=(-1)*(LONG) screen->rows;
186 bmi.bmiHeader.biPlanes=1;
187 bmi.bmiHeader.biBitCount=24;
188 bmi.bmiHeader.biCompression=BI_RGB;
189 bitmap=CreateDIBSection(hDC,&bmi,DIB_RGB_COLORS,(void **) &p,NULL,0);
190 if (bitmap == (HBITMAP) NULL)
194 ThrowReaderException(CoderError,"UnableToCreateBitmap");
196 bitmapOld=(HBITMAP) SelectObject(bitmapDC,bitmap);
197 if (bitmapOld == (HBITMAP) NULL)
201 DeleteObject(bitmap);
202 ThrowReaderException(CoderError,"UnableToCreateBitmap");
204 BitBlt(bitmapDC,0,0,(int) screen->columns,(int) screen->rows,hDC,0,0,
206 (void) SelectObject(bitmapDC,bitmapOld);
208 for (y=0; y < (ssize_t) screen->rows; y++)
210 q=QueueAuthenticPixels(screen,0,y,screen->columns,1,exception);
211 if (q == (Quantum *) NULL)
213 for (x=0; x < (ssize_t) screen->columns; x++)
215 SetPixelRed(image,ScaleCharToQuantum(p->rgbtRed),q);
216 SetPixelGreen(image,ScaleCharToQuantum(p->rgbtGreen),q);
217 SetPixelBlue(image,ScaleCharToQuantum(p->rgbtBlue),q);
218 SetPixelAlpha(image,OpaqueAlpha,q);
220 q+=GetPixelChannels(image);
222 if (SyncAuthenticPixels(screen,exception) == MagickFalse)
228 DeleteObject(bitmap);
231 #elif defined(MAGICKCORE_X11_DELEGATE)
239 XGetImportInfo(&ximage_info);
240 option=GetImageOption(image_info,"x:screen");
241 if (option != (const char *) NULL)
242 ximage_info.screen=IsStringTrue(option);
243 option=GetImageOption(image_info,"x:silent");
244 if (option != (const char *) NULL)
245 ximage_info.silent=IsStringTrue(option);
246 image=XImportImage(image_info,&ximage_info,exception);
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % R e g i s t e r S C R E E N S H O T I m a g e %
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 % RegisterSCREENSHOTImage() adds attributes for the screen shot format to
264 % the list of supported formats. The attributes include the image format
265 % tag, a method to read and/or write the format, whether the format
266 % supports the saving of more than one frame to the same file or blob,
267 % whether the format supports native in-memory I/O, and a brief
268 % description of the format.
270 % The format of the RegisterScreenShotImage method is:
272 % size_t RegisterScreenShotImage(void)
275 ModuleExport size_t RegisterSCREENSHOTImage(void)
280 entry=AcquireMagickInfo("SCREENSHOT","SCREENSHOT","Screen shot");
281 entry->decoder=(DecodeImageHandler *) ReadSCREENSHOTImage;
282 entry->format_type=ImplicitFormatType;
283 (void) RegisterMagickInfo(entry);
284 return(MagickImageCoderSignature);
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 % U n r e g i s t e r S C R E E N S H O T I m a g e %
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 % UnregisterScreenShotImage() removes format registrations made by the
299 % screen shot module from the list of supported formats.
301 % The format of the UnregisterSCREENSHOTImage method is:
303 % UnregisterSCREENSHOTImage(void)
306 ModuleExport void UnregisterSCREENSHOTImage(void)
308 (void) UnregisterMagickInfo("SCREENSHOT");