annotate libvo/jpeg_enc.c @ 4623:513f4e2a2153

unscaled BGR24 -> YV12
author michael
date Sun, 10 Feb 2002 00:43:31 +0000
parents d036a9992baf
children 49f2bc22f880
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4347
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
1 /* Straightforward (to be) optimized JPEG encoder for the YUV422 format
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
2 * based on mjpeg code from ffmpeg.
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
3 *
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
4 * Copyright (c) 2002, Rik Snel
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
5 * Parts from ffmpeg Copyright (c) 2000, 2001 Gerard Lantau
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
6 *
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
10 * (at your option) any later version.
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
11 *
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
15 * GNU General Public License for more details.
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
16 *
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
20 *
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
21 * For an excellent introduction to the JPEG format, see:
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
22 * http://www.ece.purdue.edu/~bourman/grad-labs/lab8/pdf/lab.pdf
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
23 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
24
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
25
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
26 /* stuff from libavcodec/common.h */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
27
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
28 #include <sys/types.h>
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
29 #include <stdio.h>
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
30 #include <stdlib.h>
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
31 #include "config.h"
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
32 #ifdef USE_FASTMEMCPY
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
33 #include "fastmemcpy.h"
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
34 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
35 #include "../mp_msg.h"
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
36 #include "../libavcodec/common.h"
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
37 #include "../libavcodec/dsputil.h"
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
38
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
39
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
40 static int height, width, fields, cheap_upsample, qscale, bw = 0, first = 1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
41
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
42 /* from dsputils.c */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
43
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
44 static DCTELEM **blck;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
45
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
46 extern void (*av_fdct)(DCTELEM *b);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
47
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
48 static UINT8 zr_zigzag_direct[64] = {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
49 0, 1, 8, 16, 9, 2, 3, 10,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
50 17, 24, 32, 25, 18, 11, 4, 5,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
51 12, 19, 26, 33, 40, 48, 41, 34,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
52 27, 20, 13, 6, 7, 14, 21, 28,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
53 35, 42, 49, 56, 57, 50, 43, 36,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
54 29, 22, 15, 23, 30, 37, 44, 51,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
55 58, 59, 52, 45, 38, 31, 39, 46,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
56 53, 60, 61, 54, 47, 55, 62, 63
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
57 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
58
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
59 /* bit output */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
60
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
61 static PutBitContext pb;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
62
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
63 /* from mpegvideo.c */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
64
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
65 #define QMAT_SHIFT 25
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
66 #define QMAT_SHIFT_MMX 19
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
67
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
68 static const unsigned short aanscales[64] = {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
69 /* precomputed values scaled up by 14 bits */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
70 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
71 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
72 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
73 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
74 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
75 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
76 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
77 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
78 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
79
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
80
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
81 static unsigned int simple_mmx_permutation[64]={
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
82 0x00, 0x08, 0x01, 0x09, 0x04, 0x0C, 0x05, 0x0D,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
83 0x10, 0x18, 0x11, 0x19, 0x14, 0x1C, 0x15, 0x1D,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
84 0x02, 0x0A, 0x03, 0x0B, 0x06, 0x0E, 0x07, 0x0F,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
85 0x12, 0x1A, 0x13, 0x1B, 0x16, 0x1E, 0x17, 0x1F,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
86 0x20, 0x28, 0x21, 0x29, 0x24, 0x2C, 0x25, 0x2D,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
87 0x30, 0x38, 0x31, 0x39, 0x34, 0x3C, 0x35, 0x3D,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
88 0x22, 0x2A, 0x23, 0x2B, 0x26, 0x2E, 0x27, 0x2F,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
89 0x32, 0x3A, 0x33, 0x3B, 0x36, 0x3E, 0x37, 0x3F,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
90 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
91
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
92 #if 0
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
93 void block_permute(short int *block)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
94 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
95 int tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
96 int i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
97
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
98 for(i=0;i<8;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
99 tmp1 = block[1];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
100 tmp2 = block[2];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
101 tmp3 = block[3];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
102 tmp4 = block[4];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
103 tmp5 = block[5];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
104 tmp6 = block[6];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
105 block[1] = tmp2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
106 block[2] = tmp4;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
107 block[3] = tmp6;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
108 block[4] = tmp1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
109 block[5] = tmp3;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
110 block[6] = tmp5;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
111 block += 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
112 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
113 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
114 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
115
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
116 static int q_intra_matrix[64];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
117
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
118 static int dct_quantize(DCTELEM *block, int n,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
119 int qscale)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
120 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
121 int i, j, level, last_non_zero, q;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
122 const int *qmat;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
123
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
124 av_fdct (block);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
125
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
126 /* we need this permutation so that we correct the IDCT
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
127 permutation. will be moved into DCT code */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
128 //block_permute(block);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
129
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
130 /*if (n < 4)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
131 q = s->y_dc_scale;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
132 else
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
133 q = s->c_dc_scale;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
134 q = q << 3;*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
135 q = 64;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
136 /* note: block[0] is assumed to be positive */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
137 block[0] = (block[0] + (q >> 1)) / q;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
138 i = 1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
139 last_non_zero = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
140
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
141 qmat = q_intra_matrix;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
142 for(;i<64;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
143 j = zr_zigzag_direct[i];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
144 level = block[j];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
145 level = level * qmat[j];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
146 /* XXX: slight error for the low range. Test should be equivalent to
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
147 (level <= -(1 << (QMAT_SHIFT - 3)) || level >= (1 <<
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
148 (QMAT_SHIFT - 3)))
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
149 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
150 if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) !=
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
151 level) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
152 level = level / (1 << (QMAT_SHIFT - 3));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
153 /* XXX: currently, this code is not optimal. the range should be:
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
154 mpeg1: -255..255
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
155 mpeg2: -2048..2047
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
156 h263: -128..127
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
157 mpeg4: -2048..2047
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
158 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
159 if (level > 255)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
160 level = 255;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
161 else if (level < -255)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
162 level = -255;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
163 block[j] = level;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
164 last_non_zero = i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
165 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
166 block[j] = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
167 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
168
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
169 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
170 return last_non_zero;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
171 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
172
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
173 static int dct_quantize_mmx(DCTELEM *block, int n, int qscale)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
174 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
175 int i, j, level, last_non_zero, q;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
176 const int *qmat;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
177 DCTELEM *b = block;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
178
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
179 /*for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
180 printf("%i %i %i %i %i %i %i %i\n", b[8*i], b[8*i+1], b[8*i+2],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
181 b[8*i+3], b[8*i+4], b[8*i+5], b[8*i+6], b[8*i+7]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
182 }*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
183 av_fdct (block);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
184 /*for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
185 printf("%i %i %i %i %i %i %i %i\n", b[8*i], b[8*i+1], b[8*i+2],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
186 b[8*i+3], b[8*i+4], b[8*i+5], b[8*i+6], b[8*i+7]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
187 }*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
188
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
189
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
190 /* we need this permutation so that we correct the IDCT
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
191 permutation. will be moved into DCT code */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
192 //block_permute(block);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
193
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
194 //if (n < 2)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
195 q = 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
196 /*else
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
197 q = 8;*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
198
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
199 /* note: block[0] is assumed to be positive */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
200 block[0] = (block[0] + (q >> 1)) / q;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
201 i = 1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
202 last_non_zero = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
203 qmat = q_intra_matrix;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
204
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
205 for(;i<64;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
206 j = zr_zigzag_direct[i];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
207 level = block[j];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
208 level = level * qmat[j];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
209 /* XXX: slight error for the low range. Test should be equivalent to
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
210 (level <= -(1 << (QMAT_SHIFT_MMX - 3)) || level >= (1 <<
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
211 (QMAT_SHIFT_MMX - 3)))
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
212 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
213 if (((level << (31 - (QMAT_SHIFT_MMX - 3))) >> (31 - (QMAT_SHIFT_MMX - 3))) !=
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
214 level) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
215 level = level / (1 << (QMAT_SHIFT_MMX - 3));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
216 /* XXX: currently, this code is not optimal. the range should be:
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
217 mpeg1: -255..255
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
218 mpeg2: -2048..2047
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
219 h263: -128..127
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
220 mpeg4: -2048..2047
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
221 * jpeg: -1024..1023 11 bit */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
222 if (level > 1023)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
223 level = 1023;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
224 else if (level < -1024)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
225 level = -1024;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
226 block[j] = level;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
227 last_non_zero = i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
228 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
229 block[j] = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
230 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
231 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
232 /*for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
233 printf("%i %i %i %i %i %i %i %i\n", b[8*i], b[8*i+1], b[8*i+2],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
234 b[8*i+3], b[8*i+4], b[8*i+5], b[8*i+6], b[8*i+7]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
235 }*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
236
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
237 return last_non_zero;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
238 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
239
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
240 static void convert_matrix(int *qmat, const unsigned short *quant_matrix,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
241 int qscale)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
242 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
243 int i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
244
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
245 if (av_fdct == jpeg_fdct_ifast) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
246 for(i=0;i<64;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
247 /* 16 <= qscale * quant_matrix[i] <= 7905 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
248 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
249
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
250 qmat[i] = (int)(((unsigned long long)1 << (QMAT_SHIFT + 11)) /
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
251 (aanscales[i] * qscale * quant_matrix[i]));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
252 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
253 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
254 for(i=0;i<64;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
255 /* We can safely suppose that 16 <= quant_matrix[i] <= 255
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
256 So 16 <= qscale * quant_matrix[i] <= 7905
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
257 so (1 << QMAT_SHIFT) / 16 >= qmat[i] >= (1 << QMAT_SHIFT) / 7905
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
258 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
259 qmat[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
260 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
261 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
262 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
263
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
264 #define SOF0 0xC0
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
265 #define SOI 0xD8
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
266 #define EOI 0xD9
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
267 #define DQT 0xDB
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
268 #define DHT 0xC4
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
269 #define SOS 0xDA
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
270
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
271 /* this is almost the quantisation table, used for luminance and chrominance */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
272 /*short int zr_default_intra_matrix[64] = {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
273 16, 11, 10, 16, 24, 40, 51, 61,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
274 12, 12, 14, 19, 26, 58, 60, 55,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
275 14, 13, 16, 24, 40, 57, 69, 56,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
276 14, 17, 22, 29, 51, 87, 80, 62,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
277 18, 22, 37, 56, 68, 109, 103, 77,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
278 24, 35, 55, 64, 81, 104, 113, 92,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
279 49, 64, 78, 87, 103, 121, 120, 101,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
280 72, 92, 95, 98, 112, 100, 103, 99
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
281 };*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
282 /*
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
283 short int default_intra_matrix[64] = {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
284 8, 16, 19, 22, 26, 27, 29, 34,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
285 16, 16, 22, 24, 27, 29, 34, 37,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
286 19, 22, 26, 27, 29, 34, 34, 38,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
287 22, 22, 26, 27, 29, 34, 37, 40,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
288 22, 26, 27, 29, 32, 35, 40, 48,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
289 26, 27, 29, 32, 35, 40, 48, 58,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
290 26, 27, 29, 34, 38, 46, 56, 69,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
291 27, 29, 35, 38, 46, 56, 69, 83
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
292 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
293 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
294 extern short int default_intra_matrix[64];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
295
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
296 static short int intra_matrix[64];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
297
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
298 /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
299 /* IMPORTANT: these are only valid for 8-bit data precision! */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
300 static const unsigned char bits_dc_luminance[17] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
301 { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
302 static const unsigned char val_dc_luminance[] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
303 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
304
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
305 #if 0
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
306 static const unsigned char bits_dc_chrominance[17] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
307 { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
308 static const unsigned char val_dc_chrominance[] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
309 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
310 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
311
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
312 static const unsigned char bits_ac_luminance[17] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
313 { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
314 static const unsigned char val_ac_luminance[] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
315 { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
316 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
317 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
318 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
319 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
320 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
321 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
322 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
323 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
324 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
325 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
326 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
327 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
328 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
329 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
330 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
331 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
332 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
333 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
334 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
335 0xf9, 0xfa
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
336 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
337
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
338 #if 0
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
339 static const unsigned char bits_ac_chrominance[17] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
340 { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
341
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
342 static const unsigned char val_ac_chrominance[] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
343 { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
344 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
345 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
346 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
347 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
348 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
349 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
350 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
351 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
352 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
353 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
354 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
355 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
356 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
357 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
358 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
359 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
360 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
361 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
362 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
363 0xf9, 0xfa
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
364 };
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
365 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
366
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
367 static unsigned char huff_size_dc_luminance[12];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
368 static unsigned short huff_code_dc_luminance[12];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
369 #if 0
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
370 unsigned char huff_size_dc_chrominance[12];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
371 unsigned short huff_code_dc_chrominance[12];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
372 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
373
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
374 static unsigned char huff_size_ac_luminance[256];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
375 static unsigned short huff_code_ac_luminance[256];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
376 #if 0
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
377 unsigned char huff_size_ac_chrominance[256];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
378 unsigned short huff_code_ac_chrominance[256];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
379 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
380
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
381 static int last_dc[3];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
382 static int block_last_index[4];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
383
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
384 /* isn't this function nicer than the one in the libjpeg ? */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
385 static void build_huffman_codes(unsigned char *huff_size,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
386 unsigned short *huff_code, const unsigned char *bits_table,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
387 const unsigned char *val_table)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
388 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
389 int i, j, k,nb, code, sym;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
390
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
391 code = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
392 k = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
393 for(i=1;i<=16;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
394 nb = bits_table[i];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
395 for(j=0;j<nb;j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
396 sym = val_table[k++];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
397 huff_size[sym] = i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
398 huff_code[sym] = code;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
399 code++;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
400 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
401 code <<= 1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
402 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
403 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
404
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
405 static int zr_mjpeg_init()
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
406 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
407 /* build all the huffman tables */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
408 build_huffman_codes(huff_size_dc_luminance, huff_code_dc_luminance,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
409 bits_dc_luminance, val_dc_luminance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
410 //build_huffman_codes(huff_size_dc_chrominance, huff_code_dc_chrominance,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
411 // bits_dc_chrominance, val_dc_chrominance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
412 build_huffman_codes(huff_size_ac_luminance, huff_code_ac_luminance,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
413 bits_ac_luminance, val_ac_luminance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
414 //build_huffman_codes(huff_size_ac_chrominance, huff_code_ac_chrominance,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
415 // bits_ac_chrominance, val_ac_chrominance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
416
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
417 return 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
418 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
419
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
420 static void zr_mjpeg_close()
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
421 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
422 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
423
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
424 static inline void put_marker(PutBitContext *p, int code)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
425 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
426 put_bits(p, 8, 0xff);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
427 put_bits(p, 8, code);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
428 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
429
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
430 /* table_class: 0 = DC coef, 1 = AC coefs */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
431 static int put_huffman_table(int table_class, int table_id,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
432 const unsigned char *bits_table,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
433 const unsigned char *value_table)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
434 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
435 PutBitContext *p = &pb;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
436 int n, i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
437
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
438 put_bits(p, 4, table_class);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
439 put_bits(p, 4, table_id);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
440
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
441 n = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
442 for(i=1;i<=16;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
443 n += bits_table[i];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
444 put_bits(p, 8, bits_table[i]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
445 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
446
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
447 for(i=0;i<n;i++)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
448 put_bits(p, 8, value_table[i]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
449
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
450 return n + 17;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
451 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
452
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
453 static void jpeg_qtable_header()
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
454 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
455 PutBitContext *p = &pb;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
456 int i, j, size;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
457
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
458 /* quant matrixes */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
459 put_marker(p, DQT);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
460 put_bits(p, 16, 2 + 1 * (1 + 64));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
461 put_bits(p, 4, 0); /* 8 bit precision */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
462 put_bits(p, 4, 0); /* table 0 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
463 for(i=0;i<64;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
464 j = zr_zigzag_direct[i];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
465 put_bits(p, 8, intra_matrix[j]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
466 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
467 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
468
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
469 static void jpeg_htable_header() {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
470 PutBitContext *p = &pb;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
471 int i, j, size;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
472 unsigned char *ptr;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
473 /* huffman table */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
474 put_marker(p, DHT);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
475 flush_put_bits(p);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
476 ptr = p->buf_ptr;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
477 put_bits(p, 16, 0); /* patched later */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
478 size = 2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
479 size += put_huffman_table(0, 0, bits_dc_luminance, val_dc_luminance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
480 // size += put_huffman_table(0, 1, bits_dc_chrominance, val_dc_chrominance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
481
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
482 ptr[0] = size >> 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
483 ptr[1] = size;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
484 put_marker(p, DHT);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
485 flush_put_bits(p);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
486 ptr = p->buf_ptr;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
487 put_bits(p, 16, 0); /* patched later */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
488 size = 2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
489 size += put_huffman_table(1, 0, bits_ac_luminance, val_ac_luminance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
490 // size += put_huffman_table(1, 1, bits_ac_chrominance, val_ac_chrominance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
491 ptr[0] = size >> 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
492 ptr[1] = size;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
493 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
494
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
495 static void zr_mjpeg_picture_header()
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
496 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
497 put_marker(&pb, SOI);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
498
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
499 if (first) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
500 jpeg_qtable_header();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
501 jpeg_htable_header();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
502 first = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
503 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
504 put_marker(&pb, SOF0);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
505
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
506 put_bits(&pb, 16, 17);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
507 put_bits(&pb, 8, 8); /* 8 bits/component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
508 put_bits(&pb, 16, height);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
509 put_bits(&pb, 16, width);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
510 put_bits(&pb, 8, 3); /* 3 components */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
511
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
512 /* Y component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
513 put_bits(&pb, 8, 0); /* component number */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
514 put_bits(&pb, 4, 2); /* H factor */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
515 put_bits(&pb, 4, 1); /* V factor */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
516 put_bits(&pb, 8, 0); /* select matrix */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
517
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
518 /* Cb component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
519 put_bits(&pb, 8, 1); /* component number */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
520 put_bits(&pb, 4, 1); /* H factor */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
521 put_bits(&pb, 4, 1); /* V factor */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
522 put_bits(&pb, 8, 0); /* select matrix */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
523
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
524 /* Cr component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
525 put_bits(&pb, 8, 2); /* component number */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
526 put_bits(&pb, 4, 1); /* H factor */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
527 put_bits(&pb, 4, 1); /* V factor */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
528 put_bits(&pb, 8, 0); /* select matrix */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
529
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
530
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
531 /* scan header */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
532 put_marker(&pb, SOS);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
533 put_bits(&pb, 16, 12); /* length */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
534 put_bits(&pb, 8, 3); /* 3 components */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
535
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
536 /* Y component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
537 put_bits(&pb, 8, 0); /* index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
538 put_bits(&pb, 4, 0); /* DC huffman table index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
539 put_bits(&pb, 4, 0); /* AC huffman table index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
540
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
541 /* Cb component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
542 put_bits(&pb, 8, 1); /* index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
543 put_bits(&pb, 4, 0); /* DC huffman table index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
544 put_bits(&pb, 4, 0); /* AC huffman table index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
545
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
546 /* Cr component */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
547 put_bits(&pb, 8, 2); /* index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
548 put_bits(&pb, 4, 0); /* DC huffman table index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
549 put_bits(&pb, 4, 0); /* AC huffman table index */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
550
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
551 put_bits(&pb, 8, 0); /* Ss (not used) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
552 put_bits(&pb, 8, 63); /* Se (not used) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
553 put_bits(&pb, 8, 0); /* (not used) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
554 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
555
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
556 static void zr_flush_buffer(PutBitContext *s)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
557 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
558 int size;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
559 if (s->write_data) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
560 size = s->buf_ptr - s->buf;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
561 if (size > 0)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
562 s->write_data(s->opaque, s->buf, size);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
563 s->buf_ptr = s->buf;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
564 s->data_out_size += size;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
565 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
566 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
567
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
568 /* pad the end of the output stream with ones */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
569 static void zr_jflush_put_bits(PutBitContext *s)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
570 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
571 unsigned int b;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
572 s->bit_buf |= ~1U >> s->bit_cnt; /* set all the unused bits to one */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
573
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
574 while (s->bit_cnt > 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
575 b = s->bit_buf >> 24;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
576 *s->buf_ptr++ = b;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
577 if (b == 0xff)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
578 *s->buf_ptr++ = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
579 s->bit_buf<<=8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
580 s->bit_cnt-=8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
581 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
582 zr_flush_buffer(s);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
583 s->bit_cnt=0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
584 s->bit_buf=0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
585 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
586
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
587 static void zr_mjpeg_picture_trailer()
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
588 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
589 zr_jflush_put_bits(&pb);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
590 put_marker(&pb, EOI);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
591 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
592
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
593 static inline void encode_dc(int val, unsigned char *huff_size,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
594 unsigned short *huff_code)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
595 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
596 int mant, nbits;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
597
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
598 if (val == 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
599 // printf("dc val=0 ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
600 jput_bits(&pb, huff_size[0], huff_code[0]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
601 //printf("dc encoding %d %d\n", huff_size[0], huff_code[0]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
602 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
603 mant = val;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
604 if (val < 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
605 val = -val;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
606 mant--;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
607 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
608
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
609 /* compute the log (XXX: optimize) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
610 nbits = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
611 while (val != 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
612 val = val >> 1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
613 nbits++;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
614 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
615 /*nbits = av_log2(val);*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
616
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
617 //printf("dc ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
618 jput_bits(&pb, huff_size[nbits], huff_code[nbits]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
619 //printf("dc encoding %d %d\n", huff_size[nbits], huff_code[nbits]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
620
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
621 //printf("dc ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
622 jput_bits(&pb, nbits, mant & ((1 << nbits) - 1));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
623 //printf("dc encoding %d %d\n", huff_size[nbits], huff_code[nbits]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
624 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
625 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
626
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
627 static void encode_block(DCTELEM *b, int n)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
628 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
629 int mant, nbits, code, i, j;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
630 int component, dc, run, last_index, val;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
631 unsigned char *huff_size_ac;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
632 unsigned short *huff_code_ac;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
633
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
634 /* DC coef */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
635 component = (n <= 1 ? 0 : n - 2 + 1);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
636 dc = b[0]; /* overflow is impossible */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
637 /*for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
638 printf("%i %i %i %i %i %i %i %i\n", b[8*i], b[8*i+1], b[8*i+2],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
639 b[8*i+3], b[8*i+4], b[8+i*5], b[8+i*6], b[8+i*7]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
640 }*/
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
641 val = dc - last_dc[component];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
642 //if (n < 2) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
643 encode_dc(val, huff_size_dc_luminance, huff_code_dc_luminance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
644 huff_size_ac = huff_size_ac_luminance;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
645 huff_code_ac = huff_code_ac_luminance;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
646 //} else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
647 // encode_dc(val, huff_size_dc_chrominance, huff_code_dc_chrominance);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
648 // huff_size_ac = huff_size_ac_chrominance;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
649 // huff_code_ac = huff_code_ac_chrominance;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
650 //}
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
651 last_dc[component] = dc;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
652
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
653 /* AC coefs */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
654
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
655 run = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
656 last_index = block_last_index[n];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
657 for(i=1;i<=last_index;i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
658 j = zr_zigzag_direct[i];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
659 val = b[j];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
660 if (val == 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
661 run++;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
662 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
663 while (run >= 16) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
664 //printf("ac 16 white ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
665 jput_bits(&pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
666 run -= 16;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
667 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
668 mant = val;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
669 if (val < 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
670 val = -val;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
671 mant--;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
672 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
673
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
674 /* compute the log (XXX: optimize) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
675 nbits = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
676 while (val != 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
677 val = val >> 1;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
678 nbits++;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
679 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
680 code = (run << 4) | nbits;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
681
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
682 //printf("ac ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
683 jput_bits(&pb, huff_size_ac[code], huff_code_ac[code]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
684
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
685 //printf("ac ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
686 jput_bits(&pb, nbits, mant & ((1 << nbits) - 1));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
687 run = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
688 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
689 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
690
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
691 /* output EOB only if not already 64 values */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
692 if (last_index < 63 || run != 0) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
693 //printf("ac EOB ");
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
694 jput_bits(&pb, huff_size_ac[0], huff_code_ac[0]);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
695 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
696 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
697
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
698 static void zr_mjpeg_encode_mb(DCTELEM **bla)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
699 {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
700 encode_block(*(bla), 0);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
701 encode_block(*(bla+1), 1);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
702 if (bw) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
703 jput_bits(&pb, 12, 512+128+8+2); /* 2 times code for 'no color'
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
704 * 001010001010 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
705 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
706 encode_block(*(bla+2), 2);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
707 encode_block(*(bla+3), 3);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
708 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
709 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
710
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
711 static int mb_width, mb_height, mb_x, mb_y;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
712 static unsigned char *y_data, *u_data, *v_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
713 static int y_ps, u_ps, v_ps, y_rs, u_rs, v_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
714 static char code[256*1024]; // 256kb!
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
715 /* this function can take all kinds of YUV colorspaces
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
716 * YV12, YVYU, UYVY. The necesary parameters must be set up by te caller
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
717 * y_ps means "y pixel size", y_rs means "y row size".
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
718 * For YUYV, for example, is u = y + 1, v = y + 3, y_ps = 2, u_ps = 4
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
719 * v_ps = 4, y_rs = u_rs = v_rs.
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
720 *
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
721 * The data is straightened out at the moment it is put in DCT
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
722 * blocks, there are therefore no spurious memcopies involved */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
723 /* Notice that w must be a multiple of 16 and h must be a multiple of
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
724 * fields*8 */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
725 /* We produce YUV422 jpegs, the colors must be subsampled horizontally,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
726 * if the colors are also subsampled vertically, then this function
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
727 * performs cheap upsampling (better solution will be: a DCT that is
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
728 * optimized in the case that every two rows are the same) */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
729 /* cu = 0 means 'No cheap upsampling'
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
730 * cu = 1 means 'perform cheap upsampling' */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
731 void mjpeg_encoder_init(int w, int h,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
732 unsigned char* y, int y_psize, int y_rsize,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
733 unsigned char* u, int u_psize, int u_rsize,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
734 unsigned char* v, int v_psize, int v_rsize,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
735 int f, int cu, int q, int b) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
736 int i;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
737 mp_msg(MSGT_VO, MSGL_V, "JPEnc init: %dx%d %p %d %d %p %d %d %p %d %d\n",
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
738 w, h, y, y_psize, y_rsize,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
739 u, u_psize, u_rsize,
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
740 v, v_psize, v_rsize);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
741 y_data = y; u_data = u; v_data = v;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
742 y_ps = y_psize; u_ps = u_psize; v_ps = v_psize;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
743 y_rs = y_rsize*f;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
744 u_rs = u_rsize*f;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
745 v_rs = v_rsize*f;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
746 width = w;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
747 height = h/f;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
748 fields = f;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
749 qscale = q;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
750 cheap_upsample = cu;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
751 mb_width = width/16;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
752 mb_height = height/8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
753 bw = b;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
754 zr_mjpeg_init();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
755 i = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
756 intra_matrix[0] = default_intra_matrix[0];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
757 for (i = 1; i < 64; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
758 intra_matrix[i] = (default_intra_matrix[i]*qscale) >> 3;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
759 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
760 if (
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
761 #ifdef HAVE_MMX
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
762 av_fdct != fdct_mmx &&
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
763 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
764 av_fdct != jpeg_fdct_ifast) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
765 /* libavcodec is probably not yet initialized */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
766 av_fdct = jpeg_fdct_ifast;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
767 #ifdef HAVE_MMX
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
768 dsputil_init_mmx();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
769 #endif
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
770 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
771 convert_matrix(q_intra_matrix, intra_matrix, 8);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
772 blck = malloc(4*sizeof(DCTELEM*));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
773 blck[0] = malloc(64*sizeof(DCTELEM));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
774 blck[1] = malloc(64*sizeof(DCTELEM));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
775 blck[2] = malloc(64*sizeof(DCTELEM));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
776 blck[3] = malloc(64*sizeof(DCTELEM));
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
777 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
778
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
779 int mjpeg_encode_frame(char *bufr, int field) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
780 int i, j, k, l;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
781 short int *dest;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
782 unsigned char *source;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
783 /* initialize the buffer */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
784 if (field == 1) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
785 y_data += y_rs/2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
786 u_data += u_rs/2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
787 v_data += v_rs/2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
788 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
789 init_put_bits(&pb, bufr, 1024*256, NULL, NULL);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
790
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
791 zr_mjpeg_picture_header();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
792
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
793 last_dc[0] = 128; last_dc[1] = 128; last_dc[2] = 128;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
794 mb_x = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
795 mb_y = 0;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
796 for (mb_y = 0; mb_y < mb_height; mb_y++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
797 for (mb_x = 0; mb_x < mb_width; mb_x++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
798 //printf("Processing macroblock mb_x=%d, mb_y=%d, mb_width=%d, mb_height=%d, size=%d\n", mb_x, mb_y, mb_width, mb_height, pb.buf_ptr - pb.buf);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
799 /* fill 2 Y macroblocks and one U and one V */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
800 source = mb_y * 8 * y_rs + 16 * y_ps * mb_x + y_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
801 dest = blck[0];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
802 for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
803 for (j = 0; j < 8; j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
804 dest[j] = source[j*y_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
805 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
806 dest += 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
807 source += y_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
808 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
809 source = mb_y * 8 * y_rs + (16*mb_x + 8)*y_ps + y_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
810 dest = blck[1];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
811 for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
812 for (j = 0; j < 8; j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
813 dest[j] = source[j*y_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
814 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
815 dest += 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
816 source += y_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
817 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
818 if (!bw) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
819 if (cheap_upsample) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
820 source = mb_y*4*u_rs + 8*mb_x*u_ps + u_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
821 dest = blck[2];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
822 for (i = 0; i < 4; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
823 for (j = 0; j < 8; j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
824 dest[j] = source[j*u_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
825 dest[j+8] = source[j*u_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
826 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
827 dest += 16;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
828 source += u_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
829 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
830 source = mb_y*4*v_rs + 8*mb_x*v_ps + v_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
831 dest = blck[3];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
832 for (i = 0; i < 4; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
833 for (j = 0; j < 8; j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
834 dest[j] = source[j*v_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
835 dest[j+8] = source[j*v_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
836 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
837 dest += 16;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
838 source += u_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
839 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
840 } else {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
841 source = mb_y*8*u_rs + 8*mb_x*u_ps + u_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
842 dest = blck[2];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
843 for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
844 for (j = 0; j < 8; j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
845 dest[j] = source[j*u_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
846 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
847 dest += 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
848 source += u_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
849 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
850 source = mb_y*8*v_rs + 8*mb_x*v_ps + v_data;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
851 dest = blck[3];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
852 for (i = 0; i < 8; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
853 for (j = 0; j < 8; j++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
854 dest[j] = source[j*v_ps];
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
855 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
856 dest += 8;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
857 source += u_rs;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
858 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
859 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
860 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
861 /* so, **blck is filled now... */
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
862
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
863 for(i = 0; i < 2; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
864 if (av_fdct == jpeg_fdct_ifast)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
865 block_last_index[i] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
866 dct_quantize(blck[i],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
867 i, qscale);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
868 else
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
869 block_last_index[i] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
870 dct_quantize_mmx(blck[i],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
871 i, qscale);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
872 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
873 if (!bw) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
874 for(i = 2; i < 4; i++) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
875 if (av_fdct == jpeg_fdct_ifast)
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
876 block_last_index[i] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
877 dct_quantize(blck[i],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
878 i, qscale);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
879 else
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
880 block_last_index[i] =
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
881 dct_quantize_mmx(blck[i],
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
882 i, qscale);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
883 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
884 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
885 zr_mjpeg_encode_mb(blck);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
886 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
887 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
888 emms_c();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
889 zr_mjpeg_picture_trailer();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
890 flush_put_bits(&pb);
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
891 zr_mjpeg_close();
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
892 if (field == 1) {
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
893 y_data -= y_rs/2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
894 u_data -= u_rs/2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
895 v_data -= v_rs/2;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
896 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
897 return pb.buf_ptr - pb.buf;
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
898 }
d036a9992baf fast 4:2:2 jpeg encoder, based on libavcodec. - patch by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff changeset
899