Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/boot2/bmdecompress.c

1/*
2 * Copyright (c) 1995-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#include "libsa.h"
24
25static void PreviewDecompress16(uint32_t * compressBuffer,
26uint32_t width, uint32_t height, uint32_t row,
27uint16_t * output);
28
29static void PreviewDecompress32(uint32_t * compressBuffer,
30 uint32_t width, uint32_t height, uint32_t row,
31 uint32_t * output);
32
33static void PreviewDecompress16(uint32_t * compressBuffer,
34uint32_t width, uint32_t height, uint32_t row,
35uint16_t * output)
36{
37int i, j;
38uint32_t * input;
39
40uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t));
41uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t));
42uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t));
43uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t));
44
45if (!sc0 || !sc1 || !sc2 || !sc3)
46{
47return;
48}
49
50uint32_t sr0, sr1, sr2, sr3;
51
52bzero(sc0, (width+2) * sizeof(uint16_t));
53bzero(sc1, (width+2) * sizeof(uint16_t));
54bzero(sc2, (width+2) * sizeof(uint16_t));
55bzero(sc3, (width+2) * sizeof(uint16_t));
56
57uint32_t tmp1, tmp2, out;
58for (j = 0; j < (height + 2); j++)
59{
60input = compressBuffer;
61
62if (j < height)
63{
64input += j;
65}
66else
67{
68input += height - 1;
69}
70
71input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer));
72
73uint32_t data = 0, repeat = 0, fetch = 0, count = 0;
74sr0 = sr1 = sr2 = sr3 = 0;
75
76for (i = 0; i < (width + 2); i++)
77{
78if (i < width)
79{
80if (!count)
81{
82count = *input++;
83repeat = (count & 0xff000000);
84count ^= repeat;
85fetch = true;
86}
87else
88{
89fetch = (0 == repeat);
90}
91
92count--;
93
94if (fetch)
95{
96data = *((uint16_t *)input);
97(*((uint16_t *)input))++;
98
99// grayscale
100// srgb 13933, 46871, 4732
101// ntsc 19595, 38470, 7471
102data = 13933 * (0x1f & (data >> 10))
103+ 46871 * (0x1f & (data >> 5))
104+ 4732 * (0x1f & data);
105data >>= 13;
106
107// 70% white, 30 % black
108data *= 19661;
109data += (103 << 16);
110data >>= 16;
111}
112}
113
114// gauss blur
115tmp2 = sr0 + data;
116sr0 = data;
117tmp1 = sr1 + tmp2;
118sr1 = tmp2;
119tmp2 = sr2 + tmp1;
120sr2 = tmp1;
121tmp1 = sr3 + tmp2;
122sr3 = tmp2;
123
124tmp2 = sc0[i] + tmp1;
125sc0[i] = tmp1;
126tmp1 = sc1[i] + tmp2;
127sc1[i] = tmp2;
128tmp2 = sc2[i] + tmp1;
129sc2[i] = tmp1;
130out = (128 + sc3[i] + tmp2) >> 11;
131sc3[i] = tmp2;
132
133out &= 0x1f;
134if ((i > 1) && (j > 1))
135{
136output[i-2] = out | (out << 5) | (out << 10);
137}
138}
139
140if (j > 1)
141{
142output += row;
143}
144}
145free(sc3);
146free(sc2);
147free(sc1);
148free(sc0);
149}
150
151static void PreviewDecompress32(uint32_t * compressBuffer,
152uint32_t width, uint32_t height, uint32_t row,
153uint32_t * output)
154{
155int i, j;
156uint32_t * input;
157
158uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t));
159uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t));
160uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t));
161uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t));
162
163if (!sc0 || !sc1 || !sc2 || !sc3)
164{
165return;
166}
167
168uint32_t sr0, sr1, sr2, sr3;
169
170bzero(sc0, (width+2) * sizeof(uint16_t));
171bzero(sc1, (width+2) * sizeof(uint16_t));
172bzero(sc2, (width+2) * sizeof(uint16_t));
173bzero(sc3, (width+2) * sizeof(uint16_t));
174
175uint32_t tmp1, tmp2, out;
176for (j = 0; j < (height + 2); j++)
177{
178input = compressBuffer;
179if (j < height)
180{
181input += j;
182}
183else
184{
185input += height - 1;
186}
187input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer));
188
189uint32_t data = 0, repeat = 0, fetch = 0, count = 0;
190sr0 = sr1 = sr2 = sr3 = 0;
191
192for (i = 0; i < (width + 2); i++)
193{
194if (i < width)
195{
196if (!count)
197{
198count = *input++;
199repeat = (count & 0xff000000);
200count ^= repeat;
201fetch = true;
202}
203else
204{
205fetch = (0 == repeat);
206}
207
208count--;
209
210if (fetch)
211{
212data = *input++;
213
214// grayscale
215// srgb 13933, 46871, 4732
216// ntsc 19595, 38470, 7471
217data = 13933 * (0xff & (data >> 24))
218+ 46871 * (0xff & (data >> 16))
219+ 4732 * (0xff & data);
220data >>= 16;
221
222// 70% white, 30 % black
223data *= 19661;
224data += (103 << 16);
225data >>= 16;
226}
227}
228
229// gauss blur
230tmp2 = sr0 + data;
231sr0 = data;
232tmp1 = sr1 + tmp2;
233sr1 = tmp2;
234tmp2 = sr2 + tmp1;
235sr2 = tmp1;
236tmp1 = sr3 + tmp2;
237sr3 = tmp2;
238
239tmp2 = sc0[i] + tmp1;
240sc0[i] = tmp1;
241tmp1 = sc1[i] + tmp2;
242sc1[i] = tmp2;
243tmp2 = sc2[i] + tmp1;
244sc2[i] = tmp1;
245out = (128 + sc3[i] + tmp2) >> 8;
246sc3[i] = tmp2;
247
248out &= 0xff;
249if ((i > 1) && (j > 1))
250{
251output[i-2] = out | (out << 8) | (out << 16);
252}
253}
254
255if (j > 1)
256{
257output += row;
258}
259}
260
261free(sc3);
262free(sc2);
263free(sc1);
264free(sc0);
265}
266
267void *
268DecompressData(void *srcbase, int *dw, int *dh, int *bitsPerPixel)
269{
270uint32_t *src = (uint32_t *) srcbase;
271void * ret;
272
273*bitsPerPixel = 8 * ((int) src[0]);
274*dw = (int) src[1];
275*dh = (int) src[2];
276
277ret = malloc ((*dw * *dh * *bitsPerPixel)/ 8);
278
279switch(*bitsPerPixel)
280{
281case 32:
282PreviewDecompress32((uint32_t *)srcbase, *dw, *dh, *dw, ret);
283return ret;
284case 16:
285PreviewDecompress16((uint32_t *)srcbase, *dw, *dh, *dw, ret);
286return ret;
287default:
288return 0;
289}
290}
291

Archive Download this file

Revision: 2642