Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/clipboard.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % % 00007 % % 00008 % Read/Write Windows Clipboard. % 00009 % % 00010 % Software Design % 00011 % Leonard Rosenthol % 00012 % May 2002 % 00013 % % 00014 % % 00015 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00016 % dedicated to making software imaging solutions freely available. % 00017 % % 00018 % You may not use this file except in compliance with the License. You may % 00019 % obtain a copy of the License at % 00020 % % 00021 % http://www.imagemagick.org/www/Copyright.html % 00022 % % 00023 % Unless required by applicable law or agreed to in writing, software % 00024 % distributed under the License is distributed on an "AS IS" BASIS, % 00025 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00026 % See the License for the specific language governing permissions and % 00027 % limitations under the License. % 00028 % % 00029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00030 % 00031 % 00032 */ 00033 00034 /* 00035 Include declarations. 00036 */ 00037 #include "magick/studio.h" 00038 #if defined(HasWINGDI32) 00039 # if defined(__CYGWIN__) 00040 # include <windows.h> 00041 # else 00042 // All MinGW needs ... 00043 # include <wingdi.h> 00044 # endif 00045 #endif 00046 #include "magick/blob.h" 00047 #include "magick/blob_private.h" 00048 #include "magick/error.h" 00049 #include "magick/error_private.h" 00050 #include "magick/image.h" 00051 #include "magick/image_private.h" 00052 #include "magick/list.h" 00053 #include "magick/magick.h" 00054 #include "magick/memory_.h" 00055 #include "magick/nt_feature.h" 00056 #include "magick/static.h" 00057 #include "magick/string_.h" 00058 00059 /* 00060 Forward declarations. 00061 */ 00062 #if defined(HasWINGDI32) 00063 static MagickBooleanType 00064 WriteCLIPBOARDImage(const ImageInfo *,Image *); 00065 #endif 00066 00067 /* 00068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00069 % % 00070 % % 00071 % % 00072 % R e a d C L I P B O A R D I m a g e % 00073 % % 00074 % % 00075 % % 00076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00077 % 00078 % ReadCLIPBOARDImage() reads an image from the system clipboard and returns 00079 % it. It allocates the memory necessary for the new Image structure and 00080 % returns a pointer to the new image. 00081 % 00082 % The format of the ReadCLIPBOARDImage method is: 00083 % 00084 % Image *ReadCLIPBOARDImage(const ImageInfo *image_info, 00085 % ExceptionInfo exception) 00086 % 00087 % A description of each parameter follows: 00088 % 00089 % o image_info: The image info. 00090 % 00091 % o exception: return any errors or warnings in this structure. 00092 % 00093 % 00094 */ 00095 #if defined(HasWINGDI32) 00096 static Image *ReadCLIPBOARDImage(const ImageInfo *image_info, 00097 ExceptionInfo *exception) 00098 { 00099 Image 00100 *image; 00101 00102 long 00103 y; 00104 00105 register long 00106 x; 00107 00108 register PixelPacket 00109 *q; 00110 00111 assert(image_info != (const ImageInfo *) NULL); 00112 assert(image_info->signature == MagickSignature); 00113 if (image_info->debug != MagickFalse) 00114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00115 assert(exception != (ExceptionInfo *) NULL); 00116 assert(exception->signature == MagickSignature); 00117 image=AllocateImage(image_info); 00118 { 00119 HBITMAP 00120 bitmapH; 00121 00122 HPALETTE 00123 hPal; 00124 00125 OpenClipboard(NULL); 00126 bitmapH=GetClipboardData(CF_BITMAP); 00127 hPal = GetClipboardData(CF_PALETTE); 00128 CloseClipboard(); 00129 if ( bitmapH == NULL ) 00130 ThrowReaderException(CoderError,"NoBitmapOnClipboard"); 00131 { 00132 BITMAPINFO 00133 DIBinfo; 00134 00135 BITMAP 00136 bitmap; 00137 00138 HBITMAP 00139 hBitmap, 00140 hOldBitmap; 00141 00142 HDC 00143 hDC, 00144 hMemDC; 00145 00146 RGBQUAD 00147 *pBits, 00148 *ppBits; 00149 00150 // create an offscreen DC for the source 00151 hMemDC=CreateCompatibleDC(NULL); 00152 hOldBitmap=SelectObject(hMemDC,bitmapH); 00153 GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap); 00154 if ((image->columns == 0) || (image->rows == 0)) 00155 { 00156 image->rows=bitmap.bmHeight; 00157 image->columns=bitmap.bmWidth; 00158 } 00159 /* 00160 Initialize the bitmap header info. 00161 */ 00162 (void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO)); 00163 DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 00164 DIBinfo.bmiHeader.biWidth=image->columns; 00165 DIBinfo.bmiHeader.biHeight=(-1)*image->rows; 00166 DIBinfo.bmiHeader.biPlanes=1; 00167 DIBinfo.bmiHeader.biBitCount=32; 00168 DIBinfo.bmiHeader.biCompression=BI_RGB; 00169 hDC=GetDC(NULL); 00170 if (hDC == 0) 00171 ThrowReaderException(CoderError,"UnableToCreateADC"); 00172 hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits, 00173 NULL,0); 00174 ReleaseDC(NULL,hDC); 00175 if (hBitmap == 0) 00176 ThrowReaderException(CoderError,"UnableToCreateBitmap"); 00177 // create an offscreen DC 00178 hDC=CreateCompatibleDC(NULL); 00179 if (hDC == 0) 00180 { 00181 DeleteObject(hBitmap); 00182 ThrowReaderException(CoderError,"UnableToCreateADC"); 00183 } 00184 hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap); 00185 if (hOldBitmap == 0) 00186 { 00187 DeleteDC(hDC); 00188 DeleteObject(hBitmap); 00189 ThrowReaderException(CoderError,"UnableToCreateBitmap"); 00190 } 00191 if (hPal != NULL) 00192 { 00193 // Kenichi Masuko says this is needed 00194 SelectPalette(hDC, hPal, FALSE); 00195 RealizePalette(hDC); 00196 } 00197 // bitblt from the memory to the DIB-based one 00198 BitBlt(hDC,0,0,image->columns,image->rows,hMemDC,0,0,SRCCOPY); 00199 // finally copy the pixels! 00200 pBits=ppBits; 00201 for (y=0; y < (long) image->rows; y++) 00202 { 00203 q=SetImagePixels(image,0,y,image->columns,1); 00204 if (q == (PixelPacket *) NULL) 00205 break; 00206 for (x=0; x < (long) image->columns; x++) 00207 { 00208 q->red=ScaleCharToQuantum(pBits->rgbRed); 00209 q->green=ScaleCharToQuantum(pBits->rgbGreen); 00210 q->blue=ScaleCharToQuantum(pBits->rgbBlue); 00211 q->opacity=OpaqueOpacity; 00212 pBits++; 00213 q++; 00214 } 00215 if (SyncImagePixels(image) == MagickFalse) 00216 break; 00217 } 00218 DeleteDC(hDC); 00219 DeleteObject(hBitmap); 00220 } 00221 } 00222 CloseBlob(image); 00223 return(GetFirstImageInList(image)); 00224 } 00225 #endif /* HasWINGDI32 */ 00226 00227 /* 00228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00229 % % 00230 % % 00231 % % 00232 % R e g i s t e r C L I P B O A R D I m a g e % 00233 % % 00234 % % 00235 % % 00236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00237 % 00238 % RegisterCLIPBOARDImage() adds attributes for the clipboard "image format" to 00239 % the list of supported formats. The attributes include the image format 00240 % tag, a method to read and/or write the format, whether the format 00241 % supports the saving of more than one frame to the same file or blob, 00242 % whether the format supports native in-memory I/O, and a brief 00243 % description of the format. 00244 % 00245 % The format of the RegisterCLIPBOARDImage method is: 00246 % 00247 % RegisterCLIPBOARDImage(void) 00248 % 00249 */ 00250 ModuleExport void RegisterCLIPBOARDImage(void) 00251 { 00252 MagickInfo 00253 *entry; 00254 00255 entry=SetMagickInfo("CLIPBOARD"); 00256 #if defined(HasWINGDI32) 00257 entry->decoder=(DecoderHandler *) ReadCLIPBOARDImage; 00258 entry->encoder=(EncoderHandler *) WriteCLIPBOARDImage; 00259 #endif 00260 entry->adjoin=MagickFalse; 00261 entry->description=AcquireString("The system clipboard"); 00262 entry->module=AcquireString("CLIPBOARD"); 00263 (void) RegisterMagickInfo(entry); 00264 } 00265 00266 /* 00267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00268 % % 00269 % % 00270 % % 00271 % U n r e g i s t e r C L I P B O A R D I m a g e % 00272 % % 00273 % % 00274 % % 00275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00276 % 00277 % UnregisterCLIPBOARDImage() removes format registrations made by the 00278 % RGB module from the list of supported formats. 00279 % 00280 % The format of the UnregisterCLIPBOARDImage method is: 00281 % 00282 % UnregisterCLIPBOARDImage(void) 00283 % 00284 */ 00285 ModuleExport void UnregisterCLIPBOARDImage(void) 00286 { 00287 (void) UnregisterMagickInfo("CLIPBOARD"); 00288 } 00289 00290 /* 00291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00292 % % 00293 % % 00294 % % 00295 % W r i t e C L I P B O A R D I m a g e % 00296 % % 00297 % % 00298 % % 00299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00300 % 00301 % WriteCLIPBOARDImage() writes an image to the system clipboard. 00302 % 00303 % The format of the WriteCLIPBOARDImage method is: 00304 % 00305 % MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info, 00306 % Image *image) 00307 % 00308 % A description of each parameter follows. 00309 % 00310 % o image_info: The image info. 00311 % 00312 % o image: The image. 00313 % 00314 % 00315 */ 00316 #if defined(HasWINGDI32) 00317 static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info, 00318 Image *image) 00319 { 00320 /* 00321 Allocate memory for pixels. 00322 */ 00323 assert(image_info != (const ImageInfo *) NULL); 00324 assert(image_info->signature == MagickSignature); 00325 assert(image != (Image *) NULL); 00326 assert(image->signature == MagickSignature); 00327 if (image->debug != MagickFalse) 00328 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image->filename); 00329 { 00330 HBITMAP 00331 bitmapH; 00332 00333 OpenClipboard( NULL ); 00334 EmptyClipboard(); 00335 bitmapH=ImageToHBITMAP(image); 00336 SetClipboardData(CF_BITMAP,bitmapH); 00337 CloseClipboard(); 00338 } 00339 return(MagickTrue); 00340 } 00341 #endif /* HasWINGDI32 */ 00342

Generated on Mon Oct 25 13:40:35 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC