Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Michael Niedermayer authored on 2016/08/08 07:00:46... | ... |
@@ -144,7 +144,11 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) |
144 | 144 |
|
145 | 145 |
fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * |
146 | 146 |
sizeof(*fs->sample_buffer)); |
147 |
- if (!fs->sample_buffer) { |
|
147 |
+ fs->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * |
|
148 |
+ sizeof(*fs->sample_buffer32)); |
|
149 |
+ if (!fs->sample_buffer || !fs->sample_buffer32) { |
|
150 |
+ av_freep(&fs->sample_buffer); |
|
151 |
+ av_freep(&fs->sample_buffer32); |
|
148 | 152 |
av_freep(&f->slice_context[i]); |
149 | 153 |
goto memfail; |
150 | 154 |
} |
... | ... |
@@ -154,6 +158,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) |
154 | 154 |
memfail: |
155 | 155 |
while(--i >= 0) { |
156 | 156 |
av_freep(&f->slice_context[i]->sample_buffer); |
157 |
+ av_freep(&f->slice_context[i]->sample_buffer32); |
|
157 | 158 |
av_freep(&f->slice_context[i]); |
158 | 159 |
} |
159 | 160 |
return AVERROR(ENOMEM); |
... | ... |
@@ -224,6 +229,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) |
224 | 224 |
av_freep(&p->vlc_state); |
225 | 225 |
} |
226 | 226 |
av_freep(&fs->sample_buffer); |
227 |
+ av_freep(&fs->sample_buffer32); |
|
227 | 228 |
} |
228 | 229 |
|
229 | 230 |
av_freep(&avctx->stats_out); |
... | ... |
@@ -109,6 +109,9 @@ typedef struct FFV1Context { |
109 | 109 |
int run_index; |
110 | 110 |
int colorspace; |
111 | 111 |
int16_t *sample_buffer; |
112 |
+ int32_t *sample_buffer32; |
|
113 |
+ |
|
114 |
+ int use32bit; |
|
112 | 115 |
|
113 | 116 |
int ec; |
114 | 117 |
int intra; |
... | ... |
@@ -198,4 +201,10 @@ static inline void update_vlc_state(VlcState *const state, const int v) |
198 | 198 |
#undef TYPE |
199 | 199 |
#undef RENAME |
200 | 200 |
|
201 |
+#define TYPE int32_t |
|
202 |
+#define RENAME(name) name ## 32 |
|
203 |
+#include "ffv1_template.c" |
|
204 |
+#undef TYPE |
|
205 |
+#undef RENAME |
|
206 |
+ |
|
201 | 207 |
#endif /* AVCODEC_FFV1_H */ |
... | ... |
@@ -103,6 +103,9 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, |
103 | 103 |
#undef TYPE |
104 | 104 |
#undef RENAME |
105 | 105 |
|
106 |
+#define TYPE int32_t |
|
107 |
+#define RENAME(name) name ## 32 |
|
108 |
+#include "ffv1dec_template.c" |
|
106 | 109 |
|
107 | 110 |
static void decode_plane(FFV1Context *s, uint8_t *src, |
108 | 111 |
int w, int h, int stride, int plane_index, |
... | ... |
@@ -318,6 +321,11 @@ static int decode_slice(AVCodecContext *c, void *arg) |
318 | 318 |
} else if (f->colorspace == 0) { |
319 | 319 |
decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); |
320 | 320 |
decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); |
321 |
+ } else if (f->use32bit) { |
|
322 |
+ uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0], |
|
323 |
+ p->data[1] + ps * x + y * p->linesize[1], |
|
324 |
+ p->data[2] + ps * x + y * p->linesize[2] }; |
|
325 |
+ decode_rgb_frame32(fs, planes, width, height, p->linesize); |
|
321 | 326 |
} else { |
322 | 327 |
uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0], |
323 | 328 |
p->data[1] + ps * x + y * p->linesize[1], |
... | ... |
@@ -648,6 +656,10 @@ static int read_header(FFV1Context *f) |
648 | 648 |
f->avctx->pix_fmt = AV_PIX_FMT_GBRP12; |
649 | 649 |
else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) |
650 | 650 |
f->avctx->pix_fmt = AV_PIX_FMT_GBRP14; |
651 |
+ else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) { |
|
652 |
+ f->avctx->pix_fmt = AV_PIX_FMT_GBRP16; |
|
653 |
+ f->use32bit = 1; |
|
654 |
+ } |
|
651 | 655 |
} else { |
652 | 656 |
av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n"); |
653 | 657 |
return AVERROR(ENOSYS); |
... | ... |
@@ -274,6 +274,9 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, |
274 | 274 |
#undef TYPE |
275 | 275 |
#undef RENAME |
276 | 276 |
|
277 |
+#define TYPE int32_t |
|
278 |
+#define RENAME(name) name ## 32 |
|
279 |
+#include "ffv1enc_template.c" |
|
277 | 280 |
|
278 | 281 |
static int encode_plane(FFV1Context *s, uint8_t *src, int w, int h, |
279 | 282 |
int stride, int plane_index, int pixel_stride) |
... | ... |
@@ -643,10 +646,20 @@ FF_ENABLE_DEPRECATION_WARNINGS |
643 | 643 |
case AV_PIX_FMT_GBRP14: |
644 | 644 |
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) |
645 | 645 |
s->bits_per_raw_sample = 14; |
646 |
+ case AV_PIX_FMT_GBRP16: |
|
647 |
+ if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) |
|
648 |
+ s->bits_per_raw_sample = 16; |
|
646 | 649 |
else if (!s->bits_per_raw_sample) |
647 | 650 |
s->bits_per_raw_sample = avctx->bits_per_raw_sample; |
648 | 651 |
s->colorspace = 1; |
649 | 652 |
s->chroma_planes = 1; |
653 |
+ if (s->bits_per_raw_sample >= 16) { |
|
654 |
+ s->use32bit = 1; |
|
655 |
+ if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { |
|
656 |
+ av_log(avctx, AV_LOG_ERROR, "16bit RGB is experimental and under development, only use it for experiments\n"); |
|
657 |
+ return AVERROR_INVALIDDATA; |
|
658 |
+ } |
|
659 |
+ } |
|
650 | 660 |
s->version = FFMAX(s->version, 1); |
651 | 661 |
if (s->ac == AC_GOLOMB_RICE) { |
652 | 662 |
av_log(avctx, AV_LOG_INFO, |
... | ... |
@@ -1040,6 +1053,8 @@ retry: |
1040 | 1040 |
} else if (c->pix_fmt == AV_PIX_FMT_YA8) { |
1041 | 1041 |
ret = encode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); |
1042 | 1042 |
ret |= encode_plane(fs, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); |
1043 |
+ } else if (f->use32bit) { |
|
1044 |
+ ret = encode_rgb_frame32(fs, planes, width, height, p->linesize); |
|
1043 | 1045 |
} else { |
1044 | 1046 |
ret = encode_rgb_frame(fs, planes, width, height, p->linesize); |
1045 | 1047 |
} |
... | ... |
@@ -1071,7 +1086,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
1071 | 1071 |
uint8_t *buf_p; |
1072 | 1072 |
int i, ret; |
1073 | 1073 |
int64_t maxsize = AV_INPUT_BUFFER_MIN_SIZE |
1074 |
- + avctx->width*avctx->height*35LL*4; |
|
1074 |
+ + avctx->width*avctx->height*37LL*4; |
|
1075 | 1075 |
|
1076 | 1076 |
if(!pict) { |
1077 | 1077 |
if (avctx->flags & AV_CODEC_FLAG_PASS1) { |
... | ... |
@@ -1275,6 +1290,7 @@ AVCodec ff_ffv1_encoder = { |
1275 | 1275 |
AV_PIX_FMT_GRAY16, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, |
1276 | 1276 |
AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, |
1277 | 1277 |
AV_PIX_FMT_YA8, |
1278 |
+ AV_PIX_FMT_GBRP16, |
|
1278 | 1279 |
AV_PIX_FMT_NONE |
1279 | 1280 |
|
1280 | 1281 |
}, |