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