30 #define UNCHECKED_BITSTREAM_READER 1
53 for (i = 0; i < 1024; i++) {
65 while (he[last].len == 255 && last)
68 if (he[last].len > 32) {
73 for (i = last; i >= 0; i--) {
74 codes[i] = code >> (32 - he[i].
len);
77 code += 0x80000000
u >> (he[i].
len - 1);
81 bits,
sizeof(*bits),
sizeof(*bits),
82 codes,
sizeof(*codes),
sizeof(*codes),
83 syms,
sizeof(*syms),
sizeof(*syms), 0);
97 for (i = 0; i < 256; i++) {
109 while (he[last].len == 255 && last)
112 if (he[last].len > 32)
116 for (i = last; i >= 0; i--) {
117 codes[i] = code >> (32 - he[i].
len);
120 code += 0x80000000
u >> (he[i].
len - 1);
124 bits,
sizeof(*bits),
sizeof(*bits),
125 codes,
sizeof(*codes),
sizeof(*codes),
126 syms,
sizeof(*syms),
sizeof(*syms), 0);
130 uint16_t *dst, ptrdiff_t
stride,
135 int i, j, slice, pix, ret;
147 for (slice = 0; slice < c->
slices; slice++) {
151 send = (height * (slice + 1) / c->
slices);
152 dest = dst + sstart *
stride;
155 for (j = sstart; j < send; j++) {
156 for (i = 0; i <
width; i++) {
172 for (slice = 0; slice < c->
slices; slice++) {
174 int slice_data_start, slice_data_end, slice_size;
177 send = (height * (slice + 1) / c->
slices);
178 dest = dst + sstart *
stride;
181 slice_data_start = slice ?
AV_RL32(src + slice * 4 - 4) : 0;
182 slice_data_end =
AV_RL32(src + slice * 4);
183 slice_size = slice_data_end - slice_data_start;
187 "yet a slice has a length of zero.\n");
193 (uint32_t *)(src + slice_data_start + c->
slices * 4),
194 (slice_data_end - slice_data_start + 3) >> 2);
198 for (j = sstart; j < send; j++) {
199 for (i = 0; i <
width; i++) {
215 "Slice decoding ran out of bits\n");
237 return ~(1 + 2 * is_luma);
247 int i, j, slice, pix;
256 for (slice = 0; slice < c->
slices; slice++) {
269 send = (height * (slice + 1) / c->
slices) & cmask;
270 dest = dst + sstart *
stride;
272 if (3 * ((dst + send * stride - dest + 7)/8) >
get_bits_left(&cbit))
275 for (p = dest; p < dst + send *
stride; p += 8) {
281 uint32_t sub = 0x80 >> (8 - (bits + 1)), add;
287 for (k = 0; k < 8; k++) {
290 add = (~p[k] & sub) << (8 - bits);
307 for (slice = 0; slice < c->
slices; slice++) {
311 send = (height * (slice + 1) / c->
slices) & cmask;
312 dest = dst + sstart *
stride;
315 for (j = sstart; j < send; j++) {
316 for (i = 0; i <
width; i++) {
333 for (slice = 0; slice < c->
slices; slice++) {
335 int slice_data_start, slice_data_end, slice_size;
338 send = (height * (slice + 1) / c->
slices) & cmask;
339 dest = dst + sstart *
stride;
342 slice_data_start = slice ?
AV_RL32(src + slice * 4 - 4) : 0;
343 slice_data_end =
AV_RL32(src + slice * 4);
344 slice_size = slice_data_end - slice_data_start;
348 "yet a slice has a length of zero.\n");
354 (uint32_t *)(src + slice_data_start + c->
slices * 4),
355 (slice_data_end - slice_data_start + 3) >> 2);
359 for (j = sstart; j < send; j++) {
360 for (i = 0; i <
width; i++) {
374 "Slice decoding ran out of bits\n");
402 int slice_start, slice_height;
403 const int cmask = ~rmode;
405 for (slice = 0; slice < slices; slice++) {
406 slice_start = ((slice *
height) / slices) & cmask;
407 slice_height = ((((slice + 1) * height) / slices) & cmask) -
412 bsrc = src + slice_start *
stride;
418 if (slice_height <= 1)
424 for (i = 1; i <
FFMIN(width, 16); i++) {
432 bsrc + 16, width - 16, &A, &B);
436 for (j = 2; j < slice_height; j++) {
438 bsrc, width, &A, &B);
454 int slice_start, slice_height;
455 const int cmask = ~(rmode ? 3 : 1);
456 const ptrdiff_t stride2 = stride << 1;
458 for (slice = 0; slice < slices; slice++) {
459 slice_start = ((slice *
height) / slices) & cmask;
460 slice_height = ((((slice + 1) * height) / slices) & cmask) -
466 bsrc = src + slice_start *
stride;
473 if (slice_height <= 1)
479 for (i = 1; i <
FFMIN(width, 16); i++) {
480 B = bsrc[i - stride2];
487 bsrc + 16, width - 16, &A, &B);
490 bsrc + stride, width, &A, &B);
493 for (j = 2; j < slice_height; j++) {
495 bsrc, width, &A, &B);
497 bsrc + stride, width, &A, &B);
509 int slice_start, slice_height;
510 const int cmask = ~rmode;
511 int min_width =
FFMIN(width, 32);
513 for (slice = 0; slice < slices; slice++) {
514 slice_start = ((slice *
height) / slices) & cmask;
515 slice_height = ((((slice + 1) * height) / slices) & cmask) -
520 bsrc = src + slice_start *
stride;
526 if (slice_height <= 1)
528 for (j = 1; j < slice_height; j++) {
530 bsrc[0] = (bsrc[0] + bsrc[-
stride]) & 0xFF;
531 for (i = 1; i < min_width; i++) {
533 B = bsrc[i - (stride + 1)];
535 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
550 int slice_start, slice_height;
551 const int cmask = ~(rmode ? 3 : 1);
552 const ptrdiff_t stride2 = stride << 1;
553 int min_width =
FFMIN(width, 32);
555 for (slice = 0; slice < slices; slice++) {
556 slice_start = ((slice *
height) / slices) & cmask;
557 slice_height = ((((slice + 1) * height) / slices) & cmask) -
563 bsrc = src + slice_start *
stride;
570 if (slice_height <= 1)
572 for (j = 1; j < slice_height; j++) {
574 bsrc[0] = (bsrc[0] + bsrc[-stride2]) & 0xFF;
575 for (i = 1; i < min_width; i++) {
576 A = bsrc[i - stride2];
577 B = bsrc[i - (stride2 + 1)];
579 bsrc[i] = (A - B + C + bsrc[i]) & 0xFF;
585 B = bsrc[-(1 + stride + stride -
width)];
588 for (i = 1; i <
width; i++) {
590 B = bsrc[i - (1 +
stride)];
592 bsrc[i +
stride] = (A - B + C + bsrc[i +
stride]) & 0xFF;
603 int buf_size = avpkt->
size;
607 int plane_size, max_slice_size = 0, slice_start,
slice_end, slice_size;
627 if (bytestream2_get_byte(&gb) != 1)
630 c->
offset = bytestream2_get_le32(&gb);
632 if (buf_size <= c->
offset + 8LL)
637 nb_cbs = bytestream2_get_le32(&pb);
641 packed_stream = buf + 8;
642 control_stream = packed_stream + (c->
offset - nb_cbs);
643 left = control_stream - packed_stream;
645 for (i = 0; i < c->
planes; i++) {
646 for (j = 0; j < c->
slices; j++) {
656 left = buf + buf_size - control_stream;
658 for (i = 0; i < c->
planes; i++) {
659 for (j = 0; j < c->
slices; j++) {
675 for (i = 0; i < c->
planes; i++) {
676 plane_start[i] = gb.
buffer;
683 for (j = 0; j < c->
slices; j++) {
684 slice_end = bytestream2_get_le32u(&gb);
685 if (slice_end < 0 || slice_end < slice_start ||
690 slice_size = slice_end - slice_start;
692 max_slice_size =
FFMAX(max_slice_size, slice_size);
700 for (i = 0; i < c->
planes; i++) {
701 plane_start[i] = gb.
buffer;
709 for (j = 0; j < c->
slices; j++) {
710 slice_end = bytestream2_get_le32u(&gb);
711 if (slice_end < 0 || slice_end < slice_start ||
716 slice_size = slice_end - slice_start;
718 max_slice_size =
FFMAX(max_slice_size, slice_size);
735 max_slice_size += 4*avctx->
width;
750 for (i = 0; i < c->
planes; i++) {
753 avctx->
height, plane_start[i],
787 for (i = 0; i < c->
planes; i++) {
790 avctx->
height, plane_start[i],
791 plane_start[i + 1] - 1024,
801 for (i = 0; i < 3; i++) {
833 for (i = 0; i < 3; i++) {
863 for (i = 0; i < 3; i++) {
893 for (i = 0; i < 3; i++) {
916 int h_shift, v_shift;
927 case MKTAG(
'U',
'L',
'R',
'G'):
931 case MKTAG(
'U',
'L',
'R',
'A'):
935 case MKTAG(
'U',
'L',
'Y',
'0'):
940 case MKTAG(
'U',
'L',
'Y',
'2'):
945 case MKTAG(
'U',
'L',
'Y',
'4'):
950 case MKTAG(
'U',
'Q',
'Y',
'2'):
955 case MKTAG(
'U',
'Q',
'R',
'G'):
960 case MKTAG(
'U',
'Q',
'R',
'A'):
965 case MKTAG(
'U',
'L',
'H',
'0'):
970 case MKTAG(
'U',
'L',
'H',
'2'):
975 case MKTAG(
'U',
'L',
'H',
'4'):
980 case MKTAG(
'U',
'M',
'Y',
'2'):
986 case MKTAG(
'U',
'M',
'H',
'2'):
992 case MKTAG(
'U',
'M',
'Y',
'4'):
998 case MKTAG(
'U',
'M',
'H',
'4'):
1004 case MKTAG(
'U',
'M',
'R',
'G'):
1009 case MKTAG(
'U',
'M',
'R',
'A'):
1021 if ((avctx->
width & ((1<<h_shift)-1)) ||
1022 (avctx->
height & ((1<<v_shift)-1))) {
1062 "Insufficient extradata size %d, should be at least 16\n",
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
static void restore_median_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static enum AVPixelFormat pix_fmt
int ff_ut10_huff_cmp_len(const void *a, const void *b)
ptrdiff_t const GLvoid * data
#define AV_PIX_FMT_GBRAP10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
void(* restore_rgb_planes)(uint8_t *src_r, uint8_t *src_g, uint8_t *src_b, ptrdiff_t linesize_r, ptrdiff_t linesize_g, ptrdiff_t linesize_b, int width, int height)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
#define AV_PIX_FMT_GBRP10
static av_cold int decode_end(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
av_cold void ff_utvideodsp_init(UTVideoDSPContext *c)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static void restore_gradient_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
static void restore_gradient_planar_il(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
Multithreading support functions.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define u(width, name, range_min, range_max)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
bitstream reader API header.
int interlaced_frame
The content of the picture is interlaced.
static int decode_plane10(UtvideoContext *c, int plane_no, uint16_t *dst, ptrdiff_t stride, int width, int height, const uint8_t *src, const uint8_t *huff, int use_pred)
static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int decode_init(AVCodecContext *avctx)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static void restore_median_planar(UtvideoContext *c, uint8_t *src, ptrdiff_t stride, int width, int height, int slices, int rmode)
enum AVPictureType pict_type
Picture type of the frame.
static int compute_cmask(int plane_no, int interlaced, enum AVPixelFormat pix_fmt)
int width
picture width / height.
size_t control_stream_size[4][256]
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
const uint8_t * control_stream[4][256]
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
void ff_llviddsp_init(LLVidDSPContext *c)
enum AVColorSpace colorspace
YUV colorspace type.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
void(* restore_rgb_planes10)(uint16_t *src_r, uint16_t *src_g, uint16_t *src_b, ptrdiff_t linesize_r, ptrdiff_t linesize_g, ptrdiff_t linesize_b, int width, int height)
static unsigned int get_bits_le(GetBitContext *s, int n)
#define AV_PIX_FMT_YUV422P10
static int decode_plane(UtvideoContext *c, int plane_no, uint8_t *dst, ptrdiff_t stride, int width, int height, const uint8_t *src, int use_pred)
int ff_ut_huff_cmp_len(const void *a, const void *b)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void(* add_gradient_pred)(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
planar GBRA 4:4:4:4 32bpp
size_t packed_stream_size[4][256]
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
const uint8_t * packed_stream[4][256]
#define MKTAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
AVPixelFormat
Pixel format.
AVCodec ff_utvideo_decoder
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)