73 for (plane = 0; plane < 3; plane++) {
74 unsigned shift = plane > 0;
75 unsigned w = ctx->
w >>
shift;
82 for (i = 0; i < NB_LEVELS * 3; i++) {
83 unsigned scale = ctx->
levels - (i / 3);
89 ctx->
band[
plane][i + 1].
x = (w >> scale) * (((i + 1) % 3) != 2);
90 ctx->
band[
plane][i + 1].
y = (h >> scale) * (((i + 1) % 3) != 1);
126 unsigned cnt1, nbits, k, j = 0, i = 0;
128 int rlen, escape,
flag = 0;
131 nbits =
FFMIN(
ff_clz((state >> 8) + 3) ^ 0x1F, 14);
138 escape = ((1 << nbits) - 1) * cnt1;
141 escape = value + ((1 << nbits) - 1) * cnt1 - 1;
147 value = -((escape +
flag) & 1) | 1;
148 dst[j++] = value * ((escape + flag + 1) >> 1);
154 state = 120 * (escape +
flag) + state - (120 * state >> 8);
157 if (state * 4ULL > 0xFF || i >= size)
160 nbits = ((state + 8) >> 5) + (state ?
ff_clz(state) : 32) - 24;
161 escape = av_mod_uintp2(16383, nbits);
169 rlen = value + escape * cnt1 - 1;
172 rlen = escape * cnt1;
180 for (k = 0; k < rlen; k++) {
189 flag = rlen < 0xFFFF ? 1 : 0;
202 unsigned cnt1, shbits, rlen, nbits,
length, i = 0, j = 0, k;
203 int ret, escape, pfx,
value, yflag, xflag,
flag = 0;
210 nbits = 33 -
ff_clz(a ^ (a >> 31));
220 if (state >> 8 != -3) {
221 value =
ff_clz((state >> 8) + 3) ^ 0x1F;
228 if (cnt1 >= length) {
231 pfx = 14 + ((((uint64_t)(value - 14)) >> 32) & (value - 14));
232 if (pfx < 1 || pfx > 25)
234 cnt1 *= (1 << pfx) - 1;
247 if (flag + cnt1 == 0) {
251 tmp = (int64_t)c * ((yflag + 1) >> 1) + (c >> 1);
252 value = xflag + (
tmp ^ -xflag);
261 state += (int64_t)d * (uint64_t)yflag - ((int64_t)(d * (uint64_t)
state) >> 8);
265 if ((uint64_t)state > 0xFF / 4 || i >= size)
268 pfx = ((state + 8) >> 5) + (state ?
ff_clz(state): 32) - 24;
269 escape = av_mod_uintp2(16383, pfx);
272 if (pfx < 1 || pfx > 25)
277 rlen = value + escape * cnt1 - 1;
280 rlen = escape * cnt1;
288 rlen = value + 8 * escape;
291 if (rlen > 0xFFFF || i + rlen > size)
295 for (k = 0; k < rlen; k++) {
304 flag = rlen < 0xFFFF ? 1 : 0;
317 for (i = 0; i < ctx->
levels * 3; i++) {
321 int32_t d = bytestream2_get_be32(&ctx->
gb);
322 int16_t *dest = (int16_t *)frame->
data[plane] + ctx->
band[plane][i + 1].
x +
323 stride * ctx->
band[plane][i + 1].
y;
327 magic = bytestream2_get_be32(&ctx->
gb);
328 if (magic != 0xDEADBEEF) {
330 " for plane %d, band %d\n", magic, plane, i);
338 c, (b >=
FFABS(a)) ? b : a, d,
341 av_log(avctx,
AV_LOG_ERROR,
"error in highpass coefficients for plane %d, band %d\n", plane, i);
355 memset(pred, 0, width *
sizeof(*pred));
357 for (i = 0; i <
height; i++) {
358 val = pred[0] + dst[0];
359 dst[0] = pred[0] =
val;
360 for (j = 1; j <
width; j++) {
361 val = pred[j] + dst[j];
362 dst[j] = pred[j] =
val;
371 int16_t *low, *high, *ll, *lh, *hl, *hh;
377 high = &low[hsize + 8];
379 memcpy(low, dest, size);
380 memcpy(high, dest + hsize, size);
386 for (i = 4, j = 2; i; i--, j++, ll--, hh++, lh++, hl--) {
387 low[i - 5] = low[j - 1];
389 high[i - 5] = high[j - 2];
393 for (i = 0; i < hsize; i++) {
394 value = (int64_t) low [i + 1] * -INT64_C(325392907) +
395 (int64_t) low [i + 0] * INT64_C(3687786320) +
396 (int64_t) low [i - 1] * -INT64_C(325392907) +
397 (int64_t) high[i + 0] * INT64_C(1518500249) +
398 (int64_t) high[i - 1] * INT64_C(1518500249);
399 dest[i * 2] = av_clip_int16(((value >> 32) * scale) >> 32);
402 for (i = 0; i < hsize; i++) {
403 value = (int64_t) low [i + 2] * -INT64_C(65078576) +
404 (int64_t) low [i + 1] * INT64_C(1583578880) +
405 (int64_t) low [i + 0] * INT64_C(1583578880) +
406 (int64_t) low [i - 1] * -INT64_C(65078576) +
407 (int64_t) high[i + 1] * INT64_C(303700064) +
408 (int64_t) high[i + 0] * -INT64_C(3644400640) +
409 (int64_t) high[i - 1] * INT64_C(303700064);
410 dest[i * 2 + 1] = av_clip_int16(((value >> 32) * scale) >> 32);
416 int64_t *scaling_H, int64_t *scaling_V)
419 unsigned scaled_width, scaled_height;
420 int64_t scale_H, scale_V;
424 scaled_height = height >> nb_levels;
425 scaled_width = width >> nb_levels;
428 for (i = 0; i < nb_levels; i++) {
431 scale_H = scaling_H[i];
432 scale_V = scaling_V[i];
435 for (j = 0; j < scaled_height; j++) {
440 for (j = 0; j < scaled_width; j++) {
442 for (k = 0; k < scaled_height; k++) {
450 for (k = 0; k < scaled_height; k++) {
460 uint16_t *dsty = (uint16_t *)frame->
data[0];
461 int16_t *srcy = (int16_t *)frame->
data[0];
462 ptrdiff_t stridey = frame->
linesize[0] / 2;
465 for (j = 0; j <
h; j++) {
466 for (i = 0; i < w; i++) {
469 else if (srcy[i] > ((1 << depth) - 1))
472 dsty[i] = ((int64_t) srcy[i] * srcy[i] * 65535) /
482 uint16_t *dstu = (uint16_t *)frame->
data[1];
483 uint16_t *dstv = (uint16_t *)frame->
data[2];
484 int16_t *srcu = (int16_t *)frame->
data[1];
485 int16_t *srcv = (int16_t *)frame->
data[2];
486 ptrdiff_t strideu = frame->
linesize[1] / 2;
487 ptrdiff_t stridev = frame->
linesize[2] / 2;
488 const unsigned add = 1 << (depth - 1);
492 for (j = 0; j <
h; j++) {
493 for (i = 0; i < w; i++) {
508 unsigned shift = plane > 0;
512 for (i = ctx->
levels - 1; i >= 0; i--) {
525 dst = (int16_t *)frame->
data[plane];
534 av_log(avctx,
AV_LOG_ERROR,
"error in lowpass coefficients for plane %d, top row\n", plane);
540 av_log(avctx,
AV_LOG_ERROR,
"error in lowpass coefficients for plane %d, left column\n", plane);
548 av_log(avctx,
AV_LOG_ERROR,
"error in lowpass coefficients for plane %d, rest\n", plane);
582 pktsize = bytestream2_get_be32(&ctx->
gb);
588 version = bytestream2_get_le32(&ctx->
gb);
593 if (bytestream2_get_be32(&ctx->
gb) != 1)
597 width = bytestream2_get_be32(&ctx->
gb);
598 height = bytestream2_get_be32(&ctx->
gb);
600 if ( width > INT_MAX - (1
U << (
NB_LEVELS + 1))
601 || height > INT_MAX - (1
U << (
NB_LEVELS + 1)))
607 ctx->
levels = bytestream2_get_be32(&ctx->
gb);
610 ctx->
depth = bytestream2_get_be32(&ctx->
gb);
622 if (ctx->
w != w || ctx->
h != h) {
646 for (i = 0; i < 3; i++) {
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
SubBand band[4][NB_LEVELS *3+1]
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
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 void reconstruction(AVCodecContext *avctx, int16_t *dest, unsigned width, unsigned height, ptrdiff_t stride, int nb_levels, int64_t *scaling_H, int64_t *scaling_V)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
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)
static int read_low_coeffs(AVCodecContext *avctx, int16_t *dst, int size, int width, ptrdiff_t stride)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Multithreading support functions.
static void free_buffers(AVCodecContext *avctx)
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
static void filterfn(int16_t *dest, int16_t *tmp, unsigned size, int64_t scale)
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int decode_plane(AVCodecContext *avctx, int plane, AVPacket *avpkt, AVFrame *frame)
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. ...
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
int flags
AV_CODEC_FLAG_*.
static void postprocess_luma(AVFrame *frame, int w, int h, int depth)
const char * name
Name of the codec implementation.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
static int read_highpass(AVCodecContext *avctx, uint8_t *ptr, int plane, AVFrame *frame)
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
GLsizei GLboolean const GLfloat * value
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int init_decoder(AVCodecContext *avctx)
the normal 2^n-1 "JPEG" YUV ranges
static const float pred[4]
#define AV_PIX_FMT_YUV420P16
static av_always_inline int bytestream2_tell(GetByteContext *g)
int64_t scaling[4][2][NB_LEVELS]
static av_cold int pixlet_init(AVCodecContext *avctx)
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 unsigned int get_bits1(GetBitContext *s)
Describe the class of an AVClass context structure.
static void skip_bits(GetBitContext *s, int n)
static void postprocess_chroma(AVFrame *frame, int w, int h, int depth)
static av_const int sign_extend(int val, unsigned bits)
static int pixlet_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int read_high_coeffs(AVCodecContext *avctx, uint8_t *src, int16_t *dst, int size, int c, int a, int d, int width, ptrdiff_t stride)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
GLint GLenum GLboolean GLsizei stride
common internal api header.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
int key_frame
1 -> keyframe, 0-> not
static const uint8_t * align_get_bits(GetBitContext *s)
#define av_malloc_array(a, b)
static void lowpass_prediction(int16_t *dst, int16_t *pred, int width, int height, ptrdiff_t stride)
static av_cold int pixlet_close(AVCodecContext *avctx)
This structure stores compressed data.
AVCodec ff_pixlet_decoder
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.