|
|
@ -34,7 +34,6 @@ |
|
|
|
#include "jpegls.h" |
|
|
|
#include "jpegls.h" |
|
|
|
#include "jpeglsdec.h" |
|
|
|
#include "jpeglsdec.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Uncomment this to significantly speed up decoding of broken JPEG-LS |
|
|
|
* Uncomment this to significantly speed up decoding of broken JPEG-LS |
|
|
|
* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit. |
|
|
|
* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit. |
|
|
@ -45,7 +44,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
//#define JLS_BROKEN
|
|
|
|
//#define JLS_BROKEN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Decode LSE block with initialization parameters |
|
|
|
* Decode LSE block with initialization parameters |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -86,13 +84,16 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get context-dependent Golomb code, decode it and update context |
|
|
|
* Get context-dependent Golomb code, decode it and update context |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){ |
|
|
|
static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q) |
|
|
|
|
|
|
|
{ |
|
|
|
int k, ret; |
|
|
|
int k, ret; |
|
|
|
|
|
|
|
|
|
|
|
for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); |
|
|
|
for (k = 0; (state->N[Q] << k) < state->A[Q]; k++) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef JLS_BROKEN |
|
|
|
#ifdef JLS_BROKEN |
|
|
|
if(!show_bits_long(gb, 32))return -1; |
|
|
|
if (!show_bits_long(gb, 32)) |
|
|
|
|
|
|
|
return -1; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp); |
|
|
|
ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp); |
|
|
|
|
|
|
|
|
|
|
@ -114,7 +115,9 @@ static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q) |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get Golomb code, decode it and update state for run termination |
|
|
|
* Get Golomb code, decode it and update state for run termination |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){ |
|
|
|
static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, |
|
|
|
|
|
|
|
int RItype, int limit_add) |
|
|
|
|
|
|
|
{ |
|
|
|
int k, ret, temp, map; |
|
|
|
int k, ret, temp, map; |
|
|
|
int Q = 365 + RItype; |
|
|
|
int Q = 365 + RItype; |
|
|
|
|
|
|
|
|
|
|
@ -122,12 +125,15 @@ static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RI |
|
|
|
if (RItype) |
|
|
|
if (RItype) |
|
|
|
temp += state->N[Q] >> 1; |
|
|
|
temp += state->N[Q] >> 1; |
|
|
|
|
|
|
|
|
|
|
|
for(k = 0; (state->N[Q] << k) < temp; k++); |
|
|
|
for (k = 0; (state->N[Q] << k) < temp; k++) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef JLS_BROKEN |
|
|
|
#ifdef JLS_BROKEN |
|
|
|
if(!show_bits_long(gb, 32))return -1; |
|
|
|
if (!show_bits_long(gb, 32)) |
|
|
|
|
|
|
|
return -1; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp); |
|
|
|
ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, |
|
|
|
|
|
|
|
state->qbpp); |
|
|
|
|
|
|
|
|
|
|
|
/* decode mapped error */ |
|
|
|
/* decode mapped error */ |
|
|
|
map = 0; |
|
|
|
map = 0; |
|
|
@ -153,7 +159,10 @@ static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RI |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Decode one line of image |
|
|
|
* Decode one line of image |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){ |
|
|
|
static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, |
|
|
|
|
|
|
|
void *last, void *dst, int last2, int w, |
|
|
|
|
|
|
|
int stride, int comp, int bits) |
|
|
|
|
|
|
|
{ |
|
|
|
int i, x = 0; |
|
|
|
int i, x = 0; |
|
|
|
int Ra, Rb, Rc, Rd; |
|
|
|
int Ra, Rb, Rc, Rd; |
|
|
|
int D0, D1, D2; |
|
|
|
int D0, D1, D2; |
|
|
@ -170,7 +179,9 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void * |
|
|
|
D1 = Rb - Rc; |
|
|
|
D1 = Rb - Rc; |
|
|
|
D2 = Rc - Ra; |
|
|
|
D2 = Rc - Ra; |
|
|
|
/* run mode */ |
|
|
|
/* run mode */ |
|
|
|
if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { |
|
|
|
if ((FFABS(D0) <= state->near) && |
|
|
|
|
|
|
|
(FFABS(D1) <= state->near) && |
|
|
|
|
|
|
|
(FFABS(D2) <= state->near)) { |
|
|
|
int r; |
|
|
|
int r; |
|
|
|
int RItype; |
|
|
|
int RItype; |
|
|
|
|
|
|
|
|
|
|
@ -178,9 +189,8 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void * |
|
|
|
while (get_bits1(&s->gb)) { |
|
|
|
while (get_bits1(&s->gb)) { |
|
|
|
int r; |
|
|
|
int r; |
|
|
|
r = 1 << ff_log2_run[state->run_index[comp]]; |
|
|
|
r = 1 << ff_log2_run[state->run_index[comp]]; |
|
|
|
if(x + r * stride > w) { |
|
|
|
if (x + r * stride > w) |
|
|
|
r = (w - x) / stride; |
|
|
|
r = (w - x) / stride; |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i < r; i++) { |
|
|
|
for (i = 0; i < r; i++) { |
|
|
|
W(dst, x, Ra); |
|
|
|
W(dst, x, Ra); |
|
|
|
x += stride; |
|
|
|
x += stride; |
|
|
@ -205,7 +215,8 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void * |
|
|
|
/* decode run termination value */ |
|
|
|
/* decode run termination value */ |
|
|
|
Rb = R(last, x); |
|
|
|
Rb = R(last, x); |
|
|
|
RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; |
|
|
|
RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; |
|
|
|
err = ls_get_code_runterm(&s->gb, state, RItype, ff_log2_run[state->run_index[comp]]); |
|
|
|
err = ls_get_code_runterm(&s->gb, state, RItype, |
|
|
|
|
|
|
|
ff_log2_run[state->run_index[comp]]); |
|
|
|
if (state->run_index[comp]) |
|
|
|
if (state->run_index[comp]) |
|
|
|
state->run_index[comp]--; |
|
|
|
state->run_index[comp]--; |
|
|
|
|
|
|
|
|
|
|
@ -220,7 +231,9 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void * |
|
|
|
} else { /* regular mode */ |
|
|
|
} else { /* regular mode */ |
|
|
|
int context, sign; |
|
|
|
int context, sign; |
|
|
|
|
|
|
|
|
|
|
|
context = ff_jpegls_quantize(state, D0) * 81 + ff_jpegls_quantize(state, D1) * 9 + ff_jpegls_quantize(state, D2); |
|
|
|
context = ff_jpegls_quantize(state, D0) * 81 + |
|
|
|
|
|
|
|
ff_jpegls_quantize(state, D1) * 9 + |
|
|
|
|
|
|
|
ff_jpegls_quantize(state, D2); |
|
|
|
pred = mid_pred(Ra, Ra + Rb - Rc, Rb); |
|
|
|
pred = mid_pred(Ra, Ra + Rb - Rc, Rb); |
|
|
|
|
|
|
|
|
|
|
|
if (context < 0) { |
|
|
|
if (context < 0) { |
|
|
@ -255,7 +268,9 @@ static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void * |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){ |
|
|
|
int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, |
|
|
|
|
|
|
|
int point_transform, int ilv) |
|
|
|
|
|
|
|
{ |
|
|
|
int i, t = 0; |
|
|
|
int i, t = 0; |
|
|
|
uint8_t *zero, *last, *cur; |
|
|
|
uint8_t *zero, *last, *cur; |
|
|
|
JLSState *state; |
|
|
|
JLSState *state; |
|
|
@ -282,7 +297,9 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor |
|
|
|
else |
|
|
|
else |
|
|
|
shift = point_transform + (16 - s->bits); |
|
|
|
shift = point_transform + (16 - s->bits); |
|
|
|
|
|
|
|
|
|
|
|
av_dlog(s->avctx, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n", |
|
|
|
av_dlog(s->avctx, |
|
|
|
|
|
|
|
"JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) " |
|
|
|
|
|
|
|
"RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n", |
|
|
|
s->width, s->height, state->near, state->maxval, |
|
|
|
s->width, s->height, state->near, state->maxval, |
|
|
|
state->T1, state->T2, state->T3, |
|
|
|
state->T1, state->T2, state->T3, |
|
|
|
state->reset, state->limit, state->qbpp, state->range); |
|
|
|
state->reset, state->limit, state->qbpp, state->range); |
|
|
@ -316,7 +333,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor |
|
|
|
width = s->width * 3; |
|
|
|
width = s->width * 3; |
|
|
|
for (i = 0; i < s->height; i++) { |
|
|
|
for (i = 0; i < s->height; i++) { |
|
|
|
for (j = 0; j < 3; j++) { |
|
|
|
for (j = 0; j < 3; j++) { |
|
|
|
ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8); |
|
|
|
ls_decode_line(state, s, last + j, cur + j, |
|
|
|
|
|
|
|
Rc[j], width, 3, j, 8); |
|
|
|
Rc[j] = last[j]; |
|
|
|
Rc[j] = last[j]; |
|
|
|
|
|
|
|
|
|
|
|
if (s->restart_interval && !--s->restart_count) { |
|
|
|
if (s->restart_interval && !--s->restart_count) { |
|
|
@ -328,7 +346,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor |
|
|
|
cur += s->picture_ptr->linesize[0]; |
|
|
|
cur += s->picture_ptr->linesize[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (ilv == 2) { /* sample interleaving */ |
|
|
|
} else if (ilv == 2) { /* sample interleaving */ |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n"); |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
|
|
|
"Sample interleaved images are not supported.\n"); |
|
|
|
av_free(state); |
|
|
|
av_free(state); |
|
|
|
av_free(zero); |
|
|
|
av_free(zero); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
@ -343,18 +362,16 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor |
|
|
|
uint8_t *src = s->picture_ptr->data[0]; |
|
|
|
uint8_t *src = s->picture_ptr->data[0]; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < s->height; i++) { |
|
|
|
for (i = 0; i < s->height; i++) { |
|
|
|
for(x = off; x < w; x+= stride){ |
|
|
|
for (x = off; x < w; x += stride) |
|
|
|
src[x] <<= shift; |
|
|
|
src[x] <<= shift; |
|
|
|
} |
|
|
|
|
|
|
|
src += s->picture_ptr->linesize[0]; |
|
|
|
src += s->picture_ptr->linesize[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
uint16_t *src = (uint16_t *)s->picture_ptr->data[0]; |
|
|
|
uint16_t *src = (uint16_t *)s->picture_ptr->data[0]; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < s->height; i++) { |
|
|
|
for (i = 0; i < s->height; i++) { |
|
|
|
for(x = 0; x < w; x++){ |
|
|
|
for (x = 0; x < w; x++) |
|
|
|
src[x] <<= shift; |
|
|
|
src[x] <<= shift; |
|
|
|
} |
|
|
|
|
|
|
|
src += s->picture_ptr->linesize[0] / 2; |
|
|
|
src += s->picture_ptr->linesize[0] / 2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -365,9 +382,9 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AVCodec ff_jpegls_decoder = { |
|
|
|
AVCodec ff_jpegls_decoder = { |
|
|
|
.name = "jpegls", |
|
|
|
.name = "jpegls", |
|
|
|
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"), |
|
|
|
.type = AVMEDIA_TYPE_VIDEO, |
|
|
|
.type = AVMEDIA_TYPE_VIDEO, |
|
|
|
.id = AV_CODEC_ID_JPEGLS, |
|
|
|
.id = AV_CODEC_ID_JPEGLS, |
|
|
|
.priv_data_size = sizeof(MJpegDecodeContext), |
|
|
|
.priv_data_size = sizeof(MJpegDecodeContext), |
|
|
@ -375,5 +392,4 @@ AVCodec ff_jpegls_decoder = { |
|
|
|
.close = ff_mjpeg_decode_end, |
|
|
|
.close = ff_mjpeg_decode_end, |
|
|
|
.decode = ff_mjpeg_decode_frame, |
|
|
|
.decode = ff_mjpeg_decode_frame, |
|
|
|
.capabilities = CODEC_CAP_DR1, |
|
|
|
.capabilities = CODEC_CAP_DR1, |
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"), |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|