]>
git.saurik.com Git - apple/boot.git/blob - i386/util/tif_packbits.c
820f13b627b817c1cc8d8dfac9f3f44da94f13ce
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 static char rcsid
[] = "$Header: /cvs/root/boot/i386/util/tif_packbits.c,v 1.1.1.2 1999/08/04 21:17:19 wsanchez Exp $";
30 * Copyright (c) 1988, 1989, 1990, 1991 Sam Leffler
31 * Copyright (c) 1991 Silicon Graphics, Inc.
33 * Permission to use, copy, modify, distribute, and sell this software and
34 * its documentation for any purpose is hereby granted without fee, provided
35 * that (i) the above copyright notices and this permission notice appear in
36 * all copies of the software and related documentation, and (ii) the names of
37 * Sam Leffler and Silicon Graphics may not be used in any advertising or
38 * publicity relating to the software without the specific, prior written
39 * permission of Sam Leffler and Silicon Graphics.
41 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
42 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
43 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
45 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
46 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
47 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
48 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
49 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
56 * PackBits Compression Algorithm Support
60 typedef unsigned int u_int
;
61 typedef unsigned char u_char
;
64 TIFFAppendToStrip(tif
, strip
, data
, cc
)
75 * Encode a scanline of pixels.
78 PackBitsEncode(tif
, bp
, cc
, s
)
84 register char *op
, *lastliteral
;
86 enum { BASE
, LITERAL
, RUN
, LITERAL_RUN
} state
;
91 ep
= tif
->tif_rawdata
+ tif
->tif_rawdatasize
;
96 * Find the longest string of identical bytes.
98 b
= *bp
++, cc
--, n
= 1;
99 for (; cc
> 0 && b
== *bp
; cc
--, bp
++)
102 if (op
+ 2 >= ep
) { /* insure space for new data */
104 * Be careful about writing the last
105 * literal. Must write up to that point
106 * and then copy the remainder to the
107 * front of the buffer.
109 if (state
== LITERAL
|| state
== LITERAL_RUN
) {
110 slop
= op
- lastliteral
;
111 tif
->tif_rawcc
+= lastliteral
- tif
->tif_rawcp
;
115 for (; slop
-- > 0; *op
++ = *lastliteral
++)
117 lastliteral
= tif
->tif_rawcp
;
119 tif
->tif_rawcc
+= op
- tif
->tif_rawcp
;
126 case BASE
: /* initial state, set run/literal */
144 case LITERAL
: /* last object was literal string */
153 *op
++ = -(n
-1); /* encode run */
155 } else { /* extend literal */
156 if (++(*lastliteral
) == 127)
161 case RUN
: /* last object was run */
178 case LITERAL_RUN
: /* literal followed by a run */
180 * Check to see if previous run should
181 * be converted to a literal, in which
182 * case we convert literal-run-literal
183 * to a single literal.
185 if (n
== 1 && op
[-2] == (char)-1 &&
186 *lastliteral
< 126) {
187 state
= (((*lastliteral
) += 2) == 127 ?
189 op
[-2] = op
[-1]; /* replicate */
195 tif
->tif_rawcc
+= op
- tif
->tif_rawcp
;