summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/oimageeffect.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/opieui/oimageeffect.cpp b/libopie2/opieui/oimageeffect.cpp
index be47eb2..93719bc 100644
--- a/libopie2/opieui/oimageeffect.cpp
+++ b/libopie2/opieui/oimageeffect.cpp
@@ -2006,98 +2006,101 @@ void OImageEffect::normalize(QImage &img)
gray_value = intensityValue(data[x]);
histogram[gray_value]++;
}
}
}
else{ // PsudeoClass
unsigned char *data;
unsigned int *cTable = img.colorTable();
for(y=0; y < img.height(); ++y){
data = (unsigned char *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
gray_value = intensityValue(*(cTable+data[x]));
histogram[gray_value]++;
}
}
}
// find histogram boundaries by locating the 1 percent levels
threshold_intensity = (img.width()*img.height())/100;
intense = 0;
for(low=0; low < MaxRGB; ++low){
intense+=histogram[low];
if(intense > threshold_intensity)
break;
}
intense=0;
for(high=MaxRGB; high != 0; --high){
intense+=histogram[high];
if(intense > threshold_intensity)
break;
}
if (low == high){
// Unreasonable contrast; use zero threshold to determine boundaries.
threshold_intensity=0;
intense=0;
for(low=0; low < MaxRGB; ++low){
intense+=histogram[low];
if(intense > threshold_intensity)
break;
}
intense=0;
for(high=MaxRGB; high != 0; --high)
{
intense+=histogram[high];
if(intense > threshold_intensity)
break;
}
- if(low == high)
+ if(low == high) {
+ free(histogram);
+ free(normalize_map);
return; // zero span bound
+ }
}
// Stretch the histogram to create the normalized image mapping.
for(i=0; i <= MaxRGB; i++){
if (i < (int) low)
normalize_map[i]=0;
else{
if(i > (int) high)
normalize_map[i]=MaxRGB;
else
normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low);
}
}
// Normalize
if(img.depth() > 8){ // DirectClass
unsigned int *data;
for(y=0; y < img.height(); ++y){
data = (unsigned int *)img.scanLine(y);
for(x=0; x < img.width(); ++x){
data[x] = qRgba(normalize_map[qRed(data[x])],
normalize_map[qGreen(data[x])],
normalize_map[qBlue(data[x])],
qAlpha(data[x]));
}
}
}
else{ // PsudeoClass
int colors = img.numColors();
unsigned int *cTable = img.colorTable();
for(i=0; i < colors; ++i){
cTable[i] = qRgba(normalize_map[qRed(cTable[i])],
normalize_map[qGreen(cTable[i])],
normalize_map[qBlue(cTable[i])],
qAlpha(cTable[i]));
}
}
free(histogram);
free(normalize_map);
}
void OImageEffect::equalize(QImage &img)
{
int *histogram, *map, *equalize_map;
int x, y, i, j;
unsigned int high, low;