Commit c097a32e authored by Martin Vignali's avatar Martin Vignali

avcodec/proresdec : rename dsp part for 10b and check dspinit for supported bits per raw sample

based on patch by Kieran Kunhya
parent a9709200
...@@ -48,6 +48,7 @@ static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[ ...@@ -48,6 +48,7 @@ static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[
static av_cold int decode_init(AVCodecContext *avctx) static av_cold int decode_init(AVCodecContext *avctx)
{ {
int ret = 0;
ProresContext *ctx = avctx->priv_data; ProresContext *ctx = avctx->priv_data;
uint8_t idct_permutation[64]; uint8_t idct_permutation[64];
...@@ -78,7 +79,11 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -78,7 +79,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
} }
ff_blockdsp_init(&ctx->bdsp, avctx); ff_blockdsp_init(&ctx->bdsp, avctx);
ff_proresdsp_init(&ctx->prodsp, avctx); ret = ff_proresdsp_init(&ctx->prodsp, avctx);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Fail to init proresdsp for bits per raw sample %d\n", avctx->bits_per_raw_sample);
return ret;
}
ff_init_scantable_permutation(idct_permutation, ff_init_scantable_permutation(idct_permutation,
ctx->prodsp.idct_permutation_type); ctx->prodsp.idct_permutation_type);
...@@ -86,7 +91,7 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -86,7 +91,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
permute(ctx->progressive_scan, ff_prores_progressive_scan, idct_permutation); permute(ctx->progressive_scan, ff_prores_progressive_scan, idct_permutation);
permute(ctx->interlaced_scan, ff_prores_interlaced_scan, idct_permutation); permute(ctx->interlaced_scan, ff_prores_interlaced_scan, idct_permutation);
return 0; return ret;
} }
static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
......
...@@ -27,15 +27,15 @@ ...@@ -27,15 +27,15 @@
#include "proresdsp.h" #include "proresdsp.h"
#include "simple_idct.h" #include "simple_idct.h"
#define CLIP_MIN (1 << (PRORES_BITS_PER_SAMPLE - 8)) ///< minimum value for clipping resulting pixels #define CLIP_MIN (1 << 2) ///< minimum value for clipping resulting pixels
#define CLIP_MAX (1 << PRORES_BITS_PER_SAMPLE) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels #define CLIP_MAX_10 (1 << 10) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels
#define CLIP(x) (av_clip((x), CLIP_MIN, CLIP_MAX)) #define CLIP_10(x) (av_clip((x), CLIP_MIN, CLIP_MAX_10))
/** /**
* Add bias value, clamp and output pixels of a slice * Add bias value, clamp and output pixels of a slice
*/ */
static void put_pixels(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) static void put_pixels_10(uint16_t *dst, ptrdiff_t linesize, const int16_t *in)
{ {
int x, y, src_offset, dst_offset; int x, y, src_offset, dst_offset;
...@@ -43,25 +43,30 @@ static void put_pixels(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) ...@@ -43,25 +43,30 @@ static void put_pixels(uint16_t *dst, ptrdiff_t linesize, const int16_t *in)
for (x = 0; x < 8; x++) { for (x = 0; x < 8; x++) {
src_offset = (y << 3) + x; src_offset = (y << 3) + x;
dst[dst_offset + x] = CLIP(in[src_offset]); dst[dst_offset + x] = CLIP_10(in[src_offset]);
} }
} }
} }
static void prores_idct_put_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat) static void prores_idct_put_10_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat)
{ {
ff_prores_idct(block, qmat); ff_prores_idct_10(block, qmat);
put_pixels(out, linesize >> 1, block); put_pixels_10(out, linesize >> 1, block);
} }
av_cold void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx) av_cold int ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx)
{ {
dsp->idct_put = prores_idct_put_c; if (avctx->bits_per_raw_sample == 10) {
dsp->idct_put = prores_idct_put_10_c;
dsp->idct_permutation_type = FF_IDCT_PERM_NONE; dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
} else {
return AVERROR_BUG;
}
if (ARCH_X86) if (ARCH_X86)
ff_proresdsp_init_x86(dsp, avctx); ff_proresdsp_init_x86(dsp, avctx);
ff_init_scantable_permutation(dsp->idct_permutation, ff_init_scantable_permutation(dsp->idct_permutation,
dsp->idct_permutation_type); dsp->idct_permutation_type);
return 0;
} }
...@@ -27,15 +27,13 @@ ...@@ -27,15 +27,13 @@
#include <stdint.h> #include <stdint.h>
#include "avcodec.h" #include "avcodec.h"
#define PRORES_BITS_PER_SAMPLE 10 ///< output precision of prores decoder
typedef struct ProresDSPContext { typedef struct ProresDSPContext {
int idct_permutation_type; int idct_permutation_type;
uint8_t idct_permutation[64]; uint8_t idct_permutation[64];
void (*idct_put)(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat); void (*idct_put)(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat);
} ProresDSPContext; } ProresDSPContext;
void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx); int ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx);
void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx); void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx);
......
...@@ -236,7 +236,7 @@ void ff_simple_idct44_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block) ...@@ -236,7 +236,7 @@ void ff_simple_idct44_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
} }
} }
void ff_prores_idct(int16_t *block, const int16_t *qmat) void ff_prores_idct_10(int16_t *block, const int16_t *qmat)
{ {
int i; int i;
......
...@@ -52,7 +52,7 @@ void ff_simple_idct_int16_12bit(int16_t *block); ...@@ -52,7 +52,7 @@ void ff_simple_idct_int16_12bit(int16_t *block);
* and scales by a factor of 2 more between the two IDCTs to account * and scales by a factor of 2 more between the two IDCTs to account
* for larger scale of input coefficients. * for larger scale of input coefficients.
*/ */
void ff_prores_idct(int16_t *block, const int16_t *qmat); void ff_prores_idct_10(int16_t *block, const int16_t *qmat);
void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block); void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block);
......
...@@ -73,7 +73,7 @@ static void ff_prores_idct_wrap(int16_t *dst){ ...@@ -73,7 +73,7 @@ static void ff_prores_idct_wrap(int16_t *dst){
for(i=0; i<64; i++){ for(i=0; i<64; i++){
qmat[i]=4; qmat[i]=4;
} }
ff_prores_idct(dst, qmat); ff_prores_idct_10(dst, qmat);
for(i=0; i<64; i++) { for(i=0; i<64; i++) {
dst[i] -= 512; dst[i] -= 512;
} }
......
...@@ -35,6 +35,7 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx) ...@@ -35,6 +35,7 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx)
#if ARCH_X86_64 #if ARCH_X86_64
int cpu_flags = av_get_cpu_flags(); int cpu_flags = av_get_cpu_flags();
if (avctx->bits_per_raw_sample == 10){
if (EXTERNAL_SSE2(cpu_flags)) { if (EXTERNAL_SSE2(cpu_flags)) {
dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE; dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE;
dsp->idct_put = ff_prores_idct_put_10_sse2; dsp->idct_put = ff_prores_idct_put_10_sse2;
...@@ -44,5 +45,6 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx) ...@@ -44,5 +45,6 @@ av_cold void ff_proresdsp_init_x86(ProresDSPContext *dsp, AVCodecContext *avctx)
dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE; dsp->idct_permutation_type = FF_IDCT_PERM_TRANSPOSE;
dsp->idct_put = ff_prores_idct_put_10_avx; dsp->idct_put = ff_prores_idct_put_10_avx;
} }
}
#endif /* ARCH_X86_64 */ #endif /* ARCH_X86_64 */
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment