]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/xca.h
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / xca.h
1 #ifndef _XCA_H
2 #define _XCA_H
3
4 /*
5 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
6 *
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.
11 *
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.
16 *
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
20 * 02110-1301, USA.
21 */
22
23 /**
24 * @file
25 *
26 * Xpress Compression Algorithm (MS-XCA) decompression
27 *
28 */
29
30 #include <stdint.h>
31 #include "huffman.h"
32
33 /** Number of XCA codes */
34 #define XCA_CODES 512
35
36 /** XCA decompressor */
37 struct xca {
38 /** Huffman alphabet */
39 struct huffman_alphabet alphabet;
40 /** Raw symbols
41 *
42 * Must immediately follow the Huffman alphabet.
43 */
44 huffman_raw_symbol_t raw[XCA_CODES];
45 /** Code lengths */
46 uint8_t lengths[XCA_CODES];
47 };
48
49 /** XCA symbol Huffman lengths table */
50 struct xca_huf_len {
51 /** Lengths of each symbol */
52 uint8_t nibbles[ XCA_CODES / 2 ];
53 } __attribute__ (( packed ));
54
55 /**
56 * Extract Huffman-coded length of a raw symbol
57 *
58 * @v lengths Huffman lengths table
59 * @v symbol Raw symbol
60 * @ret len Huffman-coded length
61 */
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 );
66 }
67
68 /** Get word from source data stream */
69 #define XCA_GET16( src ) ( { \
70 const uint16_t *src16 = src; \
71 src += sizeof ( *src16 ); \
72 *src16; } )
73
74 /** Get byte from source data stream */
75 #define XCA_GET8( src ) ( { \
76 const uint8_t *src8 = src; \
77 src += sizeof ( *src8 ); \
78 *src8; } )
79
80 /** XCA source data stream end marker */
81 #define XCA_END_MARKER 256
82
83 /** XCA block size */
84 #define XCA_BLOCK_SIZE ( 64 * 1024 )
85
86 extern ssize_t xca_decompress ( const void *data, size_t len, void *buf );
87
88 #endif /* _XCA_H */