/*
Include declarations.
*/
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
+#define VC_EXTRALEAN
+#include <windows.h>
+#endif
#include "MagickCore/studio.h"
#include "MagickCore/property.h"
#include "MagickCore/blob.h"
#include "MagickCore/colormap.h"
#include "MagickCore/colormap-private.h"
#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
#include "MagickCore/composite.h"
#include "MagickCore/composite-private.h"
#include "MagickCore/constitute.h"
return(((magick_info->flags & CoderSeekableStreamFlag) == 0) ? MagickFalse :
MagickTrue);
}
+\f
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% C r o p I m a g e T o H B i t m a p %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% CropImageToHBITMAP() extracts a specified region of the image and returns
+% it as a Windows HBITMAP. While the same functionality can be accomplished by
+% invoking CropImage() followed by ImageToHBITMAP(), this method is more
+% efficient since it copies pixels directly to the HBITMAP.
+%
+% The format of the CropImageToHBITMAP method is:
+%
+% HBITMAP CropImageToHBITMAP(Image* image,const RectangleInfo *geometry,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o geometry: Define the region of the image to crop with members
+% x, y, width, and height.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport void *CropImageToHBITMAP(Image *image,
+ const RectangleInfo *geometry,ExceptionInfo *exception)
+{
+#define CropImageTag "Crop/Image"
+
+ BITMAP
+ bitmap;
+
+ HBITMAP
+ bitmapH;
+
+ HANDLE
+ bitmap_bitsH;
+
+ MagickBooleanType
+ proceed;
+
+ RectangleInfo
+ page;
+
+ register const Quantum
+ *p;
+
+ register RGBQUAD
+ *q;
+
+ RGBQUAD
+ *bitmap_bits;
+
+ ssize_t
+ y;
+
+ /*
+ Check crop geometry.
+ */
+ assert(image != (const Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ assert(geometry != (const RectangleInfo *) NULL);
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickCoreSignature);
+ if (((geometry->x+(ssize_t) geometry->width) < 0) ||
+ ((geometry->y+(ssize_t) geometry->height) < 0) ||
+ (geometry->x >= (ssize_t) image->columns) ||
+ (geometry->y >= (ssize_t) image->rows))
+ ThrowImageException(OptionError,"GeometryDoesNotContainImage");
+ page=(*geometry);
+ if ((page.x+(ssize_t) page.width) > (ssize_t) image->columns)
+ page.width=image->columns-page.x;
+ if ((page.y+(ssize_t) page.height) > (ssize_t) image->rows)
+ page.height=image->rows-page.y;
+ if (page.x < 0)
+ {
+ page.width+=page.x;
+ page.x=0;
+ }
+ if (page.y < 0)
+ {
+ page.height+=page.y;
+ page.y=0;
+ }
+
+ if ((page.width == 0) || (page.height == 0))
+ ThrowImageException(OptionError,"GeometryDimensionsAreZero");
+ /*
+ Initialize crop image attributes.
+ */
+ bitmap.bmType = 0;
+ bitmap.bmWidth = (LONG) page.width;
+ bitmap.bmHeight = (LONG) page.height;
+ bitmap.bmWidthBytes = bitmap.bmWidth * 4;
+ bitmap.bmPlanes = 1;
+ bitmap.bmBitsPixel = 32;
+ bitmap.bmBits = NULL;
+
+ bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,page.width*
+ page.height*bitmap.bmBitsPixel);
+ if (bitmap_bitsH == NULL)
+ return(NULL);
+ bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
+ if ( bitmap.bmBits == NULL )
+ bitmap.bmBits = bitmap_bits;
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ SetImageColorspace(image,sRGBColorspace,exception);
+ /*
+ Extract crop image.
+ */
+ q=bitmap_bits;
+ for (y=0; y < (ssize_t) page.height; y++)
+ {
+ register ssize_t
+ x;
+
+ p=GetVirtualPixels(image,page.x,page.y+y,page.width,1,exception);
+ if (p == (const Quantum *) NULL)
+ break;
+
+ /* Transfer pixels, scaling to Quantum */
+ for( x=(ssize_t) page.width ; x> 0 ; x-- )
+ {
+ q->rgbRed = ScaleQuantumToChar(GetPixelRed(image,p));
+ q->rgbGreen = ScaleQuantumToChar(GetPixelGreen(image,p));
+ q->rgbBlue = ScaleQuantumToChar(GetPixelBlue(image,p));
+ q->rgbReserved = 0;
+ p+=GetPixelChannels(image);
+ q++;
+ }
+ proceed=SetImageProgress(image,CropImageTag,y,page.height);
+ if (proceed == MagickFalse)
+ break;
+ }
+ if (y < (ssize_t) page.height)
+ {
+ GlobalUnlock((HGLOBAL) bitmap_bitsH);
+ GlobalFree((HGLOBAL) bitmap_bitsH);
+ return((void *) NULL);
+ }
+ bitmap.bmBits=bitmap_bits;
+ bitmapH=CreateBitmapIndirect(&bitmap);
+ GlobalUnlock((HGLOBAL) bitmap_bitsH);
+ GlobalFree((HGLOBAL) bitmap_bitsH);
+ return((void *) bitmapH);
+}
+#endif
+\f
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% I m a g e T o H B i t m a p %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ImageToHBITMAP() creates a Windows HBITMAP from an image.
+%
+% The format of the ImageToHBITMAP method is:
+%
+% HBITMAP ImageToHBITMAP(Image *image,Exceptioninfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image to convert.
+%
+*/
+MagickExport void *ImageToHBITMAP(Image *image,ExceptionInfo *exception)
+{
+ BITMAP
+ bitmap;
+
+ HANDLE
+ bitmap_bitsH;
+
+ HBITMAP
+ bitmapH;
+
+ register ssize_t
+ x;
+
+ register const Quantum
+ *p;
+
+ register RGBQUAD
+ *q;
+
+ RGBQUAD
+ *bitmap_bits;
+
+ size_t
+ length;
+
+ ssize_t
+ y;
+
+ (void) memset(&bitmap,0,sizeof(bitmap));
+ bitmap.bmType=0;
+ bitmap.bmWidth=(LONG) image->columns;
+ bitmap.bmHeight=(LONG) image->rows;
+ bitmap.bmWidthBytes=4*bitmap.bmWidth;
+ bitmap.bmPlanes=1;
+ bitmap.bmBitsPixel=32;
+ bitmap.bmBits=NULL;
+ length=bitmap.bmWidthBytes*bitmap.bmHeight;
+ bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,length);
+ if (bitmap_bitsH == NULL)
+ {
+ char
+ *message;
+
+ message=GetExceptionMessage(errno);
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
+ message=DestroyString(message);
+ return(NULL);
+ }
+ bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
+ q=bitmap_bits;
+ if (bitmap.bmBits == NULL)
+ bitmap.bmBits=bitmap_bits;
+ (void) SetImageColorspace(image,sRGBColorspace,exception);
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
+ break;
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ q->rgbRed=ScaleQuantumToChar(GetPixelRed(image,p));
+ q->rgbGreen=ScaleQuantumToChar(GetPixelGreen(image,p));
+ q->rgbBlue=ScaleQuantumToChar(GetPixelBlue(image,p));
+ q->rgbReserved=0;
+ p+=GetPixelChannels(image);
+ q++;
+ }
+ }
+ bitmap.bmBits=bitmap_bits;
+ bitmapH=CreateBitmapIndirect(&bitmap);
+ if (bitmapH == NULL)
+ {
+ char
+ *message;
+
+ message=GetExceptionMessage(errno);
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
+ message=DestroyString(message);
+ }
+ GlobalUnlock((HGLOBAL) bitmap_bitsH);
+ GlobalFree((HGLOBAL) bitmap_bitsH);
+ return((void *) bitmapH);
+}
+#endif
#endif
% %
% %
% %
-% C r o p I m a g e T o H B i t m a p %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% CropImageToHBITMAP() extracts a specified region of the image and returns
-% it as a Windows HBITMAP. While the same functionality can be accomplished by
-% invoking CropImage() followed by ImageToHBITMAP(), this method is more
-% efficient since it copies pixels directly to the HBITMAP.
-%
-% The format of the CropImageToHBITMAP method is:
-%
-% HBITMAP CropImageToHBITMAP(Image* image,const RectangleInfo *geometry,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o image: the image.
-%
-% o geometry: Define the region of the image to crop with members
-% x, y, width, and height.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-MagickExport void *CropImageToHBITMAP(Image *image,
- const RectangleInfo *geometry,ExceptionInfo *exception)
-{
-#define CropImageTag "Crop/Image"
-
- BITMAP
- bitmap;
-
- HBITMAP
- bitmapH;
-
- HANDLE
- bitmap_bitsH;
-
- MagickBooleanType
- proceed;
-
- RectangleInfo
- page;
-
- register const Quantum
- *p;
-
- register RGBQUAD
- *q;
-
- RGBQUAD
- *bitmap_bits;
-
- ssize_t
- y;
-
- /*
- Check crop geometry.
- */
- assert(image != (const Image *) NULL);
- assert(image->signature == MagickCoreSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- assert(geometry != (const RectangleInfo *) NULL);
- assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickCoreSignature);
- if (((geometry->x+(ssize_t) geometry->width) < 0) ||
- ((geometry->y+(ssize_t) geometry->height) < 0) ||
- (geometry->x >= (ssize_t) image->columns) ||
- (geometry->y >= (ssize_t) image->rows))
- ThrowImageException(OptionError,"GeometryDoesNotContainImage");
- page=(*geometry);
- if ((page.x+(ssize_t) page.width) > (ssize_t) image->columns)
- page.width=image->columns-page.x;
- if ((page.y+(ssize_t) page.height) > (ssize_t) image->rows)
- page.height=image->rows-page.y;
- if (page.x < 0)
- {
- page.width+=page.x;
- page.x=0;
- }
- if (page.y < 0)
- {
- page.height+=page.y;
- page.y=0;
- }
-
- if ((page.width == 0) || (page.height == 0))
- ThrowImageException(OptionError,"GeometryDimensionsAreZero");
- /*
- Initialize crop image attributes.
- */
- bitmap.bmType = 0;
- bitmap.bmWidth = (LONG) page.width;
- bitmap.bmHeight = (LONG) page.height;
- bitmap.bmWidthBytes = bitmap.bmWidth * 4;
- bitmap.bmPlanes = 1;
- bitmap.bmBitsPixel = 32;
- bitmap.bmBits = NULL;
-
- bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,page.width*
- page.height*bitmap.bmBitsPixel);
- if (bitmap_bitsH == NULL)
- return(NULL);
- bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
- if ( bitmap.bmBits == NULL )
- bitmap.bmBits = bitmap_bits;
- if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
- SetImageColorspace(image,sRGBColorspace,exception);
- /*
- Extract crop image.
- */
- q=bitmap_bits;
- for (y=0; y < (ssize_t) page.height; y++)
- {
- register ssize_t
- x;
-
- p=GetVirtualPixels(image,page.x,page.y+y,page.width,1,exception);
- if (p == (const Quantum *) NULL)
- break;
-
- /* Transfer pixels, scaling to Quantum */
- for( x=(ssize_t) page.width ; x> 0 ; x-- )
- {
- q->rgbRed = ScaleQuantumToChar(GetPixelRed(image,p));
- q->rgbGreen = ScaleQuantumToChar(GetPixelGreen(image,p));
- q->rgbBlue = ScaleQuantumToChar(GetPixelBlue(image,p));
- q->rgbReserved = 0;
- p+=GetPixelChannels(image);
- q++;
- }
- proceed=SetImageProgress(image,CropImageTag,y,page.height);
- if (proceed == MagickFalse)
- break;
- }
- if (y < (ssize_t) page.height)
- {
- GlobalUnlock((HGLOBAL) bitmap_bitsH);
- GlobalFree((HGLOBAL) bitmap_bitsH);
- return((void *) NULL);
- }
- bitmap.bmBits=bitmap_bits;
- bitmapH=CreateBitmapIndirect(&bitmap);
- GlobalUnlock((HGLOBAL) bitmap_bitsH);
- GlobalFree((HGLOBAL) bitmap_bitsH);
- return((void *) bitmapH);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
% I s M a g i c k C o n f l i c t %
% %
% %
return(MagickTrue);
}
\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-% I m a g e T o H B i t m a p %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% ImageToHBITMAP() creates a Windows HBITMAP from an image.
-%
-% The format of the ImageToHBITMAP method is:
-%
-% HBITMAP ImageToHBITMAP(Image *image,Exceptioninfo *exception)
-%
-% A description of each parameter follows:
-%
-% o image: the image to convert.
-%
-*/
-MagickExport void *ImageToHBITMAP(Image *image,ExceptionInfo *exception)
-{
- BITMAP
- bitmap;
-
- HANDLE
- bitmap_bitsH;
-
- HBITMAP
- bitmapH;
-
- register ssize_t
- x;
-
- register const Quantum
- *p;
-
- register RGBQUAD
- *q;
-
- RGBQUAD
- *bitmap_bits;
-
- size_t
- length;
-
- ssize_t
- y;
-
- (void) memset(&bitmap,0,sizeof(bitmap));
- bitmap.bmType=0;
- bitmap.bmWidth=(LONG) image->columns;
- bitmap.bmHeight=(LONG) image->rows;
- bitmap.bmWidthBytes=4*bitmap.bmWidth;
- bitmap.bmPlanes=1;
- bitmap.bmBitsPixel=32;
- bitmap.bmBits=NULL;
- length=bitmap.bmWidthBytes*bitmap.bmHeight;
- bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,length);
- if (bitmap_bitsH == NULL)
- {
- char
- *message;
-
- message=GetExceptionMessage(errno);
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
- message=DestroyString(message);
- return(NULL);
- }
- bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
- q=bitmap_bits;
- if (bitmap.bmBits == NULL)
- bitmap.bmBits=bitmap_bits;
- (void) SetImageColorspace(image,sRGBColorspace,exception);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,exception);
- if (p == (const Quantum *) NULL)
- break;
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- q->rgbRed=ScaleQuantumToChar(GetPixelRed(image,p));
- q->rgbGreen=ScaleQuantumToChar(GetPixelGreen(image,p));
- q->rgbBlue=ScaleQuantumToChar(GetPixelBlue(image,p));
- q->rgbReserved=0;
- p+=GetPixelChannels(image);
- q++;
- }
- }
- bitmap.bmBits=bitmap_bits;
- bitmapH=CreateBitmapIndirect(&bitmap);
- if (bitmapH == NULL)
- {
- char
- *message;
-
- message=GetExceptionMessage(errno);
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
- message=DestroyString(message);
- }
- GlobalUnlock((HGLOBAL) bitmap_bitsH);
- GlobalFree((HGLOBAL) bitmap_bitsH);
- return((void *) bitmapH);
-}
-\f
#endif