1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
/*
* Modification History
*
* 2000-December-21 Jason Rohrer
* Created.
*/
#ifndef THRESHOLD_FILTER_INCLUDED
#define THRESHOLD_FILTER_INCLUDED
#include "minorGems/graphics/ChannelFilter.h"
/**
* Threshold filter.
*
* @author Jason Rohrer
*/
class ThresholdFilter : public ChannelFilter {
public:
/**
* Constructs a threshold filter.
*
* @param inThreshold threshold value. Channel values
* above or equal to inThreshold are set to 1, while
* all other values are set to 0.
*/
ThresholdFilter( double inThreshold );
/**
* Sets the threshold.
*
* @param inThreshold threshold value. Channel values
* above or equal to inThreshold are set to 1, while
* all other values are set to 0.
*/
void setThreshold( double inThreshold );
// implements the ChannelFilter interface
void apply( double *inChannel, int inWidth, int inHeight );
private:
double mThreshold;
};
inline ThresholdFilter::ThresholdFilter( double inThreshold )
: mThreshold( inThreshold ) {
}
inline void ThresholdFilter::setThreshold( double inThreshold ) {
mThreshold = inThreshold;
}
inline void ThresholdFilter::apply( double *inChannel,
int inWidth, int inHeight ) {
int numPixels = inWidth * inHeight;
for( int i=0; i<numPixels; i++ ) {
if( inChannel[i] >= mThreshold ) {
inChannel[i] = 1.0;
}
else {
inChannel[i] = 0.0;
}
}
}
#endif
|