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 | |||
@@ -1958,194 +1958,197 @@ bool OImageEffect::blendOnLower( | |||
1958 | --i; --b; | 1958 | --i; --b; |
1959 | *b += ( ((*i - *b) * a) >> 8 ); | 1959 | *b += ( ((*i - *b) * a) >> 8 ); |
1960 | i -= 2; b -= 2; | 1960 | i -= 2; b -= 2; |
1961 | #endif | 1961 | #endif |
1962 | } while (k--); | 1962 | } while (k--); |
1963 | } | 1963 | } |
1964 | 1964 | ||
1965 | return true; | 1965 | return true; |
1966 | } | 1966 | } |
1967 | 1967 | ||
1968 | // For selected icons | 1968 | // For selected icons |
1969 | QImage& OImageEffect::selectedImage( QImage &img, const QColor &col ) | 1969 | QImage& OImageEffect::selectedImage( QImage &img, const QColor &col ) |
1970 | { | 1970 | { |
1971 | return blend( col, img, 0.5); | 1971 | return blend( col, img, 0.5); |
1972 | } | 1972 | } |
1973 | 1973 | ||
1974 | // | 1974 | // |
1975 | // =================================================================== | 1975 | // =================================================================== |
1976 | // Effects originally ported from ImageMagick for PixiePlus, plus a few | 1976 | // Effects originally ported from ImageMagick for PixiePlus, plus a few |
1977 | // new ones. (mosfet 12/29/01) | 1977 | // new ones. (mosfet 12/29/01) |
1978 | // =================================================================== | 1978 | // =================================================================== |
1979 | // | 1979 | // |
1980 | 1980 | ||
1981 | void OImageEffect::normalize(QImage &img) | 1981 | void OImageEffect::normalize(QImage &img) |
1982 | { | 1982 | { |
1983 | int *histogram, threshold_intensity, intense; | 1983 | int *histogram, threshold_intensity, intense; |
1984 | int x, y, i; | 1984 | int x, y, i; |
1985 | 1985 | ||
1986 | unsigned int gray_value; | 1986 | unsigned int gray_value; |
1987 | unsigned int *normalize_map; | 1987 | unsigned int *normalize_map; |
1988 | unsigned int high, low; | 1988 | unsigned int high, low; |
1989 | 1989 | ||
1990 | // allocate histogram and normalize map | 1990 | // allocate histogram and normalize map |
1991 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); | 1991 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); |
1992 | normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int)); | 1992 | normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int)); |
1993 | if(!normalize_map || !histogram){ | 1993 | if(!normalize_map || !histogram){ |
1994 | owarn << "Unable to allocate normalize histogram and map" << oendl; | 1994 | owarn << "Unable to allocate normalize histogram and map" << oendl; |
1995 | free(normalize_map); | 1995 | free(normalize_map); |
1996 | free(histogram); | 1996 | free(histogram); |
1997 | return; | 1997 | return; |
1998 | } | 1998 | } |
1999 | 1999 | ||
2000 | // form histogram | 2000 | // form histogram |
2001 | if(img.depth() > 8){ // DirectClass | 2001 | if(img.depth() > 8){ // DirectClass |
2002 | unsigned int *data; | 2002 | unsigned int *data; |
2003 | for(y=0; y < img.height(); ++y){ | 2003 | for(y=0; y < img.height(); ++y){ |
2004 | data = (unsigned int *)img.scanLine(y); | 2004 | data = (unsigned int *)img.scanLine(y); |
2005 | for(x=0; x < img.width(); ++x){ | 2005 | for(x=0; x < img.width(); ++x){ |
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 | ||
2104 | // allocate histogram and maps | 2107 | // allocate histogram and maps |
2105 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); | 2108 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); |
2106 | map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); | 2109 | map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); |
2107 | equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); | 2110 | equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); |
2108 | 2111 | ||
2109 | if(!histogram || !map || !equalize_map){ | 2112 | if(!histogram || !map || !equalize_map){ |
2110 | owarn << "Unable to allocate equalize histogram and maps" << oendl; | 2113 | owarn << "Unable to allocate equalize histogram and maps" << oendl; |
2111 | free(histogram); | 2114 | free(histogram); |
2112 | free(map); | 2115 | free(map); |
2113 | free(equalize_map); | 2116 | free(equalize_map); |
2114 | return; | 2117 | return; |
2115 | } | 2118 | } |
2116 | // form histogram | 2119 | // form histogram |
2117 | if(img.depth() > 8){ // DirectClass | 2120 | if(img.depth() > 8){ // DirectClass |
2118 | unsigned int *data; | 2121 | unsigned int *data; |
2119 | for(y=0; y < img.height(); ++y){ | 2122 | for(y=0; y < img.height(); ++y){ |
2120 | data = (unsigned int *)img.scanLine(y); | 2123 | data = (unsigned int *)img.scanLine(y); |
2121 | for(x=0; x < img.width(); ++x){ | 2124 | for(x=0; x < img.width(); ++x){ |
2122 | histogram[intensityValue(data[x])]++; | 2125 | histogram[intensityValue(data[x])]++; |
2123 | } | 2126 | } |
2124 | } | 2127 | } |
2125 | } | 2128 | } |
2126 | else{ // PsudeoClass | 2129 | else{ // PsudeoClass |
2127 | unsigned char *data; | 2130 | unsigned char *data; |
2128 | unsigned int *cTable = img.colorTable(); | 2131 | unsigned int *cTable = img.colorTable(); |
2129 | for(y=0; y < img.height(); ++y){ | 2132 | for(y=0; y < img.height(); ++y){ |
2130 | data = (unsigned char *)img.scanLine(y); | 2133 | data = (unsigned char *)img.scanLine(y); |
2131 | for(x=0; x < img.width(); ++x){ | 2134 | for(x=0; x < img.width(); ++x){ |
2132 | histogram[intensityValue(*(cTable+data[x]))]++; | 2135 | histogram[intensityValue(*(cTable+data[x]))]++; |
2133 | } | 2136 | } |
2134 | } | 2137 | } |
2135 | } | 2138 | } |
2136 | 2139 | ||
2137 | // integrate the histogram to get the equalization map. | 2140 | // integrate the histogram to get the equalization map. |
2138 | j=0; | 2141 | j=0; |
2139 | for(i=0; i <= MaxRGB; i++){ | 2142 | for(i=0; i <= MaxRGB; i++){ |
2140 | j+=histogram[i]; | 2143 | j+=histogram[i]; |
2141 | map[i]=j; | 2144 | map[i]=j; |
2142 | } | 2145 | } |
2143 | free(histogram); | 2146 | free(histogram); |
2144 | if(map[MaxRGB] == 0){ | 2147 | if(map[MaxRGB] == 0){ |
2145 | free(equalize_map); | 2148 | free(equalize_map); |
2146 | free(map); | 2149 | free(map); |
2147 | return; | 2150 | return; |
2148 | } | 2151 | } |
2149 | // equalize | 2152 | // equalize |
2150 | low=map[0]; | 2153 | low=map[0]; |
2151 | high=map[MaxRGB]; | 2154 | high=map[MaxRGB]; |