/
SDL_nximage.c
234 lines (195 loc) · 6.82 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
4
Copyright (C) 2001 Hsieh-Fu Tsai
5
Copyright (C) 2002 Greg Haerr <greg@censoft.com>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
22
slouken@libsdl.org
23
24
25
26
27
28
Hsieh-Fu Tsai
clare@setabox.com
*/
#include <stdlib.h>
29
#include <string.h>
30
31
32
33
34
35
36
#include "SDL_error.h"
#include "SDL_nximage_c.h"
void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
{
37
int i, j, xinc, yinc, destinc, rowinc ;
38
39
40
int x, y, w, h ;
unsigned char * src = NULL, * dest = NULL ;
41
42
43
Dprintf ("enter NX_NormalUpdate\n") ;
/* These are the values for the incoming image */
44
45
46
47
48
49
50
xinc = this -> screen -> format -> BytesPerPixel ;
yinc = this -> screen -> pitch ;
for (i = 0; i < numrects; ++ i) {
x = rects [i].x, y = rects [i].y ;
w = rects [i].w, h = rects [i].h ;
src = SDL_Image + y * yinc + x * xinc ;
51
#ifdef ENABLE_NANOX_DIRECT_FB
52
53
54
55
56
57
58
59
60
if (Clientfb) {
if (currently_fullscreen)
dest = fbinfo.winpixels + (((y+OffsetY) * fbinfo.pitch) +
((x+OffsetX) * fbinfo.bytespp));
else
dest = fbinfo.winpixels + ((y * fbinfo.pitch) + (x * fbinfo.bytespp));
destinc = fbinfo.pitch;
}
else
61
#endif
62
{
63
64
dest = Image_buff ;
destinc = w * xinc ;
65
66
}
rowinc = w * xinc;
67
68
// apply GammaRamp table
69
if ((pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888)
70
71
72
&& GammaRamp_R && GammaRamp_G && GammaRamp_B) {
Uint8 * ptrsrc ;
Uint8 * ptrdst ;
73
74
int k ;
75
76
77
for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
ptrsrc = src ;
ptrdst = dest ;
78
for (k = w; k > 0; -- k) {
79
80
81
82
83
*ptrdst++ = GammaRamp_B [*ptrsrc++] >> 8;
*ptrdst++ = GammaRamp_G [*ptrsrc++] >> 8;
*ptrdst++ = GammaRamp_R [*ptrsrc++] >> 8;
*ptrdst++ = 0;
++ptrsrc;
84
85
86
}
}
}
87
#if 1 /* This is needed for microwindows 0.90 or older */
88
89
90
91
else if (pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) {
Uint8 * ptrsrc ;
Uint8 * ptrdst ;
int k ;
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
ptrsrc = src ;
ptrdst = dest ;
for (k = w; k > 0; -- k) {
*ptrdst++ = *ptrsrc++;
*ptrdst++ = *ptrsrc++;
*ptrdst++ = *ptrsrc++;
*ptrdst++ = 0;
++ptrsrc;
}
}
}
#endif
else
{
for (j = h; j > 0; -- j, src += yinc, dest += destinc)
memcpy (dest, src, rowinc) ;
}
if (!Clientfb) {
112
113
114
115
116
117
if (currently_fullscreen) {
GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff,
pixel_type) ;
} else {
GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
}
118
}
119
}
120
GrFlush();
121
122
123
124
125
126
127
128
129
130
131
Dprintf ("leave NX_NormalUpdate\n") ;
}
int NX_SetupImage (_THIS, SDL_Surface * screen)
{
int size = screen -> h * screen -> pitch ;
Dprintf ("enter NX_SetupImage\n") ;
screen -> pixels = (void *) malloc (size) ;
132
133
134
135
136
137
138
139
140
if (!Clientfb) {
Image_buff = (unsigned char *) malloc (size) ;
if (screen -> pixels == NULL || Image_buff == NULL) {
free (screen -> pixels) ;
free (Image_buff) ;
SDL_OutOfMemory () ;
return -1 ;
}
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
}
SDL_Image = (unsigned char *) screen -> pixels ;
this -> UpdateRects = NX_NormalUpdate ;
Dprintf ("leave NX_SetupImage\n") ;
return 0 ;
}
void NX_DestroyImage (_THIS, SDL_Surface * screen)
{
Dprintf ("enter NX_DestroyImage\n") ;
if (SDL_Image) free (SDL_Image) ;
if (Image_buff) free (Image_buff) ;
if (screen) screen -> pixels = NULL ;
Dprintf ("leave NX_DestroyImage\n") ;
}
int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
{
int retval ;
GR_SCREEN_INFO si ;
Dprintf ("enter NX_ResizeImage\n") ;
NX_DestroyImage (this, screen) ;
retval = NX_SetupImage (this, screen) ;
GrGetScreenInfo (& si) ;
OffsetX = (si.cols - screen -> w) / 2 ;
OffsetY = (si.rows - screen -> h) / 2 ;
175
176
177
178
179
180
181
182
183
184
#ifdef ENABLE_NANOX_DIRECT_FB
if (Clientfb) {
/* Get current window position and fb pointer*/
if (currently_fullscreen)
GrGetWindowFBInfo(FSwindow, &fbinfo);
else
GrGetWindowFBInfo(SDL_Window, &fbinfo);
}
#endif
185
186
187
188
189
190
191
192
193
194
195
196
197
Dprintf ("leave NX_ResizeImage\n") ;
return retval ;
}
void NX_RefreshDisplay (_THIS)
{
Dprintf ("enter NX_RefreshDisplay\n") ;
// Don't refresh a display that doesn't have an image (like GL)
if (! SDL_Image) {
return;
}
198
199
200
201
202
203
#ifdef ENABLE_NANOX_DIRECT_FB
if (Clientfb) {
int j;
char *src, *dest = NULL;
int xinc, yinc, rowinc;
204
GrGetWindowFBInfo(SDL_Window, &fbinfo);
205
206
207
xinc = this -> screen -> format -> BytesPerPixel ;
yinc = this -> screen -> pitch ;
208
209
210
211
212
213
214
215
src = SDL_Image;
if (currently_fullscreen)
dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) +
(OffsetX * fbinfo.bytespp));
else
dest = fbinfo.winpixels;
rowinc = xinc * this -> screen -> w;
216
217
218
219
220
for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch)
memcpy (dest, src, rowinc) ;
}
else
221
#endif
222
{
223
224
225
if (currently_fullscreen) {
GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w,
this -> screen -> h, SDL_Image, pixel_type) ;
226
} else {
227
228
GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w,
this -> screen -> h, SDL_Image, pixel_type) ;
229
}
230
}
231
GrFlush();
232
233
234
Dprintf ("leave NX_RefreshDisplay\n") ;
}