Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 399