00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef AVCODEC_JPEGLS_H
00029 #define AVCODEC_JPEGLS_H
00030
00031 #include "avcodec.h"
00032
00033 typedef struct JpeglsContext{
00034 AVCodecContext *avctx;
00035 AVFrame picture;
00036 }JpeglsContext;
00037
00038 typedef struct JLSState{
00039 int T1, T2, T3;
00040 int A[367], B[367], C[365], N[367];
00041 int limit, reset, bpp, qbpp, maxval, range;
00042 int near, twonear;
00043 int run_index[3];
00044 }JLSState;
00045
00046 extern const uint8_t ff_log2_run[32];
00047
00051 void ff_jpegls_init_state(JLSState *state);
00052
00056 static inline int ff_jpegls_quantize(JLSState *s, int v){
00057 if(v==0) return 0;
00058 if(v < 0){
00059 if(v <= -s->T3) return -4;
00060 if(v <= -s->T2) return -3;
00061 if(v <= -s->T1) return -2;
00062 if(v < -s->near) return -1;
00063 return 0;
00064 }else{
00065 if(v <= s->near) return 0;
00066 if(v < s->T1) return 1;
00067 if(v < s->T2) return 2;
00068 if(v < s->T3) return 3;
00069 return 4;
00070 }
00071 }
00072
00076 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
00077
00078
00079 static inline void ff_jpegls_downscale_state(JLSState *state, int Q){
00080 if(state->N[Q] == state->reset){
00081 state->A[Q] >>=1;
00082 state->B[Q] >>=1;
00083 state->N[Q] >>=1;
00084 }
00085 state->N[Q]++;
00086 }
00087
00088 static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){
00089 if(FFABS(err) > 0xFFFF)
00090 return -0x10000;
00091 state->A[Q] += FFABS(err);
00092 err *= state->twonear;
00093 state->B[Q] += err;
00094
00095 ff_jpegls_downscale_state(state, Q);
00096
00097 if(state->B[Q] <= -state->N[Q]) {
00098 state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]);
00099 if(state->C[Q] > -128)
00100 state->C[Q]--;
00101 }else if(state->B[Q] > 0){
00102 state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0);
00103 if(state->C[Q] < 127)
00104 state->C[Q]++;
00105 }
00106
00107 return err;
00108 }
00109
00110 #define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] )
00111 #define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v))
00112
00113 #endif