Mercurial > mplayer.hg
annotate libvo/jpeg_enc.c @ 35225:1e56eab1f210
Remove another incorrect use of realloc_struct.
author | reimar |
---|---|
date | Wed, 31 Oct 2012 20:58:39 +0000 |
parents | e0783849f3b6 |
children | 8517826b0dbd |
rev | line source |
---|---|
26739
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
1 /* |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
2 * straightforward (to be) optimized JPEG encoder for the YUV422 format |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
3 * based on MJPEG code from FFmpeg |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
4 * |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
5 * For an excellent introduction to the JPEG format, see: |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
6 * http://www.ece.purdue.edu/~bouman/grad-labs/lab8/pdf/lab.pdf |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
7 * |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
8 * Copyright (c) 2002, Rik Snel |
26739
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
9 * parts from FFmpeg Copyright (c) 2000-2002 Fabrice Bellard |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
10 * |
26739
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
11 * This file is part of MPlayer. |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
12 * |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
13 * MPlayer is free software; you can redistribute it and/or modify |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
14 * it under the terms of the GNU General Public License as published by |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
15 * the Free Software Foundation; either version 2 of the License, or |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
16 * (at your option) any later version. |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
17 * |
26739
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
18 * MPlayer is distributed in the hope that it will be useful, |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
21 * GNU General Public License for more details. |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
22 * |
26739
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
23 * You should have received a copy of the GNU General Public License along |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
24 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
2a34d9fa52ab
Use standard license headers with standard formatting.
diego
parents:
26290
diff
changeset
|
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
26 */ |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
27 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
28 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
29 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
30 #include <sys/types.h> |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
31 #include <stdio.h> |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
32 #include <stdlib.h> |
27862 | 33 #include <string.h> |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
34 #include "config.h" |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
11961
diff
changeset
|
35 #include "mp_msg.h" |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
36 /* We need this #define because we need ../libavcodec/common.h to #define |
4683
fba4289cdb41
we are now able to use the new bitwriter code in libavcodec
rik
parents:
4651
diff
changeset
|
37 * be2me_32, otherwise the linker will complain that it doesn't exist */ |
fba4289cdb41
we are now able to use the new bitwriter code in libavcodec
rik
parents:
4651
diff
changeset
|
38 #define HAVE_AV_CONFIG_H |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
11961
diff
changeset
|
39 #include "libavcodec/avcodec.h" |
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
11961
diff
changeset
|
40 #include "libavcodec/dsputil.h" |
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
11961
diff
changeset
|
41 #include "libavcodec/mpegvideo.h" |
25517
788499fc2ae7
Do not duplicate MJpegContext struct, #include the proper header instead.
diego
parents:
25100
diff
changeset
|
42 #include "libavcodec/mjpegenc.h" |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
43 |
33883
7bf488338904
zr: adjust #includes to fix compilation after av_helpers.h creation
diego
parents:
33839
diff
changeset
|
44 #include "av_helpers.h" |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
45 #include "jpeg_enc.h" |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
46 |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
47 |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
48 /* Begin excessive code duplication ************************************/ |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
49 /* Code coming from mpegvideo.c and mjpeg.c in ../libavcodec ***********/ |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
50 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
51 static const unsigned short aanscales[64] = { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
52 /* precomputed values scaled up by 14 bits */ |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
53 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
54 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
55 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
56 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
57 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
58 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
59 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
60 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
61 }; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
62 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
63 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], |
11258
9627feb8c6fb
ffmpeg sync patch by Alex (thank you), I changed qmin and qmax to be 1 and 31 in the caller
rik
parents:
11211
diff
changeset
|
64 uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, |
9627feb8c6fb
ffmpeg sync patch by Alex (thank you), I changed qmin and qmax to be 1 and 31 in the caller
rik
parents:
11211
diff
changeset
|
65 int bias, int qmin, int qmax) |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
66 { |
5864 | 67 int qscale; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
68 |
11345
97f11e488141
function convert_matrix() is fixed (off-by-one error) and it is now called with the optimal arguments so that it doesn't do unneeded work, the change was inspired by a comment from Alex
rik
parents:
11258
diff
changeset
|
69 for(qscale=qmin; qscale<=qmax; qscale++){ |
5864 | 70 int i; |
33839
22855f9368b4
vf_zrmjpeg: fix compilation after function templatization in libavcodec
diego
parents:
31960
diff
changeset
|
71 if (s->dsp.fdct == ff_jpeg_fdct_islow_8) { |
7157 | 72 for (i = 0; i < 64; i++) { |
9573 | 73 const int j = s->dsp.idct_permutation[i]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
74 /* 16 <= qscale * quant_matrix[i] <= 7905 |
7157 | 75 * 19952 <= aanscales[i] * \ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
76 * qscale * quant_matrix[i] <= 205026 |
7157 | 77 * (1<<36)/19952 >= (1<<36)/(aanscales[i] * \ |
78 * qscale * quant_matrix[i]) >= (1<<36)/249205025 | |
79 * 3444240 >= (1<<36)/(aanscales[i] * | |
80 * qscale * quant_matrix[i]) >= 275 */ | |
7902
c9d1054aa359
sync with libavcodec for unaccellerated dcts (sorry Felix, LIBAVCODEC_BUILD did not change, so also no backwards compatibility this time), and a long overdue copyright update
rik
parents:
7567
diff
changeset
|
81 qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT-3))/ |
7157 | 82 (qscale * quant_matrix[j])); |
83 } | |
34646 | 84 } else if (s->dsp.fdct == ff_fdct_ifast) { |
5864 | 85 for(i=0;i<64;i++) { |
9573 | 86 const int j = s->dsp.idct_permutation[i]; |
5864 | 87 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
88 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
89 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
90 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
91 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
92 qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / |
5864 | 93 (aanscales[i] * qscale * quant_matrix[j])); |
94 } | |
95 } else { | |
96 for(i=0;i<64;i++) { | |
9573 | 97 const int j = s->dsp.idct_permutation[i]; |
5864 | 98 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 |
99 So 16 <= qscale * quant_matrix[i] <= 7905 | |
100 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
101 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
102 */ | |
21724
019171a44e19
compilation fixes: define always_inline and don't use uint64_t_C
rik
parents:
19619
diff
changeset
|
103 qmat [qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j])); |
11258
9627feb8c6fb
ffmpeg sync patch by Alex (thank you), I changed qmin and qmax to be 1 and 31 in the caller
rik
parents:
11211
diff
changeset
|
104 qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); |
5864 | 105 |
11258
9627feb8c6fb
ffmpeg sync patch by Alex (thank you), I changed qmin and qmax to be 1 and 31 in the caller
rik
parents:
11211
diff
changeset
|
106 if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; |
9627feb8c6fb
ffmpeg sync patch by Alex (thank you), I changed qmin and qmax to be 1 and 31 in the caller
rik
parents:
11211
diff
changeset
|
107 qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); |
5864 | 108 } |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
109 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
110 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
111 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
112 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
113 static inline void encode_dc(MpegEncContext *s, int val, |
9438 | 114 uint8_t *huff_size, uint16_t *huff_code) |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
115 { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
116 int mant, nbits; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
117 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
118 if (val == 0) { |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
119 put_bits(&s->pb, huff_size[0], huff_code[0]); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
120 } else { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
121 mant = val; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
122 if (val < 0) { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
123 val = -val; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
124 mant--; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
125 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
126 |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
127 /* compute the log (XXX: optimize) */ |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
128 nbits = 0; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
129 while (val != 0) { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
130 val = val >> 1; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
131 nbits++; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
132 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
133 |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
134 put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
135 |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
136 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
137 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
138 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
139 |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
140 static void encode_block(MpegEncContext *s, DCTELEM *block, int n) |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
141 { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
142 int mant, nbits, code, i, j; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
143 int component, dc, run, last_index, val; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
144 MJpegContext *m = s->mjpeg_ctx; |
9438 | 145 uint8_t *huff_size_ac; |
146 uint16_t *huff_code_ac; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
147 |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
148 /* DC coef */ |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
149 component = (n <= 3 ? 0 : n - 4 + 1); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
150 dc = block[0]; /* overflow is impossible */ |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
151 val = dc - s->last_dc[component]; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
152 if (n < 4) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
153 encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
154 huff_size_ac = m->huff_size_ac_luminance; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
155 huff_code_ac = m->huff_code_ac_luminance; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
156 } else { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
157 encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
158 huff_size_ac = m->huff_size_ac_chrominance; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
159 huff_code_ac = m->huff_code_ac_chrominance; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
160 } |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
161 s->last_dc[component] = dc; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
162 |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
163 /* AC coefs */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
164 |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
165 run = 0; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
166 last_index = s->block_last_index[n]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
167 for(i=1;i<=last_index;i++) { |
7567
85e9956a6727
libavcodec sync; zigzag_direct and block_permute_op replaced by non-globals in MpegEncContext
rik
parents:
7157
diff
changeset
|
168 j = s->intra_scantable.permutated[i]; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
169 val = block[j]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
170 if (val == 0) { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
171 run++; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
172 } else { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
173 while (run >= 16) { |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
174 put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
175 run -= 16; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
176 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
177 mant = val; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
178 if (val < 0) { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
179 val = -val; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
180 mant--; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
181 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
182 |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
183 /* compute the log (XXX: optimize) */ |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
184 nbits = 0; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
185 while (val != 0) { |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
186 val = val >> 1; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
187 nbits++; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
188 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
189 code = (run << 4) | nbits; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
190 |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
191 put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
192 |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
193 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
194 run = 0; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
195 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
196 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
197 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
198 /* output EOB only if not already 64 values */ |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
199 if (last_index < 63 || run != 0) |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
200 put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
201 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
202 |
5864 | 203 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
204 { | |
205 int i; | |
206 const int maxlevel= s->max_qcoeff; | |
207 const int minlevel= s->min_qcoeff; | |
208 | |
209 for(i=0; i<=last_index; i++){ | |
7567
85e9956a6727
libavcodec sync; zigzag_direct and block_permute_op replaced by non-globals in MpegEncContext
rik
parents:
7157
diff
changeset
|
210 const int j = s->intra_scantable.permutated[i]; |
5864 | 211 int level = block[j]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
212 |
5864 | 213 if (level>maxlevel) level=maxlevel; |
214 else if(level<minlevel) level=minlevel; | |
215 block[j]= level; | |
216 } | |
217 } | |
218 | |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
219 /* End excessive code duplication **************************************/ |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
220 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
221 /* this function is a reproduction of the one in mjpeg, it includes two |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
222 * changes, it allows for black&white encoding (it skips the U and V |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
223 * macroblocks and it outputs the huffman code for 'no change' (dc) and |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
224 * 'all zero' (ac)) and it takes 4 macroblocks (422) instead of 6 (420) */ |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
225 static void zr_mjpeg_encode_mb(jpeg_enc_t *j) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
226 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
227 MJpegContext *m = j->s->mjpeg_ctx; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
228 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
229 encode_block(j->s, j->s->block[0], 0); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
230 encode_block(j->s, j->s->block[1], 1); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
231 if (j->bw) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
232 /* U */ |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
233 put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
234 m->huff_code_dc_chrominance[0]); |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
235 put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
236 m->huff_code_ac_chrominance[0]); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
237 /* V */ |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
238 put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
239 m->huff_code_dc_chrominance[0]); |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
240 put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
241 m->huff_code_ac_chrominance[0]); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
242 } else { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
243 /* we trick encode_block here so that it uses |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
244 * chrominance huffman tables instead of luminance ones |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
245 * (see the effect of second argument of encode_block) */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
246 encode_block(j->s, j->s->block[2], 4); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
247 encode_block(j->s, j->s->block[3], 5); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
248 } |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
249 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
250 |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
251 /* this function can take all kinds of YUV colorspaces |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
252 * YV12, YVYU, UYVY. The necesary parameters must be set up by the caller |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
253 * y_ps means "y pixel size", y_rs means "y row size". |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
254 * For YUYV, for example, is u_buf = y_buf + 1, v_buf = y_buf + 3, |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
255 * y_ps = 2, u_ps = 4, v_ps = 4, y_rs = u_rs = v_rs. |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
256 * |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
257 * The actual buffers must be passed with mjpeg_encode_frame, this is |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
258 * to make it possible to call encode on the buffer provided by the |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
259 * codec in draw_frame. |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
260 * |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
261 * The data is straightened out at the moment it is put in DCT |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
262 * blocks, there are therefore no spurious memcopies involved */ |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
263 /* Notice that w must be a multiple of 16 and h must be a multiple of 8 */ |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
264 /* We produce YUV422 jpegs, the colors must be subsampled horizontally, |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
265 * if the colors are also subsampled vertically, then this function |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
266 * performs cheap upsampling (better solution will be: a DCT that is |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
267 * optimized in the case that every two rows are the same) */ |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
268 /* cu = 0 means 'No cheap upsampling' |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
269 * cu = 1 means 'perform cheap upsampling' */ |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
270 /* The encoder doesn't know anything about interlacing, the halve height |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
271 * needs to be passed and the double rowstride. Which field gets encoded |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
272 * is decided by what buffers are passed to mjpeg_encode_frame */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
273 jpeg_enc_t *jpeg_enc_init(int w, int h, int y_psize, int y_rsize, |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
274 int u_psize, int u_rsize, int v_psize, int v_rsize, |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
275 int cu, int q, int b) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
276 jpeg_enc_t *j; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
277 int i = 0; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
278 mp_msg(MSGT_VO, MSGL_V, "JPEnc init: %dx%d %d %d %d %d %d %d\n", |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
279 w, h, y_psize, y_rsize, u_psize, |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
280 u_rsize, v_psize, v_rsize); |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
281 |
9186 | 282 j = av_malloc(sizeof(jpeg_enc_t)); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
283 if (j == NULL) return NULL; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
284 |
9186 | 285 j->s = av_malloc(sizeof(MpegEncContext)); |
9976
5843993013a8
fixes to the zr driver (uninit->reinit) by Stephan Bain <sjbain@akamail.com>
rik
parents:
9573
diff
changeset
|
286 memset(j->s,0x00,sizeof(MpegEncContext)); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
287 if (j->s == NULL) { |
9186 | 288 av_free(j); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
289 return NULL; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
290 } |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
291 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
292 /* info on how to access the pixels */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
293 j->y_ps = y_psize; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
294 j->u_ps = u_psize; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
295 j->v_ps = v_psize; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
296 j->y_rs = y_rsize; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
297 j->u_rs = u_rsize; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
298 j->v_rs = v_rsize; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
299 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
300 j->s->width = w; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
301 j->s->height = h; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
302 j->s->qscale = q; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
303 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
304 j->s->out_format = FMT_MJPEG; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
305 j->s->intra_only = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
306 j->s->encoding = 1; |
34646 | 307 j->s->pict_type = AV_PICTURE_TYPE_I; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
308 j->s->y_dc_scale = 8; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
309 j->s->c_dc_scale = 8; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
310 |
23369
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
311 //FIXME j->s->mjpeg_write_tables = 1; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
312 j->s->mjpeg_vsample[0] = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
313 j->s->mjpeg_vsample[1] = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
314 j->s->mjpeg_vsample[2] = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
315 j->s->mjpeg_hsample[0] = 2; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
316 j->s->mjpeg_hsample[1] = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
317 j->s->mjpeg_hsample[2] = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
318 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
319 j->cheap_upsample = cu; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
320 j->bw = b; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
321 |
31960
1ba5eef167aa
Refactor more instances of avcodec_initialized handling into init_avcodec().
diego
parents:
29263
diff
changeset
|
322 init_avcodec(); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
323 |
23369
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
324 if (ff_mjpeg_encode_init(j->s) < 0) { |
9186 | 325 av_free(j->s); |
326 av_free(j); | |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
327 return NULL; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
328 } |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
329 |
7136
122efc309784
fixes a segfault which was introduced in this file by the new ratecontrol code
rik
parents:
6703
diff
changeset
|
330 /* alloc bogus avctx to keep MPV_common_init from segfaulting */ |
122efc309784
fixes a segfault which was introduced in this file by the new ratecontrol code
rik
parents:
6703
diff
changeset
|
331 j->s->avctx = calloc(sizeof(*j->s->avctx), 1); |
19619
a83e5b8d2e63
Patch from Karolina Lindqvist <karolina.lindqvist@kramnet.se>
rik
parents:
15310
diff
changeset
|
332 /* Set up to encode mjpeg */ |
a83e5b8d2e63
Patch from Karolina Lindqvist <karolina.lindqvist@kramnet.se>
rik
parents:
15310
diff
changeset
|
333 j->s->avctx->codec_id = CODEC_ID_MJPEG; |
7136
122efc309784
fixes a segfault which was introduced in this file by the new ratecontrol code
rik
parents:
6703
diff
changeset
|
334 |
11961
487d1638d161
fixing segfault: libavcodec doesn't allocate some buffers if avctx->thread_count == 0
rik
parents:
11926
diff
changeset
|
335 /* make MPV_common_init allocate important buffers, like s->block */ |
487d1638d161
fixing segfault: libavcodec doesn't allocate some buffers if avctx->thread_count == 0
rik
parents:
11926
diff
changeset
|
336 j->s->avctx->thread_count = 1; |
487d1638d161
fixing segfault: libavcodec doesn't allocate some buffers if avctx->thread_count == 0
rik
parents:
11926
diff
changeset
|
337 |
34646 | 338 if (ff_MPV_common_init(j->s) < 0) { |
9186 | 339 av_free(j->s); |
340 av_free(j); | |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
341 return NULL; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
342 } |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
343 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
344 /* correct the value for sc->mb_height */ |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
345 j->s->mb_height = j->s->height/8; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
346 j->s->mb_intra = 1; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
347 |
6703
feeaffcce1fa
adapting to the 'adding fff prefix to avoid global name conflicts' changes in libavcodec
rik
parents:
6328
diff
changeset
|
348 j->s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
349 for (i = 1; i < 64; i++) |
22339 | 350 j->s->intra_matrix[i] = av_clip_uint8( |
7567
85e9956a6727
libavcodec sync; zigzag_direct and block_permute_op replaced by non-globals in MpegEncContext
rik
parents:
7157
diff
changeset
|
351 (ff_mpeg1_default_intra_matrix[i]*j->s->qscale) >> 3); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
352 convert_matrix(j->s, j->s->q_intra_matrix, j->s->q_intra_matrix16, |
11345
97f11e488141
function convert_matrix() is fixed (off-by-one error) and it is now called with the optimal arguments so that it doesn't do unneeded work, the change was inspired by a comment from Alex
rik
parents:
11258
diff
changeset
|
353 j->s->intra_matrix, j->s->intra_quant_bias, 8, 8); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
354 return j; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
355 } |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
356 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
357 int jpeg_enc_frame(jpeg_enc_t *j, unsigned char *y_data, |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
358 unsigned char *u_data, unsigned char *v_data, char *bufr) { |
5864 | 359 int i, k, mb_x, mb_y, overflow; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
360 short int *dest; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
361 unsigned char *source; |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
362 /* initialize the buffer */ |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
363 |
11211 | 364 init_put_bits(&j->s->pb, bufr, 1024*256); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
365 |
23369
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
366 ff_mjpeg_encode_picture_header(j->s); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
367 |
11926 | 368 j->s->header_bits = put_bits_count(&j->s->pb); |
8117
dda027d5a845
libavcodec sync (no LIBAVCODEC_BUILD change; no backwards compatibility)
rik
parents:
7902
diff
changeset
|
369 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
370 j->s->last_dc[0] = 128; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
371 j->s->last_dc[1] = 128; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
372 j->s->last_dc[2] = 128; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
373 |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
374 for (mb_y = 0; mb_y < j->s->mb_height; mb_y++) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
375 for (mb_x = 0; mb_x < j->s->mb_width; mb_x++) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
376 /* conversion 8 to 16 bit and filling of blocks |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
377 * must be mmx optimized */ |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
378 /* fill 2 Y macroblocks and one U and one V */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
379 source = mb_y * 8 * j->y_rs + |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
380 16 * j->y_ps * mb_x + y_data; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
381 dest = j->s->block[0]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
382 for (i = 0; i < 8; i++) { |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
383 for (k = 0; k < 8; k++) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
384 dest[k] = source[k*j->y_ps]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
385 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
386 dest += 8; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
387 source += j->y_rs; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
388 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
389 source = mb_y * 8 * j->y_rs + |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
390 (16*mb_x + 8)*j->y_ps + y_data; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
391 dest = j->s->block[1]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
392 for (i = 0; i < 8; i++) { |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
393 for (k = 0; k < 8; k++) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
394 dest[k] = source[k*j->y_ps]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
395 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
396 dest += 8; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
397 source += j->y_rs; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
398 } |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
399 if (!j->bw && j->cheap_upsample) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
400 source = mb_y*4*j->u_rs + |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
401 8*mb_x*j->u_ps + u_data; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
402 dest = j->s->block[2]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
403 for (i = 0; i < 4; i++) { |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
404 for (k = 0; k < 8; k++) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
405 dest[k] = source[k*j->u_ps]; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
406 dest[k+8] = source[k*j->u_ps]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
407 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
408 dest += 16; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
409 source += j->u_rs; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
410 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
411 source = mb_y*4*j->v_rs + |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
412 8*mb_x*j->v_ps + v_data; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
413 dest = j->s->block[3]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
414 for (i = 0; i < 4; i++) { |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
415 for (k = 0; k < 8; k++) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
416 dest[k] = source[k*j->v_ps]; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
417 dest[k+8] = source[k*j->v_ps]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
418 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
419 dest += 16; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
420 source += j->u_rs; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
421 } |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
422 } else if (!j->bw && !j->cheap_upsample) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
423 source = mb_y*8*j->u_rs + |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
424 8*mb_x*j->u_ps + u_data; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
425 dest = j->s->block[2]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
426 for (i = 0; i < 8; i++) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
427 for (k = 0; k < 8; k++) |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
428 dest[k] = source[k*j->u_ps]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
429 dest += 8; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
430 source += j->u_rs; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
431 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
432 source = mb_y*8*j->v_rs + |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
433 8*mb_x*j->v_ps + v_data; |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
434 dest = j->s->block[3]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
435 for (i = 0; i < 8; i++) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
436 for (k = 0; k < 8; k++) |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
437 dest[k] = source[k*j->v_ps]; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
438 dest += 8; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
439 source += j->u_rs; |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
440 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
441 } |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
442 emms_c(); /* is this really needed? */ |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
443 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
444 j->s->block_last_index[0] = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
445 j->s->dct_quantize(j->s, j->s->block[0], |
5864 | 446 0, 8, &overflow); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
447 if (overflow) clip_coeffs(j->s, j->s->block[0], |
5864 | 448 j->s->block_last_index[0]); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
449 j->s->block_last_index[1] = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
450 j->s->dct_quantize(j->s, j->s->block[1], |
5864 | 451 1, 8, &overflow); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
452 if (overflow) clip_coeffs(j->s, j->s->block[1], |
5864 | 453 j->s->block_last_index[1]); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
454 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
455 if (!j->bw) { |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
456 j->s->block_last_index[4] = |
7157 | 457 j->s->dct_quantize(j->s, j->s->block[2], |
5864 | 458 4, 8, &overflow); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
459 if (overflow) clip_coeffs(j->s, j->s->block[2], |
5864 | 460 j->s->block_last_index[2]); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
461 j->s->block_last_index[5] = |
7157 | 462 j->s->dct_quantize(j->s, j->s->block[3], |
5864 | 463 5, 8, &overflow); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
464 if (overflow) clip_coeffs(j->s, j->s->block[3], |
5864 | 465 j->s->block_last_index[3]); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
466 } |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
467 zr_mjpeg_encode_mb(j); |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
468 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
469 } |
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
470 emms_c(); |
23369
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
471 ff_mjpeg_encode_picture_trailer(j->s); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
472 flush_put_bits(&j->s->pb); |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
473 |
23369
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
474 //FIXME |
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
475 //if (j->s->mjpeg_write_tables == 1) |
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
476 // j->s->mjpeg_write_tables = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29138
diff
changeset
|
477 |
29138
8aeebf532e48
follow renaming of pbBufPtr() to put_bits_ptr() by stefano
rik
parents:
27862
diff
changeset
|
478 return put_bits_ptr(&(j->s->pb)) - j->s->pb.buf; |
4651
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
479 } |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
480 |
49f2bc22f880
mjpeg encoder cleanup - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
4347
diff
changeset
|
481 void jpeg_enc_uninit(jpeg_enc_t *j) { |
23369
700408f4cb51
compilation fix: ff_ _encode added and temporarily disabled mjpeg_write_tables
rik
parents:
22339
diff
changeset
|
482 ff_mjpeg_encode_close(j->s); |
9186 | 483 av_free(j->s); |
484 av_free(j); | |
4347
d036a9992baf
fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
485 } |