Mercurial > mplayer.hg
comparison libvo/jpeg_enc.c @ 8117:dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
author | rik |
---|---|
date | Wed, 06 Nov 2002 15:19:45 +0000 |
parents | c9d1054aa359 |
children | f745791c3030 |
comparison
equal
deleted
inserted
replaced
8116:3757669b825b | 8117:dda027d5a845 |
---|---|
128 UINT8 *huff_size, UINT16 *huff_code) | 128 UINT8 *huff_size, UINT16 *huff_code) |
129 { | 129 { |
130 int mant, nbits; | 130 int mant, nbits; |
131 | 131 |
132 if (val == 0) { | 132 if (val == 0) { |
133 jput_bits(&s->pb, huff_size[0], huff_code[0]); | 133 put_bits(&s->pb, huff_size[0], huff_code[0]); |
134 } else { | 134 } else { |
135 mant = val; | 135 mant = val; |
136 if (val < 0) { | 136 if (val < 0) { |
137 val = -val; | 137 val = -val; |
138 mant--; | 138 mant--; |
143 while (val != 0) { | 143 while (val != 0) { |
144 val = val >> 1; | 144 val = val >> 1; |
145 nbits++; | 145 nbits++; |
146 } | 146 } |
147 | 147 |
148 jput_bits(&s->pb, huff_size[nbits], huff_code[nbits]); | 148 put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); |
149 | 149 |
150 jput_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); | 150 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 static void encode_block(MpegEncContext *s, DCTELEM *block, int n) | 154 static void encode_block(MpegEncContext *s, DCTELEM *block, int n) |
155 { | 155 { |
183 val = block[j]; | 183 val = block[j]; |
184 if (val == 0) { | 184 if (val == 0) { |
185 run++; | 185 run++; |
186 } else { | 186 } else { |
187 while (run >= 16) { | 187 while (run >= 16) { |
188 jput_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); | 188 put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); |
189 run -= 16; | 189 run -= 16; |
190 } | 190 } |
191 mant = val; | 191 mant = val; |
192 if (val < 0) { | 192 if (val < 0) { |
193 val = -val; | 193 val = -val; |
200 val = val >> 1; | 200 val = val >> 1; |
201 nbits++; | 201 nbits++; |
202 } | 202 } |
203 code = (run << 4) | nbits; | 203 code = (run << 4) | nbits; |
204 | 204 |
205 jput_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); | 205 put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); |
206 | 206 |
207 jput_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); | 207 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
208 run = 0; | 208 run = 0; |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 /* output EOB only if not already 64 values */ | 212 /* output EOB only if not already 64 values */ |
213 if (last_index < 63 || run != 0) | 213 if (last_index < 63 || run != 0) |
214 jput_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); | 214 put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); |
215 } | 215 } |
216 | 216 |
217 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) | 217 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
218 { | 218 { |
219 int i; | 219 int i; |
242 | 242 |
243 encode_block(j->s, j->s->block[0], 0); | 243 encode_block(j->s, j->s->block[0], 0); |
244 encode_block(j->s, j->s->block[1], 1); | 244 encode_block(j->s, j->s->block[1], 1); |
245 if (j->bw) { | 245 if (j->bw) { |
246 /* U */ | 246 /* U */ |
247 jput_bits(&j->s->pb, m->huff_size_dc_chrominance[0], | 247 put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], |
248 m->huff_code_dc_chrominance[0]); | 248 m->huff_code_dc_chrominance[0]); |
249 jput_bits(&j->s->pb, m->huff_size_ac_chrominance[0], | 249 put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], |
250 m->huff_code_ac_chrominance[0]); | 250 m->huff_code_ac_chrominance[0]); |
251 /* V */ | 251 /* V */ |
252 jput_bits(&j->s->pb, m->huff_size_dc_chrominance[0], | 252 put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], |
253 m->huff_code_dc_chrominance[0]); | 253 m->huff_code_dc_chrominance[0]); |
254 jput_bits(&j->s->pb, m->huff_size_ac_chrominance[0], | 254 put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], |
255 m->huff_code_ac_chrominance[0]); | 255 m->huff_code_ac_chrominance[0]); |
256 } else { | 256 } else { |
257 /* we trick encode_block here so that it uses | 257 /* we trick encode_block here so that it uses |
258 * chrominance huffman tables instead of luminance ones | 258 * chrominance huffman tables instead of luminance ones |
259 * (see the effect of second argument of encode_block) */ | 259 * (see the effect of second argument of encode_block) */ |
379 /* initialize the buffer */ | 379 /* initialize the buffer */ |
380 | 380 |
381 init_put_bits(&j->s->pb, bufr, 1024*256, NULL, NULL); | 381 init_put_bits(&j->s->pb, bufr, 1024*256, NULL, NULL); |
382 | 382 |
383 mjpeg_picture_header(j->s); | 383 mjpeg_picture_header(j->s); |
384 | |
385 j->s->header_bits = get_bit_count(&j->s->pb); | |
384 | 386 |
385 j->s->last_dc[0] = 128; | 387 j->s->last_dc[0] = 128; |
386 j->s->last_dc[1] = 128; | 388 j->s->last_dc[1] = 128; |
387 j->s->last_dc[2] = 128; | 389 j->s->last_dc[2] = 128; |
388 | 390 |