| 2018 | // |
| 2019 | |
| 2020 | static void wav2Encode( |
| 2021 | unsigned short *in, // io: values are transformed in place |
| 2022 | int nx, // i : x size |
| 2023 | int ox, // i : x offset |
| 2024 | int ny, // i : y size |
| 2025 | int oy, // i : y offset |
| 2026 | unsigned short mx) // i : maximum in[x][y] value |
| 2027 | { |
| 2028 | bool w14 = (mx < (1 << 14)); |
| 2029 | int n = (nx > ny) ? ny : nx; |
| 2030 | int p = 1; // == 1 << level |
| 2031 | int p2 = 2; // == 1 << (level+1) |
| 2032 | |
| 2033 | // |
| 2034 | // Hierarchical loop on smaller dimension n |
| 2035 | // |
| 2036 | |
| 2037 | while (p2 <= n) { |
| 2038 | unsigned short *py = in; |
| 2039 | unsigned short *ey = in + oy * (ny - p2); |
| 2040 | int oy1 = oy * p; |
| 2041 | int oy2 = oy * p2; |
| 2042 | int ox1 = ox * p; |
| 2043 | int ox2 = ox * p2; |
| 2044 | unsigned short i00, i01, i10, i11; |
| 2045 | |
| 2046 | // |
| 2047 | // Y loop |
| 2048 | // |
| 2049 | |
| 2050 | for (; py <= ey; py += oy2) { |
| 2051 | unsigned short *px = py; |
| 2052 | unsigned short *ex = py + ox * (nx - p2); |
| 2053 | |
| 2054 | // |
| 2055 | // X loop |
| 2056 | // |
| 2057 | |
| 2058 | for (; px <= ex; px += ox2) { |
| 2059 | unsigned short *p01 = px + ox1; |
| 2060 | unsigned short *p10 = px + oy1; |
| 2061 | unsigned short *p11 = p10 + ox1; |
| 2062 | |
| 2063 | // |
| 2064 | // 2D wavelet encoding |
| 2065 | // |
| 2066 | |
| 2067 | if (w14) { |
| 2068 | wenc14(*px, *p01, i00, i01); |
| 2069 | wenc14(*p10, *p11, i10, i11); |
| 2070 | wenc14(i00, i10, *px, *p10); |
| 2071 | wenc14(i01, i11, *p01, *p11); |
| 2072 | } else { |
| 2073 | wenc16(*px, *p01, i00, i01); |
| 2074 | wenc16(*p10, *p11, i10, i11); |
| 2075 | wenc16(i00, i10, *px, *p10); |
| 2076 | wenc16(i01, i11, *p01, *p11); |
| 2077 | } |
no test coverage detected