mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
Merge commit 'ff4fc5ef12a37716c5c5d8928a2db92428e916ec'
* commit 'ff4fc5ef12a37716c5c5d8928a2db92428e916ec': jpegls: K&R formatting cosmetics Conflicts: libavcodec/jpegls.c libavcodec/jpegls.h libavcodec/jpeglsdec.c libavcodec/jpeglsenc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
39354d6089
@ -27,14 +27,16 @@
|
|||||||
|
|
||||||
#include "jpegls.h"
|
#include "jpegls.h"
|
||||||
|
|
||||||
void ff_jpegls_init_state(JLSState *state){
|
void ff_jpegls_init_state(JLSState *state)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
state->twonear = state->near * 2 + 1;
|
state->twonear = state->near * 2 + 1;
|
||||||
state->range = (state->maxval + state->twonear - 1) / state->twonear + 1;
|
state->range = (state->maxval + state->twonear - 1) / state->twonear + 1;
|
||||||
|
|
||||||
// QBPP = ceil(log2(RANGE))
|
// QBPP = ceil(log2(RANGE))
|
||||||
for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++);
|
for (state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++)
|
||||||
|
;
|
||||||
|
|
||||||
state->bpp = FFMAX(av_log2(state->maxval) + 1, 2);
|
state->bpp = FFMAX(av_log2(state->maxval) + 1, 2);
|
||||||
state->limit = 2*(state->bpp + FFMAX(state->bpp, 8)) - state->qbpp;
|
state->limit = 2*(state->bpp + FFMAX(state->bpp, 8)) - state->qbpp;
|
||||||
@ -43,45 +45,56 @@ void ff_jpegls_init_state(JLSState *state){
|
|||||||
state->A[i] = FFMAX(state->range + 32 >> 6, 2);
|
state->A[i] = FFMAX(state->range + 32 >> 6, 2);
|
||||||
state->N[i] = 1;
|
state->N[i] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom value clipping function used in T1, T2, T3 calculation
|
* Custom value clipping function used in T1, T2, T3 calculation
|
||||||
*/
|
*/
|
||||||
static inline int iso_clip(int v, int vmin, int vmax){
|
static inline int iso_clip(int v, int vmin, int vmax)
|
||||||
if(v > vmax || v < vmin) return vmin;
|
{
|
||||||
else return v;
|
if (v > vmax || v < vmin)
|
||||||
|
return vmin;
|
||||||
|
else
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all){
|
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
|
||||||
|
{
|
||||||
const int basic_t1 = 3;
|
const int basic_t1 = 3;
|
||||||
const int basic_t2 = 7;
|
const int basic_t2 = 7;
|
||||||
const int basic_t3 = 21;
|
const int basic_t3 = 21;
|
||||||
int factor;
|
int factor;
|
||||||
|
|
||||||
if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1;
|
if (s->maxval == 0 || reset_all)
|
||||||
|
s->maxval = (1 << s->bpp) - 1;
|
||||||
|
|
||||||
if (s->maxval >= 128) {
|
if (s->maxval >= 128) {
|
||||||
factor = FFMIN(s->maxval, 4095) + 128 >> 8;
|
factor = FFMIN(s->maxval, 4095) + 128 >> 8;
|
||||||
|
|
||||||
if (s->T1 == 0 || reset_all)
|
if (s->T1 == 0 || reset_all)
|
||||||
s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
|
s->T1 = iso_clip(factor * (basic_t1 - 2) + 2 + 3 * s->near,
|
||||||
|
s->near + 1, s->maxval);
|
||||||
if (s->T2 == 0 || reset_all)
|
if (s->T2 == 0 || reset_all)
|
||||||
s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval);
|
s->T2 = iso_clip(factor * (basic_t2 - 3) + 3 + 5 * s->near,
|
||||||
|
s->T1, s->maxval);
|
||||||
if (s->T3 == 0 || reset_all)
|
if (s->T3 == 0 || reset_all)
|
||||||
s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval);
|
s->T3 = iso_clip(factor * (basic_t3 - 4) + 4 + 7 * s->near,
|
||||||
|
s->T2, s->maxval);
|
||||||
} else {
|
} else {
|
||||||
factor = 256 / (s->maxval + 1);
|
factor = 256 / (s->maxval + 1);
|
||||||
|
|
||||||
if (s->T1 == 0 || reset_all)
|
if (s->T1 == 0 || reset_all)
|
||||||
s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
|
s->T1 = iso_clip(FFMAX(2, basic_t1 / factor + 3 * s->near),
|
||||||
|
s->near + 1, s->maxval);
|
||||||
if (s->T2 == 0 || reset_all)
|
if (s->T2 == 0 || reset_all)
|
||||||
s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval);
|
s->T2 = iso_clip(FFMAX(3, basic_t2 / factor + 5 * s->near),
|
||||||
|
s->T1, s->maxval);
|
||||||
if (s->T3 == 0 || reset_all)
|
if (s->T3 == 0 || reset_all)
|
||||||
s->T3= iso_clip(FFMAX(4, basic_t3/factor + 7*s->near), s->T2, s->maxval);
|
s->T3 = iso_clip(FFMAX(4, basic_t3 / factor + 7 * s->near),
|
||||||
|
s->T2, s->maxval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(s->reset==0 || reset_all) s->reset= 64;
|
if (s->reset == 0 || reset_all)
|
||||||
|
s->reset = 64;
|
||||||
av_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
|
av_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
#ifndef AVCODEC_JPEGLS_H
|
#ifndef AVCODEC_JPEGLS_H
|
||||||
#define AVCODEC_JPEGLS_H
|
#define AVCODEC_JPEGLS_H
|
||||||
|
|
||||||
#include "avcodec.h"
|
|
||||||
#include "libavutil/common.h"
|
#include "libavutil/common.h"
|
||||||
|
#include "avcodec.h"
|
||||||
|
|
||||||
typedef struct JpeglsContext {
|
typedef struct JpeglsContext {
|
||||||
AVCodecContext *avctx;
|
AVCodecContext *avctx;
|
||||||
@ -54,19 +54,29 @@ void ff_jpegls_init_state(JLSState *state);
|
|||||||
/**
|
/**
|
||||||
* Calculate quantized gradient value, used for context determination
|
* Calculate quantized gradient value, used for context determination
|
||||||
*/
|
*/
|
||||||
static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize
|
static inline int ff_jpegls_quantize(JLSState *s, int v)
|
||||||
if(v==0) return 0;
|
{
|
||||||
|
if (v == 0)
|
||||||
|
return 0;
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
if(v <= -s->T3) return -4;
|
if (v <= -s->T3)
|
||||||
if(v <= -s->T2) return -3;
|
return -4;
|
||||||
if(v <= -s->T1) return -2;
|
if (v <= -s->T2)
|
||||||
if(v < -s->near) return -1;
|
return -3;
|
||||||
|
if (v <= -s->T1)
|
||||||
|
return -2;
|
||||||
|
if (v < -s->near)
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if(v <= s->near) return 0;
|
if (v <= s->near)
|
||||||
if(v < s->T1) return 1;
|
return 0;
|
||||||
if(v < s->T2) return 2;
|
if (v < s->T1)
|
||||||
if(v < s->T3) return 3;
|
return 1;
|
||||||
|
if (v < s->T2)
|
||||||
|
return 2;
|
||||||
|
if (v < s->T3)
|
||||||
|
return 3;
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,8 +86,8 @@ static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize
|
|||||||
*/
|
*/
|
||||||
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
|
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
|
||||||
|
|
||||||
|
static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
|
||||||
static inline void ff_jpegls_downscale_state(JLSState *state, int Q){
|
{
|
||||||
if (state->N[Q] == state->reset) {
|
if (state->N[Q] == state->reset) {
|
||||||
state->A[Q] >>= 1;
|
state->A[Q] >>= 1;
|
||||||
state->B[Q] >>= 1;
|
state->B[Q] >>= 1;
|
||||||
@ -86,7 +96,9 @@ static inline void ff_jpegls_downscale_state(JLSState *state, int Q){
|
|||||||
state->N[Q]++;
|
state->N[Q]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){
|
static inline int ff_jpegls_update_state_regular(JLSState *state,
|
||||||
|
int Q, int err)
|
||||||
|
{
|
||||||
if(FFABS(err) > 0xFFFF)
|
if(FFABS(err) > 0xFFFF)
|
||||||
return -0x10000;
|
return -0x10000;
|
||||||
state->A[Q] += FFABS(err);
|
state->A[Q] += FFABS(err);
|
||||||
|
@ -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;
|
||||||
@ -208,7 +218,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]--;
|
||||||
|
|
||||||
@ -223,7 +234,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) {
|
||||||
@ -258,7 +271,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;
|
||||||
@ -286,7 +301,9 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
|
|||||||
shift = point_transform + (16 - s->bits);
|
shift = point_transform + (16 - s->bits);
|
||||||
|
|
||||||
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
|
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
|
||||||
av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",
|
av_log(s->avctx, AV_LOG_DEBUG,
|
||||||
|
"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);
|
||||||
@ -322,7 +339,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
|
|||||||
width = s->width * stride;
|
width = s->width * stride;
|
||||||
for (i = 0; i < s->height; i++) {
|
for (i = 0; i < s->height; i++) {
|
||||||
for (j = 0; j < stride; j++) {
|
for (j = 0; j < stride; j++) {
|
||||||
ls_decode_line(state, s, last + j, cur + j, Rc[j], width, stride, j, 8);
|
ls_decode_line(state, s, last + j, cur + j,
|
||||||
|
Rc[j], width, stride, j, 8);
|
||||||
Rc[j] = last[j];
|
Rc[j] = last[j];
|
||||||
|
|
||||||
if (s->restart_interval && !--s->restart_count) {
|
if (s->restart_interval && !--s->restart_count) {
|
||||||
@ -334,7 +352,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
|
|||||||
cur += s->picture.linesize[0];
|
cur += s->picture.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;
|
||||||
@ -349,18 +368,16 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor
|
|||||||
uint8_t *src = s->picture.data[0];
|
uint8_t *src = s->picture.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.linesize[0];
|
src += s->picture.linesize[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint16_t *src = (uint16_t *)s->picture.data[0];
|
uint16_t *src = (uint16_t *)s->picture.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.linesize[0] / 2;
|
src += s->picture.linesize[0] / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,9 +388,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),
|
||||||
@ -381,5 +398,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"),
|
|
||||||
};
|
};
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
*/
|
*/
|
||||||
int ff_jpegls_decode_lse(MJpegDecodeContext *s);
|
int ff_jpegls_decode_lse(MJpegDecodeContext *s);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
#endif /* AVCODEC_JPEGLSDEC_H */
|
#endif /* AVCODEC_JPEGLSDEC_H */
|
||||||
|
@ -34,16 +34,18 @@
|
|||||||
#include "mjpeg.h"
|
#include "mjpeg.h"
|
||||||
#include "jpegls.h"
|
#include "jpegls.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode error from regular symbol
|
* Encode error from regular symbol
|
||||||
*/
|
*/
|
||||||
static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q, int err){
|
static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q,
|
||||||
|
int err)
|
||||||
|
{
|
||||||
int k;
|
int k;
|
||||||
int val;
|
int val;
|
||||||
int map;
|
int map;
|
||||||
|
|
||||||
for(k = 0; (state->N[Q] << k) < state->A[Q]; k++);
|
for (k = 0; (state->N[Q] << k) < state->A[Q]; k++)
|
||||||
|
;
|
||||||
|
|
||||||
map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]);
|
map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]);
|
||||||
|
|
||||||
@ -63,7 +65,9 @@ static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q,
|
|||||||
/**
|
/**
|
||||||
* Encode error from run termination
|
* Encode error from run termination
|
||||||
*/
|
*/
|
||||||
static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RItype, int err, int limit_add){
|
static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb,
|
||||||
|
int RItype, int err, int limit_add)
|
||||||
|
{
|
||||||
int k;
|
int k;
|
||||||
int val, map;
|
int val, map;
|
||||||
int Q = 365 + RItype;
|
int Q = 365 + RItype;
|
||||||
@ -72,7 +76,8 @@ static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RIt
|
|||||||
temp = state->A[Q];
|
temp = state->A[Q];
|
||||||
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++)
|
||||||
|
;
|
||||||
map = 0;
|
map = 0;
|
||||||
if (!k && err && (2 * state->B[Q] < state->N[Q]))
|
if (!k && err && (2 * state->B[Q] < state->N[Q]))
|
||||||
map = 1;
|
map = 1;
|
||||||
@ -93,7 +98,9 @@ static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RIt
|
|||||||
/**
|
/**
|
||||||
* Encode run value as specified by JPEG-LS standard
|
* Encode run value as specified by JPEG-LS standard
|
||||||
*/
|
*/
|
||||||
static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, int comp, int trail){
|
static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run,
|
||||||
|
int comp, int trail)
|
||||||
|
{
|
||||||
while (run >= (1 << ff_log2_run[state->run_index[comp]])) {
|
while (run >= (1 << ff_log2_run[state->run_index[comp]])) {
|
||||||
put_bits(pb, 1, 1);
|
put_bits(pb, 1, 1);
|
||||||
run -= 1 << ff_log2_run[state->run_index[comp]];
|
run -= 1 << ff_log2_run[state->run_index[comp]];
|
||||||
@ -113,7 +120,10 @@ static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, in
|
|||||||
/**
|
/**
|
||||||
* Encode one line of image
|
* Encode one line of image
|
||||||
*/
|
*/
|
||||||
static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last, void *cur, int last2, int w, int stride, int comp, int bits){
|
static inline void ls_encode_line(JLSState *state, PutBitContext *pb,
|
||||||
|
void *last, void *cur, int last2, int w,
|
||||||
|
int stride, int comp, int bits)
|
||||||
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int Ra, Rb, Rc, Rd;
|
int Ra, Rb, Rc, Rd;
|
||||||
int D0, D1, D2;
|
int D0, D1, D2;
|
||||||
@ -131,7 +141,9 @@ static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last
|
|||||||
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 RUNval, RItype, run;
|
int RUNval, RItype, run;
|
||||||
|
|
||||||
run = 0;
|
run = 0;
|
||||||
@ -169,14 +181,17 @@ static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last
|
|||||||
if (err >= state->range + 1 >> 1)
|
if (err >= state->range + 1 >> 1)
|
||||||
err -= state->range;
|
err -= state->range;
|
||||||
|
|
||||||
ls_encode_runterm(state, pb, RItype, err, ff_log2_run[state->run_index[comp]]);
|
ls_encode_runterm(state, pb, RItype, err,
|
||||||
|
ff_log2_run[state->run_index[comp]]);
|
||||||
|
|
||||||
if (state->run_index[comp] > 0)
|
if (state->run_index[comp] > 0)
|
||||||
state->run_index[comp]--;
|
state->run_index[comp]--;
|
||||||
} else { /* regular mode */
|
} else { /* regular mode */
|
||||||
int context;
|
int context;
|
||||||
|
|
||||||
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) {
|
||||||
@ -208,13 +223,17 @@ static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ls_store_lse(JLSState *state, PutBitContext *pb){
|
static void ls_store_lse(JLSState *state, PutBitContext *pb)
|
||||||
|
{
|
||||||
/* Test if we have default params and don't need to store LSE */
|
/* Test if we have default params and don't need to store LSE */
|
||||||
JLSState state2 = { 0 };
|
JLSState state2 = { 0 };
|
||||||
state2.bpp = state->bpp;
|
state2.bpp = state->bpp;
|
||||||
state2.near = state->near;
|
state2.near = state->near;
|
||||||
ff_jpegls_reset_coding_parameters(&state2, 1);
|
ff_jpegls_reset_coding_parameters(&state2, 1);
|
||||||
if(state->T1 == state2.T1 && state->T2 == state2.T2 && state->T3 == state2.T3 && state->reset == state2.reset)
|
if (state->T1 == state2.T1 &&
|
||||||
|
state->T2 == state2.T2 &&
|
||||||
|
state->T3 == state2.T3 &&
|
||||||
|
state->reset == state2.reset)
|
||||||
return;
|
return;
|
||||||
/* store LSE type 1 */
|
/* store LSE type 1 */
|
||||||
put_marker(pb, LSE);
|
put_marker(pb, LSE);
|
||||||
@ -244,7 +263,8 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
p->pict_type = AV_PICTURE_TYPE_I;
|
p->pict_type = AV_PICTURE_TYPE_I;
|
||||||
p->key_frame = 1;
|
p->key_frame = 1;
|
||||||
|
|
||||||
if(avctx->pix_fmt == AV_PIX_FMT_GRAY8 || avctx->pix_fmt == AV_PIX_FMT_GRAY16)
|
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||
|
||||||
|
avctx->pix_fmt == AV_PIX_FMT_GRAY16)
|
||||||
comps = 1;
|
comps = 1;
|
||||||
else
|
else
|
||||||
comps = 3;
|
comps = 3;
|
||||||
@ -324,7 +344,8 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
width = avctx->width * 3;
|
width = avctx->width * 3;
|
||||||
for (i = 0; i < avctx->height; i++) {
|
for (i = 0; i < avctx->height; i++) {
|
||||||
for (j = 0; j < 3; j++) {
|
for (j = 0; j < 3; j++) {
|
||||||
ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8);
|
ls_encode_line(state, &pb2, last + j, cur + j, Rc[j],
|
||||||
|
width, 3, j, 8);
|
||||||
Rc[j] = last[j];
|
Rc[j] = last[j];
|
||||||
}
|
}
|
||||||
last = cur;
|
last = cur;
|
||||||
@ -337,7 +358,8 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
width = avctx->width * 3;
|
width = avctx->width * 3;
|
||||||
for (i = 0; i < avctx->height; i++) {
|
for (i = 0; i < avctx->height; i++) {
|
||||||
for (j = 2; j >= 0; j--) {
|
for (j = 2; j >= 0; j--) {
|
||||||
ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8);
|
ls_encode_line(state, &pb2, last + j, cur + j, Rc[j],
|
||||||
|
width, 3, j, 8);
|
||||||
Rc[j] = last[j];
|
Rc[j] = last[j];
|
||||||
}
|
}
|
||||||
last = cur;
|
last = cur;
|
||||||
@ -348,9 +370,9 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
av_freep(&zero);
|
av_freep(&zero);
|
||||||
av_freep(&state);
|
av_freep(&state);
|
||||||
|
|
||||||
// the specification says that after doing 0xff escaping unused bits in the
|
/* the specification says that after doing 0xff escaping unused bits in
|
||||||
// last byte must be set to 0, so just append 7 "optional" zero-bits to
|
* the last byte must be set to 0, so just append 7 "optional" zero-bits
|
||||||
// avoid special-casing.
|
* to avoid special-casing. */
|
||||||
put_bits(&pb2, 7, 0);
|
put_bits(&pb2, 7, 0);
|
||||||
size = put_bits_count(&pb2);
|
size = put_bits_count(&pb2);
|
||||||
flush_put_bits(&pb2);
|
flush_put_bits(&pb2);
|
||||||
@ -381,14 +403,19 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int encode_init_ls(AVCodecContext *ctx) {
|
static av_cold int encode_init_ls(AVCodecContext *ctx)
|
||||||
|
{
|
||||||
JpeglsContext *c = (JpeglsContext *)ctx->priv_data;
|
JpeglsContext *c = (JpeglsContext *)ctx->priv_data;
|
||||||
|
|
||||||
c->avctx = ctx;
|
c->avctx = ctx;
|
||||||
ctx->coded_frame = &c->picture;
|
ctx->coded_frame = &c->picture;
|
||||||
|
|
||||||
if(ctx->pix_fmt != AV_PIX_FMT_GRAY8 && ctx->pix_fmt != AV_PIX_FMT_GRAY16 && ctx->pix_fmt != AV_PIX_FMT_RGB24 && ctx->pix_fmt != AV_PIX_FMT_BGR24){
|
if (ctx->pix_fmt != AV_PIX_FMT_GRAY8 &&
|
||||||
av_log(ctx, AV_LOG_ERROR, "Only grayscale and RGB24/BGR24 images are supported\n");
|
ctx->pix_fmt != AV_PIX_FMT_GRAY16 &&
|
||||||
|
ctx->pix_fmt != AV_PIX_FMT_RGB24 &&
|
||||||
|
ctx->pix_fmt != AV_PIX_FMT_BGR24) {
|
||||||
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
|
"Only grayscale and RGB24/BGR24 images are supported\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -396,14 +423,15 @@ static av_cold int encode_init_ls(AVCodecContext *ctx) {
|
|||||||
|
|
||||||
AVCodec ff_jpegls_encoder = {
|
AVCodec ff_jpegls_encoder = {
|
||||||
.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(JpeglsContext),
|
.priv_data_size = sizeof(JpeglsContext),
|
||||||
.init = encode_init_ls,
|
.init = encode_init_ls,
|
||||||
.encode2 = encode_picture_ls,
|
.encode2 = encode_picture_ls,
|
||||||
.pix_fmts = (const enum AVPixelFormat[]) {
|
.pix_fmts = (const enum AVPixelFormat[]) {
|
||||||
AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
|
AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
|
||||||
|
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
|
||||||
AV_PIX_FMT_NONE
|
AV_PIX_FMT_NONE
|
||||||
},
|
},
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user