Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/i386/boot2/bmdecompress.c

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

Archive Download this file

Revision: 307