37 #define PIXLET_MAGIC 0xDEADBEEF
98 if (!
ctx->filter[0] || !
ctx->filter[1] || !
ctx->prediction)
101 for (plane = 0; plane < 3; plane++) {
102 unsigned shift = plane > 0;
111 unsigned scale =
ctx->levels - (
i / 3);
113 ctx->band[plane][
i + 1].width =
w >> scale;
114 ctx->band[plane][
i + 1].height =
h >> scale;
115 ctx->band[plane][
i + 1].size = (
w >> scale) * (
h >> scale);
117 ctx->band[plane][
i + 1].x = (
w >> scale) * (((
i + 1) % 3) != 2);
118 ctx->band[plane][
i + 1].y = (
h >> scale) * (((
i + 1) % 3) != 1);
130 unsigned cnt1, nbits, k, j = 0,
i = 0;
132 int rlen, escape,
flag = 0;
142 escape = ((1 << nbits) - 1) * cnt1;
145 escape =
value + ((1 << nbits) - 1) * cnt1 - 1;
152 dst[j++] =
value * ((escape +
flag + 1) >> 1);
173 rlen =
value + escape * cnt1 - 1;
176 rlen = escape * cnt1;
184 for (k = 0; k < rlen; k++) {
193 flag = rlen < 0xFFFF ? 1 : 0;
201 int size,
int c,
int a,
int d,
206 unsigned cnt1, shbits, rlen, nbits, length,
i = 0, j = 0, k;
207 int ret, escape, pfx,
value, yflag, xflag,
flag = 0;
225 if (((
state >> 8) + 3) & 0xFFFFFFF)
231 if (cnt1 >= length) {
234 pfx = 14 + ((((uint64_t)(
value - 14)) >> 32) & (
value - 14));
235 if (pfx < 1 || pfx > 25)
237 cnt1 *= (1 << pfx) - 1;
250 if (
flag + cnt1 == 0) {
254 tmp = (int64_t)
c * ((yflag + 1) >> 1) + (
c >> 1);
264 state += (int64_t)d * (uint64_t)yflag - ((int64_t)(d * (uint64_t)
state) >> 8);
275 if (pfx < 1 || pfx > 25)
281 rlen =
value + escape * cnt1 - 1;
284 rlen = escape * cnt1;
292 rlen =
value + 8 * escape;
295 if (rlen > 0xFFFF ||
i + rlen >
size)
299 for (k = 0; k < rlen; k++) {
308 flag = rlen < 0xFFFF ? 1 : 0;
322 for (
i = 0;
i <
ctx->levels * 3;
i++) {
327 int16_t *dest = (int16_t *)
frame->
data[plane] +
328 ctx->band[plane][
i + 1].x +
330 unsigned size =
ctx->band[plane][
i + 1].size;
331 uint32_t magic = bytestream2_get_be32(&
ctx->gb);
335 "wrong magic number: 0x%08"PRIX32
" for plane %d, band %d\n",
348 "error in highpass coefficients for plane %d, band %d\n",
369 for (j = 1; j <
width; j++) {
380 int16_t *low, *high, *ll, *lh, *hl, *hh;
386 high = &low[hsize + 8];
388 memcpy(low, dest,
size);
389 memcpy(high, dest + hsize,
size);
395 for (
i = 4, j = 2;
i;
i--, j++, ll--, hh++, lh++, hl--) {
396 low[
i - 5] = low[j - 1];
398 high[
i - 5] = high[j - 2];
402 for (
i = 0;
i < hsize;
i++) {
403 value = (int64_t) low [
i + 1] * -INT64_C(325392907) +
404 (int64_t) low [
i + 0] * INT64_C(3687786320) +
405 (int64_t) low [
i - 1] * -INT64_C(325392907) +
406 (int64_t) high[
i + 0] * INT64_C(1518500249) +
407 (int64_t) high[
i - 1] * INT64_C(1518500249);
411 for (
i = 0;
i < hsize;
i++) {
412 value = (int64_t) low [
i + 2] * -INT64_C(65078576) +
413 (int64_t) low [
i + 1] * INT64_C(1583578880) +
414 (int64_t) low [
i + 0] * INT64_C(1583578880) +
415 (int64_t) low [
i - 1] * -INT64_C(65078576) +
416 (int64_t) high[
i + 1] * INT64_C(303700064) +
417 (int64_t) high[
i + 0] * -INT64_C(3644400640) +
418 (int64_t) high[
i - 1] * INT64_C(303700064);
425 int64_t *scaling_h, int64_t *scaling_v)
428 unsigned scaled_width, scaled_height;
437 int64_t scale_v = scaling_v[
i];
438 int64_t scale_h = scaling_h[
i];
443 for (j = 0; j < scaled_height; j++) {
444 filterfn(ptr,
ctx->filter[1], scaled_width, scale_v);
448 for (j = 0; j < scaled_width; j++) {
450 for (k = 0; k < scaled_height; k++) {
458 for (k = 0; k < scaled_height; k++) {
469 int max = (1 << depth) - 1;
471 if (
ctx->depth == depth)
480 int w,
int h,
int depth)
483 uint16_t *dsty = (uint16_t *)
frame->
data[0];
484 int16_t *srcy = (int16_t *)
frame->
data[0];
486 uint16_t *lut =
ctx->lut;
489 for (j = 0; j <
h; j++) {
490 for (
i = 0;
i <
w;
i++) {
493 else if (srcy[
i] > ((1 << depth) - 1))
496 dsty[
i] = lut[srcy[
i]];
505 uint16_t *dstu = (uint16_t *)
frame->
data[1];
506 uint16_t *dstv = (uint16_t *)
frame->
data[2];
507 int16_t *srcu = (int16_t *)
frame->
data[1];
508 int16_t *srcv = (int16_t *)
frame->
data[2];
511 const unsigned add = 1 << (depth - 1);
512 const unsigned shift = 16 - depth;
515 for (j = 0; j <
h; j++) {
516 for (
i = 0;
i <
w;
i++) {
532 unsigned shift = plane > 0;
536 for (
i =
ctx->levels - 1;
i >= 0;
i--) {
543 ctx->scaling[plane][
H][
i] = (1000000ULL << 32) /
h;
544 ctx->scaling[plane][
V][
i] = (1000000ULL << 32) / v;
558 ctx->band[plane][0].width - 1, 0);
561 "error in lowpass coefficients for plane %d, top row\n", plane);
566 ctx->band[plane][0].height - 1, 1,
stride);
569 "error in lowpass coefficients for plane %d, left column\n",
575 (
ctx->band[plane][0].width - 1) * (
ctx->band[plane][0].height - 1),
579 "error in lowpass coefficients for plane %d, rest\n", plane);
598 ctx->scaling[plane][
V]);
610 uint32_t pktsize, depth;
614 pktsize = bytestream2_get_be32(&
ctx->gb);
625 if (bytestream2_get_be32(&
ctx->gb) != 1)
629 width = bytestream2_get_be32(&
ctx->gb);
639 ctx->levels = bytestream2_get_be32(&
ctx->gb);
642 depth = bytestream2_get_be32(&
ctx->gb);
643 if (depth < 8 || depth > 15) {
680 for (
i = 0;
i < 3;
i++) {
static double val(void *priv, double ch)
Libavcodec external API header.
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 void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(GetByteContext *g)
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.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static float add(float src0, float src1)
bitstream reader API header.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static const uint8_t * align_get_bits(GetBitContext *s)
static unsigned int show_bits(GetBitContext *s, int n)
Show 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_FLAG_GRAY
Only decode/encode grayscale.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#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_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.
static av_const int sign_extend(int val, unsigned bits)
#define AV_PIX_FMT_YUV420P16
@ AVCOL_RANGE_JPEG
Full range content.
static int read_highpass(AVCodecContext *avctx, uint8_t *ptr, int plane, AVFrame *frame)
static int pixlet_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static void filterfn(int16_t *dest, int16_t *tmp, unsigned size, int64_t scale)
static void reconstruction(AVCodecContext *avctx, int16_t *dest, unsigned width, unsigned height, ptrdiff_t stride, int64_t *scaling_h, int64_t *scaling_v)
static int read_low_coeffs(AVCodecContext *avctx, int16_t *dst, int size, int width, ptrdiff_t stride)
static void lowpass_prediction(int16_t *dst, int16_t *pred, int width, int height, ptrdiff_t stride)
AVCodec ff_pixlet_decoder
static void postprocess_chroma(AVFrame *frame, int w, int h, int depth)
static av_cold int pixlet_init(AVCodecContext *avctx)
static void build_luma_lut(AVCodecContext *avctx, int depth)
static av_cold int pixlet_close(AVCodecContext *avctx)
static void postprocess_luma(AVCodecContext *avctx, AVFrame *frame, int w, int h, int depth)
static int init_decoder(AVCodecContext *avctx)
static int decode_plane(AVCodecContext *avctx, int plane, const AVPacket *avpkt, AVFrame *frame)
static void free_buffers(AVCodecContext *avctx)
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)
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
static int shift(int a, int b)
Describe the class of an AVClass context structure.
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.
int flags
AV_CODEC_FLAG_*.
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
enum AVColorRange color_range
MPEG vs JPEG YUV range.
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.
SubBand band[4][NB_LEVELS *3+1]
int64_t scaling[4][2][NB_LEVELS]
#define av_malloc_array(a, b)
#define avpriv_request_sample(...)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.