Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
243 lines (206 loc) · 6.8 KB

SDL_nximage.c

File metadata and controls

243 lines (206 loc) · 6.8 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
3
Copyright (C) 1997-2004 Sam Lantinga
4
Copyright (C) 2001 Hsieh-Fu Tsai
Aug 25, 2002
Aug 25, 2002
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
Dec 14, 2001
Dec 14, 2001
22
slouken@libsdl.org
23
24
25
26
Hsieh-Fu Tsai
clare@setabox.com
*/
Feb 21, 2006
Feb 21, 2006
27
#include "SDL_config.h"
28
29
30
#include "SDL_nximage_c.h"
Jul 10, 2006
Jul 10, 2006
31
32
void
NX_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
Jul 10, 2006
Jul 10, 2006
34
35
36
37
38
int i, j, xinc, yinc, destinc, rowinc;
int x, y, w, h;
unsigned char *src = NULL, *dest = NULL;
Dprintf("enter NX_NormalUpdate\n");
Aug 25, 2002
Aug 25, 2002
40
/* These are the values for the incoming image */
Jul 10, 2006
Jul 10, 2006
41
42
43
44
45
46
47
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;
Aug 25, 2002
Aug 25, 2002
48
#ifdef ENABLE_NANOX_DIRECT_FB
Aug 30, 2003
Aug 30, 2003
49
50
if (Clientfb) {
if (currently_fullscreen)
Jul 10, 2006
Jul 10, 2006
51
52
53
dest =
fbinfo.winpixels + (((y + OffsetY) * fbinfo.pitch) +
((x + OffsetX) * fbinfo.bytespp));
Aug 30, 2003
Aug 30, 2003
54
else
Jul 10, 2006
Jul 10, 2006
55
56
57
dest =
fbinfo.winpixels + ((y * fbinfo.pitch) +
(x * fbinfo.bytespp));
Aug 30, 2003
Aug 30, 2003
58
destinc = fbinfo.pitch;
Jul 10, 2006
Jul 10, 2006
59
} else
Aug 25, 2002
Aug 25, 2002
60
#endif
Aug 30, 2003
Aug 30, 2003
61
{
Jul 10, 2006
Jul 10, 2006
62
63
dest = Image_buff;
destinc = w * xinc;
Aug 30, 2003
Aug 30, 2003
64
65
}
rowinc = w * xinc;
66
67
// apply GammaRamp table
Jul 10, 2006
Jul 10, 2006
68
69
70
71
72
73
74
75
76
77
78
79
80
81
if ((pixel_type == MWPF_TRUECOLOR0888
|| pixel_type == MWPF_TRUECOLOR888) && GammaRamp_R
&& GammaRamp_G && GammaRamp_B) {
Uint8 *ptrsrc;
Uint8 *ptrdst;
int k;
for (j = h; j > 0; --j, src += yinc, dest += destinc) {
ptrsrc = src;
ptrdst = dest;
for (k = w; k > 0; --k) {
*ptrdst++ = GammaRamp_B[*ptrsrc++] >> 8;
*ptrdst++ = GammaRamp_G[*ptrsrc++] >> 8;
*ptrdst++ = GammaRamp_R[*ptrsrc++] >> 8;
Aug 30, 2003
Aug 30, 2003
82
83
*ptrdst++ = 0;
++ptrsrc;
84
85
86
}
}
}
Jul 10, 2006
Jul 10, 2006
87
88
89
90
91
92
93
94
95
96
97
#if 1 /* This is needed for microwindows 0.90 or older */
else if (pixel_type == MWPF_TRUECOLOR0888
|| pixel_type == MWPF_TRUECOLOR888) {
Uint8 *ptrsrc;
Uint8 *ptrdst;
int k;
for (j = h; j > 0; --j, src += yinc, dest += destinc) {
ptrsrc = src;
ptrdst = dest;
for (k = w; k > 0; --k) {
Aug 30, 2003
Aug 30, 2003
98
99
100
101
102
103
104
105
106
*ptrdst++ = *ptrsrc++;
*ptrdst++ = *ptrsrc++;
*ptrdst++ = *ptrsrc++;
*ptrdst++ = 0;
++ptrsrc;
}
}
}
#endif
Jul 10, 2006
Jul 10, 2006
107
108
109
else {
for (j = h; j > 0; --j, src += yinc, dest += destinc)
SDL_memcpy(dest, src, rowinc);
Aug 30, 2003
Aug 30, 2003
110
111
}
if (!Clientfb) {
Aug 25, 2002
Aug 25, 2002
112
if (currently_fullscreen) {
Jul 10, 2006
Jul 10, 2006
113
114
GrArea(FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w,
h, Image_buff, pixel_type);
Aug 25, 2002
Aug 25, 2002
115
} else {
Jul 10, 2006
Jul 10, 2006
116
117
GrArea(SDL_Window, SDL_GC, x, y, w, h, Image_buff,
pixel_type);
Aug 25, 2002
Aug 25, 2002
118
}
Aug 30, 2003
Aug 30, 2003
119
}
Aug 25, 2002
Aug 25, 2002
121
GrFlush();
Jul 10, 2006
Jul 10, 2006
123
Dprintf("leave NX_NormalUpdate\n");
Jul 10, 2006
Jul 10, 2006
126
127
int
NX_SetupImage(_THIS, SDL_Surface * screen)
Jul 10, 2006
Jul 10, 2006
129
130
131
int size = screen->h * screen->pitch;
Dprintf("enter NX_SetupImage\n");
Jul 10, 2006
Jul 10, 2006
133
screen->pixels = (void *) SDL_malloc(size);
Aug 25, 2002
Aug 25, 2002
134
135
if (!Clientfb) {
Jul 10, 2006
Jul 10, 2006
136
137
138
139
140
141
Image_buff = (unsigned char *) SDL_malloc(size);
if (screen->pixels == NULL || Image_buff == NULL) {
SDL_free(screen->pixels);
SDL_free(Image_buff);
SDL_OutOfMemory();
return -1;
Aug 25, 2002
Aug 25, 2002
142
}
Jul 10, 2006
Jul 10, 2006
145
SDL_Image = (unsigned char *) screen->pixels;
Jul 10, 2006
Jul 10, 2006
147
this->UpdateRects = NX_NormalUpdate;
Jul 10, 2006
Jul 10, 2006
149
150
Dprintf("leave NX_SetupImage\n");
return 0;
Jul 10, 2006
Jul 10, 2006
153
154
void
NX_DestroyImage(_THIS, SDL_Surface * screen)
Jul 10, 2006
Jul 10, 2006
156
157
158
159
160
161
162
163
164
165
Dprintf("enter NX_DestroyImage\n");
if (SDL_Image)
SDL_free(SDL_Image);
if (Image_buff)
SDL_free(Image_buff);
if (screen)
screen->pixels = NULL;
Dprintf("leave NX_DestroyImage\n");
Jul 10, 2006
Jul 10, 2006
168
169
int
NX_ResizeImage(_THIS, SDL_Surface * screen, Uint32 flags)
Jul 10, 2006
Jul 10, 2006
171
172
int retval;
GR_SCREEN_INFO si;
Jul 10, 2006
Jul 10, 2006
174
Dprintf("enter NX_ResizeImage\n");
Jul 10, 2006
Jul 10, 2006
176
177
NX_DestroyImage(this, screen);
retval = NX_SetupImage(this, screen);
Jul 10, 2006
Jul 10, 2006
179
180
181
GrGetScreenInfo(&si);
OffsetX = (si.cols - screen->w) / 2;
OffsetY = (si.rows - screen->h) / 2;
Aug 25, 2002
Aug 25, 2002
182
183
184
#ifdef ENABLE_NANOX_DIRECT_FB
if (Clientfb) {
Jul 10, 2006
Jul 10, 2006
185
186
/* Get current window position and fb pointer */
if (currently_fullscreen)
Aug 25, 2002
Aug 25, 2002
187
188
189
190
191
GrGetWindowFBInfo(FSwindow, &fbinfo);
else
GrGetWindowFBInfo(SDL_Window, &fbinfo);
}
#endif
Jul 10, 2006
Jul 10, 2006
192
193
Dprintf("leave NX_ResizeImage\n");
return retval;
Jul 10, 2006
Jul 10, 2006
196
197
void
NX_RefreshDisplay(_THIS)
Jul 10, 2006
Jul 10, 2006
199
Dprintf("enter NX_RefreshDisplay\n");
200
201
// Don't refresh a display that doesn't have an image (like GL)
Jul 10, 2006
Jul 10, 2006
202
if (!SDL_Image) {
203
204
return;
}
Aug 25, 2002
Aug 25, 2002
205
206
207
208
209
210
#ifdef ENABLE_NANOX_DIRECT_FB
if (Clientfb) {
int j;
char *src, *dest = NULL;
int xinc, yinc, rowinc;
Aug 30, 2003
Aug 30, 2003
211
GrGetWindowFBInfo(SDL_Window, &fbinfo);
Aug 25, 2002
Aug 25, 2002
212
Jul 10, 2006
Jul 10, 2006
213
214
xinc = this->screen->format->BytesPerPixel;
yinc = this->screen->pitch;
Aug 25, 2002
Aug 25, 2002
215
Aug 30, 2003
Aug 30, 2003
216
217
218
src = SDL_Image;
if (currently_fullscreen)
dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) +
Jul 10, 2006
Jul 10, 2006
219
(OffsetX * fbinfo.bytespp));
Aug 30, 2003
Aug 30, 2003
220
221
else
dest = fbinfo.winpixels;
Jul 10, 2006
Jul 10, 2006
222
rowinc = xinc * this->screen->w;
Aug 25, 2002
Aug 25, 2002
223
Jul 10, 2006
Jul 10, 2006
224
225
226
227
for (j = this->screen->h; j > 0;
--j, src += yinc, dest += fbinfo.pitch)
SDL_memcpy(dest, src, rowinc);
} else
Aug 25, 2002
Aug 25, 2002
228
#endif
Aug 30, 2003
Aug 30, 2003
229
{
Aug 25, 2002
Aug 25, 2002
230
if (currently_fullscreen) {
Jul 10, 2006
Jul 10, 2006
231
232
GrArea(FSwindow, SDL_GC, OffsetX, OffsetY, this->screen->w,
this->screen->h, SDL_Image, pixel_type);
Aug 30, 2003
Aug 30, 2003
233
} else {
Jul 10, 2006
Jul 10, 2006
234
235
GrArea(SDL_Window, SDL_GC, 0, 0, this->screen->w,
this->screen->h, SDL_Image, pixel_type);
Aug 30, 2003
Aug 30, 2003
236
}
Aug 25, 2002
Aug 25, 2002
238
GrFlush();
Jul 10, 2006
Jul 10, 2006
240
Dprintf("leave NX_RefreshDisplay\n");
Jul 10, 2006
Jul 10, 2006
242
243
/* vi: set ts=4 sw=4 expandtab: */