26 #define BITSTREAM_READER_LE
75 #define HISTORY_SIZE (64 * 1024)
81 unsigned reference_pos, match_length,
delta,
pos = 0;
82 uint8_t history[64 * 1024] = { 0 };
85 uint8_t token = bytestream2_get_byte(gb);
86 unsigned num_literals = token >> 4;
88 if (num_literals == 15) {
89 unsigned char current;
91 current = bytestream2_get_byte(gb);
92 if (current > INT_MAX - num_literals)
94 num_literals += current;
95 }
while (current == 255);
105 while (num_literals-- > 0) {
106 history[
pos++] = bytestream2_get_byte(gb);
117 delta = bytestream2_get_le16(gb);
120 match_length = 4 + (token & 0x0F);
121 if (match_length == 4 + 0x0F) {
125 current = bytestream2_get_byte(gb);
126 if (current > INT_MAX - match_length)
128 match_length += current;
129 }
while (current == 255);
133 if (
pos >= reference_pos + match_length || reference_pos >=
pos + match_length) {
134 memcpy(history +
pos, history + reference_pos, match_length);
137 while (match_length-- > 0)
138 history[
pos++] = history[reference_pos++];
141 while (match_length-- > 0) {
142 history[
pos++] = history[reference_pos++];
158 unsigned uncompressed_size)
163 int ylinesize, ulinesize, vlinesize, alinesize;
164 uint16_t *dsty, *dstu, *dstv, *dsta;
167 s->texture_size_x = bytestream2_get_le32(gb);
168 s->texture_size_y = bytestream2_get_le32(gb);
174 s->uv_offset_data_offset = bytestream2_get_le32(gb);
175 if (
s->uv_offset_data_offset >= UINT_MAX / 4)
177 s->uv_offset_data_offset *= 4;
178 if (
s->uv_offset_data_offset >= uncompressed_size)
181 s->y_control_data_offset = bytestream2_get_le32(gb);
182 if (
s->y_control_data_offset >= UINT_MAX / 4)
184 s->y_control_data_offset *= 4;
185 if (
s->y_control_data_offset >= uncompressed_size)
188 s->a_control_word_offset = bytestream2_get_le32(gb);
189 if (
s->a_control_word_offset >= UINT_MAX / 4)
191 s->a_control_word_offset *= 4;
192 if (
s->a_control_word_offset >= uncompressed_size)
195 s->uv_data_offset = bytestream2_get_le32(gb);
196 if (
s->uv_data_offset >= UINT_MAX / 4)
198 s->uv_data_offset *= 4;
199 if (
s->uv_data_offset >= uncompressed_size)
202 s->y_data_size = bytestream2_get_le32(gb);
203 if (
s->y_data_size >= UINT_MAX / 4)
206 s->a_data_offset = bytestream2_get_le32(gb);
207 if (
s->a_data_offset >= UINT_MAX / 4)
209 s->a_data_offset *= 4;
210 if (
s->a_data_offset >= uncompressed_size)
213 s->a_count_size = bytestream2_get_le32(gb);
214 if (
s->a_count_size >= UINT_MAX / 4)
216 s->a_count_size *= 4;
217 if (
s->a_count_size >= uncompressed_size)
220 s->data_end = bytestream2_get_le32(gb);
221 if (
s->data_end > uncompressed_size)
225 if (
s->data_end <=
s->y_data_size)
227 s->y_data_offset =
s->data_end -
s->y_data_size;
228 if (
s->y_data_offset <=
s->a_data_offset)
230 s->uv_count_offset =
s->y_data_offset -
s->a_data_offset;
243 dsty = (uint16_t *)p->
data[0];
244 dsta = (uint16_t *)p->
data[3];
248 for (
int y = 0; y < avctx->
height; y += 4) {
249 const unsigned row_offset = bytestream2_get_le32(&
rgb);
256 for (
int x = 0; x < avctx->
width; x += 4) {
257 unsigned item = bytestream2_get_le32(gb);
258 unsigned y_min = item & 4095;
259 unsigned y_max = (item >> 12) & 4095;
260 unsigned y_diff = y_max - y_min;
263 control[0] = (item >> 24) & 3;
264 control[1] = (item >> 26) & 3;
265 control[2] = (item >> 28) & 3;
266 control[3] = (item >> 30) & 3;
268 for (
int i = 0;
i < 4;
i++) {
269 const int nb_bits = control[
i] + 1;
270 const int div = (1 << nb_bits) - 1;
271 const int add = div - 1;
280 dsty += 4 * ylinesize;
286 if (
s->uv_count_offset ==
s->a_control_word_offset) {
287 for (
int y = 0; y < avctx->
height; y++) {
288 for (
int x = 0; x < avctx->
width; x++)
296 for (
int y = 0; y < avctx->
height; y += 16) {
297 for (
int x = 0; x < avctx->
width; x += 16) {
298 unsigned m = bytestream2_get_le32(gb);
299 unsigned offset = bytestream2_get_le32(gb);
300 unsigned alpha0, alpha1;
303 if (
offset >= UINT_MAX / 4)
310 control = bytestream2_get_le64(&dgb);
311 alpha0 = control & 0xFF;
312 alpha1 = (control >> 8) & 0xFF;
313 control = control >> 16;
315 for (
int by = 0; by < 4; by++) {
316 for (
int bx = 0; bx < 4; bx++) {
319 for (
int i = 0;
i < 4;
i++) {
320 for (
int j = 0; j < 4; j++) {
321 dsta[x + (
i + by * 4) * alinesize + bx * 4 + j] = 0;
326 for (
int i = 0;
i < 4;
i++) {
327 for (
int j = 0; j < 4; j++) {
328 dsta[x + (
i + by * 4) * alinesize + bx * 4 + j] = 4095;
333 for (
int i = 0;
i < 4;
i++) {
334 for (
int j = 0; j < 4; j++) {
335 dsta[x + (
i + by * 4) * alinesize + bx * 4 + j] = (alpha0 + (alpha1 - alpha0) * (control & 7)) << 4;
349 dsta += 16 * alinesize;
355 dstu = (uint16_t *)p->
data[1];
356 dstv = (uint16_t *)p->
data[2];
360 for (
int y = 0; y < avctx->
height; y += 16) {
361 for (
int x = 0; x < avctx->
width; x += 16) {
362 unsigned offset = bytestream2_get_le32(&
rgb) * 4;
363 int u[16][16] = { 0 }, v[16][16] = { 0 };
364 int u0,
v0, u1, v1, udif, vdif;
365 unsigned escape, is8x8, loc;
369 is8x8 = bytestream2_get_le16(&dgb);
370 escape = bytestream2_get_le16(&dgb);
372 if (escape == 0 && is8x8 == 0) {
373 u0 = bytestream2_get_byte(&dgb);
374 v0 = bytestream2_get_byte(&dgb);
375 u1 = bytestream2_get_byte(&dgb);
376 v1 = bytestream2_get_byte(&dgb);
377 loc = bytestream2_get_le32(&dgb);
378 u0 = (u0 << 4) | (u0 & 0xF);
379 v0 = (
v0 << 4) | (
v0 & 0xF);
380 u1 = (u1 << 4) | (u1 & 0xF);
381 v1 = (v1 << 4) | (v1 & 0xF);
385 for (
int i = 0;
i < 16;
i += 4) {
386 for (
int j = 0; j < 16; j += 4) {
387 for (
int ii = 0; ii < 4; ii++) {
388 for (
int jj = 0; jj < 4; jj++) {
389 u[
i + ii][j + jj] = u0 + ((udif * (
int)(loc & 3) + 2) / 3);
390 v[
i + ii][j + jj] =
v0 + ((vdif * (
int)(loc & 3) + 2) / 3);
398 for (
int i = 0;
i < 16;
i += 8) {
399 for (
int j = 0; j < 16; j += 8) {
401 u0 = bytestream2_get_byte(&dgb);
402 v0 = bytestream2_get_byte(&dgb);
403 u1 = bytestream2_get_byte(&dgb);
404 v1 = bytestream2_get_byte(&dgb);
405 loc = bytestream2_get_le32(&dgb);
406 u0 = (u0 << 4) | (u0 & 0xF);
407 v0 = (
v0 << 4) | (
v0 & 0xF);
408 u1 = (u1 << 4) | (u1 & 0xF);
409 v1 = (v1 << 4) | (v1 & 0xF);
413 for (
int ii = 0; ii < 8; ii += 2) {
414 for (
int jj = 0; jj < 8; jj += 2) {
415 for (
int iii = 0; iii < 2; iii++) {
416 for (
int jjj = 0; jjj < 2; jjj++) {
417 u[
i + ii + iii][j + jj + jjj] = u0 + ((udif * (
int)(loc & 3) + 2) / 3);
418 v[
i + ii + iii][j + jj + jjj] =
v0 + ((vdif * (
int)(loc & 3) + 2) / 3);
426 for (
int ii = 0; ii < 8; ii += 4) {
427 for (
int jj = 0; jj < 8; jj += 4) {
428 u0 = bytestream2_get_byte(&dgb);
429 v0 = bytestream2_get_byte(&dgb);
430 u1 = bytestream2_get_byte(&dgb);
431 v1 = bytestream2_get_byte(&dgb);
432 loc = bytestream2_get_le32(&dgb);
433 u0 = (u0 << 4) | (u0 & 0xF);
434 v0 = (
v0 << 4) | (
v0 & 0xF);
435 u1 = (u1 << 4) | (u1 & 0xF);
436 v1 = (v1 << 4) | (v1 & 0xF);
440 for (
int iii = 0; iii < 4; iii++) {
441 for (
int jjj = 0; jjj < 4; jjj++) {
442 u[
i + ii + iii][j + jj + jjj] = u0 + ((udif * (
int)(loc & 3) + 2) / 3);
443 v[
i + ii + iii][j + jj + jjj] =
v0 + ((vdif * (
int)(loc & 3) + 2) / 3);
457 for (
int i = 0;
i < 16;
i++) {
458 for (
int j = 0; j < 16; j++) {
459 dstu[x +
i * ulinesize + j] =
u[
i][j];
460 dstv[x +
i * vlinesize + j] = v[
i][j];
465 dstu += 16 * ulinesize;
466 dstv += 16 * vlinesize;
473 void *
data,
int *got_frame,
480 unsigned uncompressed_size;
484 if (avpkt->
size <= 40)
489 if (bytestream2_get_le32(gb) !=
MKBETAG(
'N',
'L',
'C',
'1'))
492 uncompressed_size = bytestream2_get_le32(gb);
493 s->compressed_size = bytestream2_get_le32(gb);
494 s->format = bytestream2_get_le32(gb);
499 if (
s->format == 0) {
504 if (uncompressed_size >
s->lzf_size)
508 }
else if (
s->format == 1) {
514 if (!
s->uncompressed_buffer)
520 if (ret != uncompressed_size)
543 s->uncompressed_size = 0;
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
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_seek(GetByteContext *g, int offset, int whence)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
#define u(width, name, range_min, range_max)
#define bit(string, value)
#define MKBETAG(a, b, c, d)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static float add(float src0, float src1)
bitstream reader API header.
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_FRAME_THREADS
Codec supports frame-level multithreading.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AV_PICTURE_TYPE_I
Intra.
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.
int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, size_t *size, unsigned *allocated_size)
Decompress LZF data into *buf, reallocating it as needed.
AVCodec ff_notchlc_decoder
static int decode_blocks(AVCodecContext *avctx, AVFrame *p, ThreadFrame *frame, unsigned uncompressed_size)
static av_cold int decode_init(AVCodecContext *avctx)
static av_cold int decode_end(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int lz4_decompress(AVCodecContext *avctx, GetByteContext *gb, PutByteContext *pb)
@ AVCOL_RANGE_JPEG
Full range content.
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
#define AV_PIX_FMT_YUVA444P12
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static const SheerTable rgb[2]
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
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
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.
uint8_t * uncompressed_buffer
unsigned uncompressed_size
unsigned y_control_data_offset
unsigned uv_offset_data_offset
unsigned y_data_row_offsets
unsigned a_control_word_offset
static const uint8_t offset[127][2]