composite-private.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2019 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.  You may
00006   obtain a copy of the License at
00007 
00008     https://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 #include "magick/color.h"
00022 #include "magick/image.h"
00023 #include "magick/image-private.h"
00024 #include "magick/pixel-private.h"
00025 
00026 #if defined(__cplusplus) || defined(c_plusplus)
00027 extern "C" {
00028 #endif
00029 
00030 /*
00031   ImageMagick Alpha Composite Inline Methods (special export)
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   MagickRealType
00042     Da,
00043     Sa;
00044 
00045   Sa=1.0-QuantumScale*alpha;
00046   Da=1.0-QuantumScale*beta;
00047   return(Sa*p+Da*q*(1.0-Sa));
00048 }
00049 
00050 static inline void MagickCompositeOver(const PixelPacket *p,
00051   const MagickRealType alpha,const PixelPacket *q,const MagickRealType beta,
00052   PixelPacket *composite)
00053 {
00054   MagickRealType
00055     Da,
00056     gamma,
00057     Sa;
00058 
00059   /*
00060     Compose pixel p over pixel q with the given opacities.
00061   */
00062   Sa=1.0-QuantumScale*alpha;
00063   Da=1.0-QuantumScale*beta;
00064   gamma=Sa+Da-Sa*Da;
00065 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00066   SetPixelOpacity(composite,ClampToQuantum(QuantumRange*(1.0-
00067     RoundToUnity(gamma))));
00068   gamma=PerceptibleReciprocal(gamma);
00069   SetPixelRed(composite,ClampToQuantum(gamma*MagickOver_((MagickRealType)
00070     GetPixelRed(p),alpha,(MagickRealType) GetPixelRed(q),beta)));
00071   SetPixelGreen(composite,ClampToQuantum(gamma*MagickOver_((MagickRealType)
00072     GetPixelGreen(p),alpha,(MagickRealType) GetPixelGreen(q),beta)));
00073   SetPixelBlue(composite,ClampToQuantum(gamma*MagickOver_((MagickRealType)
00074     GetPixelBlue(p),alpha,(MagickRealType) GetPixelBlue(q),beta)));
00075 #else
00076   SetPixelOpacity(composite,QuantumRange*(1.0-RoundToUnity(gamma)));
00077   gamma=PerceptibleReciprocal(gamma);
00078   SetPixelRed(composite,gamma*MagickOver_((MagickRealType)
00079     GetPixelRed(p),alpha,(MagickRealType) GetPixelRed(q),beta));
00080   SetPixelGreen(composite,gamma*MagickOver_((MagickRealType)
00081     GetPixelGreen(p),alpha,(MagickRealType) GetPixelGreen(q),beta));
00082   SetPixelBlue(composite,gamma*MagickOver_((MagickRealType)
00083     GetPixelBlue(p),alpha,(MagickRealType) GetPixelBlue(q),beta));
00084 #endif
00085 }
00086 
00087 static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
00088   const MagickRealType alpha,const MagickPixelPacket *q,
00089   const MagickRealType beta,MagickPixelPacket *composite)
00090 {
00091   MagickRealType
00092     Da,
00093     gamma,
00094     Sa;
00095 
00096   /*
00097     Compose pixel p over pixel q with the given opacities.
00098   */
00099   Sa=1.0-QuantumScale*alpha;
00100   Da=1.0-QuantumScale*beta;
00101   gamma=Sa+Da-Sa*Da;
00102   composite->opacity=(MagickRealType) (QuantumRange*(1.0-RoundToUnity(gamma)));
00103   gamma=PerceptibleReciprocal(gamma);
00104   composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta);
00105   composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta);
00106   composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta);
00107   if (q->colorspace == CMYKColorspace)
00108     composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
00109 }
00110 
00111 static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
00112   const MagickRealType alpha,const MagickPixelPacket *q,
00113   const MagickRealType beta,MagickPixelPacket *composite)
00114 {
00115   MagickRealType
00116     Da,
00117     gamma,
00118     Sa;
00119 
00120   /*
00121     Add two pixels with the given opacities.
00122   */
00123   Sa=1.0-QuantumScale*alpha;
00124   Da=1.0-QuantumScale*beta;
00125   gamma=RoundToUnity(Sa+Da);  /* 'Plus' blending -- not 'Over' blending */
00126   composite->opacity=(MagickRealType) QuantumRange*(1.0-RoundToUnity(gamma));
00127   gamma=PerceptibleReciprocal(gamma);
00128   composite->red=gamma*(Sa*p->red+Da*q->red);
00129   composite->green=gamma*(Sa*p->green+Da*q->green);
00130   composite->blue=gamma*(Sa*p->blue+Da*q->blue);
00131   if (q->colorspace == CMYKColorspace)
00132     composite->index=gamma*(Sa*p->index+Da*q->index);
00133 }
00134 
00135 /*
00136   Blend pixel colors p and q by the amount given.
00137 */
00138 static inline void MagickPixelCompositeBlend(const MagickPixelPacket *p,
00139   const MagickRealType alpha,const MagickPixelPacket *q,
00140   const MagickRealType beta,MagickPixelPacket *composite)
00141 {
00142   MagickPixelCompositePlus(p,(MagickRealType) (QuantumRange-alpha*
00143     (QuantumRange-p->opacity)),q,(MagickRealType) (QuantumRange-beta*
00144     (QuantumRange-q->opacity)),composite);
00145 }
00146 
00147 /*
00148   Blend pixel colors p and q by the amount given and area.
00149 */
00150 static inline void MagickPixelCompositeAreaBlend(const MagickPixelPacket *p,
00151   const MagickRealType alpha,const MagickPixelPacket *q,
00152   const MagickRealType beta,const MagickRealType area,
00153   MagickPixelPacket *composite)
00154 {
00155   MagickPixelCompositePlus(p,(MagickRealType) QuantumRange-(1.0-area)*
00156     (QuantumRange-alpha),q,(MagickRealType) (QuantumRange-area*(QuantumRange-
00157     beta)),composite);
00158 }
00159 
00160 #if defined(__cplusplus) || defined(c_plusplus)
00161 }
00162 #endif
00163 
00164 #endif

Generated on 30 Sep 2019 for MagickCore by  doxygen 1.6.1