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