1 | Index: encode_dxa.cpp
|
---|
2 | ===================================================================
|
---|
3 | --- encode_dxa.cpp (revision 27748)
|
---|
4 | +++ encode_dxa.cpp (working copy)
|
---|
5 | @@ -32,6 +32,8 @@
|
---|
6 | const uint32 typeWAVE = 0x45564157;
|
---|
7 | const uint32 typeCMAP = 0x50414D43;
|
---|
8 | const uint32 typeNULL = 0x4C4C554E;
|
---|
9 | +const uint32 typeMAXD = 0x4458414D;
|
---|
10 | +const uint32 typeZCNT = 0x544E435A;
|
---|
11 |
|
---|
12 | #define BUFFER_LEN 1024
|
---|
13 |
|
---|
14 | @@ -55,6 +57,8 @@
|
---|
15 | int _width, _height, _framerate, _framecount, _workheight;
|
---|
16 | uint8 *_prevframe, *_prevpalette;
|
---|
17 | ScaleMode _scaleMode;
|
---|
18 | + z_stream _d_stream;
|
---|
19 | + uint32 _maxd;
|
---|
20 |
|
---|
21 | byte *_codeBuf, *_dataBuf, *_motBuf, *_maskBuf;
|
---|
22 | void grabBlock(byte *frame, int x, int y, int blockw, int blockh, byte *block);
|
---|
23 | @@ -88,6 +92,14 @@
|
---|
24 | _dataBuf = new byte[_width * _height];
|
---|
25 | _motBuf = new byte[_width * _height];
|
---|
26 | _maskBuf = new byte[_width * _height];
|
---|
27 | +
|
---|
28 | + _d_stream.zalloc = (alloc_func)NULL;
|
---|
29 | + _d_stream.zfree = (free_func)NULL;
|
---|
30 | + _d_stream.opaque = (voidpf)NULL;
|
---|
31 | + _d_stream.total_out = 0;
|
---|
32 | + deflateInit(&_d_stream, Z_BEST_COMPRESSION);
|
---|
33 | +
|
---|
34 | + _maxd = 0;
|
---|
35 |
|
---|
36 | writeHeader();
|
---|
37 | }
|
---|
38 | @@ -98,6 +110,8 @@
|
---|
39 | writeHeader();
|
---|
40 |
|
---|
41 | fclose(_dxa);
|
---|
42 | +
|
---|
43 | + deflateEnd(&_d_stream);
|
---|
44 |
|
---|
45 | delete[] _codeBuf;
|
---|
46 | delete[] _dataBuf;
|
---|
47 | @@ -125,6 +139,13 @@
|
---|
48 | writeUint32BE(_dxa, _framerate);
|
---|
49 | writeUint16BE(_dxa, _width);
|
---|
50 | writeUint16BE(_dxa, _height);
|
---|
51 | +
|
---|
52 | + // No sound block
|
---|
53 | + writeNULL();
|
---|
54 | +
|
---|
55 | + writeUint32LE(_dxa, typeMAXD);
|
---|
56 | + writeUint32BE(_dxa, _maxd);
|
---|
57 | + writeUint32LE(_dxa, typeZCNT);
|
---|
58 | }
|
---|
59 |
|
---|
60 | void DxaEncoder::writeNULL() {
|
---|
61 | @@ -159,7 +180,16 @@
|
---|
62 | {
|
---|
63 | uLong outsize = _width * _workheight;
|
---|
64 | byte *outbuf = new byte[outsize];
|
---|
65 | - compress2(outbuf, &outsize, frame, _width * _workheight, 9);
|
---|
66 | +
|
---|
67 | + _d_stream.next_in = frame;
|
---|
68 | + _d_stream.avail_in = _width * _workheight;
|
---|
69 | + _d_stream.total_in = _width * _workheight;
|
---|
70 | + _d_stream.next_out = outbuf;
|
---|
71 | + _d_stream.avail_out = outsize;
|
---|
72 | + deflate(&_d_stream, Z_SYNC_FLUSH);
|
---|
73 | + outsize -= _d_stream.avail_out;
|
---|
74 | +
|
---|
75 | + //compress2(outbuf, &outsize, frame, _width * _workheight, 9);
|
---|
76 | writeByte(_dxa, compType);
|
---|
77 | writeUint32BE(_dxa, outsize);
|
---|
78 | fwrite(outbuf, outsize, 1, _dxa);
|
---|
79 | @@ -203,11 +233,9 @@
|
---|
80 | if (m13size_z < xorsize_z) {
|
---|
81 | compType = 13;
|
---|
82 | frameoutsize = m13size_z;
|
---|
83 | - frameoutbuf = m13buf_z;
|
---|
84 | } else {
|
---|
85 | compType = 3;
|
---|
86 | frameoutsize = xorsize_z;
|
---|
87 | - frameoutbuf = xorbuf_z;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* compress the raw frame */
|
---|
91 | @@ -217,13 +245,44 @@
|
---|
92 |
|
---|
93 | if (rawsize_z < frameoutsize) {
|
---|
94 | compType = 2;
|
---|
95 | - frameoutsize = rawsize_z;
|
---|
96 | - frameoutbuf = rawbuf_z;
|
---|
97 | }
|
---|
98 |
|
---|
99 | + /* We have now selected the compression
|
---|
100 | + * type based on how it compressed. But
|
---|
101 | + * now we're going to recompress it onto
|
---|
102 | + * the end of the existing stream, where
|
---|
103 | + * it should get smaller still. */
|
---|
104 | + _d_stream.next_out = rawbuf_z;
|
---|
105 | + _d_stream.avail_out = _width * _workheight;
|
---|
106 | + switch (compType)
|
---|
107 | + {
|
---|
108 | + case 2:
|
---|
109 | + _d_stream.next_in = frame;
|
---|
110 | + _d_stream.avail_in = _width * _workheight;
|
---|
111 | + _d_stream.total_in = _width * _workheight;
|
---|
112 | + break;
|
---|
113 | + case 3:
|
---|
114 | + _d_stream.next_in = xorbuf;
|
---|
115 | + _d_stream.avail_in = _width * _workheight;
|
---|
116 | + _d_stream.total_in = _width * _workheight;
|
---|
117 | + break;
|
---|
118 | + case 13:
|
---|
119 | + _d_stream.next_in = m13buf;
|
---|
120 | + _d_stream.avail_in = m13size;
|
---|
121 | + _d_stream.total_in = m13size;
|
---|
122 | + if (m13size > _maxd)
|
---|
123 | + _maxd = m13size;
|
---|
124 | + break;
|
---|
125 | + }
|
---|
126 | + frameoutsize = _d_stream.avail_out;
|
---|
127 | + deflate(&_d_stream, Z_SYNC_FLUSH);
|
---|
128 | + frameoutsize -= _d_stream.avail_out;
|
---|
129 | + frameoutbuf = rawbuf_z;
|
---|
130 | +
|
---|
131 | writeByte(_dxa, compType);
|
---|
132 | writeUint32BE(_dxa, frameoutsize);
|
---|
133 | fwrite(frameoutbuf, frameoutsize, 1, _dxa);
|
---|
134 | +
|
---|
135 |
|
---|
136 | delete[] xorbuf_z;
|
---|
137 | delete[] rawbuf_z;
|
---|
138 | @@ -808,8 +867,8 @@
|
---|
139 | sprintf(strbuf, "%s.dxa", prefix);
|
---|
140 | DxaEncoder dxe(strbuf, width, height, framerate, scaleMode);
|
---|
141 |
|
---|
142 | - // No sound block
|
---|
143 | - dxe.writeNULL();
|
---|
144 | + // No sound block - now written as part of header
|
---|
145 | + //dxe.writeNULL();
|
---|
146 |
|
---|
147 | uint8 *image = NULL;
|
---|
148 | uint8 *palette = NULL;
|
---|