Libav 0.7.1
|
00001 /* 00002 * JPEG-LS common code 00003 * Copyright (c) 2003 Michael Niedermayer 00004 * Copyright (c) 2006 Konstantin Shishkov 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 // QBPP = ceil(log2(RANGE)) 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 // av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3); 00089 }