24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
27 #define BITSTREAM_READER_LE
55 if (avctx->
width & 1) {
80 uint8_t *dst,
const int dst_size)
85 const uint8_t *dst_end = dst + dst_size;
89 tree_size = bytestream2_get_byte(&s->
gb);
90 eof = bytestream2_get_byte(&s->
gb);
91 tree_root = eof + tree_size;
95 bits = bytestream2_get_byte(&s->
gb);
98 int bit = !!(bits &
mask);
101 node = bytestream2_get_byte(&tree);
113 bits = bytestream2_get_byteu(&s->
gb);
122 uint8_t *dest,
const int dest_len)
127 const uint8_t *dest_end = dest + dest_len;
129 while (dest < dest_end) {
133 opcode = bytestream2_get_byteu(&s->
gb);
137 if ((opcode & 0x80) == 0) {
139 back = ((opcode & 0x60) << 3) + bytestream2_get_byte(&s->
gb) + 1;
140 size2 = ((opcode & 0x1c) >> 2) + 3;
141 }
else if ((opcode & 0x40) == 0) {
142 size = bytestream2_peek_byte(&s->
gb) >> 6;
143 back = (bytestream2_get_be16(&s->
gb) & 0x3fff) + 1;
144 size2 = (opcode & 0x3f) + 4;
147 back = ((opcode & 0x10) << 12) + bytestream2_get_be16(&s->
gb) + 1;
148 size2 = ((opcode & 0x0c) << 6) + bytestream2_get_byte(&s->
gb) + 5;
149 if (size + size2 > dest_end - dest)
152 if (dest + size + size2 > dest_end ||
153 dest - orig_dest + size < back)
160 int finish = opcode >= 0xfc;
162 size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
163 if (dest_end - dest < size)
171 return dest - orig_dest;
191 mode = bytestream2_get_le16(&s->
gb);
193 table_size = bytestream2_get_le16(&s->
gb);
194 offset = table_size * 2;
213 src_end = src + dec_size;
215 for (j = 0; j < avctx->
height >> 1; j++) {
216 for (i = 0; i < avctx->
width >> 1; i++) {
217 if (src_end - src < 1)
221 if (val >= table_size)
223 val =
AV_RL16(table + (val << 1));
224 uval = (val >> 3) & 0xF8;
225 vval = (val >> 8) & 0xF8;
226 U[i] = uval | (uval >> 5);
227 V[i] = vval | (vval >> 5);
241 for (j = 0; j < avctx->
height >> 2; j++) {
242 for (i = 0; i < avctx->
width >> 1; i += 2) {
243 if (src_end - src < 1)
247 if (val >= table_size)
249 val =
AV_RL16(table + (val << 1));
250 uval = (val >> 3) & 0xF8;
251 vval = (val >> 8) & 0xF8;
252 U[i] = U[i+1] = U2[i] = U2[i+1] = uval | (uval >> 5);
253 V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5);
262 int lines = ((avctx->
height + 1) >> 1) - (avctx->
height >> 2) * 2;
276 unsigned chroma_off, corr_off;
281 chroma_off = bytestream2_get_le32(&s->
gb);
282 corr_off = bytestream2_get_le32(&s->
gb);
301 for (j = 1; j < avctx->
width - 1; j += 2) {
302 cur = (last + *src++) & 0x1F;
303 ybuf[j] = last + cur;
304 ybuf[j+1] = cur << 1;
309 ybuf += avctx->
width;
311 for (i = 1; i < avctx->
height; i++) {
312 last = ((prev_buf[0] >> 1) + *src++) & 0x1F;
314 for (j = 1; j < avctx->
width - 1; j += 2) {
315 cur = ((prev_buf[j + 1] >> 1) + *src++) & 0x1F;
316 ybuf[j] = last + cur;
317 ybuf[j+1] = cur << 1;
322 ybuf += avctx->
width;
335 for (i = 0; i < dec_size; i++)
341 for (j = 0; j < avctx->
height; j++) {
342 for (i = 0; i < avctx->
width; i++)
343 ybuf[i] = (src[i] << 2) | (src[i] >> 3);
371 for (i = 0; i < avctx->
height; i++) {
372 last = (ybuf[0] + (*src++ << 1)) & 0x3F;
374 for (j = 1; j < avctx->
width - 1; j += 2) {
375 cur = (ybuf[j + 1] + (*src++ << 1)) & 0x3F;
376 ybuf[j] = (last + cur) >> 1;
381 ybuf += avctx->
width;
386 for (j = 0; j < avctx->
height; j++) {
387 for (i = 0; i < avctx->
width; i++)
388 ybuf[i] = (src[i] << 2) | (src[i] >> 3);
397 void *
data,
int *got_frame,
408 ftype = bytestream2_get_le32(&s->
gb);
const char const char void * val
This structure describes decoded (raw) audio or video data.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
static struct endianess table[]
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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)
AVCodec ff_xan_wc4_decoder
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int xan_decode_frame_type0(AVCodecContext *avctx)
static const uint8_t offset[511][2]
const char * name
Name of the codec implementation.
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
bitstream reader API header.
static av_always_inline int bytestream2_size(GetByteContext *g)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
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. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
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_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Libavcodec external API header.
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int xan_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_always_inline int bytestream2_tell(GetByteContext *g)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static av_cold int xan_decode_end(AVCodecContext *avctx)
main external API structure.
static void close(AVCodecParserContext *s)
static int xan_unpack_luma(XanContext *s, uint8_t *dst, const int dst_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold int xan_decode_init(AVCodecContext *avctx)
common internal api header.
static int xan_decode_frame_type1(AVCodecContext *avctx)
#define AVERROR_INVALIDDATA
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)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)