annotate jpeg_ls.c @ 2988:538eed481f62 libavcodec

b frame strategy 2
author michael
date Sun, 25 Dec 2005 17:30:52 +0000
parents 583b6ac45c07
children 0b546eab515d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2970
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
1 /*
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
2 * JPEG-LS encoder and decoder
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
4 *
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
9 *
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
13 * Lesser General Public License for more details.
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
14 *
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
18 */
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
19
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
20 /**
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
21 * @file jpeg_ls.c
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
22 * JPEG-LS encoder and decoder.
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
23 */
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
24
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
25 #undef printf
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
26 #undef fprintf
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
27
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
28 static inline int quantize(MJpegDecodeContext *s, int v){ //FIXME optimize
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
29 if(v==0) return 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
30 if(v < 0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
31 if (v >-s->t1) return -1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
32 else if(v >-s->t2) return -2;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
33 else if(v >-s->t3) return -3;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
34 else return -4;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
35 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
36 if (v < s->t1) return 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
37 else if(v < s->t2) return 2;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
38 else if(v < s->t3) return 3;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
39 else return 4;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
40 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
41 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
42
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
43 static inline int predict8(uint8_t *src, uint8_t *last){ //FIXME perhaps its better to suppress these 2
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
44 const int LT= last[-1];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
45 const int T= last[ 0];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
46 const int L = src[-1];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
47
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
48 return mid_pred(L, L + T - LT, T);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
49 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
50
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
51 static inline int predict16(uint16_t *src, uint16_t *last){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
52 const int LT= last[-1];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
53 const int T= last[ 0];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
54 const int L = src[-1];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
55
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
56 return mid_pred(L, L + T - LT, T);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
57 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
58
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
59 static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
60 return 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
61 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
62
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
63 static int iso_clip(int v, int vmin, int vmax){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
64 if(v > vmax || v < vmin) return vmin;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
65 else return v;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
66 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
67
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
68 static void reset_ls_coding_parameters(MJpegDecodeContext *s, int reset_all){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
69 const int basic_t1= 3;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
70 const int basic_t2= 7;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
71 const int basic_t3= 21;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
72 int factor;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
73
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
74 if(s->maxval==0 || reset_all) s->maxval= (1<<s->bits) - 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
75
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
76 if(s->maxval >=128){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
77 factor= (FFMIN(s->maxval, 4096) + 128)>>8;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
78
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
79 if(s->t1==0 || reset_all)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
80 s->t1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
81 if(s->t2==0 || reset_all)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
82 s->t2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->t1, s->maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
83 if(s->t3==0 || reset_all)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
84 s->t3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->t2, s->maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
85 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
86 factor= 256 / (s->maxval + 1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
87
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
88 if(s->t1==0 || reset_all)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
89 s->t1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
90 if(s->t2==0 || reset_all)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
91 s->t2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->t1, s->maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
92 if(s->t3==0 || reset_all)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
93 s->t3= iso_clip(FFMAX(4, basic_t3/factor + 6*s->near), s->t2, s->maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
94 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
95
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
96 if(s->reset==0 || reset_all) s->reset= 64;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
97 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
98
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
99 static int decode_lse(MJpegDecodeContext *s)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
100 {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
101 int len, id;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
102
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
103 /* XXX: verify len field validity */
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
104 len = get_bits(&s->gb, 16);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
105 id = get_bits(&s->gb, 8);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
106
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
107 switch(id){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
108 case 1:
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
109 s->maxval= get_bits(&s->gb, 16);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
110 s->t1= get_bits(&s->gb, 16);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
111 s->t2= get_bits(&s->gb, 16);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
112 s->t3= get_bits(&s->gb, 16);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
113 s->reset= get_bits(&s->gb, 16);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
114
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
115 reset_ls_coding_parameters(s, 0);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
116 //FIXME quant table?
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
117 break;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
118 case 2:
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
119 case 3:
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
120 printf("palette not supported\n");
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
121 return -1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
122 case 4:
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
123 printf("oversize image not supported\n");
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
124 return -1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
125 default:
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
126 printf("invalid id %d\n", id);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
127 return -1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
128 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
129
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
130 return 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
131 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
132 #if 0
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
133 static inline void update_vlc_state(VlcState * const state, const int v, int half_count){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
134 int drift= state->drift;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
135 int count= state->count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
136 state->error_sum += ABS(v);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
137 drift += v;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
138
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
139 if(count == half_count){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
140 count >>= 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
141 drift >>= 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
142 state->error_sum >>= 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
143 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
144 count++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
145
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
146 if(drift <= -count){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
147 if(state->bias > -128) state->bias--;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
148
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
149 drift += count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
150 if(drift <= -count)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
151 drift= -count + 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
152 }else if(drift > 0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
153 if(state->bias < 127) state->bias++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
154
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
155 drift -= count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
156 if(drift > 0)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
157 drift= 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
158 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
159
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
160 state->drift= drift;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
161 state->count= count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
162 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
163
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
164 #define R(p, i) (is_uint8 ? (((uint8_t*)p)[i] : ((uint16_t*)p)[i])
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
165
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
166 static inline int ls_decode_line(MJpegDecodeContext *s, void *lastv, void *dstv, int last2,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
167 int w, int point_transform, int is_uint8){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
168 int i, x, y;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
169
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
170 for(x=0; x < w; x++){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
171 int l, t, lt, rt;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
172
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
173 t= R(last, 0);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
174 if(x){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
175 l = t;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
176 lt= last2;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
177 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
178 l = R(dst, x-1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
179 lt= R(last, x-1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
180 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
181
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
182 if(x<w-1) rt= R(last, x+1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
183 else rt= t;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
184
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
185 hr_gradient= rt - t;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
186 hl_gradient= t - lt;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
187 v_gradient= lt - l;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
188
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
189 context= quantize(s, v_gradient) + 9*(quantize(s, hl_gradient) + 9*quantize(s, hr_gradient));
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
190
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
191 if(context){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
192 int pred= mid_pred(l, l + t - lt, t);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
193
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
194 if(context < 0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
195 context= -context;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
196 sign= 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
197 pred= clip(0, pred - state->bias, maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
198 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
199 sign= 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
200 pred= clip(0, pred + state->bias, maxval);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
201 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
202
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
203 i= state->count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
204 k=0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
205 while(i < state->error_sum){ //FIXME optimize
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
206 k++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
207 i += i;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
208 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
209
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
210 v= get_ur_golomb_jpegls(gb, k, LIMIT-qbpp, qbpp);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
211 #if 1
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
212 v++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
213 if(v&1) v= (v>>1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
214 else v= -(v>>1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
215
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
216 if(k==0 && 2*state->drift <= - state->count) v ^= (-1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
217 #else
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
218 v ^= (k==0 && 2*state->drift <= - state->count);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
219 v++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
220 if(v&1) v= (v>>1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
221 else v= -(v>>1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
222
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
223 #endif
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
224 update_vlc_state(state, v, half_count);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
225
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
226 if(sign) v= -v;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
227
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
228 if(is_uint8) ((uint8_t *)dst)[x]= (pred + v) & maxval;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
229 else ((uint16_t*)dst)[x]= (pred + v) & maxval;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
230 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
231 int run_count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
232
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
233 while(get_bits1(&s->gb)){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
234 run_count = 1<<log2_run[run_index];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
235 if(x + run_count > w) run_count= w - x;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
236 else run_index++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
237
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
238 for(; run_count; run_count--){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
239 if(is_uint8) ((uint8_t *)dst)[x++]= l;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
240 else ((uint16_t*)dst)[x++]= l;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
241 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
242
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
243 if(x >= w) return 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
244 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
245
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
246 run_count= get_bits(&s->gb, log2_run[run_index]);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
247
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
248 for(; run_count; run_count--){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
249 if(is_uint8) ((uint8_t *)dst)[x++]= l;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
250 else ((uint16_t*)dst)[x++]= l;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
251 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
252
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
253 if(run_index) run_index--;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
254
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
255 if(x >= w) return 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
256
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
257 t= R(last, 0);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
258
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
259 RItype= (l==t);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
260 if(l==t){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
261 state= 366;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
262 temp= state->error_sum + (state->count>>1);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
263 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
264 state= 365;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
265 temp= state->error_sum;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
266 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
267
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
268 pred= t;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
269 sign= l > t;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
270
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
271 i= state->count;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
272 k=0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
273 while(i < temp){ //FIXME optimize
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
274 k++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
275 i += i;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
276 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
277
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
278 assert(Errval != 0);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
279 map = (k==0 && 2*Nn < state->count) == (Errval>0);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
280
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
281
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
282 if(run_count==0 && run_mode==1){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
283 if(get_bits1(&s->gb)){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
284 run_count = 1<<log2_run[run_index];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
285 if(x + run_count <= w) run_index++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
286 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
287 if(log2_run[run_index]) run_count = get_bits(&s->gb, log2_run[run_index]);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
288 else run_count=0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
289 if(run_index) run_index--;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
290 run_mode=2;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
291 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
292 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
293 run_count--;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
294 if(run_count < 0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
295 run_mode=0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
296 run_count=0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
297 diff= get_vlc_symbol(&s->gb, &p->vlc_state[context]);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
298 if(diff>=0) diff++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
299 }else
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
300 diff=0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
301
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
302 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
303 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
304
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
305 /* if (s->restart_interval && !s->restart_count)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
306 s->restart_count = s->restart_interval;*/
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
307
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
308 if(mb_x==0 || mb_y==0 || s->interlaced){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
309 for(i=0;i<nb_components;i++) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
310 uint8_t *ptr;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
311 int n, h, v, x, y, c, j, linesize;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
312 n = s->nb_blocks[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
313 c = s->comp_index[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
314 h = s->h_scount[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
315 v = s->v_scount[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
316 x = 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
317 y = 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
318 linesize= s->linesize[c];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
319
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
320 for(j=0; j<n; j++) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
321 int pred;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
322
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
323 ptr = s->current_picture[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
324 if(y==0 && mb_y==0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
325 if(x==0 && mb_x==0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
326 pred= 128 << point_transform;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
327 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
328 pred= ptr[-1];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
329 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
330 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
331 if(x==0 && mb_x==0){
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
332 pred= ptr[-linesize];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
333 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
334 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
335 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
336 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
337
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
338 if (s->interlaced && s->bottom_field)
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
339 ptr += linesize >> 1;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
340 *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
341
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
342 if (++x == h) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
343 x = 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
344 y++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
345 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
346 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
347 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
348 }else{
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
349 for(i=0;i<nb_components;i++) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
350 uint8_t *ptr;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
351 int n, h, v, x, y, c, j, linesize;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
352 n = s->nb_blocks[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
353 c = s->comp_index[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
354 h = s->h_scount[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
355 v = s->v_scount[i];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
356 x = 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
357 y = 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
358 linesize= s->linesize[c];
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
359
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
360 for(j=0; j<n; j++) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
361 int pred;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
362
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
363 ptr = s->current_picture[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
364 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
365 *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
366 if (++x == h) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
367 x = 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
368 y++;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
369 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
370 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
371 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
372 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
373 if (s->restart_interval && !--s->restart_count) {
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
374 align_get_bits(&s->gb);
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
375 skip_bits(&s->gb, 16); /* skip RSTn */
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
376 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
377 return 0;
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
378 }
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
379 #endif
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
380
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
381 #ifdef CONFIG_ENCODERS
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
382 AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
383 "jpegls",
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
384 CODEC_TYPE_VIDEO,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
385 CODEC_ID_JPEGLS,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
386 sizeof(MpegEncContext),
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
387 MPV_encode_init,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
388 encode_picture_ls,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
389 MPV_encode_end,
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
390 };
583b6ac45c07 unfinished jpeg-ls codec (feel free to finish it ...)
michael
parents:
diff changeset
391 #endif