]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/xpress.h
1.1.07 release
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / grub-core / ventoy / xpress.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 "huffman.h"
31
32 /** Number of XCA codes */
33 #define XCA_CODES 512
34
35 /** XCA decompressor */
36 struct xca {
37 /** Huffman alphabet */
38 struct huffman_alphabet alphabet;
39 /** Raw symbols
40 *
41 * Must immediately follow the Huffman alphabet.
42 */
43 huffman_raw_symbol_t raw[XCA_CODES];
44 /** Code lengths */
45 uint8_t lengths[XCA_CODES];
46 };
47
48 /** XCA symbol Huffman lengths table */
49 struct xca_huf_len {
50 /** Lengths of each symbol */
51 uint8_t nibbles[ XCA_CODES / 2 ];
52 } __attribute__ (( packed ));
53
54 /**
55 * Extract Huffman-coded length of a raw symbol
56 *
57 * @v lengths Huffman lengths table
58 * @v symbol Raw symbol
59 * @ret len Huffman-coded length
60 */
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 );
65 }
66
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 ); \
71 *src16; } )
72
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 ); \
77 *src8; } )
78
79 /** XCA source data stream end marker */
80 #define XCA_END_MARKER 256
81
82 /** XCA block size */
83 #define XCA_BLOCK_SIZE ( 64 * 1024 )
84
85 extern ssize_t xca_decompress ( const void *data, size_t len, void *buf );
86
87 #endif /* _XCA_H */