Mercurial > mplayer.hg
annotate libmpcodecs/vf_zrmjpeg.c @ 11770:be23eda3175e
10l
author | henry |
---|---|
date | Sat, 10 Jan 2004 13:25:39 +0000 |
parents | 173f22eb0505 |
children | 243767239228 |
rev | line source |
---|---|
11662
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
1 /* |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
2 * Copyright (C) 2003 Rik Snel <snel@phys.uu.nl>, license GPL v2 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
3 * - based on vd_lavc.c by A'rpi (C) 2002-2003 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
4 * - parts from ffmpeg Copyright (c) 2000-2003 Fabrice Bellard |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
5 * |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
6 * This files includes a straightforward (to be) optimized JPEG encoder for |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
7 * the YUV422 format, based on mjpeg code from ffmpeg. |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
8 * |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
9 * For an excellent introduction to the JPEG format, see: |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
10 * http://www.ece.purdue.edu/~bouman/grad-labs/lab8/pdf/lab.pdf |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
11 */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
12 #include <stdio.h> |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
13 #include <stdlib.h> |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
14 #include <string.h> |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
15 #include <inttypes.h> |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
16 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
17 #include "../config.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
18 #include "../mp_msg.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
19 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
20 #include "img_format.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
21 #include "mp_image.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
22 #include "vf.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
23 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
24 #ifdef USE_FASTMEMCPY |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
25 #include "../libvo/fastmemcpy.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
26 #endif |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
27 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
28 /* We need this #define because we need ../libavcodec/common.h to #define |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
29 * be2me_32, otherwise the linker will complain that it doesn't exist */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
30 #define HAVE_AV_CONFIG_H |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
31 #include "../libavcodec/avcodec.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
32 #include "../libavcodec/dsputil.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
33 #include "../libavcodec/mpegvideo.h" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
34 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
35 #undef malloc |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
36 #undef free |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
37 #undef realloc |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
38 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
39 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
40 /* some convenient #define's, is this portable enough? */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
41 #define VERBOSE(...) mp_msg(MSGT_DECVIDEO, MSGL_V, "vf_zrmjpeg: " __VA_ARGS__) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
42 #define ERROR(...) mp_msg(MSGT_DECVIDEO, MSGL_ERR, "vf_zrmjpeg: " __VA_ARGS__) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
43 #define WARNING(...) mp_msg(MSGT_DECVIDEO, MSGL_WARN, \ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
44 "vf_zrmjpeg: " __VA_ARGS__) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
45 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
46 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
47 extern int avcodec_inited; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
48 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
49 /* zrmjpeg_encode_mb needs access to these tables for the black & white |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
50 * option */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
51 typedef struct MJpegContext { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
52 uint8_t huff_size_dc_luminance[12]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
53 uint16_t huff_code_dc_luminance[12]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
54 uint8_t huff_size_dc_chrominance[12]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
55 uint16_t huff_code_dc_chrominance[12]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
56 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
57 uint8_t huff_size_ac_luminance[256]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
58 uint16_t huff_code_ac_luminance[256]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
59 uint8_t huff_size_ac_chrominance[256]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
60 uint16_t huff_code_ac_chrominance[256]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
61 } MJpegContext; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
62 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
63 /* Begin excessive code duplication ************************************/ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
64 /* Code coming from mpegvideo.c and mjpeg.c in ../libavcodec ***********/ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
65 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
66 static const unsigned short aanscales[64] = { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
67 /* precomputed values scaled up by 14 bits */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
68 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
69 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
70 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
71 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
72 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
73 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
74 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
75 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
76 }; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
77 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
78 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
79 uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
80 int bias, int qmin, int qmax) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
81 int qscale; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
82 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
83 for(qscale = qmin; qscale <= qmax; qscale++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
84 int i; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
85 if (s->dsp.fdct == ff_jpeg_fdct_islow) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
86 for (i = 0; i < 64; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
87 const int j = s->dsp.idct_permutation[i]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
88 /* 16 <= qscale * quant_matrix[i] <= 7905 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
89 * 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
90 * (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
91 * >= (1<<36)/249205026 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
92 * 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
93 qmat[qscale][i] = (int)((UINT64_C(1) << |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
94 (QMAT_SHIFT-3))/ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
95 (qscale*quant_matrix[j])); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
96 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
97 } else if (s->dsp.fdct == fdct_ifast) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
98 for (i = 0; i < 64; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
99 const int j = s->dsp.idct_permutation[i]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
100 /* 16 <= qscale * quant_matrix[i] <= 7905 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
101 * 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
102 * (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
103 * >= (1<<36)/249205026 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
104 * 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
105 qmat[qscale][i] = (int)((UINT64_C(1) << |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
106 (QMAT_SHIFT + 11))/(aanscales[i] |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
107 *qscale * quant_matrix[j])); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
108 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
109 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
110 for (i = 0; i < 64; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
111 const int j = s->dsp.idct_permutation[i]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
112 /* We can safely assume that 16 <= quant_matrix[i] <= 255 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
113 * So 16 <= qscale * quant_matrix[i] <= 7905 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
114 * so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
115 * so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
116 qmat[qscale][i] = (int)((uint64_t_C(1) << |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
117 QMAT_SHIFT_MMX) / (qscale |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
118 *quant_matrix[j])); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
119 qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
120 /(qscale * quant_matrix[j]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
121 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
122 if (qmat16[qscale][0][i] == 0 || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
123 qmat16[qscale][0][i] == 128*256) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
124 qmat16[qscale][0][i]=128*256-1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
125 qmat16[qscale][1][i]=ROUNDED_DIV(bias |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
126 <<(16-QUANT_BIAS_SHIFT), |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
127 qmat16[qscale][0][i]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
128 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
129 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
130 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
131 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
132 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
133 static inline void encode_dc(MpegEncContext *s, int val, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
134 uint8_t *huff_size, uint16_t *huff_code) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
135 int mant, nbits; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
136 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
137 if (val == 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
138 put_bits(&s->pb, huff_size[0], huff_code[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
139 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
140 mant = val; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
141 if (val < 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
142 val = -val; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
143 mant--; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
144 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
145 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
146 /* compute the log (XXX: optimize) */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
147 nbits = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
148 while (val != 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
149 val = val >> 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
150 nbits++; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
151 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
152 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
153 put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
154 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
155 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
156 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
157 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
158 static void encode_block(MpegEncContext *s, DCTELEM *block, int n) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
159 int mant, nbits, code, i, j; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
160 int component, dc, run, last_index, val; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
161 MJpegContext *m = s->mjpeg_ctx; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
162 uint8_t *huff_size_ac; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
163 uint16_t *huff_code_ac; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
164 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
165 /* DC coef */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
166 component = (n <= 3 ? 0 : n - 4 + 1); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
167 dc = block[0]; /* overflow is impossible */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
168 val = dc - s->last_dc[component]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
169 if (n < 4) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
170 encode_dc(s, val, m->huff_size_dc_luminance, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
171 m->huff_code_dc_luminance); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
172 huff_size_ac = m->huff_size_ac_luminance; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
173 huff_code_ac = m->huff_code_ac_luminance; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
174 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
175 encode_dc(s, val, m->huff_size_dc_chrominance, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
176 m->huff_code_dc_chrominance); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
177 huff_size_ac = m->huff_size_ac_chrominance; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
178 huff_code_ac = m->huff_code_ac_chrominance; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
179 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
180 s->last_dc[component] = dc; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
181 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
182 /* AC coefs */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
183 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
184 run = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
185 last_index = s->block_last_index[n]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
186 for (i = 1; i <= last_index; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
187 j = s->intra_scantable.permutated[i]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
188 val = block[j]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
189 if (val == 0) run++; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
190 else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
191 while (run >= 16) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
192 put_bits(&s->pb, huff_size_ac[0xf0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
193 huff_code_ac[0xf0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
194 run -= 16; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
195 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
196 mant = val; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
197 if (val < 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
198 val = -val; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
199 mant--; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
200 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
201 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
202 /* compute the log (XXX: optimize) */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
203 nbits = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
204 while (val != 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
205 val = val >> 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
206 nbits++; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
207 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
208 code = (run << 4) | nbits; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
209 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
210 put_bits(&s->pb, huff_size_ac[code], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
211 huff_code_ac[code]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
212 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
213 run = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
214 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
215 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
216 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
217 /* output EOB only if not already 64 values */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
218 if (last_index < 63 || run != 0) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
219 put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
220 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
221 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
222 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
223 int last_index) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
224 int i; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
225 const int maxlevel= s->max_qcoeff; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
226 const int minlevel= s->min_qcoeff; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
227 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
228 for (i = 0; i <= last_index; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
229 const int j = s->intra_scantable.permutated[i]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
230 int level = block[j]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
231 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
232 if (level > maxlevel) level=maxlevel; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
233 else if(level < minlevel) level=minlevel; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
234 block[j]= level; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
235 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
236 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
237 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
238 /* End excessive code duplication **************************************/ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
239 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
240 typedef struct { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
241 struct MpegEncContext *s; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
242 int cheap_upsample; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
243 int bw; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
244 int y_ps; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
245 int u_ps; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
246 int v_ps; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
247 int y_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
248 int u_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
249 int v_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
250 } jpeg_enc_t; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
251 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
252 /* this function is a reproduction of the one in mjpeg, it includes two |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
253 * changes, it allows for black&white encoding (it skips the U and V |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
254 * macroblocks and it outputs the huffman code for 'no change' (dc) and |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
255 * 'all zero' (ac)) and it takes 4 macroblocks (422) instead of 6 (420) */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
256 static void zr_mjpeg_encode_mb(jpeg_enc_t *j) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
257 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
258 MJpegContext *m = j->s->mjpeg_ctx; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
259 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
260 encode_block(j->s, j->s->block[0], 0); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
261 encode_block(j->s, j->s->block[1], 1); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
262 if (j->bw) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
263 /* U */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
264 put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
265 m->huff_code_dc_chrominance[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
266 put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
267 m->huff_code_ac_chrominance[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
268 /* V */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
269 put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
270 m->huff_code_dc_chrominance[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
271 put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
272 m->huff_code_ac_chrominance[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
273 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
274 /* we trick encode_block here so that it uses |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
275 * chrominance huffman tables instead of luminance ones |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
276 * (see the effect of second argument of encode_block) */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
277 encode_block(j->s, j->s->block[2], 4); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
278 encode_block(j->s, j->s->block[3], 5); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
279 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
280 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
281 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
282 /* this function can take all kinds of YUV colorspaces |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
283 * YV12, YVYU, UYVY. The necesary parameters must be set up by the caller |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
284 * y_ps means "y pixel size", y_rs means "y row size". |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
285 * For YUYV, for example, is u_buf = y_buf + 1, v_buf = y_buf + 3, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
286 * y_ps = 2, u_ps = 4, v_ps = 4, y_rs = u_rs = v_rs. |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
287 * |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
288 * The actual buffers must be passed with mjpeg_encode_frame, this is |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
289 * to make it possible to call encode on the buffer provided by the |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
290 * codec in draw_frame. |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
291 * |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
292 * The data is straightened out at the moment it is put in DCT |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
293 * blocks, there are therefore no spurious memcopies involved */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
294 /* Notice that w must be a multiple of 16 and h must be a multiple of 8 */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
295 /* We produce YUV422 jpegs, the colors must be subsampled horizontally, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
296 * if the colors are also subsampled vertically, then this function |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
297 * performs cheap upsampling (better solution will be: a DCT that is |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
298 * optimized in the case that every two rows are the same) */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
299 /* cu = 0 means 'No cheap upsampling' |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
300 * cu = 1 means 'perform cheap upsampling' */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
301 /* The encoder doesn't know anything about interlacing, the halve height |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
302 * needs to be passed and the double rowstride. Which field gets encoded |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
303 * is decided by what buffers are passed to mjpeg_encode_frame */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
304 static jpeg_enc_t *jpeg_enc_init(int w, int h, int y_psize, int y_rsize, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
305 int u_psize, int u_rsize, int v_psize, int v_rsize, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
306 int cu, int q, int b) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
307 jpeg_enc_t *j; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
308 int i = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
309 VERBOSE("JPEG encoder init: %dx%d %d %d %d %d %d %d\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
310 w, h, y_psize, y_rsize, u_psize, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
311 u_rsize, v_psize, v_rsize); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
312 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
313 j = malloc(sizeof(jpeg_enc_t)); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
314 if (j == NULL) return NULL; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
315 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
316 j->s = malloc(sizeof(MpegEncContext)); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
317 memset(j->s,0x00,sizeof(MpegEncContext)); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
318 if (j->s == NULL) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
319 free(j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
320 return NULL; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
321 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
322 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
323 /* info on how to access the pixels */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
324 j->y_ps = y_psize; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
325 j->u_ps = u_psize; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
326 j->v_ps = v_psize; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
327 j->y_rs = y_rsize; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
328 j->u_rs = u_rsize; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
329 j->v_rs = v_rsize; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
330 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
331 j->s->width = w; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
332 j->s->height = h; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
333 j->s->qscale = q; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
334 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
335 j->s->mjpeg_data_only_frames = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
336 j->s->out_format = FMT_MJPEG; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
337 j->s->intra_only = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
338 j->s->encoding = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
339 j->s->pict_type = I_TYPE; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
340 j->s->y_dc_scale = 8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
341 j->s->c_dc_scale = 8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
342 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
343 j->s->mjpeg_write_tables = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
344 j->s->mjpeg_vsample[0] = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
345 j->s->mjpeg_vsample[1] = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
346 j->s->mjpeg_vsample[2] = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
347 j->s->mjpeg_hsample[0] = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
348 j->s->mjpeg_hsample[1] = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
349 j->s->mjpeg_hsample[2] = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
350 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
351 j->cheap_upsample = cu; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
352 j->bw = b; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
353 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
354 if (mjpeg_init(j->s) < 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
355 free(j->s); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
356 free(j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
357 return NULL; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
358 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
359 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
360 /* alloc bogus avctx to keep MPV_common_init from segfaulting */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
361 j->s->avctx = calloc(sizeof(*j->s->avctx), 1); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
362 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
363 if (MPV_common_init(j->s) < 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
364 free(j->s); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
365 free(j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
366 return NULL; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
367 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
368 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
369 /* correct the value for sc->mb_height */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
370 j->s->mb_height = j->s->height/8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
371 j->s->mb_intra = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
372 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
373 j->s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
374 for (i = 1; i < 64; i++) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
375 j->s->intra_matrix[i] = CLAMP_TO_8BIT( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
376 (ff_mpeg1_default_intra_matrix[i]*j->s->qscale) >> 3); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
377 convert_matrix(j->s, j->s->q_intra_matrix, j->s->q_intra_matrix16, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
378 j->s->intra_matrix, j->s->intra_quant_bias, 8, 8); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
379 return j; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
380 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
381 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
382 static int jpeg_enc_frame(jpeg_enc_t *j, unsigned char *y_data, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
383 unsigned char *u_data, unsigned char *v_data, char *bufr) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
384 int i, k, mb_x, mb_y, overflow; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
385 short int *dest; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
386 unsigned char *source; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
387 /* initialize the buffer */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
388 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
389 init_put_bits(&j->s->pb, bufr, 1024*256); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
390 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
391 mjpeg_picture_header(j->s); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
392 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
393 j->s->header_bits = get_bit_count(&j->s->pb); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
394 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
395 j->s->last_dc[0] = 128; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
396 j->s->last_dc[1] = 128; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
397 j->s->last_dc[2] = 128; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
398 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
399 for (mb_y = 0; mb_y < j->s->mb_height; mb_y++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
400 for (mb_x = 0; mb_x < j->s->mb_width; mb_x++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
401 /* conversion 8 to 16 bit and filling of blocks |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
402 * must be mmx optimized */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
403 /* fill 2 Y macroblocks and one U and one V */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
404 source = mb_y * 8 * j->y_rs + |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
405 16 * j->y_ps * mb_x + y_data; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
406 dest = j->s->block[0]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
407 for (i = 0; i < 8; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
408 for (k = 0; k < 8; k++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
409 dest[k] = source[k*j->y_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
410 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
411 dest += 8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
412 source += j->y_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
413 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
414 source = mb_y * 8 * j->y_rs + |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
415 (16*mb_x + 8)*j->y_ps + y_data; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
416 dest = j->s->block[1]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
417 for (i = 0; i < 8; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
418 for (k = 0; k < 8; k++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
419 dest[k] = source[k*j->y_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
420 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
421 dest += 8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
422 source += j->y_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
423 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
424 if (!j->bw && j->cheap_upsample) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
425 source = mb_y*4*j->u_rs + |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
426 8*mb_x*j->u_ps + u_data; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
427 dest = j->s->block[2]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
428 for (i = 0; i < 4; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
429 for (k = 0; k < 8; k++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
430 dest[k] = source[k*j->u_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
431 dest[k+8] = source[k*j->u_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
432 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
433 dest += 16; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
434 source += j->u_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
435 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
436 source = mb_y*4*j->v_rs + |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
437 8*mb_x*j->v_ps + v_data; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
438 dest = j->s->block[3]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
439 for (i = 0; i < 4; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
440 for (k = 0; k < 8; k++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
441 dest[k] = source[k*j->v_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
442 dest[k+8] = source[k*j->v_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
443 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
444 dest += 16; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
445 source += j->u_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
446 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
447 } else if (!j->bw && !j->cheap_upsample) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
448 source = mb_y*8*j->u_rs + |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
449 8*mb_x*j->u_ps + u_data; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
450 dest = j->s->block[2]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
451 for (i = 0; i < 8; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
452 for (k = 0; k < 8; k++) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
453 dest[k] = source[k*j->u_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
454 dest += 8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
455 source += j->u_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
456 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
457 source = mb_y*8*j->v_rs + |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
458 8*mb_x*j->v_ps + v_data; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
459 dest = j->s->block[3]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
460 for (i = 0; i < 8; i++) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
461 for (k = 0; k < 8; k++) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
462 dest[k] = source[k*j->v_ps]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
463 dest += 8; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
464 source += j->u_rs; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
465 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
466 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
467 emms_c(); /* is this really needed? */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
468 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
469 j->s->block_last_index[0] = |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
470 j->s->dct_quantize(j->s, j->s->block[0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
471 0, 8, &overflow); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
472 if (overflow) clip_coeffs(j->s, j->s->block[0], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
473 j->s->block_last_index[0]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
474 j->s->block_last_index[1] = |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
475 j->s->dct_quantize(j->s, j->s->block[1], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
476 1, 8, &overflow); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
477 if (overflow) clip_coeffs(j->s, j->s->block[1], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
478 j->s->block_last_index[1]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
479 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
480 if (!j->bw) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
481 j->s->block_last_index[4] = |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
482 j->s->dct_quantize(j->s, j->s->block[2], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
483 4, 8, &overflow); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
484 if (overflow) clip_coeffs(j->s, j->s->block[2], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
485 j->s->block_last_index[2]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
486 j->s->block_last_index[5] = |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
487 j->s->dct_quantize(j->s, j->s->block[3], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
488 5, 8, &overflow); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
489 if (overflow) clip_coeffs(j->s, j->s->block[3], |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
490 j->s->block_last_index[3]); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
491 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
492 zr_mjpeg_encode_mb(j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
493 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
494 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
495 emms_c(); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
496 mjpeg_picture_trailer(j->s); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
497 flush_put_bits(&j->s->pb); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
498 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
499 if (j->s->mjpeg_write_tables == 1) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
500 j->s->mjpeg_write_tables = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
501 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
502 return pbBufPtr(&(j->s->pb)) - j->s->pb.buf; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
503 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
504 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
505 static void jpeg_enc_uninit(jpeg_enc_t *j) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
506 mjpeg_close(j->s); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
507 free(j->s); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
508 free(j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
509 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
510 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
511 struct vf_priv_s { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
512 jpeg_enc_t *j; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
513 unsigned char buf[256*1024]; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
514 int bw, fd, hdec, vdec; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
515 int fields; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
516 int y_stride; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
517 int c_stride; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
518 int quality; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
519 int maxwidth; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
520 int maxheight; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
521 }; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
522 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
523 static int config(struct vf_instance_s* vf, int width, int height, int d_width, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
524 int d_height, unsigned int flags, unsigned int outfmt){ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
525 struct vf_priv_s *priv = vf->priv; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
526 float aspect_decision; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
527 int stretchx, stretchy, err = 0, maxstretchx = 4; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
528 priv->fields = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
529 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
530 VERBOSE("config() called\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
531 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
532 if (priv->j) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
533 VERBOSE("re-configuring, resetting JPEG encoder\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
534 jpeg_enc_uninit(priv->j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
535 priv->j = NULL; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
536 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
537 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
538 aspect_decision = ((float)d_width/(float)d_height)/ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
539 ((float)width/(float)height); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
540 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
541 if (aspect_decision > 1.8 && aspect_decision < 2.2) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
542 VERBOSE("should correct aspect by stretching x times 2, %d %d\n", 2*width, priv->maxwidth); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
543 if (2*width <= priv->maxwidth) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
544 d_width = 2*width; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
545 d_height = height; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
546 maxstretchx = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
547 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
548 WARNING("unable to correct aspect by stretching, because resulting X will be too large, aspect correction by decimating y not yet implemented\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
549 d_width = width; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
550 d_height = height; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
551 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
552 /* prestretch movie */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
553 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
554 /* uncorrecting output for now */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
555 d_width = width; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
556 d_height = height; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
557 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
558 /* make the scaling decision |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
559 * we are capable of stretching the image in the horizontal |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
560 * direction by factors 1, 2 and 4 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
561 * we can stretch the image in the vertical direction by a |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
562 * factor of 1 and 2 AND we must decide about interlacing */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
563 if (d_width > priv->maxwidth/2 || height > priv->maxheight/2 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
564 || maxstretchx == 1) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
565 stretchx = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
566 stretchy = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
567 priv->fields = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
568 if (priv->vdec == 2) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
569 priv->fields = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
570 } else if (priv->vdec == 4) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
571 priv->fields = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
572 stretchy = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
573 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
574 if (priv->hdec > maxstretchx) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
575 if (priv->fd) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
576 WARNING("horizontal decimation too high, changing to %d (use fd to keep hdec=%d)\n", maxstretchx, priv->hdec); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
577 priv->hdec = maxstretchx; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
578 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
579 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
580 stretchx = priv->hdec; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
581 } else if (d_width > priv->maxwidth/4 || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
582 height > priv->maxheight/4 || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
583 maxstretchx == 2) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
584 stretchx = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
585 stretchy = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
586 priv->fields = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
587 if (priv->vdec == 2) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
588 stretchy = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
589 } else if (priv->vdec == 4) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
590 if (!priv->fd) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
591 WARNING("vertical decimation too high, changing to 2 (use fd to keep vdec=4)\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
592 priv->vdec = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
593 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
594 stretchy = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
595 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
596 if (priv->hdec == 2) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
597 stretchx = 4; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
598 } else if (priv->hdec == 4) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
599 if (priv->fd) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
600 WARNING("horizontal decimation too high, changing to 2 (use fd to keep hdec=4)\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
601 priv->hdec = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
602 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
603 stretchx = 4; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
604 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
605 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
606 /* output image is maximally stretched */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
607 stretchx = 4; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
608 stretchy = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
609 priv->fields = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
610 if (priv->vdec != 1 && !priv->fd) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
611 WARNING("vertical decimation too high, changing to 1 (use fd to keep vdec=%d)\n", priv->vdec); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
612 priv->vdec = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
613 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
614 if (priv->hdec != 1 && !priv->fd) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
615 WARNING("horizontal decimation too high, changing to 1 (use fd to keep hdec=%d)\n", priv->hdec); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
616 priv->hdec = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
617 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
618 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
619 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
620 VERBOSE("generated JPEG's %dx%s%d%s, stretched to %dx%d\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
621 width/priv->hdec, (priv->fields == 2) ? "(" : "", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
622 height/(priv->vdec*priv->fields), |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
623 (priv->fields == 2) ? "x2)" : "", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
624 (width/priv->hdec)*stretchx, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
625 (height/(priv->vdec*priv->fields))* |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
626 stretchy*priv->fields); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
627 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
628 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
629 if ((width/priv->hdec)*stretchx > priv->maxwidth || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
630 (height/(priv->vdec*priv->fields))* |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
631 stretchy*priv->fields > priv->maxheight) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
632 ERROR("output dimensions too large (%dx%d), max (%dx%d) insert crop to fix\n", (width/priv->hdec)*stretchx, (height/(priv->vdec*priv->fields))*stretchy*priv->fields, priv->maxwidth, priv->maxheight); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
633 err = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
634 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
635 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
636 if (width%(16*priv->hdec) != 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
637 ERROR("width must be a multiple of 16*hdec (%d), use expand\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
638 priv->hdec*16); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
639 err = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
640 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
641 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
642 if (height%(8*priv->fields*priv->vdec) != 0) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
643 ERROR("height must be a multiple of 8*fields*vdec (%d)," |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
644 " use expand\n", priv->vdec*priv->fields*8); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
645 err = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
646 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
647 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
648 if (err) return 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
649 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
650 priv->y_stride = width; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
651 priv->c_stride = width/2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
652 priv->j = jpeg_enc_init(width, height/priv->fields, 1, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
653 priv->fields*priv->y_stride, 1, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
654 priv->fields*priv->c_stride, 1, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
655 priv->fields*priv->c_stride, 1, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
656 priv->quality, priv->bw); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
657 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
658 if (!priv->j) return 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
659 return vf_next_config(vf, width, height, d_width, d_height, flags, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
660 (priv->fields == 2) ? IMGFMT_ZRMJPEGIT : IMGFMT_ZRMJPEGNI); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
661 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
662 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
663 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
664 struct vf_priv_s *priv = vf->priv; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
665 int size = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
666 int i; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
667 mp_image_t* dmpi; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
668 for (i = 0; i < priv->fields; i++) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
669 size += jpeg_enc_frame(priv->j, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
670 mpi->planes[0] + i*priv->y_stride, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
671 mpi->planes[1] + i*priv->c_stride, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
672 mpi->planes[2] + i*priv->c_stride, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
673 priv->buf + size); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
674 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
675 dmpi = vf_get_image(vf->next, IMGFMT_ZRMJPEGNI, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
676 MP_IMGTYPE_EXPORT, 0, mpi->w, mpi->h); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
677 dmpi->planes[0] = (uint8_t*)priv->buf; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
678 dmpi->planes[1] = (uint8_t*)size; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
679 return vf_next_put_image(vf,dmpi); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
680 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
681 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
682 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
683 VERBOSE("query_format() called\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
684 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
685 switch (fmt) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
686 case IMGFMT_YV12: |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
687 case IMGFMT_YUY2: |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
688 /* strictly speaking the output format of |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
689 * this filter will be known after config(), |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
690 * but everything that supports IMGFMT_ZRMJPEGNI |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
691 * should also support all other IMGFMT_ZRMJPEG* */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
692 return vf_next_query_format(vf, IMGFMT_ZRMJPEGNI); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
693 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
694 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
695 return 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
696 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
697 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
698 static void uninit(vf_instance_t *vf) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
699 struct vf_priv_s *priv = vf->priv; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
700 VERBOSE("uninit() called\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
701 if (priv->j) jpeg_enc_uninit(priv->j); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
702 free(priv); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
703 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
704 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
705 static int open(vf_instance_t *vf, char* args){ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
706 struct vf_priv_s *priv; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
707 VERBOSE("open() called: args=\"%s\"\n", args); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
708 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
709 vf->config = config; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
710 vf->put_image = put_image; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
711 vf->query_format = query_format; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
712 vf->uninit = uninit; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
713 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
714 priv = vf->priv = calloc(sizeof(*priv), 1); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
715 if (!vf->priv) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
716 ERROR("out of memory error\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
717 return 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
718 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
719 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
720 /* maximum displayable size by zoran card, these defaults |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
721 * are for my own zoran card in PAL mode, these can be changed |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
722 * by filter options. But... in an ideal world these values would |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
723 * be queried from the vo device itself... */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
724 priv->maxwidth = 768; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
725 priv->maxheight = 576; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
726 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
727 priv->quality = 2; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
728 priv->hdec = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
729 priv->vdec = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
730 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
731 /* if libavcodec is already initialized, we must not initialize it |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
732 * again, but if it is not initialized then we mustinitialize it now. */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
733 if (!avcodec_inited) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
734 /* we need to initialize libavcodec */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
735 avcodec_init(); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
736 avcodec_register_all(); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
737 avcodec_inited=1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
738 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
739 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
740 if (args) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
741 char *arg, *tmp, *ptr, junk; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
742 int last = 0, input; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
743 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
744 /* save arguments, to be able to safely modify them */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
745 arg = strdup(args); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
746 if (!arg) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
747 ERROR("out of memory, this is bad\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
748 return 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
749 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
750 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
751 tmp = ptr = arg; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
752 do { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
753 while (*tmp != ':' && *tmp) tmp++; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
754 if (*tmp == ':') *tmp++ = '\0'; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
755 else last = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
756 VERBOSE("processing filter option \"%s\"\n", ptr); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
757 /* These options deal with the maximum output |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
758 * resolution of the zoran card. These should |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
759 * be queried from the vo device, but it is currently |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
760 * too difficult, so the user should tell the filter */ |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
761 if (!strncmp("maxheight=", ptr, 10)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
762 if (sscanf(ptr+10, "%d%c", &input, &junk) != 1) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
763 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
764 "error parsing parameter to \"maxheight=\", \"%s\", ignoring\n" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
765 , ptr + 10); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
766 else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
767 priv->maxheight = input; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
768 VERBOSE("setting maxheight to %d\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
769 priv->maxheight); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
770 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
771 } else if (!strncmp("quality=", ptr, 8)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
772 if (sscanf(ptr+8, "%d%c", &input, &junk) != 1) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
773 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
774 "error parsing parameter to \"quality=\", \"%s\", ignoring\n" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
775 , ptr + 8); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
776 else if (input < 1 || input > 20) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
777 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
778 "parameter to \"quality=\" out of range (1..20), %d\n", input); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
779 else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
780 priv->quality = input; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
781 VERBOSE("setting JPEG quality to %d\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
782 priv->quality); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
783 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
784 } else if (!strncmp("maxwidth=", ptr, 9)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
785 if (sscanf(ptr+9, "%d%c", &input, &junk) != 1) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
786 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
787 "error parsing parameter to \"maxwidth=\", \"%s\", ignoring\n" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
788 , ptr + 9); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
789 else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
790 priv->maxwidth = input; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
791 VERBOSE("setting maxwidth to %d\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
792 priv->maxwidth); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
793 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
794 } else if (!strncmp("hdec=", ptr, 5)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
795 if (sscanf(ptr+5, "%d%c", &input, &junk) != 1) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
796 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
797 "error parsing parameter to \"hdec=\", \"%s\", ignoring\n" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
798 , ptr + 9); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
799 else if (input != 1 && input != 2 && input != 4) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
800 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
801 "illegal parameter to \"hdec=\", %d, should be 1, 2 or 4", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
802 input); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
803 else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
804 priv->hdec = input; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
805 VERBOSE( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
806 "setting horizontal decimation to %d\n", priv->maxwidth); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
807 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
808 } else if (!strncmp("vdec=", ptr, 5)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
809 if (sscanf(ptr+5, "%d%c", &input, &junk) != 1) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
810 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
811 "error parsing parameter to \"vdec=\", \"%s\", ignoring\n" |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
812 , ptr + 9); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
813 else if (input != 1 && input != 2 && input != 4) |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
814 ERROR( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
815 "illegal parameter to \"vdec=\", %d, should be 1, 2 or 4", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
816 input); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
817 else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
818 priv->vdec = input; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
819 VERBOSE( |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
820 "setting vertical decimation to %d\n", priv->maxwidth); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
821 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
822 } else if (!strcasecmp("dc10+-PAL", ptr) || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
823 !strcasecmp("dc10-PAL", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
824 priv->maxwidth = 768; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
825 priv->maxheight = 576; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
826 VERBOSE("setting DC10(+) PAL profile\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
827 } else if (!strcasecmp("fd", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
828 priv->fd = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
829 VERBOSE("forcing decimation\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
830 } else if (!strcasecmp("nofd", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
831 priv->fd = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
832 VERBOSE("decimate only if beautiful\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
833 } else if (!strcasecmp("bw", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
834 priv->bw = 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
835 VERBOSE("setting black and white encoding\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
836 } else if (!strcasecmp("color", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
837 priv->bw = 0; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
838 VERBOSE("setting color encoding\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
839 } else if (!strcasecmp("dc10+-NTSC", ptr) || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
840 !strcasecmp("dc10-NTSC", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
841 priv->maxwidth = 640; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
842 priv->maxheight = 480; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
843 VERBOSE("setting DC10(+) NTSC profile\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
844 } else if (!strcasecmp("buz-PAL", ptr) || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
845 !strcasecmp("lml33-PAL", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
846 priv->maxwidth = 720; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
847 priv->maxheight = 576; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
848 VERBOSE("setting buz/lml33 PAL profile\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
849 } else if (!strcasecmp("buz-NTSC", ptr) || |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
850 !strcasecmp("lml33-NTSC", ptr)) { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
851 priv->maxwidth = 720; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
852 priv->maxheight = 480; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
853 VERBOSE("setting buz/lml33 NTSC profile\n"); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
854 } else { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
855 WARNING("ignoring unknown filter option " |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
856 "\"%s\", or missing argument\n", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
857 ptr); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
858 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
859 ptr = tmp; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
860 } while (!last); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
861 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
862 free(arg); |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
863 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
864 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
865 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
866 return 1; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
867 } |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
868 |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
869 vf_info_t vf_info_zrmjpeg = { |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
870 "realtime zoran MJPEG encoding", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
871 "zrmjpeg", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
872 "Rik Snel", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
873 "", |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
874 open, |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
875 NULL |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
876 }; |
173f22eb0505
vf_zrmjpeg MJPEG encoding filter, works together with vo_zr2. Only YV12
rik
parents:
diff
changeset
|
877 |