MagickCore 7.1.2-37
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
decorate.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% DDDD EEEEE CCCC OOO RRRR AAA TTTTT EEEEE %
7% D D E C O O R R A A T E %
8% D D EEE C O O RRRR AAAAA T EEE %
9% D D E C O O R R A A T E %
10% DDDD EEEEE CCCC OOO R R A A T EEEEE %
11% %
12% %
13% MagickCore Image Decoration Methods %
14% %
15% Software Design %
16% Cristy %
17% July 1992 %
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/license/ %
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#include "MagickCore/cache-view.h"
45#include "MagickCore/color-private.h"
46#include "MagickCore/colorspace-private.h"
47#include "MagickCore/composite.h"
48#include "MagickCore/decorate.h"
49#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/image.h"
52#include "MagickCore/memory_.h"
53#include "MagickCore/monitor.h"
54#include "MagickCore/monitor-private.h"
55#include "MagickCore/pixel-accessor.h"
56#include "MagickCore/quantum.h"
57#include "MagickCore/quantum-private.h"
58#include "MagickCore/resource_.h"
59#include "MagickCore/thread-private.h"
60#include "MagickCore/transform.h"
61␌
62/*
63 Define declarations.
64*/
65#define AccentuateModulate ScaleCharToQuantum(80)
66#define HighlightModulate ScaleCharToQuantum(125)
67#define ShadowModulate ScaleCharToQuantum(135)
68#define DepthModulate ScaleCharToQuantum(185)
69#define TroughModulate ScaleCharToQuantum(110)
70␌
71/*
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
76% B o r d e r I m a g e %
77% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% BorderImage() surrounds the image with a border of the color defined by
83% the bordercolor member of the image structure. The width and height
84% of the border are defined by the corresponding members of the border_info
85% structure.
86%
87% The format of the BorderImage method is:
88%
89% Image *BorderImage(const Image *image,const RectangleInfo *border_info,
90% const CompositeOperator compose,ExceptionInfo *exception)
91%
92% A description of each parameter follows:
93%
94% o image: the image.
95%
96% o border_info: define the width and height of the border.
97%
98% o compose: the composite operator.
99%
100% o exception: return any errors or warnings in this structure.
101%
102*/
103MagickExport Image *BorderImage(const Image *image,
104 const RectangleInfo *border_info,const CompositeOperator compose,
105 ExceptionInfo *exception)
106{
107 Image
108 *border_image,
109 *clone_image;
110
111 FrameInfo
112 frame_info;
113
114 assert(image != (const Image *) NULL);
115 assert(image->signature == MagickCoreSignature);
116 assert(border_info != (RectangleInfo *) NULL);
117 if (IsEventLogging() != MagickFalse)
118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
119 frame_info.width=image->columns+(border_info->width << 1);
120 frame_info.height=image->rows+(border_info->height << 1);
121 frame_info.x=(ssize_t) border_info->width;
122 frame_info.y=(ssize_t) border_info->height;
123 frame_info.inner_bevel=0;
124 frame_info.outer_bevel=0;
125 clone_image=CloneImage(image,0,0,MagickTrue,exception);
126 if (clone_image == (Image *) NULL)
127 return((Image *) NULL);
128 clone_image->matte_color=image->border_color;
129 border_image=FrameImage(clone_image,&frame_info,compose,exception);
130 clone_image=DestroyImage(clone_image);
131 if (border_image != (Image *) NULL)
132 border_image->matte_color=image->matte_color;
133 return(border_image);
134}
135␌
136/*
137%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138% %
139% %
140% %
141% F r a m e I m a g e %
142% %
143% %
144% %
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146%
147% FrameImage() adds a simulated three-dimensional border around the image.
148% The color of the border is defined by the matte_color member of image.
149% Members width and height of frame_info specify the border width of the
150% vertical and horizontal sides of the frame. Members inner and outer
151% indicate the width of the inner and outer shadows of the frame.
152%
153% The format of the FrameImage method is:
154%
155% Image *FrameImage(const Image *image,const FrameInfo *frame_info,
156% const CompositeOperator compose,ExceptionInfo *exception)
157%
158% A description of each parameter follows:
159%
160% o image: the image.
161%
162% o frame_info: Define the width and height of the frame and its bevels.
163%
164% o compose: the composite operator.
165%
166% o exception: return any errors or warnings in this structure.
167%
168*/
169MagickExport Image *FrameImage(const Image *image,const FrameInfo *frame_info,
170 const CompositeOperator compose,ExceptionInfo *exception)
171{
172#define FrameImageTag "Frame/Image"
173
174 CacheView
175 *image_view,
176 *frame_view;
177
178 Image
179 *frame_image;
180
181 MagickBooleanType
182 status;
183
184 MagickOffsetType
185 progress;
186
187 PixelInfo
188 accentuate,
189 highlight,
190 matte,
191 shadow,
192 trough;
193
194 size_t
195 bevel_width,
196 height;
197
198 ssize_t
199 x_offset,
200 y,
201 y_offset;
202
203 /*
204 Check frame geometry.
205 */
206 assert(image != (Image *) NULL);
207 assert(image->signature == MagickCoreSignature);
208 assert(frame_info != (FrameInfo *) NULL);
209 if (IsEventLogging() != MagickFalse)
210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
211 if ((frame_info->outer_bevel < 0) || (frame_info->inner_bevel < 0) ||
212 (frame_info->x < 0) || (frame_info->y < 0))
213 ThrowImageException(OptionError,"FrameIsLessThanImageSize");
214 bevel_width=(size_t) frame_info->outer_bevel+(size_t) frame_info->inner_bevel;
215 if (((size_t) frame_info->x < bevel_width) ||
216 ((size_t) frame_info->y < bevel_width) ||
217 (frame_info->width < image->columns) ||
218 (frame_info->height < image->rows) ||
219 ((frame_info->width-image->columns) < ((size_t) frame_info->x+bevel_width)) ||
220 ((frame_info->height-image->rows) < ((size_t) frame_info->y+bevel_width)))
221 ThrowImageException(OptionError,"FrameIsLessThanImageSize");
222 /*
223 Initialize framed image attributes.
224 */
225 frame_image=CloneImage(image,frame_info->width,frame_info->height,MagickTrue,
226 exception);
227 if (frame_image == (Image *) NULL)
228 return((Image *) NULL);
229 if (SetImageStorageClass(frame_image,DirectClass,exception) == MagickFalse)
230 {
231 frame_image=DestroyImage(frame_image);
232 return((Image *) NULL);
233 }
234 if ((IsPixelInfoGray(&frame_image->border_color) == MagickFalse) &&
235 (IsGrayColorspace(frame_image->colorspace) != MagickFalse))
236 (void) SetImageColorspace(frame_image,sRGBColorspace,exception);
237 if ((frame_image->matte_color.alpha_trait != UndefinedPixelTrait) &&
238 (frame_image->alpha_trait == UndefinedPixelTrait))
239 (void) SetImageAlpha(frame_image,OpaqueAlpha,exception);
240 frame_image->page=image->page;
241 if ((image->page.width != 0) && (image->page.height != 0))
242 {
243 frame_image->page.width+=frame_image->columns-image->columns;
244 frame_image->page.height+=frame_image->rows-image->rows;
245 }
246 /*
247 Initialize 3D effects color.
248 */
249 matte=image->matte_color;
250 accentuate=matte;
251 accentuate.red=(QuantumScale*(((double) QuantumRange-(double)
252 AccentuateModulate)*matte.red+((double) QuantumRange*(double)
253 AccentuateModulate)));
254 accentuate.green=(QuantumScale*(((double) QuantumRange-(double)
255 AccentuateModulate)*matte.green+((double) QuantumRange*(double)
256 AccentuateModulate)));
257 accentuate.blue=(QuantumScale*(((double) QuantumRange-(double)
258 AccentuateModulate)*matte.blue+((double) QuantumRange*(double)
259 AccentuateModulate)));
260 accentuate.black=(QuantumScale*(((double) QuantumRange-(double)
261 AccentuateModulate)*matte.black+((double) QuantumRange*(double)
262 AccentuateModulate)));
263 accentuate.alpha=matte.alpha;
264 highlight=matte;
265 highlight.red=(QuantumScale*(((double) QuantumRange-(double)
266 HighlightModulate)*matte.red+((double) QuantumRange*(double)
267 HighlightModulate)));
268 highlight.green=(QuantumScale*(((double) QuantumRange-(double)
269 HighlightModulate)*matte.green+((double) QuantumRange*(double)
270 HighlightModulate)));
271 highlight.blue=(QuantumScale*(((double) QuantumRange-(double)
272 HighlightModulate)*matte.blue+((double) QuantumRange*(double)
273 HighlightModulate)));
274 highlight.black=(QuantumScale*(((double) QuantumRange-(double)
275 HighlightModulate)*matte.black+((double) QuantumRange*(double)
276 HighlightModulate)));
277 highlight.alpha=matte.alpha;
278 shadow=matte;
279 shadow.red=QuantumScale*matte.red*(double) ShadowModulate;
280 shadow.green=QuantumScale*matte.green*(double) ShadowModulate;
281 shadow.blue=QuantumScale*matte.blue*(double) ShadowModulate;
282 shadow.black=QuantumScale*matte.black*(double) ShadowModulate;
283 shadow.alpha=matte.alpha;
284 trough=matte;
285 trough.red=QuantumScale*matte.red*(double) TroughModulate;
286 trough.green=QuantumScale*matte.green*(double) TroughModulate;
287 trough.blue=QuantumScale*matte.blue*(double) TroughModulate;
288 trough.black=QuantumScale*matte.black*(double) TroughModulate;
289 trough.alpha=matte.alpha;
290 status=MagickTrue;
291 progress=0;
292 image_view=AcquireVirtualCacheView(image,exception);
293 frame_view=AcquireAuthenticCacheView(frame_image,exception);
294 height=(size_t) (frame_info->outer_bevel+(frame_info->y-(ssize_t)
295 bevel_width)+frame_info->inner_bevel);
296 if (height != 0)
297 {
298 Quantum
299 *magick_restrict q;
300
301 ssize_t
302 x;
303
304 size_t
305 width;
306
307 /*
308 Draw top of ornamental border.
309 */
310 q=QueueCacheViewAuthenticPixels(frame_view,0,0,frame_image->columns,
311 height,exception);
312 if (q != (Quantum *) NULL)
313 {
314 /*
315 Draw top of ornamental border.
316 */
317 for (y=0; y < (ssize_t) frame_info->outer_bevel; y++)
318 {
319 for (x=0; x < ((ssize_t) frame_image->columns-y); x++)
320 {
321 if (x < y)
322 SetPixelViaPixelInfo(frame_image,&highlight,q);
323 else
324 SetPixelViaPixelInfo(frame_image,&accentuate,q);
325 q+=(ptrdiff_t) GetPixelChannels(frame_image);
326 }
327 for ( ; x < (ssize_t) frame_image->columns; x++)
328 {
329 SetPixelViaPixelInfo(frame_image,&shadow,q);
330 q+=(ptrdiff_t) GetPixelChannels(frame_image);
331 }
332 }
333 for (y=0; y < (frame_info->y-(ssize_t) bevel_width); y++)
334 {
335 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
336 {
337 SetPixelViaPixelInfo(frame_image,&highlight,q);
338 q+=(ptrdiff_t) GetPixelChannels(frame_image);
339 }
340 width=frame_image->columns-2*(size_t) frame_info->outer_bevel;
341 for (x=0; x < (ssize_t) width; x++)
342 {
343 SetPixelViaPixelInfo(frame_image,&matte,q);
344 q+=(ptrdiff_t) GetPixelChannels(frame_image);
345 }
346 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
347 {
348 SetPixelViaPixelInfo(frame_image,&shadow,q);
349 q+=(ptrdiff_t) GetPixelChannels(frame_image);
350 }
351 }
352 for (y=0; y < (ssize_t) frame_info->inner_bevel; y++)
353 {
354 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
355 {
356 SetPixelViaPixelInfo(frame_image,&highlight,q);
357 q+=(ptrdiff_t) GetPixelChannels(frame_image);
358 }
359 for (x=0; x < (frame_info->x-(ssize_t) bevel_width); x++)
360 {
361 SetPixelViaPixelInfo(frame_image,&matte,q);
362 q+=(ptrdiff_t) GetPixelChannels(frame_image);
363 }
364 width=image->columns+((size_t) frame_info->inner_bevel << 1)-
365 (size_t) y;
366 for (x=0; x < (ssize_t) width; x++)
367 {
368 if (x < y)
369 SetPixelViaPixelInfo(frame_image,&shadow,q);
370 else
371 SetPixelViaPixelInfo(frame_image,&trough,q);
372 q+=(ptrdiff_t) GetPixelChannels(frame_image);
373 }
374 for ( ; x < ((ssize_t) image->columns+2*frame_info->inner_bevel); x++)
375 {
376 SetPixelViaPixelInfo(frame_image,&highlight,q);
377 q+=(ptrdiff_t) GetPixelChannels(frame_image);
378 }
379 width=frame_info->width-(size_t) frame_info->x-
380 image->columns-bevel_width;
381 for (x=0; x < (ssize_t) width; x++)
382 {
383 SetPixelViaPixelInfo(frame_image,&matte,q);
384 q+=(ptrdiff_t) GetPixelChannels(frame_image);
385 }
386 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
387 {
388 SetPixelViaPixelInfo(frame_image,&shadow,q);
389 q+=(ptrdiff_t) GetPixelChannels(frame_image);
390 }
391 }
392 (void) SyncCacheViewAuthenticPixels(frame_view,exception);
393 }
394 }
395 /*
396 Draw sides of ornamental border.
397 */
398#if defined(MAGICKCORE_OPENMP_SUPPORT)
399 #pragma omp parallel for schedule(static) shared(progress,status) \
400 magick_number_threads(image,frame_image,image->rows,1)
401#endif
402 for (y=0; y < (ssize_t) image->rows; y++)
403 {
404 ssize_t
405 x;
406
407 Quantum
408 *magick_restrict q;
409
410 size_t
411 width;
412
413 /*
414 Initialize scanline with matte color.
415 */
416 if (status == MagickFalse)
417 continue;
418 q=QueueCacheViewAuthenticPixels(frame_view,0,frame_info->y+y,
419 frame_image->columns,1,exception);
420 if (q == (Quantum *) NULL)
421 {
422 status=MagickFalse;
423 continue;
424 }
425 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
426 {
427 SetPixelViaPixelInfo(frame_image,&highlight,q);
428 q+=(ptrdiff_t) GetPixelChannels(frame_image);
429 }
430 for (x=0; x < (frame_info->x-(ssize_t) bevel_width); x++)
431 {
432 SetPixelViaPixelInfo(frame_image,&matte,q);
433 q+=(ptrdiff_t) GetPixelChannels(frame_image);
434 }
435 for (x=0; x < (ssize_t) frame_info->inner_bevel; x++)
436 {
437 SetPixelViaPixelInfo(frame_image,&shadow,q);
438 q+=(ptrdiff_t) GetPixelChannels(frame_image);
439 }
440 /*
441 Set frame interior pixels.
442 */
443 for (x=0; x < (ssize_t) image->columns; x++)
444 {
445 SetPixelViaPixelInfo(frame_image,&frame_image->border_color,q);
446 q+=(ptrdiff_t) GetPixelChannels(frame_image);
447 }
448 for (x=0; x < (ssize_t) frame_info->inner_bevel; x++)
449 {
450 SetPixelViaPixelInfo(frame_image,&highlight,q);
451 q+=(ptrdiff_t) GetPixelChannels(frame_image);
452 }
453 width=frame_info->width-(size_t) frame_info->x-image->columns-bevel_width;
454 for (x=0; x < (ssize_t) width; x++)
455 {
456 SetPixelViaPixelInfo(frame_image,&matte,q);
457 q+=(ptrdiff_t) GetPixelChannels(frame_image);
458 }
459 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
460 {
461 SetPixelViaPixelInfo(frame_image,&shadow,q);
462 q+=(ptrdiff_t) GetPixelChannels(frame_image);
463 }
464 if (SyncCacheViewAuthenticPixels(frame_view,exception) == MagickFalse)
465 status=MagickFalse;
466 if (image->progress_monitor != (MagickProgressMonitor) NULL)
467 {
468 MagickBooleanType
469 proceed;
470
471#if defined(MAGICKCORE_OPENMP_SUPPORT)
472 #pragma omp atomic
473#endif
474 progress++;
475 proceed=SetImageProgress(image,FrameImageTag,progress,image->rows);
476 if (proceed == MagickFalse)
477 status=MagickFalse;
478 }
479 }
480 height=(size_t) (frame_info->inner_bevel+(ssize_t) frame_info->height-
481 frame_info->y-(ssize_t) image->rows-(ssize_t) bevel_width+
482 frame_info->outer_bevel);
483 if (height != 0)
484 {
485 size_t
486 width;
487
488 ssize_t
489 x;
490
491 Quantum
492 *magick_restrict q;
493
494 /*
495 Draw bottom of ornamental border.
496 */
497 q=QueueCacheViewAuthenticPixels(frame_view,0,(ssize_t) (frame_image->rows-
498 height),frame_image->columns,height,exception);
499 if (q != (Quantum *) NULL)
500 {
501 /*
502 Draw bottom of ornamental border.
503 */
504 for (y=frame_info->inner_bevel-1; y >= 0; y--)
505 {
506 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
507 {
508 SetPixelViaPixelInfo(frame_image,&highlight,q);
509 q+=(ptrdiff_t) GetPixelChannels(frame_image);
510 }
511 for (x=0; x < (frame_info->x-(ssize_t) bevel_width); x++)
512 {
513 SetPixelViaPixelInfo(frame_image,&matte,q);
514 q+=(ptrdiff_t) GetPixelChannels(frame_image);
515 }
516 for (x=0; x < y; x++)
517 {
518 SetPixelViaPixelInfo(frame_image,&shadow,q);
519 q+=(ptrdiff_t) GetPixelChannels(frame_image);
520 }
521 for ( ; x < ((ssize_t) image->columns+2*frame_info->inner_bevel); x++)
522 {
523 if (x >= ((ssize_t) image->columns+2*frame_info->inner_bevel-y))
524 SetPixelViaPixelInfo(frame_image,&highlight,q);
525 else
526 SetPixelViaPixelInfo(frame_image,&accentuate,q);
527 q+=(ptrdiff_t) GetPixelChannels(frame_image);
528 }
529 width=(size_t) ((ssize_t) frame_info->width-frame_info->x-
530 (ssize_t) image->columns-(ssize_t) bevel_width);
531 for (x=0; x < (ssize_t) width; x++)
532 {
533 SetPixelViaPixelInfo(frame_image,&matte,q);
534 q+=(ptrdiff_t) GetPixelChannels(frame_image);
535 }
536 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
537 {
538 SetPixelViaPixelInfo(frame_image,&shadow,q);
539 q+=(ptrdiff_t) GetPixelChannels(frame_image);
540 }
541 }
542 height=(size_t) ((ssize_t) frame_info->height-frame_info->y-(ssize_t)
543 image->rows-(ssize_t) bevel_width);
544 for (y=0; y < (ssize_t) height; y++)
545 {
546 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
547 {
548 SetPixelViaPixelInfo(frame_image,&highlight,q);
549 q+=(ptrdiff_t) GetPixelChannels(frame_image);
550 }
551 width=(size_t) ((ssize_t) frame_image->columns-2*(ssize_t)
552 frame_info->outer_bevel);
553 for (x=0; x < (ssize_t) width; x++)
554 {
555 SetPixelViaPixelInfo(frame_image,&matte,q);
556 q+=(ptrdiff_t) GetPixelChannels(frame_image);
557 }
558 for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
559 {
560 SetPixelViaPixelInfo(frame_image,&shadow,q);
561 q+=(ptrdiff_t) GetPixelChannels(frame_image);
562 }
563 }
564 for (y=frame_info->outer_bevel-1; y >= 0; y--)
565 {
566 for (x=0; x < y; x++)
567 {
568 SetPixelViaPixelInfo(frame_image,&highlight,q);
569 q+=(ptrdiff_t) GetPixelChannels(frame_image);
570 }
571 for ( ; x < (ssize_t) frame_image->columns; x++)
572 {
573 if (x >= ((ssize_t) frame_image->columns-y))
574 SetPixelViaPixelInfo(frame_image,&shadow,q);
575 else
576 SetPixelViaPixelInfo(frame_image,&trough,q);
577 q+=(ptrdiff_t) GetPixelChannels(frame_image);
578 }
579 }
580 (void) SyncCacheViewAuthenticPixels(frame_view,exception);
581 }
582 }
583 frame_view=DestroyCacheView(frame_view);
584 image_view=DestroyCacheView(image_view);
585 x_offset=frame_info->outer_bevel+(frame_info->x-(ssize_t) bevel_width)+
586 frame_info->inner_bevel;
587 y_offset=frame_info->outer_bevel+(frame_info->y-(ssize_t) bevel_width)+
588 frame_info->inner_bevel;
589 if (status != MagickFalse)
590 status=CompositeImage(frame_image,image,compose,MagickTrue,x_offset,
591 y_offset,exception);
592 if (status == MagickFalse)
593 frame_image=DestroyImage(frame_image);
594 return(frame_image);
595}
596␌
597/*
598%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599% %
600% %
601% %
602% R a i s e I m a g e %
603% %
604% %
605% %
606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607%
608% RaiseImage() creates a simulated three-dimensional button-like effect
609% by lightening and darkening the edges of the image. Members width and
610% height of raise_info define the width of the vertical and horizontal
611% edge of the effect.
612%
613% The format of the RaiseImage method is:
614%
615% MagickBooleanType RaiseImage(const Image *image,
616% const RectangleInfo *raise_info,const MagickBooleanType raise,
617% ExceptionInfo *exception)
618%
619% A description of each parameter follows:
620%
621% o image: the image.
622%
623% o raise_info: Define the width and height of the raise area.
624%
625% o raise: A value other than zero creates a 3-D raise effect,
626% otherwise it has a lowered effect.
627%
628% o exception: return any errors or warnings in this structure.
629%
630*/
631MagickExport MagickBooleanType RaiseImage(Image *image,
632 const RectangleInfo *raise_info,const MagickBooleanType raise,
633 ExceptionInfo *exception)
634{
635#define AccentuateFactor ScaleCharToQuantum(135)
636#define HighlightFactor ScaleCharToQuantum(190)
637#define ShadowFactor ScaleCharToQuantum(190)
638#define RaiseImageTag "Raise/Image"
639#define TroughFactor ScaleCharToQuantum(135)
640
641 CacheView
642 *image_view;
643
644 MagickBooleanType
645 status;
646
647 MagickOffsetType
648 progress;
649
650 Quantum
651 foreground,
652 background;
653
654 ssize_t
655 y;
656
657 assert(image != (Image *) NULL);
658 assert(image->signature == MagickCoreSignature);
659 assert(raise_info != (RectangleInfo *) NULL);
660 if (IsEventLogging() != MagickFalse)
661 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
662 if ((image->columns <= (raise_info->width << 1)) ||
663 (image->rows <= (raise_info->height << 1)))
664 ThrowBinaryException(OptionError,"ImageSizeMustExceedBevelWidth",
665 image->filename);
666 foreground=QuantumRange;
667 background=(Quantum) 0;
668 if (raise == MagickFalse)
669 {
670 foreground=(Quantum) 0;
671 background=QuantumRange;
672 }
673 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
674 return(MagickFalse);
675 /*
676 Raise image.
677 */
678 status=MagickTrue;
679 progress=0;
680 image_view=AcquireAuthenticCacheView(image,exception);
681#if defined(MAGICKCORE_OPENMP_SUPPORT)
682 #pragma omp parallel for schedule(static) shared(progress,status) \
683 magick_number_threads(image,image,raise_info->height,1)
684#endif
685 for (y=0; y < (ssize_t) raise_info->height; y++)
686 {
687 ssize_t
688 i,
689 x;
690
691 Quantum
692 *magick_restrict q;
693
694 if (status == MagickFalse)
695 continue;
696 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
697 if (q == (Quantum *) NULL)
698 {
699 status=MagickFalse;
700 continue;
701 }
702 for (x=0; x < y; x++)
703 {
704 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
705 {
706 PixelChannel channel = GetPixelChannelChannel(image,i);
707 PixelTrait traits = GetPixelChannelTraits(image,channel);
708 if ((traits & UpdatePixelTrait) == 0)
709 continue;
710 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double)
711 HighlightFactor+(double) foreground*((double) QuantumRange-(double)
712 HighlightFactor)));
713 }
714 q+=(ptrdiff_t) GetPixelChannels(image);
715 }
716 for ( ; x < ((ssize_t) image->columns-y); x++)
717 {
718 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
719 {
720 PixelChannel channel = GetPixelChannelChannel(image,i);
721 PixelTrait traits = GetPixelChannelTraits(image,channel);
722 if ((traits & UpdatePixelTrait) == 0)
723 continue;
724 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double)
725 AccentuateFactor+(double) foreground*((double) QuantumRange-(double)
726 AccentuateFactor)));
727 }
728 q+=(ptrdiff_t) GetPixelChannels(image);
729 }
730 for ( ; x < (ssize_t) image->columns; x++)
731 {
732 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
733 {
734 PixelChannel channel = GetPixelChannelChannel(image,i);
735 PixelTrait traits = GetPixelChannelTraits(image,channel);
736 if ((traits & UpdatePixelTrait) == 0)
737 continue;
738 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double) ShadowFactor+
739 (double) background*((double) QuantumRange-(double) ShadowFactor)));
740 }
741 q+=(ptrdiff_t) GetPixelChannels(image);
742 }
743 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
744 status=MagickFalse;
745 if (image->progress_monitor != (MagickProgressMonitor) NULL)
746 {
747 MagickBooleanType
748 proceed;
749
750#if defined(MAGICKCORE_OPENMP_SUPPORT)
751 #pragma omp atomic
752#endif
753 progress++;
754 proceed=SetImageProgress(image,RaiseImageTag,progress,image->rows);
755 if (proceed == MagickFalse)
756 status=MagickFalse;
757 }
758 }
759#if defined(MAGICKCORE_OPENMP_SUPPORT)
760 #pragma omp parallel for schedule(static) shared(progress,status) \
761 magick_number_threads(image,image,image->rows-2*raise_info->height,1)
762#endif
763 for (y=(ssize_t) raise_info->height; y < (ssize_t) (image->rows-raise_info->height); y++)
764 {
765 ssize_t
766 i,
767 x;
768
769 Quantum
770 *magick_restrict q;
771
772 if (status == MagickFalse)
773 continue;
774 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
775 if (q == (Quantum *) NULL)
776 {
777 status=MagickFalse;
778 continue;
779 }
780 for (x=0; x < (ssize_t) raise_info->width; x++)
781 {
782 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
783 {
784 PixelChannel channel = GetPixelChannelChannel(image,i);
785 PixelTrait traits = GetPixelChannelTraits(image,channel);
786 if ((traits & UpdatePixelTrait) == 0)
787 continue;
788 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double)
789 HighlightFactor+(double) foreground*((double) QuantumRange-(double)
790 HighlightFactor)));
791 }
792 q+=(ptrdiff_t) GetPixelChannels(image);
793 }
794 for ( ; x < (ssize_t) (image->columns-raise_info->width); x++)
795 q+=(ptrdiff_t) GetPixelChannels(image);
796 for ( ; x < (ssize_t) image->columns; x++)
797 {
798 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
799 {
800 PixelChannel channel = GetPixelChannelChannel(image,i);
801 PixelTrait traits = GetPixelChannelTraits(image,channel);
802 if ((traits & UpdatePixelTrait) == 0)
803 continue;
804 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double) ShadowFactor+
805 (double) background*((double) QuantumRange-(double) ShadowFactor)));
806 }
807 q+=(ptrdiff_t) GetPixelChannels(image);
808 }
809 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
810 status=MagickFalse;
811 if (image->progress_monitor != (MagickProgressMonitor) NULL)
812 {
813 MagickBooleanType
814 proceed;
815
816#if defined(MAGICKCORE_OPENMP_SUPPORT)
817 #pragma omp atomic
818#endif
819 progress++;
820 proceed=SetImageProgress(image,RaiseImageTag,progress,image->rows);
821 if (proceed == MagickFalse)
822 status=MagickFalse;
823 }
824 }
825#if defined(MAGICKCORE_OPENMP_SUPPORT)
826 #pragma omp parallel for schedule(static) shared(progress,status) \
827 magick_number_threads(image,image,image->rows-raise_info->height,1)
828#endif
829 for (y=(ssize_t) (image->rows-raise_info->height); y < (ssize_t) image->rows; y++)
830 {
831 ssize_t
832 i,
833 x;
834
835 Quantum
836 *magick_restrict q;
837
838 if (status == MagickFalse)
839 continue;
840 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
841 if (q == (Quantum *) NULL)
842 {
843 status=MagickFalse;
844 continue;
845 }
846 for (x=0; x < ((ssize_t) image->rows-y); x++)
847 {
848 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
849 {
850 PixelChannel channel = GetPixelChannelChannel(image,i);
851 PixelTrait traits = GetPixelChannelTraits(image,channel);
852 if ((traits & UpdatePixelTrait) == 0)
853 continue;
854 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double)
855 HighlightFactor+(double) foreground*((double) QuantumRange-
856 (double) HighlightFactor)));
857 }
858 q+=(ptrdiff_t) GetPixelChannels(image);
859 }
860 for ( ; x < ((ssize_t) image->columns-((ssize_t) image->rows-y)); x++)
861 {
862 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
863 {
864 PixelChannel channel = GetPixelChannelChannel(image,i);
865 PixelTrait traits = GetPixelChannelTraits(image,channel);
866 if ((traits & UpdatePixelTrait) == 0)
867 continue;
868 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double) TroughFactor+
869 (double) background*((double) QuantumRange-(double) TroughFactor)));
870 }
871 q+=(ptrdiff_t) GetPixelChannels(image);
872 }
873 for ( ; x < (ssize_t) image->columns; x++)
874 {
875 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
876 {
877 PixelChannel channel = GetPixelChannelChannel(image,i);
878 PixelTrait traits = GetPixelChannelTraits(image,channel);
879 if ((traits & UpdatePixelTrait) == 0)
880 continue;
881 q[i]=ClampToQuantum(QuantumScale*((double) q[i]*(double) ShadowFactor+
882 (double) background*((double) QuantumRange-(double) ShadowFactor)));
883 }
884 q+=(ptrdiff_t) GetPixelChannels(image);
885 }
886 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
887 status=MagickFalse;
888 if (image->progress_monitor != (MagickProgressMonitor) NULL)
889 {
890 MagickBooleanType
891 proceed;
892
893#if defined(MAGICKCORE_OPENMP_SUPPORT)
894 #pragma omp atomic
895#endif
896 progress++;
897 proceed=SetImageProgress(image,RaiseImageTag,progress,image->rows);
898 if (proceed == MagickFalse)
899 status=MagickFalse;
900 }
901 }
902 image_view=DestroyCacheView(image_view);
903 return(status);
904}