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 | |||
@@ -1862,386 +1862,389 @@ bool OImageEffect::blend( | |||
1862 | // output.setAlphaBuffer(true); // I should do some benchmarks to see if | 1862 | // output.setAlphaBuffer(true); // I should do some benchmarks to see if |
1863 | // this is worth the effort | 1863 | // this is worth the effort |
1864 | 1864 | ||
1865 | register QRgb *i, *o, *b; | 1865 | register QRgb *i, *o, *b; |
1866 | 1866 | ||
1867 | register int a; | 1867 | register int a; |
1868 | register int j,k; | 1868 | register int j,k; |
1869 | for (j=0; j<ch; j++) | 1869 | for (j=0; j<ch; j++) |
1870 | { | 1870 | { |
1871 | b=reinterpret_cast<QRgb *>(&lower.scanLine(y+j) [ (x+cw) << 2 ]); | 1871 | b=reinterpret_cast<QRgb *>(&lower.scanLine(y+j) [ (x+cw) << 2 ]); |
1872 | i=reinterpret_cast<QRgb *>(&upper.scanLine(cy+j)[ (cx+cw) << 2 ]); | 1872 | i=reinterpret_cast<QRgb *>(&upper.scanLine(cy+j)[ (cx+cw) << 2 ]); |
1873 | o=reinterpret_cast<QRgb *>(&output.scanLine(j) [ cw << 2 ]); | 1873 | o=reinterpret_cast<QRgb *>(&output.scanLine(j) [ cw << 2 ]); |
1874 | 1874 | ||
1875 | k=cw-1; | 1875 | k=cw-1; |
1876 | --b; --i; --o; | 1876 | --b; --i; --o; |
1877 | do | 1877 | do |
1878 | { | 1878 | { |
1879 | while ( !(a=qAlpha(*i)) && k>0 ) | 1879 | while ( !(a=qAlpha(*i)) && k>0 ) |
1880 | { | 1880 | { |
1881 | i--; | 1881 | i--; |
1882 | //*o=0; | 1882 | //*o=0; |
1883 | *o=*b; | 1883 | *o=*b; |
1884 | --o; --b; | 1884 | --o; --b; |
1885 | k--; | 1885 | k--; |
1886 | }; | 1886 | }; |
1887 | // *o=0xFF; | 1887 | // *o=0xFF; |
1888 | *o = qRgb(qRed(*b) + (((qRed(*i) - qRed(*b)) * a) >> 8), | 1888 | *o = qRgb(qRed(*b) + (((qRed(*i) - qRed(*b)) * a) >> 8), |
1889 | qGreen(*b) + (((qGreen(*i) - qGreen(*b)) * a) >> 8), | 1889 | qGreen(*b) + (((qGreen(*i) - qGreen(*b)) * a) >> 8), |
1890 | qBlue(*b) + (((qBlue(*i) - qBlue(*b)) * a) >> 8)); | 1890 | qBlue(*b) + (((qBlue(*i) - qBlue(*b)) * a) >> 8)); |
1891 | --i; --o; --b; | 1891 | --i; --o; --b; |
1892 | } while (k--); | 1892 | } while (k--); |
1893 | } | 1893 | } |
1894 | 1894 | ||
1895 | return true; | 1895 | return true; |
1896 | } | 1896 | } |
1897 | 1897 | ||
1898 | bool OImageEffect::blendOnLower( | 1898 | bool OImageEffect::blendOnLower( |
1899 | int x, int y, | 1899 | int x, int y, |
1900 | const QImage & upper, | 1900 | const QImage & upper, |
1901 | const QImage & lower | 1901 | const QImage & lower |
1902 | ) | 1902 | ) |
1903 | { | 1903 | { |
1904 | int cx=0, cy=0, cw=upper.width(), ch=upper.height(); | 1904 | int cx=0, cy=0, cw=upper.width(), ch=upper.height(); |
1905 | 1905 | ||
1906 | if ( upper.depth() != 32 || lower.depth() != 32 ) return false; | 1906 | if ( upper.depth() != 32 || lower.depth() != 32 ) return false; |
1907 | if ( x + cw > lower.width() || | 1907 | if ( x + cw > lower.width() || |
1908 | y + ch > lower.height() || | 1908 | y + ch > lower.height() || |
1909 | x < 0 || y < 0 ) | 1909 | x < 0 || y < 0 ) |
1910 | { | 1910 | { |
1911 | if ( x > lower.width() || y > lower.height() ) return true; | 1911 | if ( x > lower.width() || y > lower.height() ) return true; |
1912 | if ( upper.width()<=0 || upper.height() <= 0 ) return true; | 1912 | if ( upper.width()<=0 || upper.height() <= 0 ) return true; |
1913 | if ( lower.width()<=0 || lower.height() <= 0 ) return true; | 1913 | if ( lower.width()<=0 || lower.height() <= 0 ) return true; |
1914 | 1914 | ||
1915 | if (x<0) {cx=-x; cw+=x; x=0; }; | 1915 | if (x<0) {cx=-x; cw+=x; x=0; }; |
1916 | if (cw + x > lower.width()) { cw=lower.width()-x; }; | 1916 | if (cw + x > lower.width()) { cw=lower.width()-x; }; |
1917 | if (y<0) {cy=-y; ch+=y; y=0; }; | 1917 | if (y<0) {cy=-y; ch+=y; y=0; }; |
1918 | if (ch + y > lower.height()) { ch=lower.height()-y; }; | 1918 | if (ch + y > lower.height()) { ch=lower.height()-y; }; |
1919 | 1919 | ||
1920 | if ( cx >= upper.width() || cy >= upper.height() ) return true; | 1920 | if ( cx >= upper.width() || cy >= upper.height() ) return true; |
1921 | if ( cw <= 0 || ch <= 0 ) return true; | 1921 | if ( cw <= 0 || ch <= 0 ) return true; |
1922 | } | 1922 | } |
1923 | 1923 | ||
1924 | register uchar *i, *b; | 1924 | register uchar *i, *b; |
1925 | register int a; | 1925 | register int a; |
1926 | register int k; | 1926 | register int k; |
1927 | 1927 | ||
1928 | for (int j=0; j<ch; j++) | 1928 | for (int j=0; j<ch; j++) |
1929 | { | 1929 | { |
1930 | b=&lower.scanLine(y+j) [ (x+cw) << 2 ]; | 1930 | b=&lower.scanLine(y+j) [ (x+cw) << 2 ]; |
1931 | i=&upper.scanLine(cy+j)[ (cx+cw) << 2 ]; | 1931 | i=&upper.scanLine(cy+j)[ (cx+cw) << 2 ]; |
1932 | 1932 | ||
1933 | k=cw-1; | 1933 | k=cw-1; |
1934 | --b; --i; | 1934 | --b; --i; |
1935 | do | 1935 | do |
1936 | { | 1936 | { |
1937 | #ifndef WORDS_BIGENDIAN | 1937 | #ifndef WORDS_BIGENDIAN |
1938 | while ( !(a=*i) && k>0 ) | 1938 | while ( !(a=*i) && k>0 ) |
1939 | #else | 1939 | #else |
1940 | while ( !(a=*(i-3)) && k>0 ) | 1940 | while ( !(a=*(i-3)) && k>0 ) |
1941 | #endif | 1941 | #endif |
1942 | { | 1942 | { |
1943 | i-=4; b-=4; k--; | 1943 | i-=4; b-=4; k--; |
1944 | }; | 1944 | }; |
1945 | 1945 | ||
1946 | #ifndef WORDS_BIGENDIAN | 1946 | #ifndef WORDS_BIGENDIAN |
1947 | --i; --b; | 1947 | --i; --b; |
1948 | *b += ( ((*i - *b) * a) >> 8 ); | 1948 | *b += ( ((*i - *b) * a) >> 8 ); |
1949 | --i; --b; | 1949 | --i; --b; |
1950 | *b += ( ((*i - *b) * a) >> 8 ); | 1950 | *b += ( ((*i - *b) * a) >> 8 ); |
1951 | --i; --b; | 1951 | --i; --b; |
1952 | *b += ( ((*i - *b) * a) >> 8 ); | 1952 | *b += ( ((*i - *b) * a) >> 8 ); |
1953 | --i; --b; | 1953 | --i; --b; |
1954 | #else | 1954 | #else |
1955 | *b += ( ((*i - *b) * a) >> 8 ); | 1955 | *b += ( ((*i - *b) * a) >> 8 ); |
1956 | --i; --b; | 1956 | --i; --b; |
1957 | *b += ( ((*i - *b) * a) >> 8 ); | 1957 | *b += ( ((*i - *b) * a) >> 8 ); |
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]; |
2152 | for(i=0; i <= MaxRGB; i++) | 2155 | for(i=0; i <= MaxRGB; i++) |
2153 | equalize_map[i]=(unsigned int) | 2156 | equalize_map[i]=(unsigned int) |
2154 | ((((double) (map[i]-low))*MaxRGB)/QMAX(high-low,1)); | 2157 | ((((double) (map[i]-low))*MaxRGB)/QMAX(high-low,1)); |
2155 | free(map); | 2158 | free(map); |
2156 | // stretch the histogram | 2159 | // stretch the histogram |
2157 | if(img.depth() > 8){ // DirectClass | 2160 | if(img.depth() > 8){ // DirectClass |
2158 | unsigned int *data; | 2161 | unsigned int *data; |
2159 | for(y=0; y < img.height(); ++y){ | 2162 | for(y=0; y < img.height(); ++y){ |
2160 | data = (unsigned int *)img.scanLine(y); | 2163 | data = (unsigned int *)img.scanLine(y); |
2161 | for(x=0; x < img.width(); ++x){ | 2164 | for(x=0; x < img.width(); ++x){ |
2162 | data[x] = qRgba(equalize_map[qRed(data[x])], | 2165 | data[x] = qRgba(equalize_map[qRed(data[x])], |
2163 | equalize_map[qGreen(data[x])], | 2166 | equalize_map[qGreen(data[x])], |
2164 | equalize_map[qBlue(data[x])], | 2167 | equalize_map[qBlue(data[x])], |
2165 | qAlpha(data[x])); | 2168 | qAlpha(data[x])); |
2166 | } | 2169 | } |
2167 | } | 2170 | } |
2168 | } | 2171 | } |
2169 | else{ // PsudeoClass | 2172 | else{ // PsudeoClass |
2170 | int colors = img.numColors(); | 2173 | int colors = img.numColors(); |
2171 | unsigned int *cTable = img.colorTable(); | 2174 | unsigned int *cTable = img.colorTable(); |
2172 | for(i=0; i < colors; ++i){ | 2175 | for(i=0; i < colors; ++i){ |
2173 | cTable[i] = qRgba(equalize_map[qRed(cTable[i])], | 2176 | cTable[i] = qRgba(equalize_map[qRed(cTable[i])], |
2174 | equalize_map[qGreen(cTable[i])], | 2177 | equalize_map[qGreen(cTable[i])], |
2175 | equalize_map[qBlue(cTable[i])], | 2178 | equalize_map[qBlue(cTable[i])], |
2176 | qAlpha(cTable[i])); | 2179 | qAlpha(cTable[i])); |
2177 | } | 2180 | } |
2178 | } | 2181 | } |
2179 | free(equalize_map); | 2182 | free(equalize_map); |
2180 | } | 2183 | } |
2181 | 2184 | ||
2182 | QImage OImageEffect::sample(QImage &src, int w, int h) | 2185 | QImage OImageEffect::sample(QImage &src, int w, int h) |
2183 | { | 2186 | { |
2184 | if(w == src.width() && h == src.height()) | 2187 | if(w == src.width() && h == src.height()) |
2185 | return(src); | 2188 | return(src); |
2186 | 2189 | ||
2187 | double *x_offset, *y_offset; | 2190 | double *x_offset, *y_offset; |
2188 | int j, k, y; | 2191 | int j, k, y; |
2189 | register int x; | 2192 | register int x; |
2190 | QImage dest(w, h, src.depth()); | 2193 | QImage dest(w, h, src.depth()); |
2191 | 2194 | ||
2192 | x_offset = (double *)malloc(w*sizeof(double)); | 2195 | x_offset = (double *)malloc(w*sizeof(double)); |
2193 | y_offset = (double *)malloc(h*sizeof(double)); | 2196 | y_offset = (double *)malloc(h*sizeof(double)); |
2194 | if(!x_offset || !y_offset){ | 2197 | if(!x_offset || !y_offset){ |
2195 | owarn << "Unable to allocate pixels buffer" << oendl; | 2198 | owarn << "Unable to allocate pixels buffer" << oendl; |
2196 | free(x_offset); | 2199 | free(x_offset); |
2197 | free(y_offset); | 2200 | free(y_offset); |
2198 | return(src); | 2201 | return(src); |
2199 | } | 2202 | } |
2200 | 2203 | ||
2201 | // init pixel offsets | 2204 | // init pixel offsets |
2202 | for(x=0; x < w; ++x) | 2205 | for(x=0; x < w; ++x) |
2203 | x_offset[x] = x*src.width()/((double)w); | 2206 | x_offset[x] = x*src.width()/((double)w); |
2204 | for(y=0; y < h; ++y) | 2207 | for(y=0; y < h; ++y) |
2205 | y_offset[y] = y*src.height()/((double)h); | 2208 | y_offset[y] = y*src.height()/((double)h); |
2206 | 2209 | ||
2207 | // sample each row | 2210 | // sample each row |
2208 | if(src.depth() > 8){ // DirectClass source image | 2211 | if(src.depth() > 8){ // DirectClass source image |
2209 | unsigned int *srcData, *destData; | 2212 | unsigned int *srcData, *destData; |
2210 | unsigned int *pixels; | 2213 | unsigned int *pixels; |
2211 | pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int)); | 2214 | pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int)); |
2212 | if(!pixels){ | 2215 | if(!pixels){ |
2213 | owarn << "Unable to allocate pixels buffer" << oendl; | 2216 | owarn << "Unable to allocate pixels buffer" << oendl; |
2214 | free(pixels); | 2217 | free(pixels); |
2215 | free(x_offset); | 2218 | free(x_offset); |
2216 | free(y_offset); | 2219 | free(y_offset); |
2217 | return(src); | 2220 | return(src); |
2218 | } | 2221 | } |
2219 | j = (-1); | 2222 | j = (-1); |
2220 | for(y=0; y < h; ++y){ | 2223 | for(y=0; y < h; ++y){ |
2221 | destData = (unsigned int *)dest.scanLine(y); | 2224 | destData = (unsigned int *)dest.scanLine(y); |
2222 | if(j != y_offset[y]){ | 2225 | if(j != y_offset[y]){ |
2223 | // read a scan line | 2226 | // read a scan line |
2224 | j = (int)(y_offset[y]); | 2227 | j = (int)(y_offset[y]); |
2225 | srcData = (unsigned int *)src.scanLine(j); | 2228 | srcData = (unsigned int *)src.scanLine(j); |
2226 | (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned int)); | 2229 | (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned int)); |
2227 | } | 2230 | } |
2228 | // sample each column | 2231 | // sample each column |
2229 | for(x=0; x < w; ++x){ | 2232 | for(x=0; x < w; ++x){ |
2230 | k = (int)(x_offset[x]); | 2233 | k = (int)(x_offset[x]); |
2231 | destData[x] = pixels[k]; | 2234 | destData[x] = pixels[k]; |
2232 | } | 2235 | } |
2233 | } | 2236 | } |
2234 | free(pixels); | 2237 | free(pixels); |
2235 | } | 2238 | } |
2236 | else{ // PsudeoClass source image | 2239 | else{ // PsudeoClass source image |
2237 | unsigned char *srcData, *destData; | 2240 | unsigned char *srcData, *destData; |
2238 | unsigned char *pixels; | 2241 | unsigned char *pixels; |
2239 | pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char)); | 2242 | pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char)); |
2240 | if(!pixels){ | 2243 | if(!pixels){ |
2241 | owarn << "Unable to allocate pixels buffer" << oendl; | 2244 | owarn << "Unable to allocate pixels buffer" << oendl; |
2242 | free(pixels); | 2245 | free(pixels); |
2243 | free(x_offset); | 2246 | free(x_offset); |
2244 | free(y_offset); | 2247 | free(y_offset); |
2245 | return(src); | 2248 | return(src); |
2246 | } | 2249 | } |
2247 | // copy colortable | 2250 | // copy colortable |