#include #include #include #include "GFilter.h" /* GFilter is an abstract decendant of GImage. Derivatives of this class can * be used to filter an image in some way (scale, rotate, etc). * * Written by: Chris Studholme * Last Update: 25-May-2000 * Copyright: GPL (http://www.fsf.org/copyleft/gpl.html) */ inline short boundcheck(int x) { if (x<-32768) return -32768; if (x>32767) return 32767; return x; } /* ================ GFilter_GammaCorrection methods ================ */ inline void GammaCorrect(short& red, short& green, short& blue, short* table) { red = *(short*)(((char*)table)+(red&0xFFFE)); green = *(short*)(((char*)table)+(green&0xFFFE)); blue = *(short*)(((char*)table)+(blue&0xFFFE)); } void GFilter_GammaCorrection::setGammaCorrection(float gamma) { // create table if (table) delete[] table; table = new short[32768]; // fill table float offset = (1-gamma)*log(range); for (int i=-32768; i<32768; ++i) { short e; if ((i<=min)||(i>=min+range)) e=i; else e=min+(int)exp((log(i-min)-offset)/gamma); *(short*)(((char*)table)+(i&0xFFFE))=e; } } void GFilter_GammaCorrection::getPixel(short& red, short& green, short& blue, float x1, float y1, float x2, float y2) { src.getPixel(red,green,blue,x1,y1,x2,y2); GammaCorrect(red,green,blue,table); } void GFilter_GammaCorrection::getScanLineHorz(short* red, short* green, short* blue, float x1, float y1, float x2, float y2, int npixels) { src.getScanLineHorz(red,green,blue,x1,y1,x2,y2,npixels); for (int i=0; i