55 int tid, wt, maxtab,
i, j;
57 int len = bytestream2_get_be16(&
s->gB);
58 id = bytestream2_get_byte(&
s->gB);
65 s->maxval = bytestream2_get_be16u(&
s->gB);
66 s->t1 = bytestream2_get_be16u(&
s->gB);
67 s->t2 = bytestream2_get_be16u(&
s->gB);
68 s->t3 = bytestream2_get_be16u(&
s->gB);
69 s->reset = bytestream2_get_be16u(&
s->gB);
73 s->maxval,
s->t1,
s->t2,
s->t3,
s->reset);
83 tid= bytestream2_get_byte(&
s->gB);
84 wt = bytestream2_get_byte(&
s->gB);
96 else if ((5 + wt*(
s->maxval+1)) < 65535)
99 maxtab = 65530/wt - 1;
102 av_log(
s->avctx,
AV_LOG_DEBUG,
"LSE palette %d tid:%d wt:%d maxtab:%d\n",
id, tid, wt, maxtab);
108 maxtab =
FFMIN(maxtab, (
len - 5) / wt +
s->palette_index);
110 if (
s->palette_index > maxtab)
115 uint32_t *pal = (uint32_t *)
s->picture_ptr->data[1];
118 if (
s->avctx->bits_per_raw_sample > 0 &&
s->avctx->bits_per_raw_sample < 8) {
119 maxtab =
FFMIN(maxtab, (1<<
s->avctx->bits_per_raw_sample)-1);
120 shift = 8 -
s->avctx->bits_per_raw_sample;
125 if (
s->force_pal8 > 1)
130 for (
i=
s->palette_index;
i<=maxtab;
i++) {
132 pal[k] = wt < 4 ? 0xFF000000 : 0;
133 for (j=0; j<wt; j++) {
134 pal[k] |= bytestream2_get_byte(&
s->gB) << (8*(wt-j-1));
137 s->palette_index =
i;
147 ff_dlog(
s->avctx,
"ID=%i, T=%i,%i,%i\n",
id,
s->t1,
s->t2,
s->t3);
159 for (k = 0; ((unsigned)
state->N[
Q] << k) <
state->A[
Q]; k++)
170 ret = -(ret + 1 >> 1);
187 int RItype,
int limit_add)
190 int Q = 365 + RItype;
196 for (k = 0; ((unsigned)
state->N[
Q] << k) <
temp; k++)
210 if (!k && (RItype || ret) && (2 *
state->B[
Q] <
state->N[
Q]))
215 ret =
map - (ret + 1 >> 1);
221 if (
FFABS(ret) > 0xFFFF)
225 ret *=
state->twonear;
235 void *last,
void *
dst,
int last2,
int w,
251 Rc = x ?
R(last, x -
stride) : last2;
269 for (
i = 0;
i <
r;
i++) {
288 for (
i = 0;
i <
r;
i++) {
301 RItype = (
FFABS(Ra - Rb) <=
state->near) ? 1 : 0;
307 if (
state->near && RItype) {
360 int point_transform =
s->Al;
363 uint8_t *
zero, *last, *cur;
366 int decoded_height = 0;
387 cur =
s->picture_ptr->data[0];
391 state->bpp = (
s->bits < 2) ? 2 :
s->bits;
392 state->maxval =
s->maxval;
412 shift = point_transform + (8 -
s->bits);
414 shift = point_transform + (16 -
s->bits);
423 "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) "
424 "RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",
429 ilv, point_transform,
s->bits,
s->cur_scan);
432 s->restart_count = -1;
435 if (
s->cur_scan >
s->nb_components) {
439 stride = (
s->nb_components > 1) ? 3 : 1;
443 for (
i = 0;
i <
s->height;
i++) {
458 t = *((uint16_t *)last);
463 cur +=
s->picture_ptr->linesize[0];
466 }
else if (ilv == 1) {
468 int Rc[3] = { 0, 0, 0 };
469 stride = (
s->nb_components > 1) ? 3 : 1;
470 memset(cur, 0,
s->picture_ptr->linesize[0]);
472 for (
i = 0;
i <
s->height;
i++) {
479 memset(Rc, 0,
sizeof(Rc));
482 for (j = 0; j <
stride; j++) {
492 cur +=
s->picture_ptr->linesize[0];
495 }
else if (ilv == 2) {
505 s->total_ls_decoded_height += decoded_height;
507 if (
s->xfrm &&
s->nb_components == 3) {
510 w =
s->width *
s->nb_components;
513 uint8_t *
src =
s->picture_ptr->data[0];
515 for (
i = 0;
i < decoded_height;
i++) {
518 for (x = off; x + 2 <
w; x += 3) {
519 src[x ] +=
src[x+1] + 128;
520 src[x+2] +=
src[x+1] + 128;
524 for (x = off; x + 2 <
w; x += 3) {
525 src[x ] +=
src[x+1] + 128;
526 src[x+2] += ((
src[x ] +
src[x+1])>>1) + 128;
530 for (x = off; x + 2 <
w; x += 3) {
531 int g =
src[x+0] - ((
src[x+2]+
src[x+1])>>2) + 64;
538 for (x = off; x + 2 <
w; x += 3) {
539 int r =
src[x+0] - (( 359 * (
src[x+2]-128) + 490) >> 8);
540 int g =
src[x+0] - (( 88 * (
src[x+1]-128) - 183 * (
src[x+2]-128) + 30) >> 8);
541 int b =
src[x+0] + ((454 * (
src[x+1]-128) + 574) >> 8);
548 src +=
s->picture_ptr->linesize[0];
557 w =
s->width *
s->nb_components;
560 uint8_t *
src =
s->picture_ptr->data[0];
562 for (
i = 0;
i < decoded_height;
i++) {
563 for (x = off; x <
w; x +=
stride)
565 src +=
s->picture_ptr->linesize[0];
568 uint16_t *
src = (uint16_t *)
s->picture_ptr->data[0];
570 for (
i = 0;
i < decoded_height;
i++) {
571 for (x = 0; x <
w; x++)
573 src +=
s->picture_ptr->linesize[0] / 2;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_jpegls_decoder
static av_cold void close(AVCodecParserContext *s)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_DEBUG_PICT_INFO
#define i(width, name, range_min, range_max)
#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...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int(* init)(AVBSFContext *ctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
static struct @346255127015250356166251341105367306144006377143 state
static const uint8_t bits[8]
bitstream reader API header.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len)
read unsigned golomb rice code (jpegls).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const VDPAUPixFmtMap * map
static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
void ff_jpegls_init_state(JLSState *state)
Calculate initial JPEG-LS parameters.
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
Calculate JPEG-LS codec values.
static int ff_jpegls_update_state_regular(JLSState *state, int Q, int err)
static void ff_jpegls_downscale_state(JLSState *state, int Q)
static int ff_jpegls_quantize(JLSState *s, int v)
Calculate quantized gradient value, used for context determination.
static int ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits)
Decode one line of image.
static int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add)
Get Golomb code, decode it and update state for run termination.
int ff_jpegls_decode_lse(MJpegDecodeContext *s)
Decode LSE block with initialization parameters.
int ff_jpegls_decode_picture(MJpegDecodeContext *s)
static int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q)
Get context-dependent Golomb code, decode it and update context.
static int shift(int a, int b)
Macro definitions for various function/variable attributes.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const uint8_t ff_log2_run[41]
Memory handling functions.
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
int ff_mjpeg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static int ff_mjpeg_handle_restart(MJpegDecodeContext *s, int *restart)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
static const float pred[4]
#define avpriv_request_sample(...)