| 1874 | // |
| 1875 | |
| 1876 | static void wav2Encode( |
| 1877 | unsigned short *in, // io: values are transformed in place |
| 1878 | int nx, // i : x size |
| 1879 | int ox, // i : x offset |
| 1880 | int ny, // i : y size |
| 1881 | int oy, // i : y offset |
| 1882 | unsigned short mx) // i : maximum in[x][y] value |
| 1883 | { |
| 1884 | bool w14 = (mx < (1 << 14)); |
| 1885 | int n = (nx > ny) ? ny : nx; |
| 1886 | int p = 1; // == 1 << level |
| 1887 | int p2 = 2; // == 1 << (level+1) |
| 1888 | |
| 1889 | // |
| 1890 | // Hierarchical loop on smaller dimension n |
| 1891 | // |
| 1892 | |
| 1893 | while (p2 <= n) { |
| 1894 | unsigned short *py = in; |
| 1895 | unsigned short *ey = in + oy * (ny - p2); |
| 1896 | int oy1 = oy * p; |
| 1897 | int oy2 = oy * p2; |
| 1898 | int ox1 = ox * p; |
| 1899 | int ox2 = ox * p2; |
| 1900 | unsigned short i00, i01, i10, i11; |
| 1901 | |
| 1902 | // |
| 1903 | // Y loop |
| 1904 | // |
| 1905 | |
| 1906 | for (; py <= ey; py += oy2) { |
| 1907 | unsigned short *px = py; |
| 1908 | unsigned short *ex = py + ox * (nx - p2); |
| 1909 | |
| 1910 | // |
| 1911 | // X loop |
| 1912 | // |
| 1913 | |
| 1914 | for (; px <= ex; px += ox2) { |
| 1915 | unsigned short *p01 = px + ox1; |
| 1916 | unsigned short *p10 = px + oy1; |
| 1917 | unsigned short *p11 = p10 + ox1; |
| 1918 | |
| 1919 | // |
| 1920 | // 2D wavelet encoding |
| 1921 | // |
| 1922 | |
| 1923 | if (w14) { |
| 1924 | wenc14(*px, *p01, i00, i01); |
| 1925 | wenc14(*p10, *p11, i10, i11); |
| 1926 | wenc14(i00, i10, *px, *p10); |
| 1927 | wenc14(i01, i11, *p01, *p11); |
| 1928 | } else { |
| 1929 | wenc16(*px, *p01, i00, i01); |
| 1930 | wenc16(*p10, *p11, i10, i11); |
| 1931 | wenc16(i00, i10, *px, *p10); |
| 1932 | wenc16(i01, i11, *p01, *p11); |
| 1933 | } |
no test coverage detected