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

Archive Download this file

Revision: 2527