Unified · Split
| @@ -34,6 +34,9 @@ typedef struct AVTXWrapper { · 33 unmodified lines | ||
| 34 | 34 | ptrdiff_t stride; |
| 35 | 35 | int len; |
| 36 | 36 | int inv; |
| 37 | + | |
| 38 | + float *tmp; | |
| 39 | + int out_of_place; | |
| 37 | 40 | } AVTXWrapper; |
| 38 | 41 | |
| 39 | 42 | /* FFT */ |
| @@ -179,29 +182,66 @@ av_cold void av_rdft_end(RDFTContext *s) · 139 unmodified lines | ||
| 179 | 182 | } |
| 180 | 183 | } |
| 181 | 184 | |
| 182 | −#if CONFIG_DCT | |
| 183 | − | |
| 184 | 185 | DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse) |
| 185 | 186 | { |
| 186 | − DCTContext *s = av_malloc(sizeof(*s)); | |
| 187 | + int ret; | |
| 188 | + const float scale_map[] = { | |
| 189 | + [DCT_II] = 0.5f, | |
| 190 | + [DCT_III] = 1.0f / (1 << nbits), | |
| 191 | + [DCT_I] = 0.5f, | |
| 192 | + [DST_I] = 2.0f, | |
| 193 | + }; | |
| 194 | + static const enum AVTXType type_map[] = { | |
| 195 | + [DCT_II] = AV_TX_FLOAT_DCT, | |
| 196 | + [DCT_III] = AV_TX_FLOAT_DCT, | |
| 197 | + [DCT_I] = AV_TX_FLOAT_DCT_I, | |
| 198 | + [DST_I] = AV_TX_FLOAT_DST_I, | |
| 199 | + }; | |
| 200 | + | |
| 201 | + AVTXWrapper *s = av_malloc(sizeof(*s)); | |
| 202 | + if (!s) | |
| 203 | + return NULL; | |
| 187 | 204 | |
| 188 | − if (s && ff_dct_init(s, nbits, inverse)) | |
| 189 | − av_freep(&s); | |
| 205 | + s->len = (1 << nbits); | |
| 206 | + s->out_of_place = (inverse == DCT_I) || (inverse == DST_I); | |
| 190 | 207 | |
| 191 | − return s; | |
| 208 | + ret = av_tx_init(&s->ctx, &s->fn, type_map[inverse], | |
| 209 | + (inverse == DCT_III), 1 << (nbits - (inverse == DCT_III)), | |
| 210 | + &scale_map[inverse], s->out_of_place ? 0 : AV_TX_INPLACE); | |
| 211 | + if (ret < 0) { | |
| 212 | + av_free(s); | |
| 213 | + return NULL; | |
| 214 | + } | |
| 215 | + | |
| 216 | + if (s->out_of_place) { | |
| 217 | + s->tmp = av_malloc((1 << (nbits + 1))*sizeof(float)); | |
| 218 | + if (!s->tmp) { | |
| 219 | + av_tx_uninit(&s->ctx); | |
| 220 | + av_free(s); | |
| 221 | + return NULL; | |
| 222 | + } | |
| 223 | + } | |
| 224 | + | |
| 225 | + return (DCTContext *)s; | |
| 192 | 226 | } |
| 193 | 227 | |
| 194 | 228 | void av_dct_calc(DCTContext *s, FFTSample *data) |
| 195 | 229 | { |
| 196 | − s->dct_calc(s, data); | |
| 230 | + AVTXWrapper *w = (AVTXWrapper *)s; | |
| 231 | + if (w->out_of_place) { | |
| 232 | + memcpy(w->tmp, data, w->len*sizeof(float)); | |
| 233 | + w->fn(w->ctx, (void *)data, w->tmp, sizeof(float)); | |
| 234 | + } else { | |
| 235 | + w->fn(w->ctx, data, (void *)data, sizeof(float)); | |
| 236 | + } | |
| 197 | 237 | } |
| 198 | 238 | |
| 199 | 239 | av_cold void av_dct_end(DCTContext *s) |
| 200 | 240 | { |
| 201 | 241 | if (s) { |
| 202 | − ff_dct_end(s); | |
| 203 | − av_free(s); | |
| 242 | + AVTXWrapper *w = (AVTXWrapper *)s; | |
| 243 | + av_tx_uninit(&w->ctx); | |
| 244 | + av_free(w->tmp); | |
| 245 | + av_free(w); | |
| 204 | 246 | } |
| 205 | 247 | } |
| 206 | − | |
| 207 | −#endif /* CONFIG_DCT */ | |