1 | ␊ |
2 | /* Graphic utility functions and data types␊ |
3 | * Prashant Vaibhav (C) 12/12/2008␊ |
4 | * Chameleon␊ |
5 | */␊ |
6 | #include "boot.h"␊ |
7 | #include "graphic_utils.h"␊ |
8 | #include "graphics.h"␊ |
9 | #include "vbe.h"␊ |
10 | #include "gui.h"␊ |
11 | ␊ |
12 | #define VIDEO(x) (bootArgs->Video.v_ ## x)␊ |
13 | ␊ |
14 | #define MIN(x, y) ((x) < (y) ? (x) : (y))␊ |
15 | ␊ |
16 | ␊ |
17 | ␊ |
18 | #ifdef OPTION_ROM␊ |
19 | int␊ |
20 | convertImage( unsigned short width,␊ |
21 | ␉␉␉ unsigned short height,␊ |
22 | ␉␉␉ const unsigned char *imageData,␊ |
23 | ␉␉␉ unsigned char **newImageData )␊ |
24 | {␊ |
25 | int cnt;␊ |
26 | unsigned char *img = 0;␊ |
27 | unsigned short *img16;␊ |
28 | unsigned long *img32;␊ |
29 | ␉␊ |
30 | switch ( VIDEO(depth) ) {␊ |
31 | ␉␉case 16 :␊ |
32 | ␉␉␉img16 = malloc(width * height * 2);␊ |
33 | ␉␉␉if ( !img16 ) break;␊ |
34 | ␉␉␉for (cnt = 0; cnt < (width * height); cnt++)␊ |
35 | ␉␉␉␉img16[cnt] = lookUpCLUTIndex(imageData[cnt], 16);␊ |
36 | ␉␉␉img = (unsigned char *)img16;␊ |
37 | ␉␉␉break;␊ |
38 | ␉␉␉␊ |
39 | ␉␉case 32 :␊ |
40 | ␉␉␉img32 = malloc(width * height * 4);␊ |
41 | ␉␉␉if ( !img32 ) break;␊ |
42 | ␉␉␉for (cnt = 0; cnt < (width * height); cnt++)␊ |
43 | ␉␉␉␉img32[cnt] = lookUpCLUTIndex(imageData[cnt], 32);␊ |
44 | ␉␉␉img = (unsigned char *)img32;␊ |
45 | ␉␉␉break;␊ |
46 | ␉␉␉␊ |
47 | ␉␉default :␊ |
48 | ␉␉␉img = malloc(width * height);␊ |
49 | ␉␉␉bcopy(imageData, img, width * height);␊ |
50 | ␉␉␉break;␊ |
51 | }␊ |
52 | *newImageData = img;␊ |
53 | return 0;␊ |
54 | }␊ |
55 | ␊ |
56 | //==========================================================================␊ |
57 | // drawDataRectangle␊ |
58 | ␊ |
59 | void drawDataRectangle( unsigned short x,␊ |
60 | ␉␉␉␉␉ unsigned short y,␊ |
61 | ␉␉␉␉␉ unsigned short width,␊ |
62 | ␉␉␉␉␉ unsigned short height,␊ |
63 | ␉␉␉␉␉ unsigned char * data )␊ |
64 | {␊ |
65 | unsigned short drawWidth;␊ |
66 | long pixelBytes = VIDEO(depth) / 8;␊ |
67 | unsigned char * vram = (unsigned char *) VIDEO(baseAddr) +␊ |
68 | ␉VIDEO(rowBytes) * y + pixelBytes * x;␊ |
69 | ␉␊ |
70 | drawWidth = MIN(width, VIDEO(width) - x);␊ |
71 | height = MIN(height, VIDEO(height) - y);␊ |
72 | while ( height-- ) {␊ |
73 | bcopy( data, vram, drawWidth * pixelBytes );␊ |
74 | vram += VIDEO(rowBytes);␊ |
75 | data += width * pixelBytes;␊ |
76 | }␊ |
77 | }␊ |
78 | #endif␊ |
79 | ␊ |
80 | ␊ |
81 | //==========================================================================␊ |
82 | //␊ |
83 | void ␊ |
84 | printVBEModeInfo()␊ |
85 | {␊ |
86 | VBEInfoBlock vbeInfo;␊ |
87 | unsigned short * modePtr;␊ |
88 | VBEModeInfoBlock modeInfo;␊ |
89 | int err;␊ |
90 | int line;␊ |
91 | ␉␊ |
92 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
93 | strcpy( (char*)&vbeInfo, "VBE2" );␊ |
94 | err = getVBEInfo( &vbeInfo );␊ |
95 | if ( err != errSuccess )␊ |
96 | return;␊ |
97 | ␉␊ |
98 | line = 0;␊ |
99 | ␉␊ |
100 | // Activate and clear page 1␊ |
101 | setActiveDisplayPage(1);␊ |
102 | clearScreenRows(0, 24);␊ |
103 | setCursorPosition( 0, 0, 1 );␊ |
104 | ␉␊ |
105 | ␉printf("Video modes supported:\n", VBEDecodeFP(const char *, vbeInfo.OEMStringPtr));␊ |
106 | ␉␊ |
107 | ␉// Loop through the mode list, and find the matching mode.␊ |
108 | ␉␊ |
109 | for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );␊ |
110 | ␉␉ *modePtr != modeEndOfList; modePtr++ )␊ |
111 | {␊ |
112 | // Get mode information.␊ |
113 | ␉␉␊ |
114 | bzero( &modeInfo, sizeof(modeInfo) );␊ |
115 | err = getVBEModeInfo( *modePtr, &modeInfo );␊ |
116 | if ( err != errSuccess )␊ |
117 | {␊ |
118 | continue;␊ |
119 | }␊ |
120 | ␉␉␊ |
121 | printf("Mode %x: %dx%dx%d mm:%d attr:%x\n",␊ |
122 | *modePtr, modeInfo.XResolution, modeInfo.YResolution,␊ |
123 | modeInfo.BitsPerPixel, modeInfo.MemoryModel,␊ |
124 | modeInfo.ModeAttributes);␊ |
125 | ␉␉␊ |
126 | if (line++ >= 20) {␊ |
127 | pause();␊ |
128 | line = 0;␊ |
129 | clearScreenRows(0, 24);␊ |
130 | setCursorPosition( 0, 0, 1 );␊ |
131 | }␊ |
132 | } ␊ |
133 | if (line != 0) {␊ |
134 | pause();␊ |
135 | }␊ |
136 | setActiveDisplayPage(0);␊ |
137 | }␊ |
138 | ␊ |
139 | ␊ |
140 | ␊ |
141 | char *getVBEModeInfoString()␊ |
142 | {␊ |
143 | ␉VBEInfoBlock vbeInfo;␊ |
144 | unsigned short * modePtr;␊ |
145 | VBEModeInfoBlock modeInfo;␊ |
146 | int err;␊ |
147 | ␉␊ |
148 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
149 | strcpy( (char*)&vbeInfo, "VBE2" );␊ |
150 | err = getVBEInfo( &vbeInfo );␊ |
151 | if ( err != errSuccess )␊ |
152 | return 0;␊ |
153 | ␉␊ |
154 | ␉char *buff=malloc(sizeof(char)*3072);␊ |
155 | ␉if(!buff) return 0;␊ |
156 | ␉␊ |
157 | ␉// Loop through the mode list, and find the matching mode.␊ |
158 | for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );␊ |
159 | ␉␉ *modePtr != modeEndOfList; modePtr++ )␊ |
160 | {␊ |
161 | // Get mode information.␊ |
162 | ␉␉␊ |
163 | bzero( &modeInfo, sizeof(modeInfo) );␊ |
164 | err = getVBEModeInfo( *modePtr, &modeInfo );␊ |
165 | if ( err != errSuccess )␊ |
166 | {␊ |
167 | continue;␊ |
168 | }␊ |
169 | ␉␉␊ |
170 | sprintf(buff+strlen(buff), "Mode %x: %dx%dx%d mm:%d attr:%x\n",␊ |
171 | ␉␉␉␉*modePtr, modeInfo.XResolution, modeInfo.YResolution,␊ |
172 | ␉␉␉␉modeInfo.BitsPerPixel, modeInfo.MemoryModel,␊ |
173 | ␉␉␉␉modeInfo.ModeAttributes);␊ |
174 | ␉␉␊ |
175 | } ␊ |
176 | ␉return buff;␊ |
177 | }␊ |
178 | ␊ |
179 | ␊ |
180 | void blendImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height,␊ |
181 | ␉␉␉␉uint8_t *data)␊ |
182 | {␊ |
183 | uint16_t drawWidth;␊ |
184 | uint8_t *vram = (uint8_t *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + 4 * x;␊ |
185 | ␉␊ |
186 | drawWidth = MIN(width, VIDEO(width) - x);␊ |
187 | height = MIN(height, VIDEO(height) - y);␊ |
188 | while (height--) {␊ |
189 | ␉␉switch (VIDEO (depth))␊ |
190 | ␉␉{␊ |
191 | ␉␉␉case 32: /* Optimized version*/␊ |
192 | ␉␉␉{␊ |
193 | ␉␉␉␉uint32_t s; uint32_t* d; // Source (img) and destination (bkgd) pixels␊ |
194 | ␉␉␉␉uint32_t a; // Alpha␊ |
195 | ␉␉␉␉uint32_t dstrb, dstg, srcrb, srcg, drb, dg, rb, g, tempB; // Intermediate variables␊ |
196 | ␉␉␉␉uint16_t pos;␊ |
197 | ␉␉␉␉␊ |
198 | ␉␉␉␉for (pos = 0; pos < drawWidth * 4; pos += 4) {␊ |
199 | ␉␉␉␉␉// Fast pseudo-vector alpha blending, adapted from: http://www.stereopsis.com/doubleblend.html␊ |
200 | ␉␉␉␉␉s = *((uint32_t*) (data + pos));␊ |
201 | ␉␉␉␉␉d = (uint32_t*) (vram + pos);␊ |
202 | ␉␉␉␉␉␊ |
203 | ␉␉␉␉␉// Flip B and R in source␊ |
204 | ␉␉␉␉␉// TODO: use XCHG and inline assembly to do this in a faster, saner way␊ |
205 | ␉␉␉␉␉tempB = (s & 0xFF0000); // save B␊ |
206 | ␉␉␉␉␉s = (s & 0xFF00FFFF) | ((s & 0xFF) << 16); // put R in B␊ |
207 | ␉␉␉␉␉s = (s & 0xFFFFFF00) | (tempB >> 16); // put B in R␊ |
208 | ␉␉␉␉␉␊ |
209 | ␉␉␉␉␉a = (s >> 24) + 1;␊ |
210 | ␉␉␉␉␉␊ |
211 | ␉␉␉␉␉dstrb = *d & 0xFF00FF; dstg = *d & 0xFF00;␊ |
212 | ␉␉␉␉␉srcrb = s & 0xFF00FF; srcg = s & 0xFF00;␊ |
213 | ␉␉␉␉␉␊ |
214 | ␉␉␉␉␉drb = srcrb - dstrb;␊ |
215 | ␉␉␉␉␉dg = srcg - dstg;␊ |
216 | ␉␉␉␉␉drb *= a; dg *= a;␊ |
217 | ␉␉␉␉␉drb >>= 8; dg >>= 8;␊ |
218 | ␉␉␉␉␉␊ |
219 | ␉␉␉␉␉rb = (drb + dstrb) & 0xFF00FF;␊ |
220 | ␉␉␉␉␉g = (dg + dstg) & 0xFF00;␊ |
221 | ␉␉␉␉␉␊ |
222 | ␉␉␉␉␉*d = rb | g;␊ |
223 | ␉␉␉␉}␊ |
224 | ␉␉␉}␊ |
225 | ␉␉␉␉break;␊ |
226 | ␉␉␉␉␊ |
227 | ␉␉␉default: /*Universal version*/␊ |
228 | ␉␉␉{␊ |
229 | ␉␉␉␉uint32_t s; ␊ |
230 | ␉␉␉␉uint32_t a; // Alpha␊ |
231 | ␉␉␉␉uint32_t dr, dg, db, sr, sg, sb; // Intermediate variables␊ |
232 | ␉␉␉␉uint16_t pos;␊ |
233 | ␉␉␉␉int bpp = (VIDEO (depth) + 7)/8;␊ |
234 | ␉␉␉␉␊ |
235 | ␉␉␉␉for (pos = 0; pos < drawWidth; pos ++) {␊ |
236 | ␉␉␉␉␉// Fast pseudo-vector alpha blending, adapted from: http://www.stereopsis.com/doubleblend.html␊ |
237 | ␉␉␉␉␉s = *((uint32_t*) (data + 4*pos));␊ |
238 | ␉␉␉␉␉␊ |
239 | ␉␉␉␉␉sb = (s & 0xFF0000) >> 16;␊ |
240 | ␉␉␉␉␉sg = (s & 0xFF00) >> 8;␊ |
241 | ␉␉␉␉␉sr = (s & 0xFF);␊ |
242 | ␉␉␉␉␉␊ |
243 | ␉␉␉␉␉a = (s >> 24) + 1;␊ |
244 | ␉␉␉␉␉␊ |
245 | ␉␉␉␉␉switch (VIDEO (depth))␊ |
246 | ␉␉␉␉␉{␊ |
247 | ␉␉␉␉␉␉case 24:␊ |
248 | ␉␉␉␉␉␉␉db = ((*(uint32_t *)(vram + bpp*pos))&0xff);␊ |
249 | ␉␉␉␉␉␉␉dg = ((*(uint32_t *)(vram + bpp*pos))&0xff00)>>8;␊ |
250 | ␉␉␉␉␉␉␉dr = ((*(uint32_t *)(vram + bpp*pos))&0xff0000)>>16;␊ |
251 | ␉␉␉␉␉␉␉break;␊ |
252 | ␉␉␉␉␉␉case 16://16-bit seems to be 15-bit␊ |
253 | ␉␉␉␉␉␉␉/*␉␉␉␉␉␉␉db = ((*(uint16_t *)(vram + bpp*pos))&0x1f)<<3;␊ |
254 | ␉␉␉␉␉␉␉ dg = ((*(uint16_t *)(vram + bpp*pos))&0x07e0)>>3;␊ |
255 | ␉␉␉␉␉␉␉ dr = ((*(uint16_t *)(vram + bpp*pos))&0xf800)>>8;␊ |
256 | ␉␉␉␉␉␉␉ break;␉␉␉␉␉␉␉*/␊ |
257 | ␉␉␉␉␉␉case 15:␊ |
258 | ␉␉␉␉␉␉␉db = ((*(uint16_t *)(vram + bpp*pos))&0x1f)<<3;␊ |
259 | ␉␉␉␉␉␉␉dg = ((*(uint16_t *)(vram + bpp*pos))&0x03e0)>>2;␊ |
260 | ␉␉␉␉␉␉␉dr = ((*(uint16_t *)(vram + bpp*pos))&0x7c00)>>7;␊ |
261 | ␉␉␉␉␉␉␉break;␉␉␊ |
262 | ␉␉␉␉␉␉default:␊ |
263 | ␉␉␉␉␉␉␉return;␊ |
264 | ␉␉␉␉␉}␊ |
265 | ␉␉␉␉␉␊ |
266 | ␉␉␉␉␉dr = (((sr - dr) * a) >> 8) + dr;␊ |
267 | ␉␉␉␉␉dg = (((sg - dg) * a) >> 8) + dg;␊ |
268 | ␉␉␉␉␉db = (((sb - db) * a) >> 8) + db;␊ |
269 | ␉␉␉␉␉switch (VIDEO (depth))␊ |
270 | ␉␉␉␉␉{␊ |
271 | ␉␉␉␉␉␉case 24:␊ |
272 | ␉␉␉␉␉␉␉*(uint32_t *)(vram + bpp*pos) = (*(uint32_t *)(vram + bpp*pos) &0xff000000)␊ |
273 | ␉␉␉␉␉␉␉| (db&0xff) | ((dg&0xff)<<8) | ((dr&0xff)<<16);␊ |
274 | ␉␉␉␉␉␉␉break;␊ |
275 | ␉␉␉␉␉␉case 16:␊ |
276 | ␉␉␉␉␉␉␉//␉␉␉␉␉␉␉*(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xfc)<<3) | ((dr&0xf8)<<8);␊ |
277 | ␉␉␉␉␉␉␉//␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
278 | ␉␉␉␉␉␉case 15:␊ |
279 | ␉␉␉␉␉␉␉*(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xf8)<<2) | ((dr&0xf8)<<7);␊ |
280 | ␉␉␉␉␉␉␉break;␉␊ |
281 | ␉␉␉␉␉␉default:␊ |
282 | ␉␉␉␉␉␉␉break;␊ |
283 | ␉␉␉␉␉}␊ |
284 | ␉␉␉␉␉␊ |
285 | ␉␉␉␉}␉␉␉␉␊ |
286 | ␉␉␉}␊ |
287 | ␉␉␉␉break;␊ |
288 | }␊ |
289 | vram += VIDEO(rowBytes);␊ |
290 | data += width * 4;␊ |
291 | }␊ |
292 | }␊ |
293 | ␊ |
294 | void drawCheckerBoard()␊ |
295 | {␊ |
296 | uint32_t *vram = (uint32_t *) VIDEO(baseAddr);␊ |
297 | uint16_t x, y;␊ |
298 | uint8_t color;␊ |
299 | ␉␊ |
300 | for (y = 0; y < VIDEO(height); y++, vram += VIDEO(width)) {␊ |
301 | for (x = 0; x < VIDEO(width); x++) {␊ |
302 | color = 204 + 51 * (((x / 8) % 2) == ((y / 8) % 2));␊ |
303 | vram[x] = (color << 16) | (color << 8) | color;␊ |
304 | }␊ |
305 | }␊ |
306 | }␊ |
307 | ␊ |
308 | void getGraphicModeParams(unsigned long params[]) {␊ |
309 | ␉␊ |
310 | ␉params[3] = 0;␊ |
311 | ␉␊ |
312 | ␉VBEModeInfoBlock minfo;␊ |
313 | ␉␊ |
314 | unsigned short vesaVersion;␊ |
315 | unsigned short mode = modeEndOfList;␊ |
316 | ␉␊ |
317 | ␉getNumberArrayFromProperty( kGraphicsModeKey, params, 4);␊ |
318 | ␉␊ |
319 | ␉mode = getVESAModeWithProperties( params[0], params[1], params[2],␊ |
320 | ␉␉␉␉␉␉␉␉␉ maColorModeBit |␊ |
321 | ␉␉␉␉␉␉␉␉␉ maModeIsSupportedBit |␊ |
322 | ␉␉␉␉␉␉␉␉␉ maGraphicsModeBit |␊ |
323 | ␉␉␉␉␉␉␉␉␉ maLinearFrameBufferAvailBit,␊ |
324 | ␉␉␉␉␉␉␉␉␉ 0,␊ |
325 | ␉␉␉␉␉␉␉␉␉ &minfo, &vesaVersion );␊ |
326 | ␉␊ |
327 | ␉params[0] = minfo.XResolution;␊ |
328 | ␉params[1] = minfo.YResolution;␊ |
329 | ␉params[2] = 32;␊ |
330 | }␊ |
331 | ␊ |
332 | ␊ |
333 | //==========================================================================␊ |
334 | // getVBEInfoString␊ |
335 | ␊ |
336 | char *getVBEInfoString()␊ |
337 | {␊ |
338 | ␉VBEInfoBlock vbeInfo;␊ |
339 | ␉int err, small;␊ |
340 | ␉char *buff = malloc(sizeof(char)*256);␊ |
341 | ␉if(!buff) return 0;␊ |
342 | ␉␊ |
343 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
344 | ␉strcpy( (char*)&vbeInfo, "VBE2" );␊ |
345 | ␉err = getVBEInfo( &vbeInfo );␊ |
346 | ␉if (err != errSuccess)␊ |
347 | ␉␉return 0;␊ |
348 | ␉␊ |
349 | ␉if ( strncmp( (char *)vbeInfo.VESASignature, "VESA", 4 ) )␊ |
350 | ␉␉return 0;␊ |
351 | ␉␊ |
352 | ␉small = (vbeInfo.TotalMemory < 16);␊ |
353 | ␉␊ |
354 | ␉sprintf(buff, "VESA v%d.%d %d%s (%s)\n",␊ |
355 | ␉␉␉vbeInfo.VESAVersion >> 8,␊ |
356 | ␉␉␉vbeInfo.VESAVersion & 0xf,␊ |
357 | ␉␉␉small ? (vbeInfo.TotalMemory * 64) : (vbeInfo.TotalMemory / 16),␊ |
358 | ␉␉␉small ? "KB" : "MB",␊ |
359 | ␉␉␉VBEDecodeFP(const char *, vbeInfo.OEMStringPtr) );␊ |
360 | ␉␊ |
361 | ␉return buff;␊ |
362 | }␊ |
363 | ␊ |
364 | void blend( const pixmap_t *blendThis, // Source image␊ |
365 | ␉␉ pixmap_t *blendInto, // Dest image␊ |
366 | ␉␉ const position_t position) // Where to place the source image␊ |
367 | {␊ |
368 | uint16_t sx, sy, dx, dy;␊ |
369 | uint32_t dstrb, dstag, srcrb, srcag, drb, dag, rb, ag, alpha;␊ |
370 | ␉␊ |
371 | ␉uint16_t width = (blendThis->width + position.x < blendInto->width) ? blendThis->width: blendInto->width-position.x;␊ |
372 | ␉uint16_t height = (blendThis->height + position.y < blendInto->height) ? blendThis->height: blendInto->height-position.y;␊ |
373 | ␉␊ |
374 | ␉for (dy = position.y, sy = 0; sy < height; dy++, sy++) ␊ |
375 | ␉{␊ |
376 | for (dx = position.x, sx = 0; sx < width; dx++, sx++) ␊ |
377 | ␉␉{␊ |
378 | alpha = (pixel(blendThis, sx, sy).ch.a);␊ |
379 | ␉␉␉␊ |
380 | ␉␉␉/* Skip blending for fully transparent pixel */␊ |
381 | ␉␉␉if (alpha == 0) continue;␊ |
382 | ␉␉␉␊ |
383 | ␉␉␉/* For fully opaque pixel, there is no need to interpolate */␊ |
384 | ␉␉␉if (alpha == 255)␊ |
385 | ␉␉␉{␊ |
386 | ␉␉␉␉pixel(blendInto, dx, dy).value = pixel(blendThis, sx, sy).value;␊ |
387 | ␉␉␉␉continue;␊ |
388 | ␉␉␉}␊ |
389 | ␉␉␉␊ |
390 | ␉␉␉/* For semi-transparent pixels, do a full blend */␊ |
391 | ␉␉␉//alpha++␊ |
392 | ␉␉␉/* This is needed to spread the alpha over [0..256] instead of [0..255]␊ |
393 | ␉␉␉ Boundary conditions were handled above */␊ |
394 | dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;␊ |
395 | dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;␊ |
396 | srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;␊ |
397 | srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;␊ |
398 | drb = srcrb - dstrb;␊ |
399 | dag = srcag - dstag;␊ |
400 | drb *= alpha; dag *= alpha;␊ |
401 | drb >>= 8; dag >>= 8;␊ |
402 | rb = (drb + dstrb) & 0x00FF00FF;␊ |
403 | ag = ((dag + dstag) << 8) & 0xFF00FF00;␊ |
404 | pixel(blendInto, dx, dy).value = (rb | ag);␊ |
405 | }␊ |
406 | }␊ |
407 | }␊ |
408 | ␊ |
409 | position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter )␊ |
410 | {␊ |
411 | position_t centered;␊ |
412 | centered.x = ( background->width - toCenter->width ) / 2;␊ |
413 | centered.y = ( background->height - toCenter->height ) / 2;␊ |
414 | return centered;␊ |
415 | }␊ |
416 | ␊ |
417 | position_t centeredAt( const pixmap_t *pixmap, const position_t center )␊ |
418 | {␊ |
419 | position_t topleft;␊ |
420 | topleft.x = center.x - (pixmap->width / 2);␊ |
421 | topleft.y = center.y - (pixmap->height / 2);␊ |
422 | return topleft;␊ |
423 | }␊ |
424 | ␊ |
425 | position_t pos(const uint16_t x, const uint16_t y) { position_t p; p.x = x; p.y = y; return p; }␊ |
426 | ␊ |
427 | void flipRB(pixmap_t *p)␊ |
428 | {␊ |
429 | ␉//if(testForQemu()) return;␊ |
430 | ␉␊ |
431 | ␉uint32_t x;␊ |
432 | register uint8_t tempB;␊ |
433 | ␉for (x = 0; x < (unsigned long)(p->height) * (p->width) ; x++) {␊ |
434 | ␉␉tempB = (p->pixels[x]).ch.b;␊ |
435 | (p->pixels[x]).ch.b = (p->pixels[x]).ch.r;␊ |
436 | (p->pixels[x]).ch.r = tempB;␊ |
437 | ␉}␊ |
438 | }␊ |
439 | |