26 #define BITSTREAM_READER_LE
49 if (avctx->
width & 1) {
68 uint8_t *dst,
const int dst_size)
73 const uint8_t *dst_end = dst + dst_size;
77 tree_size = bytestream2_get_byte(&s->
gb);
78 eof = bytestream2_get_byte(&s->
gb);
79 tree_root = eof + tree_size;
83 bits = bytestream2_get_byte(&s->
gb);
86 int bit = !!(bits &
mask);
89 node = bytestream2_get_byte(&tree);
101 bits = bytestream2_get_byteu(&s->
gb);
110 uint8_t *dest,
const int dest_len)
114 uint8_t *orig_dest = dest;
115 const uint8_t *dest_end = dest + dest_len;
117 while (dest < dest_end) {
121 opcode = bytestream2_get_byteu(&s->
gb);
125 if ((opcode & 0x80) == 0) {
127 back = ((opcode & 0x60) << 3) + bytestream2_get_byte(&s->
gb) + 1;
128 size2 = ((opcode & 0x1c) >> 2) + 3;
129 }
else if ((opcode & 0x40) == 0) {
130 size = bytestream2_peek_byte(&s->
gb) >> 6;
131 back = (bytestream2_get_be16(&s->
gb) & 0x3fff) + 1;
132 size2 = (opcode & 0x3f) + 4;
135 back = ((opcode & 0x10) << 12) + bytestream2_get_be16(&s->
gb) + 1;
136 size2 = ((opcode & 0x0c) << 6) + bytestream2_get_byte(&s->
gb) + 5;
137 if (size + size2 > dest_end - dest)
140 if (dest + size + size2 > dest_end ||
141 dest - orig_dest + size < back)
148 int finish = opcode >= 0xfc;
150 size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
151 if (dest_end - dest < size)
159 return dest - orig_dest;
168 const uint8_t *src, *src_end;
169 const uint8_t *table;
170 int mode, offset, dec_size, table_size;
179 mode = bytestream2_get_le16(&s->
gb);
181 table_size = bytestream2_get_le16(&s->
gb);
182 offset = table_size * 2;
201 src_end = src + dec_size;
203 for (j = 0; j < avctx->
height >> 1; j++) {
204 for (i = 0; i < avctx->
width >> 1; i++) {
206 if (val && val < table_size) {
207 val =
AV_RL16(table + (val << 1));
208 uval = (val >> 3) & 0xF8;
209 vval = (val >> 8) & 0xF8;
210 U[i] = uval | (uval >> 5);
211 V[i] = vval | (vval >> 5);
223 for (j = 0; j < avctx->
height >> 2; j++) {
224 for (i = 0; i < avctx->
width >> 1; i += 2) {
226 if (val && val < table_size) {
227 val =
AV_RL16(table + (val << 1));
228 uval = (val >> 3) & 0xF8;
229 vval = (val >> 8) & 0xF8;
230 U[i] = U[i+1] = U2[i] = U2[i+1] = uval | (uval >> 5);
231 V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5);
248 unsigned chroma_off, corr_off;
253 chroma_off = bytestream2_get_le32(&s->
gb);
254 corr_off = bytestream2_get_le32(&s->
gb);
273 for (j = 1; j < avctx->
width - 1; j += 2) {
274 cur = (last + *src++) & 0x1F;
275 ybuf[j] = last + cur;
276 ybuf[j+1] = cur << 1;
281 ybuf += avctx->
width;
283 for (i = 1; i < avctx->
height; i++) {
284 last = ((prev_buf[0] >> 1) + *src++) & 0x1F;
286 for (j = 1; j < avctx->
width - 1; j += 2) {
287 cur = ((prev_buf[j + 1] >> 1) + *src++) & 0x1F;
288 ybuf[j] = last + cur;
289 ybuf[j+1] = cur << 1;
294 ybuf += avctx->
width;
298 int corr_end, dec_size;
301 if (chroma_off > corr_off)
302 corr_end = chroma_off;
307 for (i = 0; i < dec_size; i++)
313 for (j = 0; j < avctx->
height; j++) {
314 for (i = 0; i < avctx->
width; i++)
315 ybuf[i] = (src[i] << 2) | (src[i] >> 3);
343 for (i = 0; i < avctx->
height; i++) {
344 last = (ybuf[0] + (*src++ << 1)) & 0x3F;
346 for (j = 1; j < avctx->
width - 1; j += 2) {
347 cur = (ybuf[j + 1] + (*src++ << 1)) & 0x3F;
348 ybuf[j] = (last + cur) >> 1;
353 ybuf += avctx->
width;
358 for (j = 0; j < avctx->
height; j++) {
359 for (i = 0; i < avctx->
width; i++)
360 ybuf[i] = (src[i] << 2) | (src[i] >> 3);
369 void *
data,
int *data_size,
386 ftype = bytestream2_get_le32(&s->
gb);
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define FF_BUFFER_HINTS_VALID
int buffer_hints
codec suggestion on buffer type if != 0
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
AVCodec ff_xan_wc4_decoder
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int xan_decode_frame_type0(AVCodecContext *avctx)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
bitstream reader API header.
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int xan_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
static const uint16_t mask[17]
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
const uint8_t * buffer_end
int width
picture width / height.
struct AVFrame AVFrame
Audio Video Frame.
#define FF_BUFFER_HINTS_REUSABLE
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_cold int xan_decode_end(AVCodecContext *avctx)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint8_t * buffer_start
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define FF_BUFFER_HINTS_PRESERVE
static int xan_unpack_luma(XanContext *s, uint8_t *dst, const int dst_size)
static av_cold int xan_decode_init(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
struct XanContext XanContext
static int xan_decode_frame_type1(AVCodecContext *avctx)
static int xan_unpack(XanContext *s, uint8_t *dest, const int dest_len)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)