25 #define CACHED_BITSTREAM_READER !ARCH_X86_32
76 VLC *vlc,
int nb_elems,
void *logctx)
80 for (
int i = 31;
i > 0;
i--)
81 codes_pos[
i] += codes_pos[
i + 1];
83 for (
unsigned i = nb_elems;
i-- > 0;)
88 &he[0].
len,
sizeof(he[0]),
89 &he[0].sym,
sizeof(he[0]),
sizeof(he[0].sym),
94 const uint16_t *
diff, intptr_t
w,
95 int *left,
int *left_top,
int max)
103 for (
i = 0;
i <
w;
i++) {
119 const int bps =
s->bps;
120 const int max =
s->max - 1;
126 for (
i = 0;
i <
s->planes;
i++) {
127 int left, lefttop, top;
135 s->slices[
i][j].size);
143 dst = (uint16_t *)p->
data[
i] + j * sheight *
stride;
147 for (k = 0; k <
height; k++) {
148 for (x = 0; x <
width; x++)
154 for (k = 0; k <
height; k++) {
155 for (x = 0; x <
width; x++) {
160 pix =
get_vlc2(&gb,
s->vlc[
i].table,
s->vlc[
i].bits, 3);
172 dst = (uint16_t *)p->
data[
i] + j * sheight *
stride;
173 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, 0);
176 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, 0);
180 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, dst[-fake_stride]);
185 dst = (uint16_t *)p->
data[
i] + j * sheight *
stride;
186 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, 0);
189 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, 0);
193 top = dst[-fake_stride];
196 for (x = 1; x <
width; x++) {
197 top = dst[x - fake_stride];
198 lefttop = dst[x - (fake_stride + 1)];
199 left += top - lefttop + dst[x];
206 dst = (uint16_t *)p->
data[
i] + j * sheight *
stride;
207 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, 0);
210 s->llviddsp.add_left_pred_int16(dst, dst,
max,
width, 0);
213 lefttop = left = dst[0];
216 lefttop = left = dst[0];
225 if (
s->decorrelate) {
228 uint16_t *
r = (uint16_t *)p->
data[0] + j *
s->slice_height * p->
linesize[0] / 2;
229 uint16_t *
g = (uint16_t *)p->
data[1] + j *
s->slice_height * p->
linesize[1] / 2;
230 uint16_t *
b = (uint16_t *)p->
data[2] + j *
s->slice_height * p->
linesize[2] / 2;
233 for (k = 0; k <
width; k++) {
234 b[k] = (
b[k] +
g[k]) &
max;
235 r[k] = (
r[k] +
g[k]) &
max;
252 int i, k, x, min_width;
256 for (
i = 0;
i <
s->planes;
i++) {
257 int left, lefttop, top;
263 const uint8_t *slice =
s->buf +
s->slices[
i][j].start;
266 flags = bytestream_get_byte(&slice);
267 pred = bytestream_get_byte(&slice);
273 for (k = 0; k <
height; k++) {
283 for (k = 0; k <
height; k++) {
284 for (x = 0; x <
width; x++) {
289 pix =
get_vlc2(&gb,
s->vlc[
i].table,
s->vlc[
i].bits, 3);
302 s->llviddsp.add_left_pred(dst, dst,
width, 0);
305 s->llviddsp.add_left_pred(dst, dst,
width, 0);
309 s->llviddsp.add_left_pred(dst, dst,
width, dst[-fake_stride]);
315 s->llviddsp.add_left_pred(dst, dst,
width, 0);
318 s->llviddsp.add_left_pred(dst, dst,
width, 0);
323 top = dst[-fake_stride];
326 for (x = 1; x < min_width; x++) {
327 top = dst[x - fake_stride];
328 lefttop = dst[x - (fake_stride + 1)];
329 left += top - lefttop + dst[x];
333 s->llviddsp.add_gradient_pred(dst + 32, fake_stride,
width - 32);
339 s->llviddsp.add_left_pred(dst, dst,
width, 0);
342 s->llviddsp.add_left_pred(dst, dst,
width, 0);
345 lefttop = left = dst[0];
347 s->llviddsp.add_median_pred(dst, dst - fake_stride,
348 dst,
width, &left, &lefttop);
349 lefttop = left = dst[0];
358 if (
s->decorrelate) {
378 int table_size,
int max)
383 uint16_t length_count[33] = { 0 };
389 int b = bytestream2_peek_byteu(&gb) & 0x80;
390 int x = bytestream2_get_byteu(&gb) & ~0x80;
396 l += bytestream2_get_byteu(&gb);
399 if (k >
max || x == 0 || x > 32) {
404 length_count[x] += l;
415 if (
i ==
s->planes) {
418 memset(length_count, 0,
sizeof(length_count));
422 if (
i !=
s->planes) {
437 uint32_t first_offset,
offset, next_offset, header_size, slice_width;
441 if (avpkt->
size < 36)
445 if (bytestream2_get_le32u(&gb) !=
MKTAG(
'M',
'A',
'G',
'Y'))
448 header_size = bytestream2_get_le32u(&gb);
449 if (header_size < 32 || header_size >= avpkt->
size) {
451 "header or packet too small %"PRIu32
"\n", header_size);
455 version = bytestream2_get_byteu(&gb);
468 format = bytestream2_get_byteu(&gb);
545 s->max = 1 <<
s->bps;
550 s->color_matrix = bytestream2_get_byteu(&gb);
551 s->flags = bytestream2_get_byteu(&gb);
552 s->interlaced = !!(
s->flags & 2);
555 width = bytestream2_get_le32u(&gb);
556 height = bytestream2_get_le32u(&gb);
561 slice_width = bytestream2_get_le32u(&gb);
566 s->slice_height = bytestream2_get_le32u(&gb);
567 if (
s->slice_height <= 0 ||
s->slice_height > INT_MAX - avctx->
coded_height) {
569 "invalid slice height: %d\n",
s->slice_height);
575 s->nb_slices = (avctx->
coded_height +
s->slice_height - 1) /
s->slice_height;
578 "invalid number of slices: %d\n",
s->nb_slices);
583 if ((
s->slice_height >>
s->vshift[1]) < 2) {
595 for (
i = 0;
i <
s->planes;
i++) {
600 offset = bytestream2_get_le32u(&gb);
607 for (j = 0; j <
s->nb_slices - 1; j++) {
608 s->slices[
i][j].start =
offset + header_size;
610 next_offset = bytestream2_get_le32u(&gb);
611 if (next_offset <= offset || next_offset >= avpkt->
size - header_size)
614 s->slices[
i][j].size = next_offset -
offset;
615 if (
s->slices[
i][j].size < 2)
620 s->slices[
i][j].start =
offset + header_size;
621 s->slices[
i][j].size = avpkt->
size -
s->slices[
i][j].start;
623 if (
s->slices[
i][j].size < 2)
627 if (bytestream2_get_byteu(&gb) !=
s->planes)
647 s->buf = avpkt->
data;
660 switch (
s->color_matrix) {
690 s->slices_size[
i] = 0;
static const char *const format[]
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
void ff_free_vlc(VLC *vlc)
int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell(GetByteContext *g)
#define flags(name, subs,...)
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
#define AV_CEIL_RSHIFT(a, b)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AV_PICTURE_TYPE_I
Intra.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void ff_llviddsp_init(LLVidDSPContext *c)
static av_cold int magy_decode_init(AVCodecContext *avctx)
static av_cold int magy_decode_end(AVCodecContext *avctx)
static int magy_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int magy_decode_slice10(AVCodecContext *avctx, void *tdata, int j, int threadnr)
static int huff_build(const uint8_t len[], uint16_t codes_pos[33], VLC *vlc, int nb_elems, void *logctx)
static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1, const uint16_t *diff, intptr_t w, int *left, int *left_top, int max)
AVCodec ff_magicyuv_decoder
static int build_huffman(AVCodecContext *avctx, const uint8_t *table, int table_size, int max)
static int magy_decode_slice(AVCodecContext *avctx, void *tdata, int j, int threadnr)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P10
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUV444P10
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
static const uint16_t table[]
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
int coded_width
Bitstream width / height, may be different from width/height e.g.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorSpace colorspace
YUV colorspace type.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int(* magy_decode_slice)(AVCodecContext *avctx, void *tdata, int j, int threadnr)
unsigned int slices_size[4]
#define avpriv_request_sample(...)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const uint8_t offset[127][2]