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