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 #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){ //FIXME optimize 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 state->A[Q] += FFABS(err); 00090 err *= state->twonear; 00091 state->B[Q] += err; 00092 00093 ff_jpegls_downscale_state(state, Q); 00094 00095 if(state->B[Q] <= -state->N[Q]) { 00096 state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]); 00097 if(state->C[Q] > -128) 00098 state->C[Q]--; 00099 }else if(state->B[Q] > 0){ 00100 state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0); 00101 if(state->C[Q] < 127) 00102 state->C[Q]++; 00103 } 00104 00105 return err; 00106 } 00107 00108 #define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] ) 00109 #define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v)) 00110 00111 #endif /* AVCODEC_JPEGLS_H */