]>
git.saurik.com Git - apple/boot.git/blob - i386/boot2/lzss.c
9cc50fb6b8b10b1f0c1ce288e172a7e801af5718
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.2 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /**************************************************************
23 LZSS.C -- A Data Compression Program
24 ***************************************************************
25 4/6/1989 Haruhiko Okumura
26 Use, distribute, and modify this program freely.
27 Please send me your improved versions.
32 **************************************************************/
34 * lzss.c - Package for decompressing lzss compressed objects
36 * Copyright (c) 2003 Apple Computer, Inc.
43 #define N 4096 /* size of ring buffer - must be power of 2 */
44 #define F 18 /* upper limit for match_length */
45 #define THRESHOLD 2 /* encode string into position and length
46 if match_length is greater than this */
47 #define NIL N /* index for root of binary search trees */
50 decompress_lzss(u_int8_t
*dst
, u_int8_t
*src
, u_int32_t srclen
)
52 /* ring buffer of size N, with extra F-1 bytes to aid string comparison */
53 u_int8_t text_buf
[N
+ F
- 1];
54 u_int8_t
*dststart
= dst
;
55 u_int8_t
*srcend
= src
+ srclen
;
60 srcend
= src
+ srclen
;
61 for (i
= 0; i
< N
- F
; i
++)
66 if (((flags
>>= 1) & 0x100) == 0) {
67 if (src
< srcend
) c
= *src
++; else break;
68 flags
= c
| 0xFF00; /* uses higher byte cleverly */
69 } /* to count eight */
71 if (src
< srcend
) c
= *src
++; else break;
76 if (src
< srcend
) i
= *src
++; else break;
77 if (src
< srcend
) j
= *src
++; else break;
78 i
|= ((j
& 0xF0) << 4);
79 j
= (j
& 0x0F) + THRESHOLD
;
80 for (k
= 0; k
<= j
; k
++) {
81 c
= text_buf
[(i
+ k
) & (N
- 1)];
89 return dst
- dststart
;