32 AVCodecContext *
avctx;
65 if (avctx->
width & 1) {
74 s->scratch_buffer =
av_malloc(
s->buffer_size + 130);
75 if (!
s->scratch_buffer)
86 uint8_t *
dst,
const int dst_size)
91 const uint8_t *dst_end =
dst + dst_size;
95 tree_size = bytestream2_get_byte(&
s->gb);
96 eof = bytestream2_get_byte(&
s->gb);
97 tree_root = eof + tree_size;
101 bits = bytestream2_get_byte(&
s->gb);
107 node = bytestream2_get_byte(&
tree);
119 bits = bytestream2_get_byteu(&
s->gb);
128 uint8_t *dest,
const int dest_len)
132 uint8_t *orig_dest = dest;
133 const uint8_t *dest_end = dest + dest_len;
135 while (dest < dest_end) {
139 opcode = bytestream2_get_byteu(&
s->gb);
143 if ((opcode & 0x80) == 0) {
145 back = ((opcode & 0x60) << 3) + bytestream2_get_byte(&
s->gb) + 1;
146 size2 = ((opcode & 0x1c) >> 2) + 3;
147 }
else if ((opcode & 0x40) == 0) {
148 size = bytestream2_peek_byte(&
s->gb) >> 6;
149 back = (bytestream2_get_be16(&
s->gb) & 0x3fff) + 1;
150 size2 = (opcode & 0x3f) + 4;
153 back = ((opcode & 0x10) << 12) + bytestream2_get_be16(&
s->gb) + 1;
154 size2 = ((opcode & 0x0c) << 6) + bytestream2_get_byte(&
s->gb) + 5;
155 if (
size + size2 > dest_end - dest)
158 if (dest +
size + size2 > dest_end ||
159 dest - orig_dest +
size < back)
166 int finish = opcode >= 0xfc;
168 size =
finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
169 if (dest_end - dest <
size)
177 return dest - orig_dest;
186 const uint8_t *
src, *src_end;
187 const uint8_t *
table;
197 mode = bytestream2_get_le16(&
s->gb);
199 table_size = bytestream2_get_le16(&
s->gb);
209 memset(
s->scratch_buffer, 0,
s->buffer_size);
218 src =
s->scratch_buffer;
219 src_end =
src + dec_size;
221 for (j = 0; j < avctx->
height >> 1; j++) {
222 for (
i = 0;
i < avctx->
width >> 1;
i++) {
223 if (src_end -
src < 1)
227 if (
val >= table_size)
230 uval = (
val >> 3) & 0xF8;
231 vval = (
val >> 8) & 0xF8;
232 U[
i] = uval | (uval >> 5);
233 V[
i] = vval | (vval >> 5);
236 U +=
s->pic->linesize[1];
237 V +=
s->pic->linesize[2];
240 memcpy(
U,
U -
s->pic->linesize[1], avctx->
width >> 1);
241 memcpy(
V,
V -
s->pic->linesize[2], avctx->
width >> 1);
244 uint8_t *U2 =
U +
s->pic->linesize[1];
245 uint8_t *V2 =
V +
s->pic->linesize[2];
247 for (j = 0; j < avctx->
height >> 2; j++) {
248 for (
i = 0;
i < avctx->
width >> 1;
i += 2) {
249 if (src_end -
src < 1)
253 if (
val >= table_size)
256 uval = (
val >> 3) & 0xF8;
257 vval = (
val >> 8) & 0xF8;
258 U[
i] =
U[
i+1] = U2[
i] = U2[
i+1] = uval | (uval >> 5);
259 V[
i] =
V[
i+1] = V2[
i] = V2[
i+1] = vval | (vval >> 5);
262 U +=
s->pic->linesize[1] * 2;
263 V +=
s->pic->linesize[2] * 2;
264 U2 +=
s->pic->linesize[1] * 2;
265 V2 +=
s->pic->linesize[2] * 2;
268 int lines = ((avctx->
height + 1) >> 1) - (avctx->
height >> 2) * 2;
270 memcpy(
U,
U - lines *
s->pic->linesize[1], lines *
s->pic->linesize[1]);
271 memcpy(
V,
V - lines *
s->pic->linesize[2], lines *
s->pic->linesize[2]);
281 uint8_t *ybuf, *prev_buf, *
src =
s->scratch_buffer;
282 unsigned chroma_off, corr_off;
287 chroma_off = bytestream2_get_le32(&
s->gb);
288 corr_off = bytestream2_get_le32(&
s->gb);
307 for (j = 1; j < avctx->
width - 1; j += 2) {
308 cur = (last + *
src++) & 0x1F;
309 ybuf[j] = last + cur;
310 ybuf[j+1] = cur << 1;
315 ybuf += avctx->
width;
318 last = ((prev_buf[0] >> 1) + *
src++) & 0x1F;
320 for (j = 1; j < avctx->
width - 1; j += 2) {
321 cur = ((prev_buf[j + 1] >> 1) + *
src++) & 0x1F;
322 ybuf[j] = last + cur;
323 ybuf[j+1] = cur << 1;
328 ybuf += avctx->
width;
335 dec_size =
xan_unpack(
s,
s->scratch_buffer,
s->buffer_size / 2);
339 dec_size =
FFMIN(dec_size,
s->buffer_size/2 - 1);
341 for (
i = 0;
i < dec_size;
i++)
342 s->y_buffer[
i*2+1] = (
s->y_buffer[
i*2+1] + (
s->scratch_buffer[
i] << 1)) & 0x3F;
346 ybuf =
s->pic->data[0];
347 for (j = 0; j < avctx->
height; j++) {
351 ybuf +=
s->pic->linesize[0];
360 uint8_t *ybuf, *
src =
s->scratch_buffer;
370 s->buffer_size >> 1);
378 last = (ybuf[0] + (*
src++ << 1)) & 0x3F;
380 for (j = 1; j < avctx->
width - 1; j += 2) {
381 cur = (ybuf[j + 1] + (*
src++ << 1)) & 0x3F;
382 ybuf[j] = (last + cur) >> 1;
387 ybuf += avctx->
width;
391 ybuf =
s->pic->data[0];
392 for (j = 0; j < avctx->
height; j++) {
396 ybuf +=
s->pic->linesize[0];
413 ftype = bytestream2_get_le32(&
s->gb);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_xan_wc4_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
static av_always_inline int bytestream2_size(const GetByteContext *g)
#define i(width, name, range_min, range_max)
#define bit(string, value)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
static const uint16_t mask[17]
Memory handling functions.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static const uint16_t table[]
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
static av_cold int xan_decode_init(AVCodecContext *avctx)
static int xan_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static av_cold int xan_decode_end(AVCodecContext *avctx)
static int xan_decode_frame_type1(AVCodecContext *avctx)
static av_cold int xan_decode_init(AVCodecContext *avctx)
static int xan_unpack_luma(XanContext *s, uint8_t *dst, const int dst_size)
static int xan_unpack(XanContext *s, uint8_t *dest, const int dest_len)
static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off)
static int xan_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static av_cold int xan_decode_end(AVCodecContext *avctx)
static int xan_decode_frame_type0(AVCodecContext *avctx)