Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>tags/n3.2
| @@ -144,7 +144,11 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) | |||
| fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * | |||
| sizeof(*fs->sample_buffer)); | |||
| if (!fs->sample_buffer) { | |||
| fs->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * | |||
| sizeof(*fs->sample_buffer32)); | |||
| if (!fs->sample_buffer || !fs->sample_buffer32) { | |||
| av_freep(&fs->sample_buffer); | |||
| av_freep(&fs->sample_buffer32); | |||
| av_freep(&f->slice_context[i]); | |||
| goto memfail; | |||
| } | |||
| @@ -154,6 +158,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) | |||
| memfail: | |||
| while(--i >= 0) { | |||
| av_freep(&f->slice_context[i]->sample_buffer); | |||
| av_freep(&f->slice_context[i]->sample_buffer32); | |||
| av_freep(&f->slice_context[i]); | |||
| } | |||
| return AVERROR(ENOMEM); | |||
| @@ -224,6 +229,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) | |||
| av_freep(&p->vlc_state); | |||
| } | |||
| av_freep(&fs->sample_buffer); | |||
| av_freep(&fs->sample_buffer32); | |||
| } | |||
| av_freep(&avctx->stats_out); | |||
| @@ -109,6 +109,9 @@ typedef struct FFV1Context { | |||
| int run_index; | |||
| int colorspace; | |||
| int16_t *sample_buffer; | |||
| int32_t *sample_buffer32; | |||
| int use32bit; | |||
| int ec; | |||
| int intra; | |||
| @@ -198,4 +201,10 @@ static inline void update_vlc_state(VlcState *const state, const int v) | |||
| #undef TYPE | |||
| #undef RENAME | |||
| #define TYPE int32_t | |||
| #define RENAME(name) name ## 32 | |||
| #include "ffv1_template.c" | |||
| #undef TYPE | |||
| #undef RENAME | |||
| #endif /* AVCODEC_FFV1_H */ | |||
| @@ -103,6 +103,9 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, | |||
| #undef TYPE | |||
| #undef RENAME | |||
| #define TYPE int32_t | |||
| #define RENAME(name) name ## 32 | |||
| #include "ffv1dec_template.c" | |||
| static void decode_plane(FFV1Context *s, uint8_t *src, | |||
| int w, int h, int stride, int plane_index, | |||
| @@ -318,6 +321,11 @@ static int decode_slice(AVCodecContext *c, void *arg) | |||
| } else if (f->colorspace == 0) { | |||
| decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); | |||
| decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); | |||
| } else if (f->use32bit) { | |||
| uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0], | |||
| p->data[1] + ps * x + y * p->linesize[1], | |||
| p->data[2] + ps * x + y * p->linesize[2] }; | |||
| decode_rgb_frame32(fs, planes, width, height, p->linesize); | |||
| } else { | |||
| uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0], | |||
| p->data[1] + ps * x + y * p->linesize[1], | |||
| @@ -648,6 +656,10 @@ static int read_header(FFV1Context *f) | |||
| f->avctx->pix_fmt = AV_PIX_FMT_GBRP12; | |||
| else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) | |||
| f->avctx->pix_fmt = AV_PIX_FMT_GBRP14; | |||
| else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) { | |||
| f->avctx->pix_fmt = AV_PIX_FMT_GBRP16; | |||
| f->use32bit = 1; | |||
| } | |||
| } else { | |||
| av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n"); | |||
| return AVERROR(ENOSYS); | |||
| @@ -274,6 +274,9 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, | |||
| #undef TYPE | |||
| #undef RENAME | |||
| #define TYPE int32_t | |||
| #define RENAME(name) name ## 32 | |||
| #include "ffv1enc_template.c" | |||
| static int encode_plane(FFV1Context *s, uint8_t *src, int w, int h, | |||
| int stride, int plane_index, int pixel_stride) | |||
| @@ -643,10 +646,20 @@ FF_ENABLE_DEPRECATION_WARNINGS | |||
| case AV_PIX_FMT_GBRP14: | |||
| if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |||
| s->bits_per_raw_sample = 14; | |||
| case AV_PIX_FMT_GBRP16: | |||
| if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |||
| s->bits_per_raw_sample = 16; | |||
| else if (!s->bits_per_raw_sample) | |||
| s->bits_per_raw_sample = avctx->bits_per_raw_sample; | |||
| s->colorspace = 1; | |||
| s->chroma_planes = 1; | |||
| if (s->bits_per_raw_sample >= 16) { | |||
| s->use32bit = 1; | |||
| if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { | |||
| av_log(avctx, AV_LOG_ERROR, "16bit RGB is experimental and under development, only use it for experiments\n"); | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| } | |||
| s->version = FFMAX(s->version, 1); | |||
| if (s->ac == AC_GOLOMB_RICE) { | |||
| av_log(avctx, AV_LOG_INFO, | |||
| @@ -1040,6 +1053,8 @@ retry: | |||
| } else if (c->pix_fmt == AV_PIX_FMT_YA8) { | |||
| ret = encode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); | |||
| ret |= encode_plane(fs, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); | |||
| } else if (f->use32bit) { | |||
| ret = encode_rgb_frame32(fs, planes, width, height, p->linesize); | |||
| } else { | |||
| ret = encode_rgb_frame(fs, planes, width, height, p->linesize); | |||
| } | |||
| @@ -1071,7 +1086,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, | |||
| uint8_t *buf_p; | |||
| int i, ret; | |||
| int64_t maxsize = AV_INPUT_BUFFER_MIN_SIZE | |||
| + avctx->width*avctx->height*35LL*4; | |||
| + avctx->width*avctx->height*37LL*4; | |||
| if(!pict) { | |||
| if (avctx->flags & AV_CODEC_FLAG_PASS1) { | |||
| @@ -1275,6 +1290,7 @@ AVCodec ff_ffv1_encoder = { | |||
| AV_PIX_FMT_GRAY16, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, | |||
| AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, | |||
| AV_PIX_FMT_YA8, | |||
| AV_PIX_FMT_GBRP16, | |||
| AV_PIX_FMT_NONE | |||
| }, | |||