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
33 /** Number of XCA codes */
36 /** XCA decompressor */
38 /** Huffman alphabet */
39 struct huffman_alphabet alphabet
;
42 * Must immediately follow the Huffman alphabet.
44 huffman_raw_symbol_t raw
[XCA_CODES
];
46 uint8_t lengths
[XCA_CODES
];
49 /** XCA symbol Huffman lengths table */
51 /** Lengths of each symbol */
52 uint8_t nibbles
[ XCA_CODES
/ 2 ];
53 } __attribute__ (( packed
));
56 * Extract Huffman-coded length of a raw symbol
58 * @v lengths Huffman lengths table
59 * @v symbol Raw symbol
60 * @ret len Huffman-coded length
62 static inline unsigned int xca_huf_len ( const struct xca_huf_len
*lengths
,
63 unsigned int symbol
) {
64 return ( ( ( lengths
->nibbles
[ symbol
/ 2 ] ) >>
65 ( 4 * ( symbol
% 2 ) ) ) & 0x0f );
68 /** Get word from source data stream */
69 #define XCA_GET16( src ) ( { \
70 const uint16_t *src16 = src; \
71 src += sizeof ( *src16 ); \
74 /** Get byte from source data stream */
75 #define XCA_GET8( src ) ( { \
76 const uint8_t *src8 = src; \
77 src += sizeof ( *src8 ); \
80 /** XCA source data stream end marker */
81 #define XCA_END_MARKER 256
84 #define XCA_BLOCK_SIZE ( 64 * 1024 )
86 extern ssize_t
xca_decompress ( const void *data
, size_t len
, void *buf
);