aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2016-08-08 00:00:46 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2016-08-08 00:32:09 +0200
commitce2217b25eccda9f5c14022bd69792e71b417b73 (patch)
tree7ea358b77eb60739b9ec153bcc74b0408e8ab575 /libavcodec
parent74314f1f5f9ef69700eb18b85a8260e2754a31ef (diff)
downloadffmpeg-ce2217b25eccda9f5c14022bd69792e71b417b73.tar.gz
avcodec/ffv1: add AV_PIX_FMT_GBRP16 support
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/ffv1.c8
-rw-r--r--libavcodec/ffv1.h9
-rw-r--r--libavcodec/ffv1dec.c12
-rw-r--r--libavcodec/ffv1enc.c18
4 files changed, 45 insertions, 2 deletions
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 80a9434eb7..a14dd2aab2 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -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);
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 5f4a340a87..c2bae1e6da 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -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 */
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index e8b726cc7e..d8f35c34b9 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -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);
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 552f653846..d4f0577ab9 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -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
},