5 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 * Xpress Compression Algorithm (MS-XCA) decompression
32 /** Number of XCA codes */
35 /** XCA decompressor */
37 /** Huffman alphabet */
38 struct huffman_alphabet alphabet
;
41 * Must immediately follow the Huffman alphabet.
43 huffman_raw_symbol_t raw
[XCA_CODES
];
45 uint8_t lengths
[XCA_CODES
];
48 /** XCA symbol Huffman lengths table */
50 /** Lengths of each symbol */
51 uint8_t nibbles
[ XCA_CODES
/ 2 ];
52 } __attribute__ (( packed
));
55 * Extract Huffman-coded length of a raw symbol
57 * @v lengths Huffman lengths table
58 * @v symbol Raw symbol
59 * @ret len Huffman-coded length
61 static inline unsigned int xca_huf_len ( const struct xca_huf_len
*lengths
,
62 unsigned int symbol
) {
63 return ( ( ( lengths
->nibbles
[ symbol
/ 2 ] ) >>
64 ( 4 * ( symbol
% 2 ) ) ) & 0x0f );
67 /** Get word from source data stream */
68 #define XCA_GET16( src ) ( { \
69 const uint16_t *src16 = src; \
70 src = ( uint8_t * ) src + sizeof ( *src16 ); \
73 /** Get byte from source data stream */
74 #define XCA_GET8( src ) ( { \
75 const uint8_t *src8 = src; \
76 src = ( uint8_t * ) src + sizeof ( *src8 ); \
79 /** XCA source data stream end marker */
80 #define XCA_END_MARKER 256
83 #define XCA_BLOCK_SIZE ( 64 * 1024 )
85 extern ssize_t
xca_decompress ( const void *data
, size_t len
, void *buf
);