| 1843 | } |
| 1844 | |
| 1845 | static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ |
| 1846 | int level, orientation, ys, xs, x, y, pass; |
| 1847 | IDWTELEM best_dequant[height * stride]; |
| 1848 | IDWTELEM idwt2_buffer[height * stride]; |
| 1849 | const int score_stride= (width + 10)/Q2_STEP; |
| 1850 | int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size |
| 1851 | int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size |
| 1852 | int threshold= (s->m.lambda * s->m.lambda) >> 6; |
| 1853 | |
| 1854 | //FIXME pass the copy cleanly ? |
| 1855 | |
| 1856 | // memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); |
| 1857 | ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); |
| 1858 | |
| 1859 | for(level=0; level<s->spatial_decomposition_count; level++){ |
| 1860 | for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
| 1861 | SubBand *b= &p->band[level][orientation]; |
| 1862 | IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
| 1863 | DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); |
| 1864 | assert(src == b->buf); // code does not depend on this but it is true currently |
| 1865 | |
| 1866 | quantize(s, b, dst, src, b->stride, s->qbias); |
| 1867 | } |
| 1868 | } |
| 1869 | for(pass=0; pass<1; pass++){ |
| 1870 | if(s->qbias == 0) //keyframe |
| 1871 | continue; |
| 1872 | for(level=0; level<s->spatial_decomposition_count; level++){ |
| 1873 | for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
| 1874 | SubBand *b= &p->band[level][orientation]; |
| 1875 | IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); |
| 1876 | IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
| 1877 | |
| 1878 | for(ys= 0; ys<Q2_STEP; ys++){ |
| 1879 | for(xs= 0; xs<Q2_STEP; xs++){ |
| 1880 | memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
| 1881 | dequantize_all(s, p, idwt2_buffer, width, height); |
| 1882 | ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); |
| 1883 | find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
| 1884 | memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
| 1885 | for(y=ys; y<b->height; y+= Q2_STEP){ |
| 1886 | for(x=xs; x<b->width; x+= Q2_STEP){ |
| 1887 | if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; |
| 1888 | if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; |
| 1889 | //FIXME try more than just -- |
| 1890 | } |
| 1891 | } |
| 1892 | dequantize_all(s, p, idwt2_buffer, width, height); |
| 1893 | ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); |
| 1894 | find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
| 1895 | for(y=ys; y<b->height; y+= Q2_STEP){ |
| 1896 | for(x=xs; x<b->width; x+= Q2_STEP){ |
| 1897 | int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; |
| 1898 | if(score[score_idx] <= best_score[score_idx] + threshold){ |
| 1899 | best_score[score_idx]= score[score_idx]; |
| 1900 | if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; |
| 1901 | if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; |
| 1902 | //FIXME copy instead |
nothing calls this directly
no test coverage detected