annotate ffmpeg/libavcodec/jpegls.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * JPEG-LS common code
yading@10 3 * Copyright (c) 2003 Michael Niedermayer
yading@10 4 * Copyright (c) 2006 Konstantin Shishkov
yading@10 5 *
yading@10 6 * This file is part of FFmpeg.
yading@10 7 *
yading@10 8 * FFmpeg is free software; you can redistribute it and/or
yading@10 9 * modify it under the terms of the GNU Lesser General Public
yading@10 10 * License as published by the Free Software Foundation; either
yading@10 11 * version 2.1 of the License, or (at your option) any later version.
yading@10 12 *
yading@10 13 * FFmpeg is distributed in the hope that it will be useful,
yading@10 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 16 * Lesser General Public License for more details.
yading@10 17 *
yading@10 18 * You should have received a copy of the GNU Lesser General Public
yading@10 19 * License along with FFmpeg; if not, write to the Free Software
yading@10 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 21 */
yading@10 22
yading@10 23 /**
yading@10 24 * @file
yading@10 25 * JPEG-LS common code.
yading@10 26 */
yading@10 27
yading@10 28 #include "jpegls.h"
yading@10 29
yading@10 30 void ff_jpegls_init_state(JLSState *state){
yading@10 31 int i;
yading@10 32
yading@10 33 state->twonear = state->near * 2 + 1;
yading@10 34 state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1;
yading@10 35
yading@10 36 // QBPP = ceil(log2(RANGE))
yading@10 37 for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++);
yading@10 38
yading@10 39 state->bpp = FFMAX(av_log2(state->maxval)+1, 2);
yading@10 40 state->limit = 2*(state->bpp + FFMAX(state->bpp, 8)) - state->qbpp;
yading@10 41
yading@10 42 for(i = 0; i < 367; i++) {
yading@10 43 state->A[i] = FFMAX((state->range + 32) >> 6, 2);
yading@10 44 state->N[i] = 1;
yading@10 45 }
yading@10 46
yading@10 47 }
yading@10 48
yading@10 49 /**
yading@10 50 * Custom value clipping function used in T1, T2, T3 calculation
yading@10 51 */
yading@10 52 static inline int iso_clip(int v, int vmin, int vmax){
yading@10 53 if(v > vmax || v < vmin) return vmin;
yading@10 54 else return v;
yading@10 55 }
yading@10 56
yading@10 57 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all){
yading@10 58 const int basic_t1= 3;
yading@10 59 const int basic_t2= 7;
yading@10 60 const int basic_t3= 21;
yading@10 61 int factor;
yading@10 62
yading@10 63 if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1;
yading@10 64
yading@10 65 if(s->maxval >=128){
yading@10 66 factor= (FFMIN(s->maxval, 4095) + 128)>>8;
yading@10 67
yading@10 68 if(s->T1==0 || reset_all)
yading@10 69 s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
yading@10 70 if(s->T2==0 || reset_all)
yading@10 71 s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval);
yading@10 72 if(s->T3==0 || reset_all)
yading@10 73 s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval);
yading@10 74 }else{
yading@10 75 factor= 256 / (s->maxval + 1);
yading@10 76
yading@10 77 if(s->T1==0 || reset_all)
yading@10 78 s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
yading@10 79 if(s->T2==0 || reset_all)
yading@10 80 s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval);
yading@10 81 if(s->T3==0 || reset_all)
yading@10 82 s->T3= iso_clip(FFMAX(4, basic_t3/factor + 7*s->near), s->T2, s->maxval);
yading@10 83 }
yading@10 84
yading@10 85 if(s->reset==0 || reset_all) s->reset= 64;
yading@10 86 av_dlog(NULL, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3);
yading@10 87 }