00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "plstdpch.h"
00012 #include "plfilterintensity.h"
00013 #include "plbitmap.h"
00014 #include "plpaintlibdefs.h"
00015
00016 #include <math.h>
00017
00018 PLFilterIntensity::PLFilterIntensity(double intensity, PLBYTE offset, double exponent)
00019 : PLFilter(),
00020 m_intensity(intensity),
00021 m_offset(offset),
00022 m_exponent(exponent)
00023 {
00024
00025 }
00026
00027 PLFilterIntensity::~PLFilterIntensity()
00028 {
00029
00030 }
00031
00032 void PLFilterIntensity::Apply(PLBmp * pBmpSource, PLBmp * pBmpDest) const
00033 {
00034 double h, s, v;
00035 double intensityFactor;
00036 register int inc=0;
00037 extern void fp_rgb_to_hsv(double* r, double* g, double *b);
00038 extern void fp_hsv_to_rgb(double* r, double* g, double *b);
00039
00040
00041 double intensity = m_intensity-20;
00042 intensity /= 4.0;
00043 PLASSERT (pBmpSource->GetBitsPerPixel() >= 24);
00044
00045 pBmpDest->Create (pBmpSource->GetWidth(),
00046 pBmpSource->GetHeight(),
00047 pBmpSource->GetBitsPerPixel(),
00048 pBmpSource->HasAlpha(),
00049 pBmpSource->GetResolution());
00050
00051 PLBYTE ** pSrcLines = pBmpSource->GetLineArray();
00052 PLBYTE ** pDstLines = pBmpDest->GetLineArray();
00053
00054 register int destWidth = pBmpDest->GetWidth();
00055
00056 if(pBmpSource->GetBitsPerPixel() == 24)
00057 inc = 3;
00058
00059 if(pBmpSource->GetBitsPerPixel() == 32)
00060 inc = sizeof(PLPixel32);
00061
00062 double csupp = intensity/pow(255.0, m_exponent);
00063
00064 for (int y = 0; y < pBmpDest->GetHeight(); ++y)
00065 {
00066 PLBYTE * pSrcPixel = pSrcLines[y];
00067 PLBYTE * pDstPixel = pDstLines[y];
00068
00069 for (register int x = 0; x < destWidth; ++x)
00070 {
00071
00072 h =(double) pSrcPixel[PL_RGBA_RED];
00073 s =(double) pSrcPixel[PL_RGBA_GREEN];
00074 v =(double) pSrcPixel[PL_RGBA_BLUE];
00075
00076 fp_rgb_to_hsv(&h, &s, &v);
00077
00078
00079 if (v >= m_offset)
00080 intensityFactor = 1.0 + csupp * pow((v-m_offset), m_exponent);
00081 else
00082 intensityFactor = 1.0;
00083
00084 v *= intensityFactor;
00085
00086
00087 fp_hsv_to_rgb(&h, &s, &v);
00088
00089 pDstPixel[PL_RGBA_RED] = (PLBYTE) h;
00090 pDstPixel[PL_RGBA_GREEN] = (PLBYTE) s;
00091 pDstPixel[PL_RGBA_BLUE] = (PLBYTE) v;
00092
00093 if(h >= 255.0)
00094 pDstPixel[PL_RGBA_RED] = (PLBYTE) 255;
00095 if(s >= 255.0)
00096 pDstPixel[PL_RGBA_GREEN] = (PLBYTE) 255;
00097 if(v >= 255.0)
00098 pDstPixel[PL_RGBA_BLUE] = (PLBYTE) 255;
00099 if(h <= 0.0)
00100 pDstPixel[PL_RGBA_RED] = (PLBYTE) 0;
00101 if(s <= 0.0)
00102 pDstPixel[PL_RGBA_GREEN] = (PLBYTE) 0;
00103 if(v <= 0.0)
00104 pDstPixel[PL_RGBA_BLUE] = (PLBYTE) 0;
00105
00106 pSrcPixel += inc;
00107 pDstPixel += inc;
00108 }
00109 }
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158