asfdec: also read Metadata Library Object
[FFMpeg-mirror/mplayer-patches.git] / libavcodec / jpegls.h
blob18c71a82d0a2e43694dbf30f6e8b26b1ab39addd
1 /*
2 * JPEG-LS common code
3 * Copyright (c) 2003 Michael Niedermayer
4 * Copyright (c) 2006 Konstantin Shishkov
6 * This file is part of Libav.
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 /**
24 * @file
25 * JPEG-LS common code.
28 #ifndef AVCODEC_JPEGLS_H
29 #define AVCODEC_JPEGLS_H
31 #include "avcodec.h"
32 #include "libavutil/common.h"
34 typedef struct JpeglsContext{
35 AVCodecContext *avctx;
36 AVFrame picture;
37 }JpeglsContext;
39 typedef struct JLSState{
40 int T1, T2, T3;
41 int A[367], B[367], C[365], N[367];
42 int limit, reset, bpp, qbpp, maxval, range;
43 int near, twonear;
44 int run_index[3];
45 }JLSState;
47 extern const uint8_t ff_log2_run[32];
49 /**
50 * Calculate initial JPEG-LS parameters
52 void ff_jpegls_init_state(JLSState *state);
54 /**
55 * Calculate quantized gradient value, used for context determination
57 static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize
58 if(v==0) return 0;
59 if(v < 0){
60 if(v <= -s->T3) return -4;
61 if(v <= -s->T2) return -3;
62 if(v <= -s->T1) return -2;
63 if(v < -s->near) return -1;
64 return 0;
65 }else{
66 if(v <= s->near) return 0;
67 if(v < s->T1) return 1;
68 if(v < s->T2) return 2;
69 if(v < s->T3) return 3;
70 return 4;
74 /**
75 * Calculate JPEG-LS codec values
77 void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all);
80 static inline void ff_jpegls_downscale_state(JLSState *state, int Q){
81 if(state->N[Q] == state->reset){
82 state->A[Q] >>=1;
83 state->B[Q] >>=1;
84 state->N[Q] >>=1;
86 state->N[Q]++;
89 static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){
90 state->A[Q] += FFABS(err);
91 err *= state->twonear;
92 state->B[Q] += err;
94 ff_jpegls_downscale_state(state, Q);
96 if(state->B[Q] <= -state->N[Q]) {
97 state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]);
98 if(state->C[Q] > -128)
99 state->C[Q]--;
100 }else if(state->B[Q] > 0){
101 state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0);
102 if(state->C[Q] < 127)
103 state->C[Q]++;
106 return err;
109 #define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] )
110 #define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v))
112 #endif /* AVCODEC_JPEGLS_H */