MagickCore  7.1.1-43
Convert, Edit, Or Compose Bitmap Images
deprecate.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % DDDD EEEEE PPPP RRRR EEEEE CCCC AAA TTTTT EEEEE %
7 % D D E P P R R E C A A T E %
8 % D D EEE PPPPP RRRR EEE C AAAAA T EEE %
9 % D D E P R R E C A A T E %
10 % DDDD EEEEE P R R EEEEE CCCC A A T EEEEE %
11 % %
12 % %
13 % MagickCore Deprecated Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % October 2002 %
18 % %
19 % %
20 % Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
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. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 
40 /*
41  Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
45 # if defined(__CYGWIN__)
46 # include <windows.h>
47 # else
48  /* All MinGW needs ... */
49 # include "MagickCore/nt-base-private.h"
50 # include <wingdi.h>
51 # endif
52 #endif
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"
102 
103 #if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
104 
105 /*
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % %
108 % %
109 % %
110 + G e t M a g i c k S e e k a b l e S t r e a m %
111 % %
112 % %
113 % %
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 %
116 % GetMagickSeekableStream() returns MagickTrue if the magick supports a
117 % seekable stream.
118 %
119 % The format of the GetMagickSeekableStream method is:
120 %
121 % MagickBooleanType GetMagickSeekableStream(const MagickInfo *magick_info)
122 %
123 % A description of each parameter follows:
124 %
125 % o magick_info: The magick info.
126 %
127 */
128 MagickExport MagickBooleanType GetMagickSeekableStream(
129  const MagickInfo *magick_info)
130 {
131  assert(magick_info != (MagickInfo *) NULL);
132  assert(magick_info->signature == MagickCoreSignature);
133  return(((magick_info->flags & CoderSeekableStreamFlag) == 0) ? MagickFalse :
134  MagickTrue);
135 }
136 
137 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
138 /*
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % %
141 % %
142 % %
143 % C r o p I m a g e T o H B i t m a p %
144 % %
145 % %
146 % %
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 %
149 % CropImageToHBITMAP() extracts a specified region of the image and returns
150 % it as a Windows HBITMAP. While the same functionality can be accomplished by
151 % invoking CropImage() followed by ImageToHBITMAP(), this method is more
152 % efficient since it copies pixels directly to the HBITMAP.
153 %
154 % The format of the CropImageToHBITMAP method is:
155 %
156 % HBITMAP CropImageToHBITMAP(Image* image,const RectangleInfo *geometry,
157 % ExceptionInfo *exception)
158 %
159 % A description of each parameter follows:
160 %
161 % o image: the image.
162 %
163 % o geometry: Define the region of the image to crop with members
164 % x, y, width, and height.
165 %
166 % o exception: return any errors or warnings in this structure.
167 %
168 */
169 MagickExport void *CropImageToHBITMAP(Image *image,
170  const RectangleInfo *geometry,ExceptionInfo *exception)
171 {
172 #define CropImageTag "Crop/Image"
173 
174  BITMAP
175  bitmap;
176 
177  HBITMAP
178  bitmapH;
179 
180  HANDLE
181  bitmap_bitsH;
182 
183  MagickBooleanType
184  proceed;
185 
187  page;
188 
189  const Quantum
190  *p;
191 
192  RGBQUAD
193  *q;
194 
195  RGBQUAD
196  *bitmap_bits;
197 
198  ssize_t
199  y;
200 
201  /*
202  Check crop geometry.
203  */
204  assert(image != (const Image *) NULL);
205  assert(image->signature == MagickCoreSignature);
206  if (IsEventLogging() != MagickFalse)
207  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
208  assert(geometry != (const RectangleInfo *) NULL);
209  assert(exception != (ExceptionInfo *) NULL);
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");
216  page=(*geometry);
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;
221  if (page.x < 0)
222  {
223  page.width+=page.x;
224  page.x=0;
225  }
226  if (page.y < 0)
227  {
228  page.height+=page.y;
229  page.y=0;
230  }
231 
232  if ((page.width == 0) || (page.height == 0))
233  ThrowImageException(OptionError,"GeometryDimensionsAreZero");
234  /*
235  Initialize crop image attributes.
236  */
237  bitmap.bmType = 0;
238  bitmap.bmWidth = (LONG) page.width;
239  bitmap.bmHeight = (LONG) page.height;
240  bitmap.bmWidthBytes = bitmap.bmWidth * 4;
241  bitmap.bmPlanes = 1;
242  bitmap.bmBitsPixel = 32;
243  bitmap.bmBits = NULL;
244 
245  bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,page.width*
246  page.height*bitmap.bmBitsPixel);
247  if (bitmap_bitsH == NULL)
248  return(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);
254  /*
255  Extract crop image.
256  */
257  q=bitmap_bits;
258  for (y=0; y < (ssize_t) page.height; y++)
259  {
260  ssize_t
261  x;
262 
263  p=GetVirtualPixels(image,page.x,page.y+y,page.width,1,exception);
264  if (p == (const Quantum *) NULL)
265  break;
266 
267  /* Transfer pixels, scaling to Quantum */
268  for( x=(ssize_t) page.width ; x> 0 ; x-- )
269  {
270  q->rgbRed = ScaleQuantumToChar(GetPixelRed(image,p));
271  q->rgbGreen = ScaleQuantumToChar(GetPixelGreen(image,p));
272  q->rgbBlue = ScaleQuantumToChar(GetPixelBlue(image,p));
273  q->rgbReserved = 0;
274  p+=(ptrdiff_t) GetPixelChannels(image);
275  q++;
276  }
277  proceed=SetImageProgress(image,CropImageTag,y,page.height);
278  if (proceed == MagickFalse)
279  break;
280  }
281  if (y < (ssize_t) page.height)
282  {
283  GlobalUnlock((HGLOBAL) bitmap_bitsH);
284  GlobalFree((HGLOBAL) bitmap_bitsH);
285  return((void *) NULL);
286  }
287  bitmap.bmBits=bitmap_bits;
288  bitmapH=CreateBitmapIndirect(&bitmap);
289  GlobalUnlock((HGLOBAL) bitmap_bitsH);
290  GlobalFree((HGLOBAL) bitmap_bitsH);
291  return((void *) bitmapH);
292 }
293 #endif
294 
295 #if defined(MAGICKCORE_WINGDI32_DELEGATE)
296 /*
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 % %
299 % %
300 % %
301 % I m a g e T o H B i t m a p %
302 % %
303 % %
304 % %
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 %
307 % ImageToHBITMAP() creates a Windows HBITMAP from an image.
308 %
309 % The format of the ImageToHBITMAP method is:
310 %
311 % HBITMAP ImageToHBITMAP(Image *image,Exceptioninfo *exception)
312 %
313 % A description of each parameter follows:
314 %
315 % o image: the image to convert.
316 %
317 */
318 MagickExport void *ImageToHBITMAP(Image *image,ExceptionInfo *exception)
319 {
320  BITMAP
321  bitmap;
322 
323  HANDLE
324  bitmap_bitsH;
325 
326  HBITMAP
327  bitmapH;
328 
329  ssize_t
330  x;
331 
332  const Quantum
333  *p;
334 
335  RGBQUAD
336  *q;
337 
338  RGBQUAD
339  *bitmap_bits;
340 
341  size_t
342  length;
343 
344  ssize_t
345  y;
346 
347  (void) memset(&bitmap,0,sizeof(bitmap));
348  bitmap.bmType=0;
349  bitmap.bmWidth=(LONG) image->columns;
350  bitmap.bmHeight=(LONG) image->rows;
351  bitmap.bmWidthBytes=4*bitmap.bmWidth;
352  bitmap.bmPlanes=1;
353  bitmap.bmBitsPixel=32;
354  bitmap.bmBits=NULL;
355  length=bitmap.bmWidthBytes*bitmap.bmHeight;
356  bitmap_bitsH=(HANDLE) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,length);
357  if (bitmap_bitsH == NULL)
358  {
359  char
360  *message;
361 
362  message=GetExceptionMessage(errno);
363  (void) ThrowMagickException(exception,GetMagickModule(),
364  ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
365  message=DestroyString(message);
366  return(NULL);
367  }
368  bitmap_bits=(RGBQUAD *) GlobalLock((HGLOBAL) bitmap_bitsH);
369  q=bitmap_bits;
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++)
374  {
375  p=GetVirtualPixels(image,0,y,image->columns,1,exception);
376  if (p == (const Quantum *) NULL)
377  break;
378  for (x=0; x < (ssize_t) image->columns; x++)
379  {
380  q->rgbRed=ScaleQuantumToChar(GetPixelRed(image,p));
381  q->rgbGreen=ScaleQuantumToChar(GetPixelGreen(image,p));
382  q->rgbBlue=ScaleQuantumToChar(GetPixelBlue(image,p));
383  q->rgbReserved=0;
384  p+=(ptrdiff_t) GetPixelChannels(image);
385  q++;
386  }
387  }
388  bitmap.bmBits=bitmap_bits;
389  bitmapH=CreateBitmapIndirect(&bitmap);
390  if (bitmapH == NULL)
391  {
392  char
393  *message;
394 
395  message=GetExceptionMessage(errno);
396  (void) ThrowMagickException(exception,GetMagickModule(),
397  ResourceLimitError,"MemoryAllocationFailed","`%s'",message);
398  message=DestroyString(message);
399  }
400  GlobalUnlock((HGLOBAL) bitmap_bitsH);
401  GlobalFree((HGLOBAL) bitmap_bitsH);
402  return((void *) bitmapH);
403 }
404 #endif
405 
406 /*
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 % %
409 % %
410 % %
411 + I n i t i a l i z e P i x e l C h a n n e l M a p %
412 % %
413 % %
414 % %
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 %
417 % InitializePixelChannelMap() defines the standard pixel component map.
418 %
419 % The format of the InitializePixelChannelMap() method is:
420 %
421 % void InitializePixelChannelMap(Image *image)
422 %
423 % A description of each parameter follows:
424 %
425 % o image: the image.
426 %
427 */
428 MagickExport void InitializePixelChannelMap(Image *image)
429 {
431  *exception = AcquireExceptionInfo();
432 
433  (void) ResetPixelChannelMap(image,exception);
434  exception=DestroyExceptionInfo(exception);
435 }
436 #endif
_RectangleInfo
Definition: geometry.h:129
_MagickInfo
Definition: magick.h:66
_Image
Definition: image.h:131
_ExceptionInfo
Definition: exception.h:101