composite-private.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004 
00005   You may not use this file except in compliance with the License.
00006   obtain a copy of the License at
00007 
00008     http://www.imagemagick.org/script/license.php
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore image composite private methods.
00017 */
00018 #ifndef _MAGICKCORE_COMPOSITE_PRIVATE_H
00019 #define _MAGICKCORE_COMPOSITE_PRIVATE_H
00020 
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 /*
00026   ImageMagick Alpha Composite Inline Methods (special export)
00027 */
00028 
00029 #include "magick/color.h"
00030 #include "magick/image.h"
00031 #include "magick/image-private.h"
00032 
00033 static inline MagickRealType RoundToUnity(const MagickRealType value)
00034 {
00035   return(value < 0.0 ? 0.0 : (value > 1.0) ? 1.0 : value);
00036 }
00037 
00038 static inline MagickRealType MagickOver_(const MagickRealType p,
00039   const MagickRealType alpha,const MagickRealType q,const MagickRealType beta)
00040 {
00041   return((1.0-QuantumScale*alpha)*p+
00042          (1.0-QuantumScale*beta)*q*QuantumScale*alpha);
00043 }
00044 
00045 static inline void MagickCompositeOver(const PixelPacket *p,
00046   const MagickRealType alpha,const PixelPacket *q,const MagickRealType beta,
00047   PixelPacket *composite)
00048 {
00049   MagickRealType
00050     gamma;
00051 
00052   /*
00053     Compose pixel p over pixel q with the given opacities.
00054   */
00055   if (alpha == TransparentOpacity)
00056     {
00057       if (composite != q)
00058         *composite=(*q);
00059       return;
00060     }
00061   gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
00062 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00063   composite->opacity=(Quantum) (QuantumRange*(1.0-gamma)+0.5);
00064   gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
00065   composite->red=(Quantum) (gamma*MagickOver_((MagickRealType) p->red,alpha,
00066     (MagickRealType) q->red,beta)+0.5);
00067   composite->green=(Quantum) (gamma*MagickOver_((MagickRealType) p->green,alpha,
00068     (MagickRealType) q->green,beta)+0.5);
00069   composite->blue=(Quantum) (gamma*MagickOver_((MagickRealType) p->blue,alpha,
00070     (MagickRealType) q->blue,beta)+0.5);
00071 #else
00072   composite->opacity=(Quantum) (QuantumRange*(1.0-gamma));
00073   gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
00074   composite->red=(Quantum) (gamma*MagickOver_((MagickRealType) p->red,alpha,
00075     (MagickRealType) q->red,beta));
00076   composite->green=(Quantum) (gamma*MagickOver_((MagickRealType) p->green,alpha,
00077     (MagickRealType) q->green,beta));
00078   composite->blue=(Quantum) (gamma*MagickOver_((MagickRealType) p->blue,alpha,
00079     (MagickRealType) q->blue,beta));
00080 #endif
00081 }
00082 
00083 static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
00084   const MagickRealType alpha,const MagickPixelPacket *q,
00085   const MagickRealType beta,MagickPixelPacket *composite)
00086 {
00087   MagickRealType
00088     gamma;
00089 
00090   /*
00091     Compose pixel p over pixel q with the given opacities.
00092   */
00093   if (alpha == OpaqueOpacity)
00094     {
00095       *composite=(*p);
00096       return;
00097     }
00098   gamma=1.0-QuantumScale*QuantumScale*alpha*beta;
00099   composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
00100   gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : gamma);
00101   composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta);
00102   composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta);
00103   composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta);
00104   if (q->colorspace == CMYKColorspace)
00105     composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
00106 }
00107 
00108 static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
00109   const MagickRealType alpha,const MagickPixelPacket *q,
00110   const MagickRealType beta,MagickPixelPacket *composite)
00111 {
00112   MagickRealType
00113     Da,
00114     gamma,
00115     Sa;
00116 
00117   /*
00118     Add two pixels with the given opacities.
00119   */
00120   Sa=1.0-QuantumScale*alpha;
00121   Da=1.0-QuantumScale*beta;
00122   gamma=RoundToUnity(Sa+Da);  /* 'Plus' blending -- not 'Over' blending */
00123   composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
00124   gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : gamma);
00125   composite->red=gamma*(Sa*p->red+Da*q->red);
00126   composite->green=gamma*(Sa*p->green+Da*q->green);
00127   composite->blue=gamma*(Sa*p->blue+Da*q->blue);
00128   if (q->colorspace == CMYKColorspace)
00129     composite->index=gamma*(Sa*p->index+Da*q->index);
00130 }
00131 
00132 /*
00133   Blend pixel colors p and q by the amount given.
00134 */
00135 static inline void MagickPixelCompositeBlend(const MagickPixelPacket *p,
00136   const MagickRealType alpha,const MagickPixelPacket *q,
00137   const MagickRealType beta,MagickPixelPacket *composite)
00138 {
00139   MagickPixelCompositePlus(p,(MagickRealType) (QuantumRange-alpha*
00140     (QuantumRange-p->opacity)),q,(MagickRealType) (QuantumRange-beta*
00141     (QuantumRange-q->opacity)),composite);
00142 }
00143 
00144 /*
00145   Blend pixel colors p and q by the amount given and area.
00146 */
00147 static inline void MagickPixelCompositeAreaBlend(const MagickPixelPacket *p,
00148   const MagickRealType alpha,const MagickPixelPacket *q,
00149   const MagickRealType beta,const MagickRealType area,
00150   MagickPixelPacket *composite)
00151 {
00152   MagickPixelCompositePlus(p,(MagickRealType) QuantumRange-(1.0-area)*
00153     (QuantumRange-alpha),q,(MagickRealType) (QuantumRange-area*(QuantumRange-
00154     beta)),composite);
00155 }
00156 
00157 #if defined(__cplusplus) || defined(c_plusplus)
00158 }
00159 #endif
00160 
00161 #endif

Generated on 19 Nov 2009 for MagickCore by  doxygen 1.6.1