00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "jpegls.h"
00029
00030 void ff_jpegls_init_state(JLSState *state){
00031 int i;
00032
00033 state->twonear = state->near * 2 + 1;
00034 state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1;
00035
00036
00037 for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++);
00038
00039 if(state->bpp < 8)
00040 state->limit = 16 + 2 * state->bpp - state->qbpp;
00041 else
00042 state->limit = (4 * state->bpp) - state->qbpp;
00043
00044 for(i = 0; i < 367; i++) {
00045 state->A[i] = FFMAX((state->range + 32) >> 6, 2);
00046 state->N[i] = 1;
00047 }
00048
00049 }
00050
00054 static inline int iso_clip(int v, int vmin, int vmax){
00055 if(v > vmax || v < vmin) return vmin;
00056 else return v;
00057 }
00058
00059 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all){
00060 const int basic_t1= 3;
00061 const int basic_t2= 7;
00062 const int basic_t3= 21;
00063 int factor;
00064
00065 if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1;
00066
00067 if(s->maxval >=128){
00068 factor= (FFMIN(s->maxval, 4095) + 128)>>8;
00069
00070 if(s->T1==0 || reset_all)
00071 s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
00072 if(s->T2==0 || reset_all)
00073 s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval);
00074 if(s->T3==0 || reset_all)
00075 s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval);
00076 }else{
00077 factor= 256 / (s->maxval + 1);
00078
00079 if(s->T1==0 || reset_all)
00080 s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
00081 if(s->T2==0 || reset_all)
00082 s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval);
00083 if(s->T3==0 || reset_all)
00084 s->T3= iso_clip(FFMAX(4, basic_t3/factor + 7*s->near), s->T2, s->maxval);
00085 }
00086
00087 if(s->reset==0 || reset_all) s->reset= 64;
00088
00089 }