| 1948 | // |
| 1949 | |
| 1950 | static void wav2Encode( |
| 1951 | unsigned short *in, // io: values are transformed in place |
| 1952 | int nx, // i : x size |
| 1953 | int ox, // i : x offset |
| 1954 | int ny, // i : y size |
| 1955 | int oy, // i : y offset |
| 1956 | unsigned short mx) // i : maximum in[x][y] value |
| 1957 | { |
| 1958 | bool w14 = (mx < (1 << 14)); |
| 1959 | int n = (nx > ny) ? ny : nx; |
| 1960 | int p = 1; // == 1 << level |
| 1961 | int p2 = 2; // == 1 << (level+1) |
| 1962 | |
| 1963 | // |
| 1964 | // Hierarchical loop on smaller dimension n |
| 1965 | // |
| 1966 | |
| 1967 | while (p2 <= n) { |
| 1968 | unsigned short *py = in; |
| 1969 | unsigned short *ey = in + oy * (ny - p2); |
| 1970 | int oy1 = oy * p; |
| 1971 | int oy2 = oy * p2; |
| 1972 | int ox1 = ox * p; |
| 1973 | int ox2 = ox * p2; |
| 1974 | unsigned short i00, i01, i10, i11; |
| 1975 | |
| 1976 | // |
| 1977 | // Y loop |
| 1978 | // |
| 1979 | |
| 1980 | for (; py <= ey; py += oy2) { |
| 1981 | unsigned short *px = py; |
| 1982 | unsigned short *ex = py + ox * (nx - p2); |
| 1983 | |
| 1984 | // |
| 1985 | // X loop |
| 1986 | // |
| 1987 | |
| 1988 | for (; px <= ex; px += ox2) { |
| 1989 | unsigned short *p01 = px + ox1; |
| 1990 | unsigned short *p10 = px + oy1; |
| 1991 | unsigned short *p11 = p10 + ox1; |
| 1992 | |
| 1993 | // |
| 1994 | // 2D wavelet encoding |
| 1995 | // |
| 1996 | |
| 1997 | if (w14) { |
| 1998 | wenc14(*px, *p01, i00, i01); |
| 1999 | wenc14(*p10, *p11, i10, i11); |
| 2000 | wenc14(i00, i10, *px, *p10); |
| 2001 | wenc14(i01, i11, *p01, *p11); |
| 2002 | } else { |
| 2003 | wenc16(*px, *p01, i00, i01); |
| 2004 | wenc16(*p10, *p11, i10, i11); |
| 2005 | wenc16(i00, i10, *px, *p10); |
| 2006 | wenc16(i01, i11, *p01, *p11); |
| 2007 | } |
no test coverage detected