Skip to content

Latest commit

 

History

History
747 lines (634 loc) · 16.9 KB

SDL_atarigl.c

File metadata and controls

747 lines (634 loc) · 16.9 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
/* Atari OSMesa.ldg implementation of SDL OpenGL support */
/*--- Includes ---*/
Nov 26, 2004
Nov 26, 2004
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
30
31
32
33
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
Nov 26, 2004
Nov 26, 2004
34
35
#include <mint/osbind.h>
36
37
38
39
#include "SDL_video.h"
#include "SDL_error.h"
#include "SDL_endian.h"
#include "SDL_atarigl_c.h"
Nov 26, 2004
Nov 26, 2004
40
41
42
43
44
#ifdef ENABLE_OSMESA_SHARED
#include "SDL_loadso.h"
#endif
/*--- Defines ---*/
Nov 26, 2004
Nov 26, 2004
46
47
48
#define PATH_OSMESA_LDG "osmesa.ldg"
#define PATH_MESAGL_LDG "mesa_gl.ldg"
#define PATH_TINYGL_LDG "tiny_gl.ldg"
49
50
51
/*--- Functions prototypes ---*/
Nov 26, 2004
Nov 26, 2004
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
static void SDL_AtariGL_UnloadLibrary(_THIS);
static void CopyShadowNull(_THIS, SDL_Surface *surface);
static void CopyShadowDirect(_THIS, SDL_Surface *surface);
static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
static void ConvertNull(_THIS, SDL_Surface *surface);
static void Convert565To555be(_THIS, SDL_Surface *surface);
static void Convert565To555le(_THIS, SDL_Surface *surface);
static void Convert565le(_THIS, SDL_Surface *surface);
static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
static int InitNew(_THIS, SDL_Surface *current);
static int InitOld(_THIS, SDL_Surface *current);
67
68
69
70
71
72
/*--- Public functions ---*/
int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
{
#ifdef HAVE_OPENGL
Nov 26, 2004
Nov 26, 2004
73
74
75
76
if (gl_oldmesa) {
gl_active = InitOld(this, current);
} else {
gl_active = InitNew(this, current);
Nov 26, 2004
Nov 26, 2004
78
#endif
79
80
81
82
return (gl_active);
}
Nov 26, 2004
Nov 26, 2004
83
void SDL_AtariGL_Quit(_THIS, SDL_bool unload)
84
85
{
#ifdef HAVE_OPENGL
Nov 26, 2004
Nov 26, 2004
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
if (gl_oldmesa) {
/* Old mesa implementations */
if (this->gl_data->OSMesaDestroyLDG) {
this->gl_data->OSMesaDestroyLDG();
}
if (gl_shadow) {
Mfree(gl_shadow);
gl_shadow = NULL;
}
} else {
/* New mesa implementation */
if (gl_ctx) {
if (this->gl_data->OSMesaDestroyContext) {
this->gl_data->OSMesaDestroyContext(gl_ctx);
}
gl_ctx = NULL;
}
}
Nov 26, 2004
Nov 26, 2004
105
106
107
if (unload) {
SDL_AtariGL_UnloadLibrary(this);
}
Nov 26, 2004
Nov 26, 2004
108
109
#endif /* HAVE_OPENGL */
110
111
112
113
114
115
gl_active = 0;
}
int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
{
#ifdef HAVE_OPENGL
Nov 26, 2004
Nov 26, 2004
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifdef ENABLE_OSMESA_SHARED
void *handle;
if (gl_active) {
SDL_SetError("OpenGL context already created");
return -1;
}
/* Unload previous driver */
SDL_AtariGL_UnloadLibrary(this);
/* Load library given by path */
handle = SDL_LoadObject(path);
if (handle == NULL) {
/* Try to load another one */
path = getenv("SDL_VIDEO_GL_DRIVER");
if ( path != NULL ) {
handle = SDL_LoadObject(path);
}
/* If it does not work, try some other */
if (handle == NULL) {
path = PATH_OSMESA_LDG;
handle = SDL_LoadObject(path);
}
if (handle == NULL) {
path = PATH_MESAGL_LDG;
handle = SDL_LoadObject(path);
}
if (handle == NULL) {
path = PATH_TINYGL_LDG;
handle = SDL_LoadObject(path);
}
}
if (handle == NULL) {
SDL_SetError("Could not load OpenGL library");
return -1;
}
/* Load functions pointers (osmesa.ldg) */
this->gl_data->OSMesaCreateContextExt = SDL_LoadFunction(handle, "OSMesaCreateContextExt");
this->gl_data->OSMesaDestroyContext = SDL_LoadFunction(handle, "OSMesaDestroyContext");
this->gl_data->OSMesaMakeCurrent = SDL_LoadFunction(handle, "OSMesaMakeCurrent");
this->gl_data->OSMesaPixelStore = SDL_LoadFunction(handle, "OSMesaPixelStore");
this->gl_data->OSMesaGetProcAddress = SDL_LoadFunction(handle, "OSMesaGetProcAddress");
this->gl_data->glGetIntegerv = SDL_LoadFunction(handle, "glGetIntegerv");
/* Load old functions pointers (mesa_gl.ldg, tiny_gl.ldg) */
this->gl_data->OSMesaCreateLDG = SDL_LoadFunction(handle, "OSMesaCreateLDG");
this->gl_data->OSMesaDestroyLDG = SDL_LoadFunction(handle, "OSMesaDestroyLDG");
gl_oldmesa = 0;
if ( (this->gl_data->OSMesaCreateContextExt == NULL) ||
(this->gl_data->OSMesaDestroyContext == NULL) ||
(this->gl_data->OSMesaMakeCurrent == NULL) ||
(this->gl_data->OSMesaPixelStore == NULL) ||
(this->gl_data->glGetIntegerv == NULL) ||
(this->gl_data->OSMesaGetProcAddress == NULL)) {
/* Hum, maybe old library ? */
if ( (this->gl_data->OSMesaCreateLDG == NULL) ||
(this->gl_data->OSMesaDestroyLDG == NULL)) {
SDL_SetError("Could not retrieve OpenGL functions");
return -1;
} else {
gl_oldmesa = 1;
}
}
this->gl_config.dll_handle = handle;
if ( path ) {
strncpy(this->gl_config.driver_path, path,
sizeof(this->gl_config.driver_path)-1);
} else {
strcpy(this->gl_config.driver_path, "");
}
197
#endif
Nov 26, 2004
Nov 26, 2004
198
199
this->gl_config.driver_loaded = 1;
200
return 0;
Nov 26, 2004
Nov 26, 2004
201
202
203
#else
return -1;
#endif
204
205
206
207
208
209
}
void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
{
void *func = NULL;
#ifdef HAVE_OPENGL
Nov 26, 2004
Nov 26, 2004
210
211
212
213
214
if (this->gl_config.dll_handle) {
func = SDL_LoadFunction(this->gl_config.dll_handle, (void *)proc);
} else if (this->gl_data->OSMesaGetProcAddress) {
func = this->gl_data->OSMesaGetProcAddress(proc);
Nov 26, 2004
Nov 26, 2004
216
217
218
219
220
221
222
223
224
225
226
#endif
return func;
}
int SDL_AtariGL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
{
#ifdef HAVE_OPENGL
GLenum mesa_attrib;
SDL_Surface *surface;
Nov 26, 2004
Nov 26, 2004
227
228
229
230
231
232
233
if (this->gl_config.dll_handle) {
if (this->gl_data->glGetIntegerv == NULL) {
return -1;
}
}
if (!gl_active) {
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
return -1;
}
switch(attrib) {
case SDL_GL_RED_SIZE:
mesa_attrib = GL_RED_BITS;
break;
case SDL_GL_GREEN_SIZE:
mesa_attrib = GL_GREEN_BITS;
break;
case SDL_GL_BLUE_SIZE:
mesa_attrib = GL_BLUE_BITS;
break;
case SDL_GL_ALPHA_SIZE:
mesa_attrib = GL_ALPHA_BITS;
break;
case SDL_GL_DOUBLEBUFFER:
surface = this->screen;
*value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF);
return 0;
case SDL_GL_DEPTH_SIZE:
mesa_attrib = GL_DEPTH_BITS;
break;
case SDL_GL_STENCIL_SIZE:
mesa_attrib = GL_STENCIL_BITS;
break;
case SDL_GL_ACCUM_RED_SIZE:
mesa_attrib = GL_ACCUM_RED_BITS;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
mesa_attrib = GL_ACCUM_GREEN_BITS;
break;
case SDL_GL_ACCUM_BLUE_SIZE:
mesa_attrib = GL_ACCUM_BLUE_BITS;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
mesa_attrib = GL_ACCUM_ALPHA_BITS;
break;
default :
return -1;
}
Nov 26, 2004
Nov 26, 2004
276
this->gl_data->glGetIntegerv(mesa_attrib, value);
277
278
279
280
281
282
283
284
285
286
287
288
return 0;
#else
return -1;
#endif
}
int SDL_AtariGL_MakeCurrent(_THIS)
{
#ifdef HAVE_OPENGL
SDL_Surface *surface;
GLenum type;
Nov 26, 2004
Nov 26, 2004
289
290
291
292
293
294
295
296
297
298
299
300
if (gl_oldmesa && gl_active) {
return 0;
}
if (this->gl_config.dll_handle) {
if ((this->gl_data->OSMesaMakeCurrent == NULL) ||
(this->gl_data->OSMesaPixelStore == NULL)) {
return -1;
}
}
if (!gl_active) {
301
302
303
304
305
306
307
308
309
310
311
312
SDL_SetError("Invalid OpenGL context");
return -1;
}
surface = this->screen;
if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
type = GL_UNSIGNED_SHORT_5_6_5;
} else {
type = GL_UNSIGNED_BYTE;
}
Nov 26, 2004
Nov 26, 2004
313
if (!(this->gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h))) {
314
315
316
317
318
SDL_SetError("Can not make OpenGL context current");
return -1;
}
/* OSMesa draws upside down */
Nov 26, 2004
Nov 26, 2004
319
this->gl_data->OSMesaPixelStore(OSMESA_Y_UP, 0);
320
321
322
323
324
325
326
327
328
329
return 0;
#else
return -1;
#endif
}
void SDL_AtariGL_SwapBuffers(_THIS)
{
#ifdef HAVE_OPENGL
Nov 26, 2004
Nov 26, 2004
330
331
332
if (gl_active) {
gl_copyshadow(this, this->screen);
gl_convert(this, this->screen);
Nov 26, 2004
Nov 26, 2004
334
335
#endif
}
Nov 26, 2004
Nov 26, 2004
337
338
339
340
341
342
343
344
345
void SDL_AtariGL_InitPointers(_THIS)
{
#if defined(HAVE_OPENGL)
this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
this->gl_data->glGetIntegerv = glGetIntegerv;
346
347
348
349
350
#endif
}
/*--- Private functions ---*/
Nov 26, 2004
Nov 26, 2004
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
static void SDL_AtariGL_UnloadLibrary(_THIS)
{
#if defined(HAVE_OPENGL)
if (this->gl_config.dll_handle) {
SDL_UnloadObject(this->gl_config.dll_handle);
this->gl_config.dll_handle = NULL;
/* Restore pointers to static library */
this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
this->gl_data->glGetIntegerv = glGetIntegerv;
this->gl_data->OSMesaCreateLDG = NULL;
this->gl_data->OSMesaDestroyLDG = NULL;
}
#endif
}
/*--- Creation of an OpenGL context using new/old functions ---*/
static int InitNew(_THIS, SDL_Surface *current)
{
GLenum osmesa_format;
SDL_PixelFormat *pixel_format;
Uint32 redmask;
Nov 26, 2004
Nov 26, 2004
379
380
int recreatecontext;
GLint newaccumsize;
Nov 26, 2004
Nov 26, 2004
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
if (this->gl_config.dll_handle) {
if (this->gl_data->OSMesaCreateContextExt == NULL) {
return 0;
}
}
/* Init OpenGL context using OSMesa */
gl_convert = ConvertNull;
gl_copyshadow = CopyShadowNull;
pixel_format = current->format;
redmask = pixel_format->Rmask;
switch (pixel_format->BitsPerPixel) {
case 15:
/* 1555, big and little endian, unsupported */
gl_pixelsize = 2;
osmesa_format = OSMESA_RGB_565;
if (redmask == 31<<10) {
gl_convert = Convert565To555be;
} else {
gl_convert = Convert565To555le;
}
break;
case 16:
gl_pixelsize = 2;
if (redmask == 31<<11) {
osmesa_format = OSMESA_RGB_565;
} else {
/* 565, little endian, unsupported */
osmesa_format = OSMESA_RGB_565;
gl_convert = Convert565le;
}
break;
case 24:
gl_pixelsize = 3;
if (redmask == 255<<16) {
osmesa_format = OSMESA_RGB;
} else {
osmesa_format = OSMESA_BGR;
}
break;
case 32:
gl_pixelsize = 4;
if (redmask == 255<<16) {
osmesa_format = OSMESA_ARGB;
} else if (redmask == 255<<8) {
osmesa_format = OSMESA_BGRA;
} else if (redmask == 255<<24) {
osmesa_format = OSMESA_RGBA;
} else {
/* ABGR format unsupported */
osmesa_format = OSMESA_BGRA;
gl_convert = ConvertBGRAToABGR;
}
break;
default:
gl_pixelsize = 1;
osmesa_format = OSMESA_COLOR_INDEX;
break;
}
Nov 26, 2004
Nov 26, 2004
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/* Try to keep current context if possible */
newaccumsize =
this->gl_config.accum_red_size +
this->gl_config.accum_green_size +
this->gl_config.accum_blue_size +
this->gl_config.accum_alpha_size;
recreatecontext=1;
if (gl_ctx &&
(gl_curformat == osmesa_format) &&
(gl_curdepth == this->gl_config.depth_size) &&
(gl_curstencil == this->gl_config.stencil_size) &&
(gl_curaccum == newaccumsize)) {
recreatecontext = 0;
}
if (recreatecontext) {
SDL_AtariGL_Quit(this, SDL_FALSE);
gl_ctx = this->gl_data->OSMesaCreateContextExt(
osmesa_format, this->gl_config.depth_size,
this->gl_config.stencil_size, newaccumsize, NULL );
if (gl_ctx) {
gl_curformat = osmesa_format;
gl_curdepth = this->gl_config.depth_size;
gl_curstencil = this->gl_config.stencil_size;
gl_curaccum = newaccumsize;
} else {
gl_curformat = 0;
gl_curdepth = 0;
gl_curstencil = 0;
gl_curaccum = 0;
}
}
Nov 26, 2004
Nov 26, 2004
476
477
478
479
480
481
482
483
484
return (gl_ctx != NULL);
}
static int InitOld(_THIS, SDL_Surface *current)
{
GLenum osmesa_format;
SDL_PixelFormat *pixel_format;
Uint32 redmask;
Nov 26, 2004
Nov 26, 2004
485
int recreatecontext;
Nov 26, 2004
Nov 26, 2004
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
if (this->gl_config.dll_handle) {
if (this->gl_data->OSMesaCreateLDG == NULL) {
return 0;
}
}
/* Init OpenGL context using OSMesa */
gl_convert = ConvertNull;
gl_copyshadow = CopyShadowNull;
pixel_format = current->format;
redmask = pixel_format->Rmask;
switch (pixel_format->BitsPerPixel) {
case 15:
/* 15 bits unsupported */
gl_pixelsize = 2;
osmesa_format = OSMESA_ARGB;
if (redmask == 31<<10) {
gl_copyshadow = CopyShadow8888To555;
} else {
gl_copyshadow = CopyShadow8888To565;
gl_convert = Convert565To555le;
}
break;
case 16:
/* 16 bits unsupported */
gl_pixelsize = 2;
osmesa_format = OSMESA_ARGB;
gl_copyshadow = CopyShadow8888To565;
if (redmask != 31<<11) {
/* 565, little endian, unsupported */
gl_convert = Convert565le;
}
break;
case 24:
gl_pixelsize = 3;
gl_copyshadow = CopyShadowDirect;
if (redmask == 255<<16) {
osmesa_format = OSMESA_RGB;
} else {
osmesa_format = OSMESA_BGR;
}
break;
case 32:
gl_pixelsize = 4;
gl_copyshadow = CopyShadowDirect;
if (redmask == 255<<16) {
osmesa_format = OSMESA_ARGB;
} else if (redmask == 255<<8) {
osmesa_format = OSMESA_BGRA;
} else if (redmask == 255<<24) {
osmesa_format = OSMESA_RGBA;
} else {
/* ABGR format unsupported */
osmesa_format = OSMESA_BGRA;
gl_convert = ConvertBGRAToABGR;
}
break;
default:
gl_pixelsize = 1;
gl_copyshadow = CopyShadowDirect;
osmesa_format = OSMESA_COLOR_INDEX;
break;
}
Nov 26, 2004
Nov 26, 2004
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
/* Try to keep current context if possible */
recreatecontext=1;
if (gl_shadow &&
(gl_curformat == osmesa_format) &&
(gl_curwidth == current->w) &&
(gl_curheight == current->h)) {
recreatecontext = 0;
}
if (recreatecontext) {
SDL_AtariGL_Quit(this, SDL_FALSE);
gl_shadow = this->gl_data->OSMesaCreateLDG(
osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
);
if (gl_shadow) {
gl_curformat = osmesa_format;
gl_curwidth = current->w;
gl_curheight = current->h;
} else {
gl_curformat = 0;
gl_curwidth = 0;
gl_curheight = 0;
}
}
Nov 26, 2004
Nov 26, 2004
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
return (gl_shadow != NULL);
}
/*--- Conversions routines from shadow buffer to the screen ---*/
static void CopyShadowNull(_THIS, SDL_Surface *surface)
{
}
static void CopyShadowDirect(_THIS, SDL_Surface *surface)
{
int y, srcpitch, dstpitch;
Uint8 *srcline, *dstline;
srcline = gl_shadow;
srcpitch = surface->w * gl_pixelsize;
dstline = surface->pixels;
dstpitch = surface->pitch;
for (y=0; y<surface->h; y++) {
memcpy(dstline, srcline, srcpitch);
srcline += srcpitch;
dstline += dstpitch;
}
}
static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
{
int x,y, srcpitch, dstpitch;
Uint16 *dstline, *dstcol;
Uint32 *srcline, *srccol;
srcline = (Uint32 *)gl_shadow;
srcpitch = surface->w;
dstline = surface->pixels;
dstpitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
srccol = srcline;
dstcol = dstline;
for (x=0; x<surface->w; x++) {
Uint32 srccolor;
Uint16 dstcolor;
srccolor = *srccol++;
dstcolor = (srccolor>>9) & (31<<10);
dstcolor |= (srccolor>>6) & (31<<5);
dstcolor |= (srccolor>>3) & 31;
*dstcol++ = dstcolor;
}
srcline += srcpitch;
dstline += dstpitch;
}
}
static void CopyShadow8888To565(_THIS, SDL_Surface *surface)
{
int x,y, srcpitch, dstpitch;
Uint16 *dstline, *dstcol;
Uint32 *srcline, *srccol;
srcline = (Uint32 *)gl_shadow;
srcpitch = surface->w;
dstline = surface->pixels;
dstpitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
srccol = srcline;
dstcol = dstline;
for (x=0; x<surface->w; x++) {
Uint32 srccolor;
Uint16 dstcolor;
srccolor = *srccol++;
dstcolor = (srccolor>>8) & (31<<11);
dstcolor |= (srccolor>>5) & (63<<5);
dstcolor |= (srccolor>>3) & 31;
*dstcol++ = dstcolor;
}
srcline += srcpitch;
dstline += dstpitch;
}
}
/*--- Conversions routines in the screen ---*/
static void ConvertNull(_THIS, SDL_Surface *surface)
669
670
671
{
}
Nov 26, 2004
Nov 26, 2004
672
static void Convert565To555be(_THIS, SDL_Surface *surface)
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >> 1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
*pixel++ = (color & 0x1f)|((color>>1) & 0xffe0);
}
line += pitch;
}
}
Nov 26, 2004
Nov 26, 2004
691
static void Convert565To555le(_THIS, SDL_Surface *surface)
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
color = (color & 0x1f)|((color>>1) & 0xffe0);
*pixel++ = SDL_Swap16(color);
}
line += pitch;
}
}
Nov 26, 2004
Nov 26, 2004
711
static void Convert565le(_THIS, SDL_Surface *surface)
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
*pixel++ = SDL_Swap16(color);
}
line += pitch;
}
}
Nov 26, 2004
Nov 26, 2004
730
static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface)
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
{
int x,y, pitch;
unsigned long *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>2;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned long color = *pixel;
*pixel++ = (color<<24)|(color>>8);
}
line += pitch;
}
}