]> granicus.if.org Git - imagemagick/blob - MagickCore/decorate.c
(no commit message)
[imagemagick] / MagickCore / 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-2014 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 %    http://www.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 \f
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 \f
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 \f
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 */
103 MagickExport 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 == MagickSignature);
116   if (image->debug != MagickFalse)
117     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
118   assert(border_info != (RectangleInfo *) NULL);
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 \f
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 */
169 MagickExport 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     interior,
191     matte,
192     shadow,
193     trough;
194
195   register ssize_t
196     x;
197
198   size_t
199     bevel_width,
200     height,
201     width;
202
203   ssize_t
204     y;
205
206   /*
207     Check frame geometry.
208   */
209   assert(image != (Image *) NULL);
210   assert(image->signature == MagickSignature);
211   if (image->debug != MagickFalse)
212     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
213   assert(frame_info != (FrameInfo *) NULL);
214   if ((frame_info->outer_bevel < 0) || (frame_info->inner_bevel < 0))
215     ThrowImageException(OptionError,"FrameIsLessThanImageSize");
216   bevel_width=(size_t) (frame_info->outer_bevel+frame_info->inner_bevel);
217   width=frame_info->width-frame_info->x-bevel_width;
218   height=frame_info->height-frame_info->y-bevel_width;
219   if ((width < image->columns) || (height < image->rows))
220     ThrowImageException(OptionError,"FrameIsLessThanImageSize");
221   /*
222     Initialize framed image attributes.
223   */
224   frame_image=CloneImage(image,frame_info->width,frame_info->height,MagickTrue,
225     exception);
226   if (frame_image == (Image *) NULL)
227     return((Image *) NULL);
228   if (SetImageStorageClass(frame_image,DirectClass,exception) == MagickFalse)
229     {
230       frame_image=DestroyImage(frame_image);
231       return((Image *) NULL);
232     }
233   if ((IsPixelInfoGray(&frame_image->border_color) == MagickFalse) &&
234       (IsGrayColorspace(frame_image->colorspace) != MagickFalse))
235     (void) SetImageColorspace(frame_image,sRGBColorspace,exception);
236   if ((frame_image->matte_color.alpha_trait == BlendPixelTrait) &&
237       (frame_image->alpha_trait != BlendPixelTrait))
238     (void) SetImageAlpha(frame_image,OpaqueAlpha,exception);
239   frame_image->page=image->page;
240   if ((image->page.width != 0) && (image->page.height != 0))
241     {
242       frame_image->page.width+=frame_image->columns-image->columns;
243       frame_image->page.height+=frame_image->rows-image->rows;
244     }
245   /*
246     Initialize 3D effects color.
247   */
248   interior=image->border_color;
249   matte=image->matte_color;
250   accentuate=matte;
251   accentuate.red=(double) (QuantumScale*((QuantumRange-
252     AccentuateModulate)*matte.red+(QuantumRange*AccentuateModulate)));
253   accentuate.green=(double) (QuantumScale*((QuantumRange-
254     AccentuateModulate)*matte.green+(QuantumRange*AccentuateModulate)));
255   accentuate.blue=(double) (QuantumScale*((QuantumRange-
256     AccentuateModulate)*matte.blue+(QuantumRange*AccentuateModulate)));
257   accentuate.black=(double) (QuantumScale*((QuantumRange-
258     AccentuateModulate)*matte.black+(QuantumRange*AccentuateModulate)));
259   accentuate.alpha=matte.alpha;
260   highlight=matte;
261   highlight.red=(double) (QuantumScale*((QuantumRange-
262     HighlightModulate)*matte.red+(QuantumRange*HighlightModulate)));
263   highlight.green=(double) (QuantumScale*((QuantumRange-
264     HighlightModulate)*matte.green+(QuantumRange*HighlightModulate)));
265   highlight.blue=(double) (QuantumScale*((QuantumRange-
266     HighlightModulate)*matte.blue+(QuantumRange*HighlightModulate)));
267   highlight.black=(double) (QuantumScale*((QuantumRange-
268     HighlightModulate)*matte.black+(QuantumRange*HighlightModulate)));
269   highlight.alpha=matte.alpha;
270   shadow=matte;
271   shadow.red=QuantumScale*matte.red*ShadowModulate;
272   shadow.green=QuantumScale*matte.green*ShadowModulate;
273   shadow.blue=QuantumScale*matte.blue*ShadowModulate;
274   shadow.black=QuantumScale*matte.black*ShadowModulate;
275   shadow.alpha=matte.alpha;
276   trough=matte;
277   trough.red=QuantumScale*matte.red*TroughModulate;
278   trough.green=QuantumScale*matte.green*TroughModulate;
279   trough.blue=QuantumScale*matte.blue*TroughModulate;
280   trough.black=QuantumScale*matte.black*TroughModulate;
281   trough.alpha=matte.alpha;
282   status=MagickTrue;
283   progress=0;
284   image_view=AcquireVirtualCacheView(image,exception);
285   frame_view=AcquireAuthenticCacheView(frame_image,exception);
286   height=(size_t) (frame_info->outer_bevel+(frame_info->y-bevel_width)+
287     frame_info->inner_bevel);
288   if (height != 0)
289     {
290       register ssize_t
291         x;
292
293       register Quantum
294         *restrict q;
295
296       /*
297         Draw top of ornamental border.
298       */
299       q=QueueCacheViewAuthenticPixels(frame_view,0,0,frame_image->columns,
300         height,exception);
301       if (q != (Quantum *) NULL)
302         {
303           /*
304             Draw top of ornamental border.
305           */
306           for (y=0; y < (ssize_t) frame_info->outer_bevel; y++)
307           {
308             for (x=0; x < (ssize_t) (frame_image->columns-y); x++)
309             {
310               if (x < y)
311                 SetPixelInfoPixel(frame_image,&highlight,q);
312               else
313                 SetPixelInfoPixel(frame_image,&accentuate,q);
314               q+=GetPixelChannels(frame_image);
315             }
316             for ( ; x < (ssize_t) frame_image->columns; x++)
317             {
318               SetPixelInfoPixel(frame_image,&shadow,q);
319               q+=GetPixelChannels(frame_image);
320             }
321           }
322           for (y=0; y < (ssize_t) (frame_info->y-bevel_width); y++)
323           {
324             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
325             {
326               SetPixelInfoPixel(frame_image,&highlight,q);
327               q+=GetPixelChannels(frame_image);
328             }
329             width=frame_image->columns-2*frame_info->outer_bevel;
330             for (x=0; x < (ssize_t) width; x++)
331             {
332               SetPixelInfoPixel(frame_image,&matte,q);
333               q+=GetPixelChannels(frame_image);
334             }
335             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
336             {
337               SetPixelInfoPixel(frame_image,&shadow,q);
338               q+=GetPixelChannels(frame_image);
339             }
340           }
341           for (y=0; y < (ssize_t) frame_info->inner_bevel; y++)
342           {
343             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
344             {
345               SetPixelInfoPixel(frame_image,&highlight,q);
346               q+=GetPixelChannels(frame_image);
347             }
348             for (x=0; x < (ssize_t) (frame_info->x-bevel_width); x++)
349             {
350               SetPixelInfoPixel(frame_image,&matte,q);
351               q+=GetPixelChannels(frame_image);
352             }
353             width=image->columns+((size_t) frame_info->inner_bevel << 1)-
354               y;
355             for (x=0; x < (ssize_t) width; x++)
356             {
357               if (x < y)
358                 SetPixelInfoPixel(frame_image,&shadow,q);
359               else
360                 SetPixelInfoPixel(frame_image,&trough,q);
361               q+=GetPixelChannels(frame_image);
362             }
363             for ( ; x < (ssize_t) (image->columns+2*frame_info->inner_bevel); x++)
364             {
365               SetPixelInfoPixel(frame_image,&highlight,q);
366               q+=GetPixelChannels(frame_image);
367             }
368             width=frame_info->width-frame_info->x-image->columns-bevel_width;
369             for (x=0; x < (ssize_t) width; x++)
370             {
371               SetPixelInfoPixel(frame_image,&matte,q);
372               q+=GetPixelChannels(frame_image);
373             }
374             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
375             {
376               SetPixelInfoPixel(frame_image,&shadow,q);
377               q+=GetPixelChannels(frame_image);
378             }
379           }
380           (void) SyncCacheViewAuthenticPixels(frame_view,exception);
381         }
382     }
383   /*
384     Draw sides of ornamental border.
385   */
386 #if defined(MAGICKCORE_OPENMP_SUPPORT)
387   #pragma omp parallel for schedule(static,4) shared(progress,status) \
388     magick_threads(image,frame_image,1,1)
389 #endif
390   for (y=0; y < (ssize_t) image->rows; y++)
391   {
392     register ssize_t
393       x;
394
395     register Quantum
396       *restrict q;
397
398     size_t
399       width;
400
401     /*
402       Initialize scanline with matte color.
403     */
404     if (status == MagickFalse)
405       continue;
406     q=QueueCacheViewAuthenticPixels(frame_view,0,frame_info->y+y,
407       frame_image->columns,1,exception);
408     if (q == (Quantum *) NULL)
409       {
410         status=MagickFalse;
411         continue;
412       }
413     for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
414     {
415       SetPixelInfoPixel(frame_image,&highlight,q);
416       q+=GetPixelChannels(frame_image);
417     }
418     for (x=0; x < (ssize_t) (frame_info->x-bevel_width); x++)
419     {
420       SetPixelInfoPixel(frame_image,&matte,q);
421       q+=GetPixelChannels(frame_image);
422     }
423     for (x=0; x < (ssize_t) frame_info->inner_bevel; x++)
424     {
425       SetPixelInfoPixel(frame_image,&shadow,q);
426       q+=GetPixelChannels(frame_image);
427     }
428     /*
429       Set frame interior to interior color.
430     */
431     if ((compose != CopyCompositeOp) && ((compose != OverCompositeOp) ||
432         (image->alpha_trait == BlendPixelTrait)))
433       for (x=0; x < (ssize_t) image->columns; x++)
434       {
435         SetPixelInfoPixel(frame_image,&interior,q);
436         q+=GetPixelChannels(frame_image);
437       }
438     else
439       {
440         register const Quantum
441           *p;
442
443         p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
444         if (p == (const Quantum *) NULL)
445           {
446             status=MagickFalse;
447             continue;
448           }
449         for (x=0; x < (ssize_t) image->columns; x++)
450         {
451           register ssize_t
452             i;
453
454           if (GetPixelReadMask(image,q) == 0)
455             {
456               SetPixelBackgoundColor(frame_image,q);
457               p+=GetPixelChannels(image);
458               q+=GetPixelChannels(frame_image);
459               continue;
460             }
461           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
462           {
463             PixelChannel channel=GetPixelChannelChannel(image,i);
464             PixelTrait traits=GetPixelChannelTraits(image,channel);
465             PixelTrait frame_traits=GetPixelChannelTraits(frame_image,channel);
466             if ((traits == UndefinedPixelTrait) ||
467                 (frame_traits == UndefinedPixelTrait))
468               continue;
469             SetPixelChannel(frame_image,channel,p[i],q);
470           }
471           SetPixelRed(frame_image,GetPixelRed(image,p),q);
472           SetPixelGreen(frame_image,GetPixelGreen(image,p),q);
473           SetPixelBlue(frame_image,GetPixelBlue(image,p),q);
474           SetPixelAlpha(frame_image,GetPixelAlpha(image,p),q);
475           p+=GetPixelChannels(image);
476           q+=GetPixelChannels(frame_image);
477         }
478       }
479     for (x=0; x < (ssize_t) frame_info->inner_bevel; x++)
480     {
481       SetPixelInfoPixel(frame_image,&highlight,q);
482       q+=GetPixelChannels(frame_image);
483     }
484     width=frame_info->width-frame_info->x-image->columns-bevel_width;
485     for (x=0; x < (ssize_t) width; x++)
486     {
487       SetPixelInfoPixel(frame_image,&matte,q);
488       q+=GetPixelChannels(frame_image);
489     }
490     for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
491     {
492       SetPixelInfoPixel(frame_image,&shadow,q);
493       q+=GetPixelChannels(frame_image);
494     }
495     if (SyncCacheViewAuthenticPixels(frame_view,exception) == MagickFalse)
496       status=MagickFalse;
497     if (image->progress_monitor != (MagickProgressMonitor) NULL)
498       {
499         MagickBooleanType
500           proceed;
501
502 #if defined(MAGICKCORE_OPENMP_SUPPORT)
503         #pragma omp critical (MagickCore_FrameImage)
504 #endif
505         proceed=SetImageProgress(image,FrameImageTag,progress++,image->rows);
506         if (proceed == MagickFalse)
507           status=MagickFalse;
508       }
509   }
510   height=(size_t) (frame_info->inner_bevel+frame_info->height-
511     frame_info->y-image->rows-bevel_width+frame_info->outer_bevel);
512   if (height != 0)
513     {
514       register ssize_t
515         x;
516
517       register Quantum
518         *restrict q;
519
520       /*
521         Draw bottom of ornamental border.
522       */
523       q=QueueCacheViewAuthenticPixels(frame_view,0,(ssize_t) (frame_image->rows-
524         height),frame_image->columns,height,exception);
525       if (q != (Quantum *) NULL)
526         {
527           /*
528             Draw bottom of ornamental border.
529           */
530           for (y=frame_info->inner_bevel-1; y >= 0; y--)
531           {
532             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
533             {
534               SetPixelInfoPixel(frame_image,&highlight,q);
535               q+=GetPixelChannels(frame_image);
536             }
537             for (x=0; x < (ssize_t) (frame_info->x-bevel_width); x++)
538             {
539               SetPixelInfoPixel(frame_image,&matte,q);
540               q+=GetPixelChannels(frame_image);
541             }
542             for (x=0; x < y; x++)
543             {
544               SetPixelInfoPixel(frame_image,&shadow,q);
545               q+=GetPixelChannels(frame_image);
546             }
547             for ( ; x < (ssize_t) (image->columns+2*frame_info->inner_bevel); x++)
548             {
549               if (x >= (ssize_t) (image->columns+2*frame_info->inner_bevel-y))
550                 SetPixelInfoPixel(frame_image,&highlight,q);
551               else
552                 SetPixelInfoPixel(frame_image,&accentuate,q);
553               q+=GetPixelChannels(frame_image);
554             }
555             width=frame_info->width-frame_info->x-image->columns-bevel_width;
556             for (x=0; x < (ssize_t) width; x++)
557             {
558               SetPixelInfoPixel(frame_image,&matte,q);
559               q+=GetPixelChannels(frame_image);
560             }
561             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
562             {
563               SetPixelInfoPixel(frame_image,&shadow,q);
564               q+=GetPixelChannels(frame_image);
565             }
566           }
567           height=frame_info->height-frame_info->y-image->rows-bevel_width;
568           for (y=0; y < (ssize_t) height; y++)
569           {
570             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
571             {
572               SetPixelInfoPixel(frame_image,&highlight,q);
573               q+=GetPixelChannels(frame_image);
574             }
575             width=frame_image->columns-2*frame_info->outer_bevel;
576             for (x=0; x < (ssize_t) width; x++)
577             {
578               SetPixelInfoPixel(frame_image,&matte,q);
579               q+=GetPixelChannels(frame_image);
580             }
581             for (x=0; x < (ssize_t) frame_info->outer_bevel; x++)
582             {
583               SetPixelInfoPixel(frame_image,&shadow,q);
584               q+=GetPixelChannels(frame_image);
585             }
586           }
587           for (y=frame_info->outer_bevel-1; y >= 0; y--)
588           {
589             for (x=0; x < y; x++)
590             {
591               SetPixelInfoPixel(frame_image,&highlight,q);
592               q+=GetPixelChannels(frame_image);
593             }
594             for ( ; x < (ssize_t) frame_image->columns; x++)
595             {
596               if (x >= (ssize_t) (frame_image->columns-y))
597                 SetPixelInfoPixel(frame_image,&shadow,q);
598               else
599                 SetPixelInfoPixel(frame_image,&trough,q);
600               q+=GetPixelChannels(frame_image);
601             }
602           }
603           (void) SyncCacheViewAuthenticPixels(frame_view,exception);
604         }
605     }
606   frame_view=DestroyCacheView(frame_view);
607   image_view=DestroyCacheView(image_view);
608   if ((compose != CopyCompositeOp) && ((compose != OverCompositeOp) ||
609       (image->alpha_trait == BlendPixelTrait)))
610     {
611       x=(ssize_t) (frame_info->outer_bevel+(frame_info->x-bevel_width)+
612         frame_info->inner_bevel);
613       y=(ssize_t) (frame_info->outer_bevel+(frame_info->y-bevel_width)+
614         frame_info->inner_bevel);
615       (void) CompositeImage(frame_image,image,compose,MagickTrue,x,y,
616         exception);
617     }
618   if (status == MagickFalse)
619     frame_image=DestroyImage(frame_image);
620   return(frame_image);
621 }
622 \f
623 /*
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 %                                                                             %
626 %                                                                             %
627 %                                                                             %
628 %   R a i s e I m a g e                                                       %
629 %                                                                             %
630 %                                                                             %
631 %                                                                             %
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633 %
634 %  RaiseImage() creates a simulated three-dimensional button-like effect
635 %  by lightening and darkening the edges of the image.  Members width and
636 %  height of raise_info define the width of the vertical and horizontal
637 %  edge of the effect.
638 %
639 %  The format of the RaiseImage method is:
640 %
641 %      MagickBooleanType RaiseImage(const Image *image,
642 %        const RectangleInfo *raise_info,const MagickBooleanType raise,
643 %        ExceptionInfo *exception)
644 %
645 %  A description of each parameter follows:
646 %
647 %    o image: the image.
648 %
649 %    o raise_info: Define the width and height of the raise area.
650 %
651 %    o raise: A value other than zero creates a 3-D raise effect,
652 %      otherwise it has a lowered effect.
653 %
654 %    o exception: return any errors or warnings in this structure.
655 %
656 */
657 MagickExport MagickBooleanType RaiseImage(Image *image,
658   const RectangleInfo *raise_info,const MagickBooleanType raise,
659   ExceptionInfo *exception)
660 {
661 #define AccentuateFactor  ScaleCharToQuantum(135)
662 #define HighlightFactor  ScaleCharToQuantum(190)
663 #define ShadowFactor  ScaleCharToQuantum(190)
664 #define RaiseImageTag  "Raise/Image"
665 #define TroughFactor  ScaleCharToQuantum(135)
666
667   CacheView
668     *image_view;
669
670   MagickBooleanType
671     status;
672
673   MagickOffsetType
674     progress;
675
676   Quantum
677     foreground,
678     background;
679
680   ssize_t
681     y;
682
683   assert(image != (Image *) NULL);
684   assert(image->signature == MagickSignature);
685   if (image->debug != MagickFalse)
686     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
687   assert(raise_info != (RectangleInfo *) NULL);
688   if ((image->columns <= (raise_info->width << 1)) ||
689       (image->rows <= (raise_info->height << 1)))
690     ThrowBinaryException(OptionError,"ImageSizeMustExceedBevelWidth",
691       image->filename);
692   foreground=QuantumRange;
693   background=(Quantum) 0;
694   if (raise == MagickFalse)
695     {
696       foreground=(Quantum) 0;
697       background=QuantumRange;
698     }
699   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
700     return(MagickFalse);
701   /*
702     Raise image.
703   */
704   status=MagickTrue;
705   progress=0;
706   image_view=AcquireAuthenticCacheView(image,exception);
707 #if defined(MAGICKCORE_OPENMP_SUPPORT)
708   #pragma omp parallel for schedule(static,4) shared(progress,status) \
709     magick_threads(image,image,1,1)
710 #endif
711   for (y=0; y < (ssize_t) raise_info->height; y++)
712   {
713     register ssize_t
714       i,
715       x;
716
717     register Quantum
718       *restrict q;
719
720     if (status == MagickFalse)
721       continue;
722     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
723     if (q == (Quantum *) NULL)
724       {
725         status=MagickFalse;
726         continue;
727       }
728     for (x=0; x < y; x++)
729     {
730       if (GetPixelReadMask(image,q) == 0)
731         {
732           q+=GetPixelChannels(image);
733           continue;
734         }
735       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
736       {
737         PixelChannel channel=GetPixelChannelChannel(image,i);
738         PixelTrait traits=GetPixelChannelTraits(image,channel);
739         if ((traits & UpdatePixelTrait) == 0)
740           continue;
741         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*HighlightFactor+(double)
742           foreground*(QuantumRange-HighlightFactor)));
743       }
744       q+=GetPixelChannels(image);
745     }
746     for ( ; x < (ssize_t) (image->columns-y); x++)
747     {
748       if (GetPixelReadMask(image,q) == 0)
749         {
750           q+=GetPixelChannels(image);
751           continue;
752         }
753       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
754       {
755         PixelChannel channel=GetPixelChannelChannel(image,i);
756         PixelTrait traits=GetPixelChannelTraits(image,channel);
757         if ((traits & UpdatePixelTrait) == 0)
758           continue;
759         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*AccentuateFactor+
760           (double) foreground*(QuantumRange-AccentuateFactor)));
761       }
762       q+=GetPixelChannels(image);
763     }
764     for ( ; x < (ssize_t) image->columns; x++)
765     {
766       if (GetPixelReadMask(image,q) == 0)
767         {
768           q+=GetPixelChannels(image);
769           continue;
770         }
771       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
772       {
773         PixelChannel channel=GetPixelChannelChannel(image,i);
774         PixelTrait traits=GetPixelChannelTraits(image,channel);
775         if ((traits & UpdatePixelTrait) == 0)
776           continue;
777         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*ShadowFactor+(double)
778           background*(QuantumRange-ShadowFactor)));
779       }
780       q+=GetPixelChannels(image);
781     }
782     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
783       status=MagickFalse;
784     if (image->progress_monitor != (MagickProgressMonitor) NULL)
785       {
786         MagickBooleanType
787           proceed;
788
789 #if defined(MAGICKCORE_OPENMP_SUPPORT)
790         #pragma omp critical (MagickCore_RaiseImage)
791 #endif
792         proceed=SetImageProgress(image,RaiseImageTag,progress++,image->rows);
793         if (proceed == MagickFalse)
794           status=MagickFalse;
795       }
796   }
797 #if defined(MAGICKCORE_OPENMP_SUPPORT)
798   #pragma omp parallel for schedule(static,4) shared(progress,status) \
799     magick_threads(image,image,1,1)
800 #endif
801   for (y=(ssize_t) raise_info->height; y < (ssize_t) (image->rows-raise_info->height); y++)
802   {
803     register ssize_t
804       i,
805       x;
806
807     register Quantum
808       *restrict q;
809
810     if (status == MagickFalse)
811       continue;
812     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
813     if (q == (Quantum *) NULL)
814       {
815         status=MagickFalse;
816         continue;
817       }
818     for (x=0; x < (ssize_t) raise_info->width; x++)
819     {
820       if (GetPixelReadMask(image,q) == 0)
821         {
822           q+=GetPixelChannels(image);
823           continue;
824         }
825       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
826       {
827         PixelChannel channel=GetPixelChannelChannel(image,i);
828         PixelTrait traits=GetPixelChannelTraits(image,channel);
829         if ((traits & UpdatePixelTrait) == 0)
830           continue;
831         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*HighlightFactor+(double)
832           foreground*(QuantumRange-HighlightFactor)));
833       }
834       q+=GetPixelChannels(image);
835     }
836     for ( ; x < (ssize_t) (image->columns-raise_info->width); x++)
837       q+=GetPixelChannels(image);
838     for ( ; x < (ssize_t) image->columns; x++)
839     {
840       if (GetPixelReadMask(image,q) == 0)
841         {
842           q+=GetPixelChannels(image);
843           continue;
844         }
845       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
846       {
847         PixelChannel channel=GetPixelChannelChannel(image,i);
848         PixelTrait traits=GetPixelChannelTraits(image,channel);
849         if ((traits & UpdatePixelTrait) == 0)
850           continue;
851         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*ShadowFactor+(double)
852           background*(QuantumRange-ShadowFactor)));
853       }
854       q+=GetPixelChannels(image);
855     }
856     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
857       status=MagickFalse;
858     if (image->progress_monitor != (MagickProgressMonitor) NULL)
859       {
860         MagickBooleanType
861           proceed;
862
863 #if defined(MAGICKCORE_OPENMP_SUPPORT)
864         #pragma omp critical (MagickCore_RaiseImage)
865 #endif
866         proceed=SetImageProgress(image,RaiseImageTag,progress++,image->rows);
867         if (proceed == MagickFalse)
868           status=MagickFalse;
869       }
870   }
871 #if defined(MAGICKCORE_OPENMP_SUPPORT)
872   #pragma omp parallel for schedule(static,4) shared(progress,status) \
873     magick_threads(image,image,1,1)
874 #endif
875   for (y=(ssize_t) (image->rows-raise_info->height); y < (ssize_t) image->rows; y++)
876   {
877     register ssize_t
878       i,
879       x;
880
881     register Quantum
882       *restrict q;
883
884     if (status == MagickFalse)
885       continue;
886     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
887     if (q == (Quantum *) NULL)
888       {
889         status=MagickFalse;
890         continue;
891       }
892     for (x=0; x < (ssize_t) (image->rows-y); x++)
893     {
894       if (GetPixelReadMask(image,q) == 0)
895         {
896           q+=GetPixelChannels(image);
897           continue;
898         }
899       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
900       {
901         PixelChannel channel=GetPixelChannelChannel(image,i);
902         PixelTrait traits=GetPixelChannelTraits(image,channel);
903         if ((traits & UpdatePixelTrait) == 0)
904           continue;
905         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*HighlightFactor+(double)
906           foreground*(QuantumRange-HighlightFactor)));
907       }
908       q+=GetPixelChannels(image);
909     }
910     for ( ; x < (ssize_t) (image->columns-(image->rows-y)); x++)
911     {
912       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
913       {
914         PixelChannel channel=GetPixelChannelChannel(image,i);
915         PixelTrait traits=GetPixelChannelTraits(image,channel);
916         if ((traits & UpdatePixelTrait) == 0)
917           continue;
918         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*TroughFactor+
919           (double) background*(QuantumRange-TroughFactor)));
920       }
921       q+=GetPixelChannels(image);
922     }
923     for ( ; x < (ssize_t) image->columns; x++)
924     {
925       if (GetPixelReadMask(image,q) == 0)
926         {
927           q+=GetPixelChannels(image);
928           continue;
929         }
930       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
931       {
932         PixelChannel channel=GetPixelChannelChannel(image,i);
933         PixelTrait traits=GetPixelChannelTraits(image,channel);
934         if ((traits & UpdatePixelTrait) == 0)
935           continue;
936         q[i]=ClampToQuantum(QuantumScale*((double) q[i]*ShadowFactor+(double)
937           background*(QuantumRange-ShadowFactor)));
938       }
939       q+=GetPixelChannels(image);
940     }
941     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
942       status=MagickFalse;
943     if (image->progress_monitor != (MagickProgressMonitor) NULL)
944       {
945         MagickBooleanType
946           proceed;
947
948 #if defined(MAGICKCORE_OPENMP_SUPPORT)
949         #pragma omp critical (MagickCore_RaiseImage)
950 #endif
951         proceed=SetImageProgress(image,RaiseImageTag,progress++,image->rows);
952         if (proceed == MagickFalse)
953           status=MagickFalse;
954       }
955   }
956   image_view=DestroyCacheView(image_view);
957   return(status);
958 }