43#include "MagickCore/studio.h"
44#if defined(MAGICKCORE_WINGDI32_DELEGATE)
45# if defined(__CYGWIN__)
49# include "MagickCore/nt-base-private.h"
53#include "MagickCore/property.h"
54#include "MagickCore/blob.h"
55#include "MagickCore/blob-private.h"
56#include "MagickCore/cache.h"
57#include "MagickCore/cache-view.h"
58#include "MagickCore/client.h"
59#include "MagickCore/color.h"
60#include "MagickCore/color-private.h"
61#include "MagickCore/colormap.h"
62#include "MagickCore/colormap-private.h"
63#include "MagickCore/colorspace.h"
64#include "MagickCore/colorspace-private.h"
65#include "MagickCore/composite.h"
66#include "MagickCore/composite-private.h"
67#include "MagickCore/constitute.h"
68#include "MagickCore/draw.h"
69#include "MagickCore/draw-private.h"
70#include "MagickCore/effect.h"
71#include "MagickCore/enhance.h"
72#include "MagickCore/exception.h"
73#include "MagickCore/exception-private.h"
74#include "MagickCore/fx.h"
75#include "MagickCore/geometry.h"
76#include "MagickCore/identify.h"
77#include "MagickCore/image.h"
78#include "MagickCore/image-private.h"
79#include "MagickCore/list.h"
80#include "MagickCore/log.h"
81#include "MagickCore/memory_.h"
82#include "MagickCore/magick.h"
83#include "MagickCore/monitor.h"
84#include "MagickCore/monitor-private.h"
85#include "MagickCore/morphology.h"
86#include "MagickCore/nt-feature.h"
87#include "MagickCore/paint.h"
88#include "MagickCore/pixel.h"
89#include "MagickCore/pixel-accessor.h"
90#include "MagickCore/pixel-private.h"
91#include "MagickCore/quantize.h"
92#include "MagickCore/random_.h"
93#include "MagickCore/resource_.h"
94#include "MagickCore/semaphore.h"
95#include "MagickCore/segment.h"
96#include "MagickCore/splay-tree.h"
97#include "MagickCore/statistic.h"
98#include "MagickCore/string_.h"
99#include "MagickCore/threshold.h"
100#include "MagickCore/transform.h"
101#include "MagickCore/utility.h"
103#if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
128MagickExport MagickBooleanType GetMagickSeekableStream(
132 assert(magick_info->signature == MagickCoreSignature);
133 return(((magick_info->flags & CoderSeekableStreamFlag) == 0) ? MagickFalse :
137#if defined(MAGICKCORE_WINGDI32_DELEGATE)
169MagickExport
void *CropImageToHBITMAP(
Image *image,
172#define CropImageTag "Crop/Image"
204 assert(image != (
const Image *) NULL);
205 assert(image->signature == MagickCoreSignature);
206 if (IsEventLogging() != MagickFalse)
207 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
210 assert(exception->signature == MagickCoreSignature);
211 if (((geometry->x+(ssize_t) geometry->width) < 0) ||
212 ((geometry->y+(ssize_t) geometry->height) < 0) ||
213 (geometry->x >= (ssize_t) image->columns) ||
214 (geometry->y >= (ssize_t) image->rows))
215 ThrowImageException(OptionError,
"GeometryDoesNotContainImage");
217 if ((page.x+(ssize_t) page.width) > (ssize_t) image->columns)
218 page.width=image->columns-page.x;
219 if ((page.y+(ssize_t) page.height) > (ssize_t) image->rows)
220 page.height=image->rows-page.y;
232 if ((page.width == 0) || (page.height == 0))
233 ThrowImageException(OptionError,
"GeometryDimensionsAreZero");
238 bitmap.bmWidth = (LONG) page.width;
239 bitmap.bmHeight = (LONG) page.height;
240 bitmap.bmWidthBytes = bitmap.bmWidth * 4;
242 bitmap.bmBitsPixel = 32;
243 bitmap.bmBits = NULL;
245 bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,page.width*
246 page.height*bitmap.bmBitsPixel);
247 if (bitmap_bitsH == NULL)
249 bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
250 if ( bitmap.bmBits == NULL )
251 bitmap.bmBits = bitmap_bits;
252 if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
253 SetImageColorspace(image,sRGBColorspace,exception);
258 for (y=0; y < (ssize_t) page.height; y++)
263 p=GetVirtualPixels(image,page.x,page.y+y,page.width,1,exception);
264 if (p == (
const Quantum *) NULL)
268 for( x=(ssize_t) page.width ; x> 0 ; x-- )
270 q->rgbRed = ScaleQuantumToChar(GetPixelRed(image,p));
271 q->rgbGreen = ScaleQuantumToChar(GetPixelGreen(image,p));
272 q->rgbBlue = ScaleQuantumToChar(GetPixelBlue(image,p));
274 p+=GetPixelChannels(image);
277 proceed=SetImageProgress(image,CropImageTag,y,page.height);
278 if (proceed == MagickFalse)
281 if (y < (ssize_t) page.height)
283 GlobalUnlock((HGLOBAL) bitmap_bitsH);
284 GlobalFree((HGLOBAL) bitmap_bitsH);
285 return((
void *) NULL);
287 bitmap.bmBits=bitmap_bits;
288 bitmapH=CreateBitmapIndirect(&bitmap);
289 GlobalUnlock((HGLOBAL) bitmap_bitsH);
290 GlobalFree((HGLOBAL) bitmap_bitsH);
291 return((
void *) bitmapH);
295#if defined(MAGICKCORE_WINGDI32_DELEGATE)
347 (void) memset(&bitmap,0,
sizeof(bitmap));
349 bitmap.bmWidth=(LONG) image->columns;
350 bitmap.bmHeight=(LONG) image->rows;
351 bitmap.bmWidthBytes=4*bitmap.bmWidth;
353 bitmap.bmBitsPixel=32;
355 length=bitmap.bmWidthBytes*bitmap.bmHeight;
356 bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,length);
357 if (bitmap_bitsH == NULL)
362 message=GetExceptionMessage(errno);
363 (void) ThrowMagickException(exception,GetMagickModule(),
364 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",message);
365 message=DestroyString(message);
368 bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
370 if (bitmap.bmBits == NULL)
371 bitmap.bmBits=bitmap_bits;
372 (void) SetImageColorspace(image,sRGBColorspace,exception);
373 for (y=0; y < (ssize_t) image->rows; y++)
375 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
376 if (p == (
const Quantum *) NULL)
378 for (x=0; x < (ssize_t) image->columns; x++)
380 q->rgbRed=ScaleQuantumToChar(GetPixelRed(image,p));
381 q->rgbGreen=ScaleQuantumToChar(GetPixelGreen(image,p));
382 q->rgbBlue=ScaleQuantumToChar(GetPixelBlue(image,p));
384 p+=GetPixelChannels(image);
388 bitmap.bmBits=bitmap_bits;
389 bitmapH=CreateBitmapIndirect(&bitmap);
395 message=GetExceptionMessage(errno);
396 (void) ThrowMagickException(exception,GetMagickModule(),
397 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",message);
398 message=DestroyString(message);
400 GlobalUnlock((HGLOBAL) bitmap_bitsH);
401 GlobalFree((HGLOBAL) bitmap_bitsH);
402 return((
void *) bitmapH);
428MagickExport
void InitializePixelChannelMap(
Image *image)
431 *exception = AcquireExceptionInfo();
433 (void) ResetPixelChannelMap(image,exception);
434 exception=DestroyExceptionInfo(exception);