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}
49}
50char *ptr=(char *)output+x*(op/8)+y*or;
51switch (op)
52{
53case 16:
54*((uint16_t *)ptr) = ((red & 0xF8) << 7) |
55((green & 0xF8) << 2) |
56((blue & 0xF8) >> 3);
57break;
58case 32 :
59*((uint32_t *)ptr) = (red << 16) | (green << 8) | blue;
60break;
61}
62}
63}
64
65DECLARE_IOHIBERNATEPROGRESSALPHA
66
67void drawPreview(void *src, uint8_t * saveunder)
68{
69uint8_t * screen;
70uint32_t rowBytes, pixelShift;
71uint32_t x, y;
72int32_t blob;
73uint32_t alpha, in, color, result;
74uint8_t * out;
75void *uncomp;
76int origwidth, origheight, origbpx;
77uint32_t saveindex[kIOHibernateProgressCount] = { 0 };
78
79if (src && (uncomp=DecompressData(src, &origwidth, &origheight, &origbpx)))
80{
81if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0))
82if (initGraphicsMode () != errSuccess)
83return;
84screen = (uint8_t *) VIDEO (baseAddr);
85rowBytes = VIDEO (rowBytes);
86loadImageScale (uncomp, origwidth, origheight, origbpx, screen, VIDEO(width), VIDEO(height), VIDEO(depth), VIDEO (rowBytes));
87}
88else
89{
90if (initGraphicsMode () != errSuccess)
91return;
92screen = (uint8_t *) VIDEO (baseAddr);
93rowBytes = VIDEO (rowBytes);
94// Set the screen to 75% grey.
95 drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01 /* color index */);
96}
97
98
99pixelShift = VIDEO (depth) >> 4;
100if (pixelShift < 1) return;
101
102screen += ((VIDEO (width)
103- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))
104+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;
105
106for (y = 0; y < kIOHibernateProgressHeight; y++)
107{
108out = screen + y * rowBytes;
109for (blob = 0; blob < kIOHibernateProgressCount; blob++)
110{
111color = blob ? kIOHibernateProgressDarkGray : kIOHibernateProgressMidGray;
112for (x = 0; x < kIOHibernateProgressWidth; x++)
113{
114alpha = gIOHibernateProgressAlpha[y][x];
115result = color;
116if (alpha)
117{
118if (0xff != alpha)
119{
120if (1 == pixelShift)
121{
122in = *((uint16_t *)out) & 0x1f;// 16
123in = (in << 3) | (in >> 2);
124}
125else
126in = *((uint32_t *)out) & 0xff;// 32
127saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++] = in;
128result = ((255 - alpha) * in + alpha * result + 0xff) >> 8;
129}
130if (1 == pixelShift)
131{
132result >>= 3;
133*((uint16_t *)out) = (result << 10) | (result << 5) | result;// 16
134}
135else
136*((uint32_t *)out) = (result << 16) | (result << 8) | result;// 32
137}
138out += (1 << pixelShift);
139}
140out += (kIOHibernateProgressSpacing << pixelShift);
141}
142}
143}
144
145void updateProgressBar(uint8_t * saveunder, int32_t firstBlob, int32_t select)
146{
147uint8_t * screen;
148uint32_t rowBytes, pixelShift;
149uint32_t x, y;
150int32_t blob, lastBlob;
151uint32_t alpha, in, color, result;
152uint8_t * out;
153uint32_t saveindex[kIOHibernateProgressCount] = { 0 };
154
155pixelShift = VIDEO(depth) >> 4;
156if (pixelShift < 1) return;
157screen = (uint8_t *) VIDEO (baseAddr);
158rowBytes = VIDEO (rowBytes);
159
160screen += ((VIDEO (width)
161- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))
162+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;
163
164lastBlob = (select < kIOHibernateProgressCount) ? select : (kIOHibernateProgressCount - 1);
165
166screen += (firstBlob * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << pixelShift;
167
168for (y = 0; y < kIOHibernateProgressHeight; y++)
169{
170out = screen + y * rowBytes;
171for (blob = firstBlob; blob <= lastBlob; blob++)
172{
173color = (blob < select) ? kIOHibernateProgressLightGray : kIOHibernateProgressMidGray;
174for (x = 0; x < kIOHibernateProgressWidth; x++)
175{
176alpha = gIOHibernateProgressAlpha[y][x];
177result = color;
178if (alpha)
179{
180if (0xff != alpha)
181{
182in = saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++];
183result = ((255 - alpha) * in + alpha * result + 0xff) / 255;
184}
185if (1 == pixelShift)
186{
187result >>= 3;
188*((uint16_t *)out) = (result << 10) | (result << 5) | result;// 16
189}
190else
191*((uint32_t *)out) = (result << 16) | (result << 8) | result;// 32
192}
193out += (1 << pixelShift);
194}
195out += (kIOHibernateProgressSpacing << pixelShift);
196}
197}
198}
199
200void
201spinActivityIndicator_hook(void *arg1, void *arg2, void *arg3, void *arg4, void* arg5, void* arg6)
202{
203int sectors = *(int*)arg1;
204bool *doreturn = (bool*)arg2;
205
206if (previewTotalSectors && previewSaveunder)
207{
208int blob, lastBlob;
209
210lastBlob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;
211previewLoadedSectors+=sectors;
212blob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;
213
214if (blob!=lastBlob)
215updateProgressBar (previewSaveunder, lastBlob, blob);
216*doreturn = true;
217}
218}

Archive Download this file

Revision: 789