root / ImageMagick / branches / ImageMagick-6.3.5 / magick / composite-private.h

Revision 8037, 5.0 kB (checked in by cristy, 14 months ago)
Line 
1/*
2  Copyright 1999-2007 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)
22extern "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
33static inline MagickRealType RoundToUnity(const MagickRealType value)
34{
35  return(value < 0.0 ? 0.0 : (value > 1.0) ? 1.0 : value);
36}
37
38static inline MagickRealType MagickOver_(const MagickRealType p,
39  const MagickRealType alpha,const MagickRealType q,const MagickRealType beta)
40{
41  MagickRealType
42    pixel;
43
44  pixel=(1.0-QuantumScale*alpha)*p+(1.0-QuantumScale*beta)*q*QuantumScale*alpha;
45  return(pixel);
46}
47
48/*
49  Compose pixel p over pixel q with the given opacities
50*/
51static inline void MagickCompositeOver(const PixelPacket *p,
52  const MagickRealType alpha,const PixelPacket *q,const MagickRealType beta,
53  PixelPacket *composite)
54{
55  MagickRealType
56    gamma;
57
58  if (alpha == TransparentOpacity)
59    {
60      *composite=(*q);
61      return;
62    }
63  gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
64#if !defined(UseHDRI)
65  composite->opacity=(Quantum) (QuantumRange*(1.0-gamma)+0.5);
66  gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
67  composite->red=(Quantum) (gamma*MagickOver_((MagickRealType) p->red,alpha,
68    (MagickRealType) q->red,beta)+0.5);
69  composite->green=(Quantum) (gamma*MagickOver_((MagickRealType) p->green,alpha,
70    (MagickRealType) q->green,beta)+0.5);
71  composite->blue=(Quantum) (gamma*MagickOver_((MagickRealType) p->blue,alpha,
72    (MagickRealType) q->blue,beta)+0.5);
73#else
74  composite->opacity=(Quantum) (QuantumRange*(1.0-gamma));
75  gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
76  composite->red=(Quantum) (gamma*MagickOver_((MagickRealType) p->red,alpha,
77    (MagickRealType) q->red,beta));
78  composite->green=(Quantum) (gamma*MagickOver_((MagickRealType) p->green,alpha,
79    (MagickRealType) q->green,beta));
80  composite->blue=(Quantum) (gamma*MagickOver_((MagickRealType) p->blue,alpha,
81    (MagickRealType) q->blue,beta));
82#endif
83}
84
85/*
86  Compose pixel p over pixel q with the given opacities
87*/
88static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
89  const MagickRealType alpha,const MagickPixelPacket *q,
90  const MagickRealType beta,MagickPixelPacket *composite)
91{
92  MagickRealType
93    gamma;
94
95  if (alpha == TransparentOpacity)
96    {
97      *composite=(*q);
98      return;
99    }
100  gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
101  composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
102  gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
103  composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta);
104  composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta);
105  composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta);
106  if ((p->colorspace == CMYKColorspace) && (q->colorspace == CMYKColorspace))
107    composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
108}
109
110
111static inline MagickRealType MagickPlus_(const MagickRealType p,
112  const MagickRealType alpha,const MagickRealType q,const MagickRealType beta)
113{
114  return((1.0-QuantumScale*alpha)*p+(1.0-QuantumScale*beta)*q);
115}
116
117/*
118  Add two pixels with the given opacities
119*/
120static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
121  const MagickRealType alpha,const MagickPixelPacket *q,
122  const MagickRealType beta,MagickPixelPacket *composite)
123{
124  MagickRealType
125    gamma;
126
127  gamma=RoundToUnity((1.0-QuantumScale*alpha)+(1.0-QuantumScale*beta));
128  composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
129  gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : gamma);
130  composite->red=gamma*MagickPlus_(p->red,alpha,q->red,beta);
131  composite->green=gamma*MagickPlus_(p->green,alpha,q->green,beta);
132  composite->blue=gamma*MagickPlus_(p->blue,alpha,q->blue,beta);
133  if (q->colorspace == CMYKColorspace)
134    composite->index=gamma*MagickPlus_(p->index,alpha,q->index,beta);
135}
136
137/*
138  Blend pixel colors p and q by the amount given
139*/
140static inline void MagickPixelCompositeBlend(const MagickPixelPacket *p,
141  const MagickRealType alpha,const MagickPixelPacket *q,
142  const MagickRealType beta,MagickPixelPacket *composite)
143{
144  MagickPixelCompositePlus(p,(MagickRealType) QuantumRange-alpha*
145    (QuantumRange-p->opacity),q,(MagickRealType) QuantumRange-beta*
146    (QuantumRange-q->opacity),composite);
147}
148
149#if defined(__cplusplus) || defined(c_plusplus)
150}
151#endif
152
153#endif
Note: See TracBrowser for help on using the browser.