00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "plstdpch.h"
00012 #include "plfilterthreshold.h"
00013 #include "plbitmap.h"
00014
00015
00017
00019
00020
00021 PLFilterThreshold::PLFilterThreshold(int threshold_min,int threshold_max, int channel)
00022 : PLFilter(),
00023 m_threshold_min(threshold_min),
00024 m_threshold_max(threshold_max),
00025 m_channel(channel)
00026 {
00027 }
00028
00029 PLFilterThreshold::~PLFilterThreshold()
00030 {
00031
00032 }
00033
00034 void PLFilterThreshold::Apply(PLBmp * pBmpSource, PLBmp * pBmpDest) const
00035 {
00036
00037 int threshold_min = m_threshold_min;
00038 int threshold_max = m_threshold_max;
00039 int channel = m_channel;
00040
00041
00042 PLASSERT (pBmpSource->GetBitsPerPixel() == 32);
00043
00044 pBmpDest->Create (pBmpSource->GetWidth(), pBmpSource->GetHeight(), 8,
00045 false, pBmpSource->GetResolution());
00046 PLBYTE ** pSrcLines = pBmpSource->GetLineArray();
00047 PLBYTE ** pDstLines = pBmpDest->GetLineArray();
00048
00049 for (int y = 0; y<pBmpDest->GetHeight(); ++y)
00050 {
00051 PLBYTE * pSrcPixel = pSrcLines[y];
00052 PLBYTE * pDstPixel = pDstLines[y];
00053
00054 for (int x = 0; x < pBmpDest->GetWidth(); ++x)
00055 {
00056 if ((PLBYTE (pSrcPixel[channel]) <= PLBYTE (threshold_min)) ||
00057 (PLBYTE (pSrcPixel[channel]) >= PLBYTE(threshold_max)))
00058 *pDstPixel = 0;
00059 else
00060 *pDstPixel = pSrcPixel[channel];
00061 pSrcPixel += sizeof(PLPixel32);
00062 ++pDstPixel;
00063 }
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104