MagickCore  6.8.5
composite-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License.
6  obtain a copy of the License at
7 
8  http://www.imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore image composite private methods.
17 */
18 #ifndef _MAGICKCORE_COMPOSITE_PRIVATE_H
19 #define _MAGICKCORE_COMPOSITE_PRIVATE_H
20 
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24 
25 /*
26  ImageMagick Alpha Composite Inline Methods (special export)
27 */
28 
29 #include "magick/color.h"
30 #include "magick/image.h"
31 #include "magick/image-private.h"
32 #include "magick/pixel-private.h"
33 
34 static inline MagickRealType RoundToUnity(const MagickRealType value)
35 {
36  return(value < 0.0 ? 0.0 : (value > 1.0) ? 1.0 : value);
37 }
38 
40  const MagickRealType alpha,const MagickRealType q,const MagickRealType beta)
41 {
42  return((1.0-QuantumScale*alpha)*p+(1.0-QuantumScale*beta)*q*
43  QuantumScale*alpha);
44 }
45 
46 static inline void MagickCompositeOver(const PixelPacket *p,
47  const MagickRealType alpha,const PixelPacket *q,const MagickRealType beta,
48  PixelPacket *composite)
49 {
50  double
51  gamma;
52 
53  /*
54  Compose pixel p over pixel q with the given opacities.
55  */
56  if (alpha == TransparentOpacity)
57  {
58  if (composite != q)
59  *composite=(*q);
60  return;
61  }
62  gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
63 #if !defined(MAGICKCORE_HDRI_SUPPORT)
64  composite->opacity=(Quantum) (QuantumRange*(1.0-gamma)+0.5);
65  gamma=PerceptibleReciprocal(gamma);
66  SetPixelRed(composite,gamma*MagickOver_((MagickRealType)
67  GetPixelRed(p),alpha,(MagickRealType) GetPixelRed(q),beta)+0.5);
68  SetPixelGreen(composite,gamma*MagickOver_((MagickRealType)
69  GetPixelGreen(p),alpha,(MagickRealType) GetPixelGreen(q),beta)+0.5);
70  SetPixelBlue(composite,gamma*MagickOver_((MagickRealType)
71  GetPixelBlue(p),alpha,(MagickRealType) GetPixelBlue(q),beta)+0.5);
72 #else
73  SetPixelOpacity(composite,QuantumRange*(1.0-gamma));
74  gamma=PerceptibleReciprocal(gamma);
75  SetPixelRed(composite,gamma*MagickOver_((MagickRealType)
76  GetPixelRed(p),alpha,(MagickRealType) GetPixelRed(q),beta));
77  SetPixelGreen(composite,gamma*MagickOver_((MagickRealType)
78  GetPixelGreen(p),alpha,(MagickRealType) GetPixelGreen(q),beta));
79  SetPixelBlue(composite,gamma*MagickOver_((MagickRealType)
80  GetPixelBlue(p),alpha,(MagickRealType) GetPixelBlue(q),beta));
81 #endif
82 }
83 
84 static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
85  const MagickRealType alpha,const MagickPixelPacket *q,
86  const MagickRealType beta,MagickPixelPacket *composite)
87 {
88  double
89  gamma;
90 
91  /*
92  Compose pixel p over pixel q with the given opacities.
93  */
94  if (alpha == OpaqueOpacity)
95  {
96  *composite=(*p);
97  return;
98  }
99  gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
100  composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
101  gamma=PerceptibleReciprocal(gamma);
102  composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta);
103  composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta);
104  composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta);
105  if (q->colorspace == CMYKColorspace)
106  composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
107 }
108 
109 static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
110  const MagickRealType alpha,const MagickPixelPacket *q,
111  const MagickRealType beta,MagickPixelPacket *composite)
112 {
113  double
114  gamma;
115 
117  Da,
118  Sa;
119 
120  /*
121  Add two pixels with the given opacities.
122  */
123  Sa=1.0-QuantumScale*alpha;
124  Da=1.0-QuantumScale*beta;
125  gamma=RoundToUnity(Sa+Da); /* 'Plus' blending -- not 'Over' blending */
126  composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
127  gamma=PerceptibleReciprocal(gamma);
128  composite->red=gamma*(Sa*p->red+Da*q->red);
129  composite->green=gamma*(Sa*p->green+Da*q->green);
130  composite->blue=gamma*(Sa*p->blue+Da*q->blue);
131  if (q->colorspace == CMYKColorspace)
132  composite->index=gamma*(Sa*p->index+Da*q->index);
133 }
134 
135 /*
136  Blend pixel colors p and q by the amount given.
137 */
138 static inline void MagickPixelCompositeBlend(const MagickPixelPacket *p,
139  const MagickRealType alpha,const MagickPixelPacket *q,
140  const MagickRealType beta,MagickPixelPacket *composite)
141 {
144  (QuantumRange-q->opacity)),composite);
145 }
146 
147 /*
148  Blend pixel colors p and q by the amount given and area.
149 */
151  const MagickRealType alpha,const MagickPixelPacket *q,
152  const MagickRealType beta,const MagickRealType area,
153  MagickPixelPacket *composite)
154 {
157  beta)),composite);
158 }
159 
160 #if defined(__cplusplus) || defined(c_plusplus)
161 }
162 #endif
163 
164 #endif