Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c

1
2/* Graphic utility functions and data types
3 * Prashant Vaibhav (C) 12/12/2008
4 * Chameleon
5 */
6
7#include "graphic_utils.h"
8#include "graphics.h"
9#include "IOHibernatePrivate.h"
10#include "bmdecompress.h"
11
12#define VIDEO(x) (bootArgs->Video.v_ ## x)
13
14//#define MIN(x, y) ((x) < (y) ? (x) : (y))
15
16int previewTotalSectors = 0;
17uint8_t *previewSaveunder = 0;
18int previewLoadedSectors = 0;
19
20void
21loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or)
22{
23int x,y, off;
24int red=0x7f, green=0x7f, blue=0x7f;
25for (x=0;x<ow;x++)
26for (y=0;y<oh;y++)
27{
28off=(x*iw)/ow+((y*ih)/oh)*iw;
29switch (ip)
30{
31case 16:
32{
33uint16_t val;
34val=((uint16_t *)input)[off];
35red=(val>>7)&0xf8;
36green=(val>>2)&0xf8;
37blue=(val<<3)&0xf8;
38break;
39}
40case 32:
41{
42uint32_t val;
43val=((uint32_t *)input)[off];
44red=(val>>16)&0xff;
45green=(val>>8)&0xff;
46blue=(val)&0xff;
47break;
48}
49default:
50break;
51}
52char *ptr=(char *)output+x*(op/8)+y*or;
53switch (op)
54{
55case 16:
56*((uint16_t *)ptr) = ((red & 0xF8) << 7) |
57((green & 0xF8) << 2) |
58((blue & 0xF8) >> 3);
59break;
60case 32 :
61*((uint32_t *)ptr) = (red << 16) | (green << 8) | blue;
62break;
63default:
64break;
65}
66}
67}
68
69DECLARE_IOHIBERNATEPROGRESSALPHA
70
71void drawPreview(void *src, uint8_t * saveunder)
72{
73uint8_t * screen;
74uint32_t rowBytes, pixelShift;
75uint32_t x, y;
76int32_t blob;
77uint32_t alpha, in, color, result;
78uint8_t * out;
79void *uncomp;
80int origwidth, origheight, origbpx;
81uint32_t saveindex[kIOHibernateProgressCount] = { 0 };
82
83if (src && (uncomp=DecompressData(src, &origwidth, &origheight, &origbpx)))
84{
85#if UNUSED
86if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0))
87#else
88if (!setVESAGraphicsMode(origwidth, origheight, origbpx))
89#endif
90if (initGraphicsMode () != errSuccess)
91return;
92screen = (uint8_t *) VIDEO (baseAddr);
93rowBytes = VIDEO (rowBytes);
94loadImageScale (uncomp, origwidth, origheight, origbpx, screen, VIDEO(width), VIDEO(height), VIDEO(depth), VIDEO (rowBytes));
95}
96else
97{
98if (initGraphicsMode () != errSuccess)
99return;
100screen = (uint8_t *) VIDEO (baseAddr);
101rowBytes = VIDEO (rowBytes);
102// Set the screen to 75% grey.
103 drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01 /* color index */);
104}
105
106
107pixelShift = VIDEO (depth) >> 4;
108if (pixelShift < 1) return;
109
110screen += ((VIDEO (width)
111- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))
112+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;
113
114for (y = 0; y < kIOHibernateProgressHeight; y++)
115{
116out = screen + y * rowBytes;
117for (blob = 0; blob < kIOHibernateProgressCount; blob++)
118{
119color = blob ? kIOHibernateProgressDarkGray : kIOHibernateProgressMidGray;
120for (x = 0; x < kIOHibernateProgressWidth; x++)
121{
122alpha = gIOHibernateProgressAlpha[y][x];
123result = color;
124if (alpha)
125{
126if (0xff != alpha)
127{
128if (1 == pixelShift)
129{
130in = *((uint16_t *)out) & 0x1f;// 16
131in = (in << 3) | (in >> 2);
132}
133else
134in = *((uint32_t *)out) & 0xff;// 32
135saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++] = in;
136result = ((255 - alpha) * in + alpha * result + 0xff) >> 8;
137}
138if (1 == pixelShift)
139{
140result >>= 3;
141*((uint16_t *)out) = (result << 10) | (result << 5) | result;// 16
142}
143else
144*((uint32_t *)out) = (result << 16) | (result << 8) | result;// 32
145}
146out += (1 << pixelShift);
147}
148out += (kIOHibernateProgressSpacing << pixelShift);
149}
150}
151}
152
153void updateProgressBar(uint8_t * saveunder, int32_t firstBlob, int32_t select)
154{
155uint8_t * screen;
156uint32_t rowBytes, pixelShift;
157uint32_t x, y;
158int32_t blob, lastBlob;
159uint32_t alpha, in, color, result;
160uint8_t * out;
161uint32_t saveindex[kIOHibernateProgressCount] = { 0 };
162
163pixelShift = VIDEO(depth) >> 4;
164if (pixelShift < 1) return;
165screen = (uint8_t *) VIDEO (baseAddr);
166rowBytes = VIDEO (rowBytes);
167
168screen += ((VIDEO (width)
169- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))
170+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;
171
172lastBlob = (select < kIOHibernateProgressCount) ? select : (kIOHibernateProgressCount - 1);
173
174screen += (firstBlob * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << pixelShift;
175
176for (y = 0; y < kIOHibernateProgressHeight; y++)
177{
178out = screen + y * rowBytes;
179for (blob = firstBlob; blob <= lastBlob; blob++)
180{
181color = (blob < select) ? kIOHibernateProgressLightGray : kIOHibernateProgressMidGray;
182for (x = 0; x < kIOHibernateProgressWidth; x++)
183{
184alpha = gIOHibernateProgressAlpha[y][x];
185result = color;
186if (alpha)
187{
188if (0xff != alpha)
189{
190in = saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++];
191result = ((255 - alpha) * in + alpha * result + 0xff) / 255;
192}
193if (1 == pixelShift)
194{
195result >>= 3;
196*((uint16_t *)out) = (result << 10) | (result << 5) | result;// 16
197}
198else
199*((uint32_t *)out) = (result << 16) | (result << 8) | result;// 32
200}
201out += (1 << pixelShift);
202}
203out += (kIOHibernateProgressSpacing << pixelShift);
204}
205}
206}
207
208void
209spinActivityIndicator_hook(void *arg1, void *arg2, void *arg3, void *arg4, void* arg5, void* arg6)
210{
211int sectors = *(int*)arg1;
212bool *doreturn = (bool*)arg2;
213
214if (previewTotalSectors && previewSaveunder)
215{
216int blob, lastBlob;
217
218lastBlob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;
219previewLoadedSectors+=sectors;
220blob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;
221
222if (blob!=lastBlob)
223updateProgressBar (previewSaveunder, lastBlob, blob);
224*doreturn = true;
225}
226}

Archive Download this file

Revision: 1119