26 #define BITSTREAM_READER_LE 74 #define HISTORY_SIZE (64 * 1024) 80 unsigned reference_pos, match_length,
delta,
pos = 0;
84 uint8_t token = bytestream2_get_byte(gb);
85 unsigned num_literals = token >> 4;
87 if (num_literals == 15) {
88 unsigned char current;
90 current = bytestream2_get_byte(gb);
91 num_literals += current;
92 }
while (current == 255);
102 while (num_literals-- > 0) {
103 history[pos++] = bytestream2_get_byte(gb);
114 delta = bytestream2_get_byte(gb);
115 delta |= (unsigned)bytestream2_get_byte(gb) << 8;
118 match_length = 4 + (token & 0x0F);
119 if (match_length == 4 + 0x0F) {
123 current = bytestream2_get_byte(gb);
124 match_length += current;
125 }
while (current == 255);
129 if (pos >= reference_pos + match_length || reference_pos >= pos + match_length) {
130 memcpy(history + pos, history + reference_pos, match_length);
133 while (match_length-- > 0)
134 history[pos++] = history[reference_pos++];
137 while (match_length-- > 0) {
138 history[pos++] = history[reference_pos++];
159 int ylinesize, ulinesize, vlinesize, alinesize;
160 uint16_t *dsty, *dstu, *dstv, *dsta;
216 s->
data_end = bytestream2_get_le32(gb);
217 if (s->
data_end > uncompressed_size)
236 dsty = (uint16_t *)p->
data[0];
237 dsta = (uint16_t *)p->
data[3];
241 for (
int y = 0; y < avctx->
height; y += 4) {
242 const unsigned row_offset = bytestream2_get_le32(&rgb);
249 for (
int x = 0; x < avctx->
width; x += 4) {
250 unsigned item = bytestream2_get_le32(gb);
251 unsigned y_min = item & 4095;
252 unsigned y_max = (item >> 12) & 4095;
253 unsigned y_diff = y_max - y_min;
256 control[0] = (item >> 24) & 3;
257 control[1] = (item >> 26) & 3;
258 control[2] = (item >> 28) & 3;
259 control[3] = (item >> 30) & 3;
261 for (
int i = 0;
i < 4;
i++) {
262 const int nb_bits = control[
i] + 1;
263 const int div = (1 << nb_bits) - 1;
264 const int add = div - 1;
266 dsty[x +
i * ylinesize + 0] = av_clip_uintp2(y_min + ((y_diff *
get_bits(&bit, nb_bits) + add) / div), 12);
267 dsty[x +
i * ylinesize + 1] = av_clip_uintp2(y_min + ((y_diff *
get_bits(&bit, nb_bits) + add) / div), 12);
268 dsty[x +
i * ylinesize + 2] = av_clip_uintp2(y_min + ((y_diff *
get_bits(&bit, nb_bits) + add) / div), 12);
269 dsty[x +
i * ylinesize + 3] = av_clip_uintp2(y_min + ((y_diff *
get_bits(&bit, nb_bits) + add) / div), 12);
273 dsty += 4 * ylinesize;
274 dsta += 4 * alinesize;
282 dstu = (uint16_t *)p->
data[1];
283 dstv = (uint16_t *)p->
data[2];
287 for (
int y = 0; y < avctx->
height; y += 16) {
288 for (
int x = 0; x < avctx->
width; x += 16) {
289 unsigned offset = bytestream2_get_le32(&rgb) * 4;
290 int u[16][16] = { 0 }, v[16][16] = { 0 };
291 int u0,
v0, u1, v1, udif, vdif;
292 unsigned escape, is8x8, loc;
296 is8x8 = bytestream2_get_le16(&dgb);
297 escape = bytestream2_get_le16(&dgb);
299 if (escape == 0 && is8x8 == 0) {
300 u0 = bytestream2_get_byte(&dgb);
301 v0 = bytestream2_get_byte(&dgb);
302 u1 = bytestream2_get_byte(&dgb);
303 v1 = bytestream2_get_byte(&dgb);
304 loc = bytestream2_get_le32(&dgb);
305 u0 = (u0 << 4) | (u0 & 0xF);
306 v0 = (v0 << 4) | (v0 & 0xF);
307 u1 = (u1 << 4) | (u1 & 0xF);
308 v1 = (v1 << 4) | (v1 & 0xF);
312 for (
int i = 0;
i < 16;
i += 4) {
313 for (
int j = 0; j < 16; j += 4) {
314 for (
int ii = 0; ii < 4; ii++) {
315 for (
int jj = 0; jj < 4; jj++) {
316 u[
i + ii][j + jj] = u0 + ((udif * (
int)(loc & 3) + 2) / 3);
317 v[
i + ii][j + jj] = v0 + ((vdif * (
int)(loc & 3) + 2) / 3);
325 for (
int i = 0;
i < 16;
i += 8) {
326 for (
int j = 0; j < 16; j += 8) {
328 u0 = bytestream2_get_byte(&dgb);
329 v0 = bytestream2_get_byte(&dgb);
330 u1 = bytestream2_get_byte(&dgb);
331 v1 = bytestream2_get_byte(&dgb);
332 loc = bytestream2_get_le32(&dgb);
333 u0 = (u0 << 4) | (u0 & 0xF);
334 v0 = (v0 << 4) | (v0 & 0xF);
335 u1 = (u1 << 4) | (u1 & 0xF);
336 v1 = (v1 << 4) | (v1 & 0xF);
340 for (
int ii = 0; ii < 8; ii += 2) {
341 for (
int jj = 0; jj < 8; jj += 2) {
342 for (
int iii = 0; iii < 2; iii++) {
343 for (
int jjj = 0; jjj < 2; jjj++) {
344 u[
i + ii + iii][j + jj + jjj] = u0 + ((udif * (
int)(loc & 3) + 2) / 3);
345 v[
i + ii + iii][j + jj + jjj] = v0 + ((vdif * (
int)(loc & 3) + 2) / 3);
353 for (
int ii = 0; ii < 8; ii += 4) {
354 for (
int jj = 0; jj < 8; jj += 4) {
355 u0 = bytestream2_get_byte(&dgb);
356 v0 = bytestream2_get_byte(&dgb);
357 u1 = bytestream2_get_byte(&dgb);
358 v1 = bytestream2_get_byte(&dgb);
359 loc = bytestream2_get_le32(&dgb);
360 u0 = (u0 << 4) | (u0 & 0xF);
361 v0 = (v0 << 4) | (v0 & 0xF);
362 u1 = (u1 << 4) | (u1 & 0xF);
363 v1 = (v1 << 4) | (v1 & 0xF);
367 for (
int iii = 0; iii < 4; iii++) {
368 for (
int jjj = 0; jjj < 4; jjj++) {
369 u[
i + ii + iii][j + jj + jjj] = u0 + ((udif * (
int)(loc & 3) + 2) / 3);
370 v[
i + ii + iii][j + jj + jjj] = v0 + ((vdif * (
int)(loc & 3) + 2) / 3);
384 for (
int i = 0;
i < 16;
i++) {
385 for (
int j = 0; j < 16; j++) {
386 dstu[x +
i * ulinesize + j] = u[
i][j];
387 dstv[x +
i * vlinesize + j] = v[
i][j];
392 dstu += 16 * ulinesize;
393 dstv += 16 * vlinesize;
400 void *
data,
int *got_frame,
411 if (avpkt->
size <= 40)
416 if (bytestream2_get_le32(gb) !=
MKBETAG(
'N',
'L',
'C',
'1'))
419 uncompressed_size = bytestream2_get_le32(gb);
421 s->
format = bytestream2_get_le32(gb);
431 if (uncompressed_size > s->
lzf_size)
435 }
else if (s->
format == 1) {
444 if (ret != uncompressed_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
unsigned a_control_word_offset
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
unsigned uncompressed_size
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.
static av_cold int init(AVCodecContext *avctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
unsigned y_data_row_offsets
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)
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...
static av_cold int decode_init(AVCodecContext *avctx)
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
AVCodec ff_notchlc_decoder
Multithreading support functions.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define u(width, name, range_min, range_max)
unsigned y_control_data_offset
bitstream reader API header.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
int ff_lzf_uncompress(GetByteContext *gb, uint8_t **buf, int64_t *size)
#define i(width, name, range_min, range_max)
#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)
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
enum AVPictureType pict_type
Picture type of the frame.
static int decode_blocks(AVCodecContext *avctx, AVFrame *p, ThreadFrame *frame, unsigned uncompressed_size)
int width
picture width / height.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
the normal 2^n-1 "JPEG" YUV ranges
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
static av_cold int decode_end(AVCodecContext *avctx)
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
uint8_t * uncompressed_buffer
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
IEC 61966-2-1 (sRGB or sYCC)
common internal api header.
static int lz4_decompress(AVCodecContext *avctx, GetByteContext *gb, PutByteContext *pb)
#define bit(string, value)
unsigned uv_offset_data_offset
#define MKBETAG(a, b, c, d)
int key_frame
1 -> keyframe, 0-> not
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.