Mercurial > libavcodec.hg
annotate jpeg_ls.c @ 4069:0df780a93aa8 libavcodec
JPEG-LS 16-bit gray support
| author | kostya |
|---|---|
| date | Tue, 24 Oct 2006 05:01:04 +0000 |
| parents | 34fdffe98bd0 |
| children | 00ad06966bff |
| rev | line source |
|---|---|
| 2970 | 1 /* |
| 2 * JPEG-LS encoder and decoder | |
| 3 * Copyright (c) 2003 Michael Niedermayer | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
4 * Copyright (c) 2006 Konstantin Shishkov |
| 2970 | 5 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3773
diff
changeset
|
6 * This file is part of FFmpeg. |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3773
diff
changeset
|
7 * |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3773
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
| 2970 | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3773
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
| 2970 | 12 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3773
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
| 2970 | 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. | |
| 17 * | |
| 18 * You should have received a copy of the GNU Lesser General Public | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3773
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
|
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2970
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 2970 | 21 */ |
| 22 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
23 #include "golomb.h" |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
24 |
| 2970 | 25 /** |
| 26 * @file jpeg_ls.c | |
| 27 * JPEG-LS encoder and decoder. | |
| 28 */ | |
| 29 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
30 typedef struct JpeglsContext{ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
31 AVCodecContext *avctx; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
32 AVFrame picture; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
33 }JpeglsContext; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
34 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
35 typedef struct JLSState{ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
36 int T1, T2, T3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
37 int A[367], B[367], C[365], N[367]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
38 int limit, reset, bpp, qbpp, maxval, range; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
39 int near, twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
40 int run_index[3]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
41 }JLSState; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
42 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
43 static const uint8_t log2_run[32]={ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
44 0, 0, 0, 0, 1, 1, 1, 1, |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
45 2, 2, 2, 2, 3, 3, 3, 3, |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
46 4, 4, 5, 5, 6, 6, 7, 7, |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
47 8, 9,10,11,12,13,14,15 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
48 }; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
49 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
50 /* |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
51 * Uncomment this to significantly speed up decoding of broken JPEG-LS |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
52 * (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit. |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
53 * |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
54 * There is no Golomb code with length >= 32 bits possible, so check and |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
55 * avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
56 * on this errors. |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
57 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
58 //#define JLS_BROKEN |
| 2970 | 59 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
60 /********** Functions for both encoder and decoder **********/ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
61 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
62 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
63 * Calculate initial JPEG-LS parameters |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
64 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
65 static void ls_init_state(JLSState *state){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
66 int i; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
67 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
68 state->twonear = state->near * 2 + 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
69 state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
70 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
71 // QBPP = ceil(log2(RANGE)) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
72 for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
73 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
74 if(state->bpp < 8) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
75 state->limit = 16 + 2 * state->bpp - state->qbpp; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
76 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
77 state->limit = (4 * state->bpp) - state->qbpp; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
78 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
79 for(i = 0; i < 367; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
80 state->A[i] = (state->range + 32) >> 6; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
81 if(state->A[i] < 2) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
82 state->A[i] = 2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
83 state->N[i] = 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
84 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
85 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
86 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
87 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
88 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
89 * Calculate quantized gradient value, used for context determination |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
90 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
91 static inline int quantize(JLSState *s, int v){ //FIXME optimize |
| 2970 | 92 if(v==0) return 0; |
| 93 if(v < 0){ | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
94 if(v <= -s->T3) return -4; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
95 if(v <= -s->T2) return -3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
96 if(v <= -s->T1) return -2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
97 if(v < -s->near) return -1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
98 return 0; |
| 2970 | 99 }else{ |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
100 if(v <= s->near) return 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
101 if(v < s->T1) return 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
102 if(v < s->T2) return 2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
103 if(v < s->T3) return 3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
104 return 4; |
| 2970 | 105 } |
| 106 } | |
| 107 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
108 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
109 * Custom value clipping function used in T1, T2, T3 calculation |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
110 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
111 static inline int iso_clip(int v, int vmin, int vmax){ |
| 2970 | 112 if(v > vmax || v < vmin) return vmin; |
| 113 else return v; | |
| 114 } | |
| 115 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
116 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
117 * Calculate JPEG-LS codec values |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
118 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
119 static void reset_ls_coding_parameters(JLSState *s, int reset_all){ |
| 2970 | 120 const int basic_t1= 3; |
| 121 const int basic_t2= 7; | |
| 122 const int basic_t3= 21; | |
| 123 int factor; | |
| 124 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
125 if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
126 |
| 2970 | 127 if(s->maxval >=128){ |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
128 factor= (FFMIN(s->maxval, 4095) + 128)>>8; |
| 2970 | 129 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
130 if(s->T1==0 || reset_all) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
131 s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
132 if(s->T2==0 || reset_all) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
133 s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
134 if(s->T3==0 || reset_all) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
135 s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval); |
| 2970 | 136 }else{ |
| 137 factor= 256 / (s->maxval + 1); | |
| 138 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
139 if(s->T1==0 || reset_all) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
140 s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
141 if(s->T2==0 || reset_all) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
142 s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
143 if(s->T3==0 || reset_all) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
144 s->T3= iso_clip(FFMAX(4, basic_t3/factor + 6*s->near), s->T2, s->maxval); |
| 2970 | 145 } |
| 146 | |
| 147 if(s->reset==0 || reset_all) s->reset= 64; | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
148 // av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3); |
| 2970 | 149 } |
| 150 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
151 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
152 /********** Decoder-specific functions **********/ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
153 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
154 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
155 * Decode LSE block with initialization parameters |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
156 */ |
| 2970 | 157 static int decode_lse(MJpegDecodeContext *s) |
| 158 { | |
| 159 int len, id; | |
| 160 | |
| 161 /* XXX: verify len field validity */ | |
| 162 len = get_bits(&s->gb, 16); | |
| 163 id = get_bits(&s->gb, 8); | |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
164 |
| 2970 | 165 switch(id){ |
| 166 case 1: | |
| 167 s->maxval= get_bits(&s->gb, 16); | |
| 168 s->t1= get_bits(&s->gb, 16); | |
| 169 s->t2= get_bits(&s->gb, 16); | |
| 170 s->t3= get_bits(&s->gb, 16); | |
| 171 s->reset= get_bits(&s->gb, 16); | |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
172 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
173 // reset_ls_coding_parameters(s, 0); |
| 2970 | 174 //FIXME quant table? |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
175 break; |
| 2970 | 176 case 2: |
| 177 case 3: | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
178 av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n"); |
| 2970 | 179 return -1; |
| 180 case 4: | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
181 av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n"); |
| 2970 | 182 return -1; |
| 183 default: | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
184 av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id); |
| 2970 | 185 return -1; |
| 186 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
187 // av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3); |
| 2970 | 188 |
| 189 return 0; | |
| 190 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
191 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
192 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
193 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
194 * Get context-dependent Golomb code, decode it and update context |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
195 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
196 static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
197 int k, ret; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
198 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
199 for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
200 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
201 #ifdef JLS_BROKEN |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
202 if(!show_bits_long(gb, 32))return -1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
203 #endif |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
204 ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp); |
| 2970 | 205 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
206 /* decode mapped error */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
207 if(ret & 1) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
208 ret = -((ret + 1) >> 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
209 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
210 ret >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
211 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
212 /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
213 if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q])) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
214 ret = -(ret + 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
215 |
| 4001 | 216 state->A[Q] += FFABS(ret); |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
217 ret *= state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
218 state->B[Q] += ret; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
219 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
220 if(state->N[Q] == state->reset) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
221 state->A[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
222 state->B[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
223 state->N[Q] >>= 1; |
| 2970 | 224 } |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
225 state->N[Q]++; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
226 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
227 if(state->B[Q] <= -state->N[Q]) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
228 state->B[Q] += state->N[Q]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
229 if(state->C[Q] > -128) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
230 state->C[Q]--; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
231 if(state->B[Q] <= -state->N[Q]) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
232 state->B[Q] = -state->N[Q] + 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
233 }else if(state->B[Q] > 0){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
234 state->B[Q] -= state->N[Q]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
235 if(state->C[Q] < 127) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
236 state->C[Q]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
237 if(state->B[Q] > 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
238 state->B[Q] = 0; |
| 2970 | 239 } |
| 240 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
241 return ret; |
| 2970 | 242 } |
| 243 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
244 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
245 * Get Golomb code, decode it and update state for run termination |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
246 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
247 static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
248 int k, ret, temp, map; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
249 int Q = 365 + RItype; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
250 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
251 if(!RItype) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
252 temp = state->A[Q]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
253 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
254 temp = state->A[Q] + (state->N[Q] >> 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
255 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
256 for(k = 0; (state->N[Q] << k) < temp; k++); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
257 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
258 #ifdef JLS_BROKEN |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
259 if(!show_bits_long(gb, 32))return -1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
260 #endif |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
261 ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp); |
| 2970 | 262 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
263 /* decode mapped error */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
264 map = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
265 if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q])) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
266 map = 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
267 ret += RItype + map; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
268 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
269 if(ret & 1){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
270 ret = map - ((ret + 1) >> 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
271 state->B[Q]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
272 } else { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
273 ret = ret >> 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
274 } |
| 2970 | 275 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
276 /* update state */ |
| 4001 | 277 state->A[Q] += FFABS(ret) - RItype; |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
278 ret *= state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
279 if(state->N[Q] == state->reset){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
280 state->A[Q] >>=1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
281 state->B[Q] >>=1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
282 state->N[Q] >>=1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
283 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
284 state->N[Q]++; |
| 2970 | 285 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
286 return ret; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
287 } |
| 2970 | 288 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
289 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
290 * Decode one line of image |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
291 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
292 static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, uint8_t *last, uint8_t *dst, int last2, int w, int stride, int comp){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
293 int i, x = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
294 int Ra, Rb, Rc, Rd; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
295 int D0, D1, D2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
296 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
297 while(x < w) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
298 int err, pred; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
299 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
300 /* compute gradients */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
301 Ra = x ? dst[x - stride] : last[x]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
302 Rb = last[x]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
303 Rc = x ? last[x - stride] : last2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
304 Rd = (x >= w - stride) ? last[x] : last[x + stride]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
305 D0 = Rd - Rb; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
306 D1 = Rb - Rc; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
307 D2 = Rc - Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
308 /* run mode */ |
| 4001 | 309 if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
310 int r; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
311 int RItype; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
312 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
313 /* decode full runs while available */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
314 while(get_bits1(&s->gb)) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
315 int r; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
316 r = 1 << log2_run[state->run_index[comp]]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
317 if(x + r * stride > w) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
318 r = (w - x) / stride; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
319 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
320 for(i = 0; i < r; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
321 dst[x] = Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
322 x += stride; |
| 2970 | 323 } |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
324 /* if EOL reached, we stop decoding */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
325 if(r != (1 << log2_run[state->run_index[comp]])) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
326 return; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
327 if(state->run_index[comp] < 31) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
328 state->run_index[comp]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
329 if(x + stride > w) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
330 return; |
| 2970 | 331 } |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
332 /* decode aborted run */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
333 r = log2_run[state->run_index[comp]]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
334 if(r) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
335 r = get_bits_long(&s->gb, r); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
336 for(i = 0; i < r; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
337 dst[x] = Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
338 x += stride; |
| 2970 | 339 } |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
340 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
341 /* decode run termination value */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
342 Rb = last[x]; |
| 4001 | 343 RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
344 err = ls_get_code_runterm(&s->gb, state, RItype, log2_run[state->run_index[comp]]); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
345 if(state->run_index[comp]) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
346 state->run_index[comp]--; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
347 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
348 if(state->near && RItype){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
349 pred = Ra + err; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
350 } else { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
351 if(Rb < Ra) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
352 pred = Rb - err; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
353 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
354 pred = Rb + err; |
| 2970 | 355 } |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
356 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
357 if(state->near){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
358 if(pred < -state->near) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
359 pred += state->range * state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
360 else if(pred > state->maxval + state->near) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
361 pred -= state->range * state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
362 pred = clip(pred, 0, state->maxval); |
| 2970 | 363 } |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
364 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
365 dst[x] = pred; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
366 x += stride; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
367 } else { /* regular mode */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
368 int context, sign; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
369 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
370 context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
371 pred = mid_pred(Ra, Ra + Rb - Rc, Rb); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
372 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
373 if(context < 0){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
374 context = -context; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
375 sign = 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
376 }else{ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
377 sign = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
378 } |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
379 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
380 if(sign){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
381 pred = clip(pred - state->C[context], 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
382 err = -ls_get_code_regular(&s->gb, state, context); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
383 } else { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
384 pred = clip(pred + state->C[context], 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
385 err = ls_get_code_regular(&s->gb, state, context); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
386 } |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
387 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
388 /* we have to do something more for near-lossless coding */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
389 pred += err; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
390 if(state->near) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
391 if(pred < -state->near) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
392 pred += state->range * state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
393 else if(pred > state->maxval + state->near) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
394 pred -= state->range * state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
395 pred = clip(pred, 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
396 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
397 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
398 dst[x] = pred; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
399 x += stride; |
| 2970 | 400 } |
| 401 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
402 } |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
403 |
| 4069 | 404 /** |
| 405 * Decode one line of image - 16bpp version | |
| 406 */ | |
| 407 static inline void ls_decode_line_16bpp(JLSState *state, MJpegDecodeContext *s, uint16_t *last, uint16_t *dst, int last2, int w, int stride, int comp){ | |
| 408 int i, x = 0; | |
| 409 int Ra, Rb, Rc, Rd; | |
| 410 int D0, D1, D2; | |
| 411 | |
| 412 while(x < w) { | |
| 413 int err, pred; | |
| 414 | |
| 415 /* compute gradients */ | |
| 416 Ra = x ? dst[x - stride] : last[x]; | |
| 417 Rb = last[x]; | |
| 418 Rc = x ? last[x - stride] : last2; | |
| 419 Rd = (x >= w - stride) ? last[x] : last[x + stride]; | |
| 420 D0 = Rd - Rb; | |
| 421 D1 = Rb - Rc; | |
| 422 D2 = Rc - Ra; | |
| 423 /* run mode */ | |
| 424 if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { | |
| 425 int r; | |
| 426 int RItype; | |
| 427 | |
| 428 /* decode full runs while available */ | |
| 429 while(get_bits1(&s->gb)) { | |
| 430 int r; | |
| 431 r = 1 << log2_run[state->run_index[comp]]; | |
| 432 if(x + r * stride > w) { | |
| 433 r = (w - x) / stride; | |
| 434 } | |
| 435 for(i = 0; i < r; i++) { | |
| 436 dst[x] = Ra; | |
| 437 x += stride; | |
| 438 } | |
| 439 /* if EOL reached, we stop decoding */ | |
| 440 if(r != (1 << log2_run[state->run_index[comp]])) | |
| 441 return; | |
| 442 if(state->run_index[comp] < 31) | |
| 443 state->run_index[comp]++; | |
| 444 if(x + stride > w) | |
| 445 return; | |
| 446 } | |
| 447 /* decode aborted run */ | |
| 448 r = log2_run[state->run_index[comp]]; | |
| 449 if(r) | |
| 450 r = get_bits_long(&s->gb, r); | |
| 451 for(i = 0; i < r; i++) { | |
| 452 dst[x] = Ra; | |
| 453 x += stride; | |
| 454 } | |
| 455 | |
| 456 /* decode run termination value */ | |
| 457 Rb = last[x]; | |
| 458 RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; | |
| 459 err = ls_get_code_runterm(&s->gb, state, RItype, log2_run[state->run_index[comp]]); | |
| 460 if(state->run_index[comp]) | |
| 461 state->run_index[comp]--; | |
| 462 | |
| 463 if(state->near && RItype){ | |
| 464 pred = Ra + err; | |
| 465 } else { | |
| 466 if(Rb < Ra) | |
| 467 pred = Rb - err; | |
| 468 else | |
| 469 pred = Rb + err; | |
| 470 } | |
| 471 | |
| 472 if(state->near){ | |
| 473 if(pred < -state->near) | |
| 474 pred += state->range * state->twonear; | |
| 475 else if(pred > state->maxval + state->near) | |
| 476 pred -= state->range * state->twonear; | |
| 477 pred = clip(pred, 0, state->maxval); | |
| 478 } | |
| 479 | |
| 480 dst[x] = pred; | |
| 481 x += stride; | |
| 482 } else { /* regular mode */ | |
| 483 int context, sign; | |
| 484 | |
| 485 context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2); | |
| 486 pred = mid_pred(Ra, Ra + Rb - Rc, Rb); | |
| 487 | |
| 488 if(context < 0){ | |
| 489 context = -context; | |
| 490 sign = 1; | |
| 491 }else{ | |
| 492 sign = 0; | |
| 493 } | |
| 494 | |
| 495 if(sign){ | |
| 496 pred = clip(pred - state->C[context], 0, state->maxval); | |
| 497 err = -ls_get_code_regular(&s->gb, state, context); | |
| 498 } else { | |
| 499 pred = clip(pred + state->C[context], 0, state->maxval); | |
| 500 err = ls_get_code_regular(&s->gb, state, context); | |
| 501 } | |
| 502 | |
| 503 /* we have to do something more for near-lossless coding */ | |
| 504 pred += err; | |
| 505 if(state->near) { | |
| 506 if(pred < -state->near) | |
| 507 pred += state->range * state->twonear; | |
| 508 else if(pred > state->maxval + state->near) | |
| 509 pred -= state->range * state->twonear; | |
| 510 pred = clip(pred, 0, state->maxval); | |
| 511 } | |
| 512 | |
| 513 dst[x] = pred; | |
| 514 x += stride; | |
| 515 } | |
| 516 } | |
| 517 } | |
| 518 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
519 static int ls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
520 int i, t = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
521 uint8_t *zero, *last, *cur; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
522 JLSState *state; |
| 4069 | 523 int off = 0, stride = 1, width, shift; |
| 2970 | 524 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
525 zero = av_mallocz(s->picture.linesize[0]); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
526 last = zero; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
527 cur = s->picture.data[0]; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
528 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
529 state = av_mallocz(sizeof(JLSState)); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
530 /* initialize JPEG-LS state from JPEG parameters */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
531 state->near = near; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
532 state->bpp = (s->bits < 2) ? 2 : s->bits; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
533 state->maxval = s->maxval; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
534 state->T1 = s->t1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
535 state->T2 = s->t2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
536 state->T3 = s->t3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
537 state->reset = s->reset; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
538 reset_ls_coding_parameters(state, 0); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
539 ls_init_state(state); |
| 2970 | 540 |
| 4069 | 541 if(s->bits <= 8) |
| 542 shift = point_transform + (8 - s->bits); | |
| 543 else | |
| 544 shift = point_transform + (16 - s->bits); | |
| 545 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
546 // av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
547 // av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
548 if(ilv == 0) { /* separate planes */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
549 off = s->cur_scan - 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
550 stride = (s->nb_components > 1) ? 3 : 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
551 width = s->width * stride; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
552 cur += off; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
553 for(i = 0; i < s->height; i++) { |
| 4069 | 554 if(s->bits <= 8){ |
| 555 ls_decode_line(state, s, last, cur, t, width, stride, off); | |
| 556 t = last[0]; | |
| 557 }else{ | |
| 558 ls_decode_line_16bpp(state, s, last, cur, t, width, stride, off); | |
| 559 t = *((uint16_t*)last); | |
| 560 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
561 last = cur; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
562 cur += s->picture.linesize[0]; |
|
3063
f02d0b59279c
Remove all stray tabs and trailing whitespace, this time for good.
diego
parents:
3036
diff
changeset
|
563 |
| 2970 | 564 if (s->restart_interval && !--s->restart_count) { |
| 565 align_get_bits(&s->gb); | |
| 566 skip_bits(&s->gb, 16); /* skip RSTn */ | |
| 567 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
568 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
569 } else if(ilv == 1) { /* line interleaving */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
570 int j; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
571 int Rc[3] = {0, 0, 0}; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
572 memset(cur, 0, s->picture.linesize[0]); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
573 width = s->width * 3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
574 for(i = 0; i < s->height; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
575 for(j = 0; j < 3; j++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
576 ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
577 Rc[j] = last[j]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
578 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
579 if (s->restart_interval && !--s->restart_count) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
580 align_get_bits(&s->gb); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
581 skip_bits(&s->gb, 16); /* skip RSTn */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
582 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
583 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
584 last = cur; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
585 cur += s->picture.linesize[0]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
586 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
587 } else if(ilv == 2) { /* sample interleaving */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
588 av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n"); |
| 3773 | 589 av_free(state); |
| 590 av_free(zero); | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
591 return -1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
592 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
593 |
| 4069 | 594 if(shift){ /* we need to do point transform or normalize samples */ |
| 595 int x, w; | |
| 596 | |
| 597 w = s->width * s->nb_components; | |
| 598 | |
| 599 if(s->bits <= 8){ | |
| 600 uint8_t *src = s->picture.data[0]; | |
| 601 | |
| 602 for(i = 0; i < s->height; i++){ | |
| 603 for(x = off; x < w; x+= stride){ | |
| 604 src[x] <<= shift; | |
| 605 } | |
| 606 src += s->picture.linesize[0]; | |
| 607 } | |
| 608 }else{ | |
| 609 uint16_t *src = s->picture.data[0]; | |
| 610 | |
| 611 for(i = 0; i < s->height; i++){ | |
| 612 for(x = 0; x < w; x++){ | |
| 613 src[x] <<= shift; | |
| 614 } | |
| 615 src += s->picture.linesize[0]/2; | |
| 616 } | |
| 617 } | |
| 618 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
619 av_free(state); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
620 av_free(zero); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
621 |
| 2970 | 622 return 0; |
| 623 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
624 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
625 #if defined(CONFIG_ENCODERS) && defined(CONFIG_JPEGLS_ENCODER) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
626 /********** Encoder-specific functions **********/ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
627 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
628 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
629 * Encode error from regular symbol |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
630 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
631 static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q, int err){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
632 int k; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
633 int val; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
634 int map; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
635 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
636 for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
637 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
638 map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
639 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
640 if(err < 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
641 err += state->range; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
642 if(err >= ((state->range + 1) >> 1)) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
643 err -= state->range; |
| 4001 | 644 val = 2 * FFABS(err) - 1 - map; |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
645 } else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
646 val = 2 * err + map; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
647 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
648 set_ur_golomb_jpegls(pb, val, k, state->limit, state->qbpp); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
649 |
| 4001 | 650 state->A[Q] += FFABS(err); |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
651 state->B[Q] += err * state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
652 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
653 if(state->N[Q] == state->reset) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
654 state->A[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
655 state->B[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
656 state->N[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
657 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
658 state->N[Q]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
659 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
660 if(state->B[Q] <= -state->N[Q]) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
661 state->B[Q] += state->N[Q]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
662 if(state->C[Q] > -128) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
663 state->C[Q]--; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
664 if(state->B[Q] <= -state->N[Q]) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
665 state->B[Q] = -state->N[Q] + 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
666 }else if(state->B[Q] > 0){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
667 state->B[Q] -= state->N[Q]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
668 if(state->C[Q] < 127) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
669 state->C[Q]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
670 if(state->B[Q] > 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
671 state->B[Q] = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
672 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
673 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
674 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
675 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
676 * Encode error from run termination |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
677 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
678 static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RItype, int err, int limit_add){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
679 int k; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
680 int val, map; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
681 int Q = 365 + RItype; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
682 int temp; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
683 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
684 temp = state->A[Q]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
685 if(RItype) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
686 temp += state->N[Q] >> 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
687 for(k = 0; (state->N[Q] << k) < temp; k++); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
688 map = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
689 if(!k && err && (2 * state->B[Q] < state->N[Q])) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
690 map = 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
691 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
692 if(err < 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
693 val = - (2 * err) - 1 - RItype + map; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
694 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
695 val = 2 * err - RItype - map; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
696 set_ur_golomb_jpegls(pb, val, k, state->limit - limit_add - 1, state->qbpp); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
697 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
698 if(err < 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
699 state->B[Q]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
700 state->A[Q] += (val + 1 - RItype) >> 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
701 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
702 if(state->N[Q] == state->reset) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
703 state->A[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
704 state->B[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
705 state->N[Q] >>= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
706 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
707 state->N[Q]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
708 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
709 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
710 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
711 * Encode run value as specified by JPEG-LS standard |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
712 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
713 static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, int comp, int trail){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
714 while(run >= (1 << log2_run[state->run_index[comp]])){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
715 put_bits(pb, 1, 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
716 run -= 1 << log2_run[state->run_index[comp]]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
717 if(state->run_index[comp] < 31) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
718 state->run_index[comp]++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
719 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
720 /* if hit EOL, encode another full run, else encode aborted run */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
721 if(!trail && run) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
722 put_bits(pb, 1, 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
723 }else if(trail){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
724 put_bits(pb, 1, 0); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
725 if(log2_run[state->run_index[comp]]) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
726 put_bits(pb, log2_run[state->run_index[comp]], run); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
727 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
728 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
729 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
730 /** |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
731 * Encode one line of image |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
732 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
733 static inline void ls_encode_line(JLSState *state, PutBitContext *pb, uint8_t *last, uint8_t *cur, int last2, int w, int stride, int comp){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
734 int x = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
735 int Ra, Rb, Rc, Rd; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
736 int D0, D1, D2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
737 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
738 while(x < w) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
739 int err, pred, sign; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
740 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
741 /* compute gradients */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
742 Ra = x ? cur[x - stride] : last[x]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
743 Rb = last[x]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
744 Rc = x ? last[x - stride] : last2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
745 Rd = (x >= w - stride) ? last[x] : last[x + stride]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
746 D0 = Rd - Rb; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
747 D1 = Rb - Rc; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
748 D2 = Rc - Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
749 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
750 /* run mode */ |
| 4001 | 751 if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
752 int RUNval, RItype, run; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
753 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
754 run = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
755 RUNval = Ra; |
| 4001 | 756 while(x < w && (FFABS(cur[x] - RUNval) <= state->near)){ |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
757 run++; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
758 cur[x] = Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
759 x += stride; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
760 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
761 ls_encode_run(state, pb, run, comp, x < w); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
762 if(x >= w) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
763 return; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
764 Rb = last[x]; |
| 4001 | 765 RItype = (FFABS(Ra - Rb) <= state->near); |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
766 pred = RItype ? Ra : Rb; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
767 err = cur[x] - pred; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
768 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
769 if(!RItype && Ra > Rb) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
770 err = -err; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
771 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
772 if(state->near){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
773 if(err > 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
774 err = (state->near + err) / state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
775 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
776 err = -(state->near - err) / state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
777 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
778 if(RItype || (Rb >= Ra)) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
779 Ra = clip(pred + err * state->twonear, 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
780 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
781 Ra = clip(pred - err * state->twonear, 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
782 cur[x] = Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
783 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
784 if(err < 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
785 err += state->range; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
786 if(err >= ((state->range + 1) >> 1)) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
787 err -= state->range; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
788 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
789 ls_encode_runterm(state, pb, RItype, err, log2_run[state->run_index[comp]]); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
790 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
791 if(state->run_index[comp] > 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
792 state->run_index[comp]--; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
793 x += stride; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
794 } else { /* regular mode */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
795 int context; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
796 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
797 context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
798 pred = mid_pred(Ra, Ra + Rb - Rc, Rb); |
| 2970 | 799 |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
800 if(context < 0){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
801 context = -context; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
802 sign = 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
803 pred = clip(pred - state->C[context], 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
804 err = pred - cur[x]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
805 }else{ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
806 sign = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
807 pred = clip(pred + state->C[context], 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
808 err = cur[x] - pred; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
809 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
810 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
811 if(state->near){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
812 if(err > 0) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
813 err = (state->near + err) / state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
814 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
815 err = -(state->near - err) / state->twonear; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
816 if(!sign) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
817 Ra = clip(pred + err * state->twonear, 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
818 else |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
819 Ra = clip(pred - err * state->twonear, 0, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
820 cur[x] = Ra; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
821 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
822 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
823 ls_encode_regular(state, pb, context, err); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
824 x += stride; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
825 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
826 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
827 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
828 |
| 4069 | 829 /** |
| 830 * Encode one line of image with 16 bpp sample size | |
| 831 */ | |
| 832 static inline void ls_encode_line_16bpp(JLSState *state, PutBitContext *pb, uint16_t *last, uint16_t *cur, int last2, int w, int stride, int comp){ | |
| 833 int x = 0; | |
| 834 int Ra, Rb, Rc, Rd; | |
| 835 int D0, D1, D2; | |
| 836 | |
| 837 while(x < w) { | |
| 838 int err, pred, sign; | |
| 839 | |
| 840 /* compute gradients */ | |
| 841 Ra = x ? cur[x - stride] : last[x]; | |
| 842 Rb = last[x]; | |
| 843 Rc = x ? last[x - stride] : last2; | |
| 844 Rd = (x >= w - stride) ? last[x] : last[x + stride]; | |
| 845 D0 = Rd - Rb; | |
| 846 D1 = Rb - Rc; | |
| 847 D2 = Rc - Ra; | |
| 848 | |
| 849 /* run mode */ | |
| 850 if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { | |
| 851 int RUNval, RItype, run; | |
| 852 | |
| 853 run = 0; | |
| 854 RUNval = Ra; | |
| 855 while(x < w && (FFABS(cur[x] - RUNval) <= state->near)){ | |
| 856 run++; | |
| 857 cur[x] = Ra; | |
| 858 x += stride; | |
| 859 } | |
| 860 ls_encode_run(state, pb, run, comp, x < w); | |
| 861 if(x >= w) | |
| 862 return; | |
| 863 Rb = last[x]; | |
| 864 RItype = (FFABS(Ra - Rb) <= state->near); | |
| 865 pred = RItype ? Ra : Rb; | |
| 866 err = cur[x] - pred; | |
| 867 | |
| 868 if(!RItype && Ra > Rb) | |
| 869 err = -err; | |
| 870 | |
| 871 if(state->near){ | |
| 872 if(err > 0) | |
| 873 err = (state->near + err) / state->twonear; | |
| 874 else | |
| 875 err = -(state->near - err) / state->twonear; | |
| 876 | |
| 877 if(RItype || (Rb >= Ra)) | |
| 878 Ra = clip(pred + err * state->twonear, 0, state->maxval); | |
| 879 else | |
| 880 Ra = clip(pred - err * state->twonear, 0, state->maxval); | |
| 881 cur[x] = Ra; | |
| 882 } | |
| 883 if(err < 0) | |
| 884 err += state->range; | |
| 885 if(err >= ((state->range + 1) >> 1)) | |
| 886 err -= state->range; | |
| 887 | |
| 888 ls_encode_runterm(state, pb, RItype, err, log2_run[state->run_index[comp]]); | |
| 889 | |
| 890 if(state->run_index[comp] > 0) | |
| 891 state->run_index[comp]--; | |
| 892 x += stride; | |
| 893 } else { /* regular mode */ | |
| 894 int context; | |
| 895 | |
| 896 context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2); | |
| 897 pred = mid_pred(Ra, Ra + Rb - Rc, Rb); | |
| 898 | |
| 899 if(context < 0){ | |
| 900 context = -context; | |
| 901 sign = 1; | |
| 902 pred = clip(pred - state->C[context], 0, state->maxval); | |
| 903 err = pred - cur[x]; | |
| 904 }else{ | |
| 905 sign = 0; | |
| 906 pred = clip(pred + state->C[context], 0, state->maxval); | |
| 907 err = cur[x] - pred; | |
| 908 } | |
| 909 | |
| 910 if(state->near){ | |
| 911 if(err > 0) | |
| 912 err = (state->near + err) / state->twonear; | |
| 913 else | |
| 914 err = -(state->near - err) / state->twonear; | |
| 915 if(!sign) | |
| 916 Ra = clip(pred + err * state->twonear, 0, state->maxval); | |
| 917 else | |
| 918 Ra = clip(pred - err * state->twonear, 0, state->maxval); | |
| 919 cur[x] = Ra; | |
| 920 } | |
| 921 | |
| 922 ls_encode_regular(state, pb, context, err); | |
| 923 x += stride; | |
| 924 } | |
| 925 } | |
| 926 } | |
| 927 | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
928 static void ls_store_lse(JLSState *state, PutBitContext *pb){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
929 /* Test if we have default params and don't need to store LSE */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
930 JLSState state2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
931 memset(&state2, 0, sizeof(JLSState)); |
| 4069 | 932 state2.bpp = state->bpp; |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
933 state2.near = state->near; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
934 reset_ls_coding_parameters(&state2, 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
935 if(state->T1 == state2.T1 && state->T2 == state2.T2 && state->T3 == state2.T3 && state->reset == state2.reset) |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
936 return; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
937 /* store LSE type 1 */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
938 put_marker(pb, LSE); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
939 put_bits(pb, 16, 13); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
940 put_bits(pb, 8, 1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
941 put_bits(pb, 16, state->maxval); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
942 put_bits(pb, 16, state->T1); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
943 put_bits(pb, 16, state->T2); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
944 put_bits(pb, 16, state->T3); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
945 put_bits(pb, 16, state->reset); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
946 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
947 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
948 static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
949 JpeglsContext * const s = avctx->priv_data; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
950 AVFrame *pict = data; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
951 AVFrame * const p= (AVFrame*)&s->picture; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
952 const int near = avctx->prediction_method; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
953 PutBitContext pb, pb2; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
954 GetBitContext gb; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
955 uint8_t *buf2, *zero, *cur, *last; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
956 JLSState *state; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
957 int i, size; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
958 int comps; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
959 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
960 buf2 = av_malloc(buf_size); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
961 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
962 init_put_bits(&pb, buf, buf_size); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
963 init_put_bits(&pb2, buf2, buf_size); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
964 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
965 *p = *pict; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
966 p->pict_type= FF_I_TYPE; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
967 p->key_frame= 1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
968 |
| 4069 | 969 if(avctx->pix_fmt == PIX_FMT_GRAY8 || avctx->pix_fmt == PIX_FMT_GRAY16) |
| 970 comps = 1; | |
| 971 else | |
| 972 comps = 3; | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
973 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
974 /* write our own JPEG header, can't use mjpeg_picture_header */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
975 put_marker(&pb, SOI); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
976 put_marker(&pb, SOF48); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
977 put_bits(&pb, 16, 8 + comps * 3); // header size depends on components |
| 4069 | 978 put_bits(&pb, 8, (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8); // bpp |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
979 put_bits(&pb, 16, avctx->height); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
980 put_bits(&pb, 16, avctx->width); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
981 put_bits(&pb, 8, comps); // components |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
982 for(i = 1; i <= comps; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
983 put_bits(&pb, 8, i); // component ID |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
984 put_bits(&pb, 8, 0x11); // subsampling: none |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
985 put_bits(&pb, 8, 0); // Tiq, used by JPEG-LS ext |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
986 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
987 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
988 put_marker(&pb, SOS); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
989 put_bits(&pb, 16, 6 + comps * 2); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
990 put_bits(&pb, 8, comps); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
991 for(i = 1; i <= comps; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
992 put_bits(&pb, 8, i); // component ID |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
993 put_bits(&pb, 8, 0); // mapping index: none |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
994 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
995 put_bits(&pb, 8, near); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
996 put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
997 put_bits(&pb, 8, 0); // point transform: none |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
998 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
999 state = av_mallocz(sizeof(JLSState)); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1000 /* initialize JPEG-LS state from JPEG parameters */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1001 state->near = near; |
| 4069 | 1002 state->bpp = (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8; |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1003 reset_ls_coding_parameters(state, 0); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1004 ls_init_state(state); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1005 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1006 ls_store_lse(state, &pb); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1007 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1008 zero = av_mallocz(p->linesize[0]); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1009 last = zero; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1010 cur = p->data[0]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1011 if(avctx->pix_fmt == PIX_FMT_GRAY8){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1012 int t = 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1013 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1014 for(i = 0; i < avctx->height; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1015 ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1016 t = last[0]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1017 last = cur; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1018 cur += p->linesize[0]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1019 } |
| 4069 | 1020 }else if(avctx->pix_fmt == PIX_FMT_GRAY16){ |
| 1021 int t = 0; | |
| 1022 | |
| 1023 for(i = 0; i < avctx->height; i++) { | |
| 1024 ls_encode_line_16bpp(state, &pb2, last, cur, t, avctx->width, 1, 0); | |
| 1025 t = *((uint16_t*)last); | |
| 1026 last = cur; | |
| 1027 cur += p->linesize[0]; | |
| 1028 } | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1029 }else if(avctx->pix_fmt == PIX_FMT_RGB24){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1030 int j, width; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1031 int Rc[3] = {0, 0, 0}; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1032 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1033 width = avctx->width * 3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1034 for(i = 0; i < avctx->height; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1035 for(j = 0; j < 3; j++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1036 ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1037 Rc[j] = last[j]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1038 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1039 last = cur; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1040 cur += s->picture.linesize[0]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1041 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1042 }else if(avctx->pix_fmt == PIX_FMT_BGR24){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1043 int j, width; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1044 int Rc[3] = {0, 0, 0}; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1045 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1046 width = avctx->width * 3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1047 for(i = 0; i < avctx->height; i++) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1048 for(j = 2; j >= 0; j--) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1049 ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1050 Rc[j] = last[j]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1051 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1052 last = cur; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1053 cur += s->picture.linesize[0]; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1054 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1055 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1056 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1057 av_free(zero); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1058 av_free(state); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1059 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1060 flush_put_bits(&pb2); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1061 /* do escape coding */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1062 size = put_bits_count(&pb2) >> 3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1063 init_get_bits(&gb, buf2, size); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1064 while(get_bits_count(&gb) < size * 8){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1065 int v; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1066 v = get_bits(&gb, 8); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1067 put_bits(&pb, 8, v); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1068 if(v == 0xFF){ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1069 v = get_bits(&gb, 7); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1070 put_bits(&pb, 8, v); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1071 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1072 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1073 align_put_bits(&pb); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1074 av_free(buf2); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1075 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1076 /* End of image */ |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1077 put_marker(&pb, EOI); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1078 flush_put_bits(&pb); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1079 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1080 emms_c(); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1081 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1082 return put_bits_count(&pb) >> 3; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1083 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1084 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1085 static int encode_init_ls(AVCodecContext *ctx) { |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1086 JpeglsContext *c = (JpeglsContext*)ctx->priv_data; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1087 |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1088 c->avctx = ctx; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1089 ctx->coded_frame = &c->picture; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1090 |
| 4069 | 1091 if(ctx->pix_fmt != PIX_FMT_GRAY8 && ctx->pix_fmt != PIX_FMT_GRAY16 && ctx->pix_fmt != PIX_FMT_RGB24 && ctx->pix_fmt != PIX_FMT_BGR24){ |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1092 av_log(ctx, AV_LOG_ERROR, "Only grayscale and RGB24/BGR24 images are supported\n"); |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1093 return -1; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1094 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1095 return 0; |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1096 } |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1097 |
| 2970 | 1098 AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them |
| 1099 "jpegls", | |
| 1100 CODEC_TYPE_VIDEO, | |
| 1101 CODEC_ID_JPEGLS, | |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1102 sizeof(JpeglsContext), |
|
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1103 encode_init_ls, |
| 2970 | 1104 encode_picture_ls, |
|
3078
1e63c12c2c71
JPEG-LS codec by (Kostya | kostya.forjunk gmail com)
michael
parents:
3063
diff
changeset
|
1105 NULL, |
| 4069 | 1106 .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, -1}, |
| 2970 | 1107 }; |
| 1108 #endif |
