]>
git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/sl.subproj/bmdecompress.c
2 * Copyright (c) 1995-2002 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.1 (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@
26 typedef uint8_t UInt8
;
27 typedef uint16_t UInt16
;
28 typedef uint32_t UInt32
;
30 typedef int16_t SInt16
;
31 typedef int32_t SInt32
;
33 enum { false = 0, true = 1 };
36 PreviewDecompress16(uint32_t * compressBuffer
,
37 uint32_t width
, uint32_t height
, uint32_t row
,
43 uint16_t * sc0
= malloc((width
+2) * sizeof(uint16_t));
44 uint16_t * sc1
= malloc((width
+2) * sizeof(uint16_t));
45 uint16_t * sc2
= malloc((width
+2) * sizeof(uint16_t));
46 uint16_t * sc3
= malloc((width
+2) * sizeof(uint16_t));
47 uint32_t sr0
, sr1
, sr2
, sr3
;
49 bzero(sc0
, (width
+2) * sizeof(uint16_t));
50 bzero(sc1
, (width
+2) * sizeof(uint16_t));
51 bzero(sc2
, (width
+2) * sizeof(uint16_t));
52 bzero(sc3
, (width
+2) * sizeof(uint16_t));
54 uint32_t tmp1
, tmp2
, out
;
55 for (j
= 0; j
< (height
+ 2); j
++)
57 input
= compressBuffer
;
62 input
= (uint32_t *)(input
[3] + ((uint8_t *)compressBuffer
));
64 uint32_t data
, repeat
, fetch
, count
= 0;
65 sr0
= sr1
= sr2
= sr3
= 0;
67 for (i
= 0; i
< (width
+ 2); i
++)
74 repeat
= (count
& 0xff000000);
79 fetch
= (0 == repeat
);
85 data
= *((uint16_t *)input
)++;
88 // srgb 13933, 46871, 4732
89 // ntsc 19595, 38470, 7471
90 data
= 13933 * (0x1f & (data
>> 10))
91 + 46871 * (0x1f & (data
>> 5))
92 + 4732 * (0x1f & data
);
95 // 70% white, 30 % black
112 tmp2
= sc0
[i
] + tmp1
;
114 tmp1
= sc1
[i
] + tmp2
;
116 tmp2
= sc2
[i
] + tmp1
;
118 out
= (128 + sc3
[i
] + tmp2
) >> 11;
122 if ((i
> 1) && (j
> 1))
123 output
[i
-2] = out
| (out
<< 5) | (out
<< 10);
136 PreviewDecompress32(uint32_t * compressBuffer
,
137 uint32_t width
, uint32_t height
, uint32_t row
,
143 uint16_t * sc0
= malloc((width
+2) * sizeof(uint16_t));
144 uint16_t * sc1
= malloc((width
+2) * sizeof(uint16_t));
145 uint16_t * sc2
= malloc((width
+2) * sizeof(uint16_t));
146 uint16_t * sc3
= malloc((width
+2) * sizeof(uint16_t));
147 uint32_t sr0
, sr1
, sr2
, sr3
;
149 bzero(sc0
, (width
+2) * sizeof(uint16_t));
150 bzero(sc1
, (width
+2) * sizeof(uint16_t));
151 bzero(sc2
, (width
+2) * sizeof(uint16_t));
152 bzero(sc3
, (width
+2) * sizeof(uint16_t));
154 uint32_t tmp1
, tmp2
, out
;
155 for (j
= 0; j
< (height
+ 2); j
++)
157 input
= compressBuffer
;
162 input
= (uint32_t *)(input
[3] + ((uint8_t *)compressBuffer
));
164 uint32_t data
, repeat
, fetch
, count
= 0;
165 sr0
= sr1
= sr2
= sr3
= 0;
167 for (i
= 0; i
< (width
+ 2); i
++)
174 repeat
= (count
& 0xff000000);
179 fetch
= (0 == repeat
);
188 // srgb 13933, 46871, 4732
189 // ntsc 19595, 38470, 7471
190 data
= 13933 * (0xff & (data
>> 24))
191 + 46871 * (0xff & (data
>> 16))
192 + 4732 * (0xff & data
);
195 // 70% white, 30 % black
212 tmp2
= sc0
[i
] + tmp1
;
214 tmp1
= sc1
[i
] + tmp2
;
216 tmp2
= sc2
[i
] + tmp1
;
218 out
= (128 + sc3
[i
] + tmp2
) >> 8;
222 if ((i
> 1) && (j
> 1))
223 output
[i
-2] = out
| (out
<< 8) | (out
<< 16);
237 DecompressData(void *srcbase
, void *dstbase
,
238 int dw
, int dh
, int bytesPerPixel
, int rowbytes
)
240 uint32_t * src
= (uint32_t *) srcbase
;
242 if ((bytesPerPixel
!= (int) src
[0]) || (dw
!= (int) src
[1]) || (dh
!= (int) src
[2]))
245 switch(bytesPerPixel
)
248 PreviewDecompress32((uint32_t *)srcbase
, dw
, dh
, rowbytes
>> 2, (uint32_t *) dstbase
);
251 PreviewDecompress16((uint32_t *)srcbase
, dw
, dh
, rowbytes
>> 1, (uint16_t *) dstbase
);