author | erik <erik> | 2007-01-24 19:46:19 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:46:19 (UTC) |
commit | a017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (unidiff) | |
tree | 008be2b62ee5487dc55b8a7c7f043c94268f8362 /libopie2/opieui | |
parent | a4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff) | |
download | opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.zip opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.gz opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.bz2 |
Every file in this commit has a memory leak of some kind or another. I think
all of them are minor and should not effect properly running code. But if I
were you I would give libstocks and the stockticker plugin in Today a wide
berth. That library is atrocious.
-rw-r--r-- | libopie2/opieui/oimageeffect.cpp | 5 |
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) | |||
2006 | gray_value = intensityValue(data[x]); | 2006 | gray_value = intensityValue(data[x]); |
2007 | histogram[gray_value]++; | 2007 | histogram[gray_value]++; |
2008 | } | 2008 | } |
2009 | } | 2009 | } |
2010 | } | 2010 | } |
2011 | else{ // PsudeoClass | 2011 | else{ // PsudeoClass |
2012 | unsigned char *data; | 2012 | unsigned char *data; |
2013 | unsigned int *cTable = img.colorTable(); | 2013 | unsigned int *cTable = img.colorTable(); |
2014 | for(y=0; y < img.height(); ++y){ | 2014 | for(y=0; y < img.height(); ++y){ |
2015 | data = (unsigned char *)img.scanLine(y); | 2015 | data = (unsigned char *)img.scanLine(y); |
2016 | for(x=0; x < img.width(); ++x){ | 2016 | for(x=0; x < img.width(); ++x){ |
2017 | gray_value = intensityValue(*(cTable+data[x])); | 2017 | gray_value = intensityValue(*(cTable+data[x])); |
2018 | histogram[gray_value]++; | 2018 | histogram[gray_value]++; |
2019 | } | 2019 | } |
2020 | } | 2020 | } |
2021 | } | 2021 | } |
2022 | 2022 | ||
2023 | // find histogram boundaries by locating the 1 percent levels | 2023 | // find histogram boundaries by locating the 1 percent levels |
2024 | threshold_intensity = (img.width()*img.height())/100; | 2024 | threshold_intensity = (img.width()*img.height())/100; |
2025 | intense = 0; | 2025 | intense = 0; |
2026 | for(low=0; low < MaxRGB; ++low){ | 2026 | for(low=0; low < MaxRGB; ++low){ |
2027 | intense+=histogram[low]; | 2027 | intense+=histogram[low]; |
2028 | if(intense > threshold_intensity) | 2028 | if(intense > threshold_intensity) |
2029 | break; | 2029 | break; |
2030 | } | 2030 | } |
2031 | intense=0; | 2031 | intense=0; |
2032 | for(high=MaxRGB; high != 0; --high){ | 2032 | for(high=MaxRGB; high != 0; --high){ |
2033 | intense+=histogram[high]; | 2033 | intense+=histogram[high]; |
2034 | if(intense > threshold_intensity) | 2034 | if(intense > threshold_intensity) |
2035 | break; | 2035 | break; |
2036 | } | 2036 | } |
2037 | 2037 | ||
2038 | if (low == high){ | 2038 | if (low == high){ |
2039 | // Unreasonable contrast; use zero threshold to determine boundaries. | 2039 | // Unreasonable contrast; use zero threshold to determine boundaries. |
2040 | threshold_intensity=0; | 2040 | threshold_intensity=0; |
2041 | intense=0; | 2041 | intense=0; |
2042 | for(low=0; low < MaxRGB; ++low){ | 2042 | for(low=0; low < MaxRGB; ++low){ |
2043 | intense+=histogram[low]; | 2043 | intense+=histogram[low]; |
2044 | if(intense > threshold_intensity) | 2044 | if(intense > threshold_intensity) |
2045 | break; | 2045 | break; |
2046 | } | 2046 | } |
2047 | intense=0; | 2047 | intense=0; |
2048 | for(high=MaxRGB; high != 0; --high) | 2048 | for(high=MaxRGB; high != 0; --high) |
2049 | { | 2049 | { |
2050 | intense+=histogram[high]; | 2050 | intense+=histogram[high]; |
2051 | if(intense > threshold_intensity) | 2051 | if(intense > threshold_intensity) |
2052 | break; | 2052 | break; |
2053 | } | 2053 | } |
2054 | if(low == high) | 2054 | if(low == high) { |
2055 | free(histogram); | ||
2056 | free(normalize_map); | ||
2055 | return; // zero span bound | 2057 | return; // zero span bound |
2058 | } | ||
2056 | } | 2059 | } |
2057 | 2060 | ||
2058 | // Stretch the histogram to create the normalized image mapping. | 2061 | // Stretch the histogram to create the normalized image mapping. |
2059 | for(i=0; i <= MaxRGB; i++){ | 2062 | for(i=0; i <= MaxRGB; i++){ |
2060 | if (i < (int) low) | 2063 | if (i < (int) low) |
2061 | normalize_map[i]=0; | 2064 | normalize_map[i]=0; |
2062 | else{ | 2065 | else{ |
2063 | if(i > (int) high) | 2066 | if(i > (int) high) |
2064 | normalize_map[i]=MaxRGB; | 2067 | normalize_map[i]=MaxRGB; |
2065 | else | 2068 | else |
2066 | normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low); | 2069 | normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low); |
2067 | } | 2070 | } |
2068 | } | 2071 | } |
2069 | // Normalize | 2072 | // Normalize |
2070 | if(img.depth() > 8){ // DirectClass | 2073 | if(img.depth() > 8){ // DirectClass |
2071 | unsigned int *data; | 2074 | unsigned int *data; |
2072 | for(y=0; y < img.height(); ++y){ | 2075 | for(y=0; y < img.height(); ++y){ |
2073 | data = (unsigned int *)img.scanLine(y); | 2076 | data = (unsigned int *)img.scanLine(y); |
2074 | for(x=0; x < img.width(); ++x){ | 2077 | for(x=0; x < img.width(); ++x){ |
2075 | data[x] = qRgba(normalize_map[qRed(data[x])], | 2078 | data[x] = qRgba(normalize_map[qRed(data[x])], |
2076 | normalize_map[qGreen(data[x])], | 2079 | normalize_map[qGreen(data[x])], |
2077 | normalize_map[qBlue(data[x])], | 2080 | normalize_map[qBlue(data[x])], |
2078 | qAlpha(data[x])); | 2081 | qAlpha(data[x])); |
2079 | } | 2082 | } |
2080 | } | 2083 | } |
2081 | } | 2084 | } |
2082 | else{ // PsudeoClass | 2085 | else{ // PsudeoClass |
2083 | int colors = img.numColors(); | 2086 | int colors = img.numColors(); |
2084 | unsigned int *cTable = img.colorTable(); | 2087 | unsigned int *cTable = img.colorTable(); |
2085 | for(i=0; i < colors; ++i){ | 2088 | for(i=0; i < colors; ++i){ |
2086 | cTable[i] = qRgba(normalize_map[qRed(cTable[i])], | 2089 | cTable[i] = qRgba(normalize_map[qRed(cTable[i])], |
2087 | normalize_map[qGreen(cTable[i])], | 2090 | normalize_map[qGreen(cTable[i])], |
2088 | normalize_map[qBlue(cTable[i])], | 2091 | normalize_map[qBlue(cTable[i])], |
2089 | qAlpha(cTable[i])); | 2092 | qAlpha(cTable[i])); |
2090 | } | 2093 | } |
2091 | } | 2094 | } |
2092 | free(histogram); | 2095 | free(histogram); |
2093 | free(normalize_map); | 2096 | free(normalize_map); |
2094 | } | 2097 | } |
2095 | 2098 | ||
2096 | 2099 | ||
2097 | void OImageEffect::equalize(QImage &img) | 2100 | void OImageEffect::equalize(QImage &img) |
2098 | { | 2101 | { |
2099 | int *histogram, *map, *equalize_map; | 2102 | int *histogram, *map, *equalize_map; |
2100 | int x, y, i, j; | 2103 | int x, y, i, j; |
2101 | 2104 | ||
2102 | unsigned int high, low; | 2105 | unsigned int high, low; |
2103 | 2106 | ||