Commit ff4fc5ef authored by Luca Barbato's avatar Luca Barbato Committed by Diego Biurrun

jpegls: K&R formatting cosmetics

Signed-off-by: 's avatarDiego Biurrun <diego@biurrun.de>
parent 9cacdabd
......@@ -27,63 +27,76 @@
#include "jpegls.h"
void ff_jpegls_init_state(JLSState *state){
void ff_jpegls_init_state(JLSState *state)
{
int i;
state->twonear = state->near * 2 + 1;
state->range = (state->maxval + state->twonear - 1) / state->twonear + 1;
// 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++)
;
if(state->bpp < 8)
state->limit = 16 + 2 * state->bpp - state->qbpp;
if (state->bpp < 8)
state->limit = 2 * state->bpp - state->qbpp + 16;
else
state->limit = 4 * state->bpp - state->qbpp;
for(i = 0; i < 367; i++) {
for (i = 0; i < 367; i++) {
state->A[i] = FFMAX(state->range + 32 >> 6, 2);
state->N[i] = 1;
}
}
/**
* Custom value clipping function used in T1, T2, T3 calculation
*/
static inline int iso_clip(int v, int vmin, int vmax){
if(v > vmax || v < vmin) return vmin;
else return v;
static inline int iso_clip(int v, int vmin, int vmax)
{
if (v > vmax || v < vmin)
return vmin;
else
return v;
}
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all){
const int basic_t1= 3;
const int basic_t2= 7;
const int basic_t3= 21;
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all)
{
const int basic_t1 = 3;
const int basic_t2 = 7;
const int basic_t3 = 21;
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;
if(s->T1==0 || reset_all)
s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
if(s->T2==0 || reset_all)
s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval);
if(s->T3==0 || reset_all)
s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval);
}else{
factor= 256 / (s->maxval + 1);
if (s->T1 == 0 || reset_all)
s->T1 = iso_clip(factor * (basic_t1 - 2) + 2 + 3 * s->near,
s->near + 1, s->maxval);
if (s->T2 == 0 || reset_all)
s->T2 = iso_clip(factor * (basic_t2 - 3) + 3 + 5 * s->near,
s->T1, s->maxval);
if (s->T3 == 0 || reset_all)
s->T3 = iso_clip(factor * (basic_t3 - 4) + 4 + 7 * s->near,
s->T2, s->maxval);
} else {
factor = 256 / (s->maxval + 1);
if(s->T1==0 || reset_all)
s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
if(s->T2==0 || reset_all)
s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval);
if(s->T3==0 || reset_all)
s->T3= iso_clip(FFMAX(4, basic_t3/factor + 7*s->near), s->T2, s->maxval);
if (s->T1 == 0 || reset_all)
s->T1 = iso_clip(FFMAX(2, basic_t1 / factor + 3 * s->near),
s->near + 1, s->maxval);
if (s->T2 == 0 || reset_all)
s->T2 = iso_clip(FFMAX(3, basic_t2 / factor + 5 * s->near),
s->T1, s->maxval);
if (s->T3 == 0 || reset_all)
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);
}
......@@ -28,21 +28,21 @@
#ifndef AVCODEC_JPEGLS_H
#define AVCODEC_JPEGLS_H
#include "avcodec.h"
#include "libavutil/common.h"
#include "avcodec.h"
typedef struct JpeglsContext{
typedef struct JpeglsContext {
AVCodecContext *avctx;
AVFrame picture;
}JpeglsContext;
} JpeglsContext;
typedef struct JLSState{
typedef struct JLSState {
int T1, T2, T3;
int A[367], B[367], C[365], N[367];
int limit, reset, bpp, qbpp, maxval, range;
int near, twonear;
int run_index[3];
}JLSState;
} JLSState;
extern const uint8_t ff_log2_run[32];
......@@ -54,19 +54,29 @@ void ff_jpegls_init_state(JLSState *state);
/**
* Calculate quantized gradient value, used for context determination
*/
static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize
if(v==0) return 0;
if(v < 0){
if(v <= -s->T3) return -4;
if(v <= -s->T2) return -3;
if(v <= -s->T1) return -2;
if(v < -s->near) return -1;
static inline int ff_jpegls_quantize(JLSState *s, int v)
{
if (v == 0)
return 0;
}else{
if(v <= s->near) return 0;
if(v < s->T1) return 1;
if(v < s->T2) return 2;
if(v < s->T3) return 3;
if (v < 0) {
if (v <= -s->T3)
return -4;
if (v <= -s->T2)
return -3;
if (v <= -s->T1)
return -2;
if (v < -s->near)
return -1;
return 0;
} else {
if (v <= s->near)
return 0;
if (v < s->T1)
return 1;
if (v < s->T2)
return 2;
if (v < s->T3)
return 3;
return 4;
}
}
......@@ -76,37 +86,39 @@ static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize
*/
void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
static inline void ff_jpegls_downscale_state(JLSState *state, int Q){
if(state->N[Q] == state->reset){
state->A[Q] >>=1;
state->B[Q] >>=1;
state->N[Q] >>=1;
static inline void ff_jpegls_downscale_state(JLSState *state, int Q)
{
if (state->N[Q] == state->reset) {
state->A[Q] >>= 1;
state->B[Q] >>= 1;
state->N[Q] >>= 1;
}
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)
{
state->A[Q] += FFABS(err);
err *= state->twonear;
err *= state->twonear;
state->B[Q] += err;
ff_jpegls_downscale_state(state, Q);
if(state->B[Q] <= -state->N[Q]) {
state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]);
if(state->C[Q] > -128)
if (state->B[Q] <= -state->N[Q]) {
state->B[Q] = FFMAX(state->B[Q] + state->N[Q], 1 - state->N[Q]);
if (state->C[Q] > -128)
state->C[Q]--;
}else if(state->B[Q] > 0){
state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0);
if(state->C[Q] < 127)
} else if (state->B[Q] > 0) {
state->B[Q] = FFMIN(state->B[Q] - state->N[Q], 0);
if (state->C[Q] < 127)
state->C[Q]++;
}
return err;
}
#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] )
#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v))
#define R(a, i) (bits == 8 ? ((uint8_t *)(a))[i] : ((uint16_t *)(a))[i])
#define W(a, i, v) (bits == 8 ? (((uint8_t *)(a))[i] = v) : (((uint16_t *)(a))[i] = v))
#endif /* AVCODEC_JPEGLS_H */
This diff is collapsed.
......@@ -36,6 +36,7 @@
*/
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 */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment