2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
4 Copyright (C) 2001 Hsieh-Fu Tsai
5 Copyright (C) 2002 Greg Haerr <greg@censoft.com>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with this library; if not, write to the Free
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "SDL_config.h"
29 #include "SDL_nximage_c.h"
31 void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
33 int i, j, xinc, yinc, destinc, rowinc ;
35 unsigned char * src = NULL, * dest = NULL ;
37 Dprintf ("enter NX_NormalUpdate\n") ;
39 /* These are the values for the incoming image */
40 xinc = this -> screen -> format -> BytesPerPixel ;
41 yinc = this -> screen -> pitch ;
43 for (i = 0; i < numrects; ++ i) {
44 x = rects [i].x, y = rects [i].y ;
45 w = rects [i].w, h = rects [i].h ;
46 src = SDL_Image + y * yinc + x * xinc ;
47 #ifdef ENABLE_NANOX_DIRECT_FB
49 if (currently_fullscreen)
50 dest = fbinfo.winpixels + (((y+OffsetY) * fbinfo.pitch) +
51 ((x+OffsetX) * fbinfo.bytespp));
53 dest = fbinfo.winpixels + ((y * fbinfo.pitch) + (x * fbinfo.bytespp));
54 destinc = fbinfo.pitch;
64 // apply GammaRamp table
65 if ((pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888)
66 && GammaRamp_R && GammaRamp_G && GammaRamp_B) {
71 for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
74 for (k = w; k > 0; -- k) {
75 *ptrdst++ = GammaRamp_B [*ptrsrc++] >> 8;
76 *ptrdst++ = GammaRamp_G [*ptrsrc++] >> 8;
77 *ptrdst++ = GammaRamp_R [*ptrsrc++] >> 8;
83 #if 1 /* This is needed for microwindows 0.90 or older */
84 else if (pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) {
89 for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
92 for (k = w; k > 0; -- k) {
93 *ptrdst++ = *ptrsrc++;
94 *ptrdst++ = *ptrsrc++;
95 *ptrdst++ = *ptrsrc++;
104 for (j = h; j > 0; -- j, src += yinc, dest += destinc)
105 SDL_memcpy (dest, src, rowinc) ;
108 if (currently_fullscreen) {
109 GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff,
112 GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
118 Dprintf ("leave NX_NormalUpdate\n") ;
121 int NX_SetupImage (_THIS, SDL_Surface * screen)
123 int size = screen -> h * screen -> pitch ;
125 Dprintf ("enter NX_SetupImage\n") ;
127 screen -> pixels = (void *) SDL_malloc (size) ;
130 Image_buff = (unsigned char *) SDL_malloc (size) ;
131 if (screen -> pixels == NULL || Image_buff == NULL) {
132 SDL_free (screen -> pixels) ;
133 SDL_free (Image_buff) ;
139 SDL_Image = (unsigned char *) screen -> pixels ;
141 this -> UpdateRects = NX_NormalUpdate ;
143 Dprintf ("leave NX_SetupImage\n") ;
147 void NX_DestroyImage (_THIS, SDL_Surface * screen)
149 Dprintf ("enter NX_DestroyImage\n") ;
151 if (SDL_Image) SDL_free (SDL_Image) ;
152 if (Image_buff) SDL_free (Image_buff) ;
153 if (screen) screen -> pixels = NULL ;
155 Dprintf ("leave NX_DestroyImage\n") ;
158 int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
163 Dprintf ("enter NX_ResizeImage\n") ;
165 NX_DestroyImage (this, screen) ;
166 retval = NX_SetupImage (this, screen) ;
168 GrGetScreenInfo (& si) ;
169 OffsetX = (si.cols - screen -> w) / 2 ;
170 OffsetY = (si.rows - screen -> h) / 2 ;
172 #ifdef ENABLE_NANOX_DIRECT_FB
174 /* Get current window position and fb pointer*/
175 if (currently_fullscreen)
176 GrGetWindowFBInfo(FSwindow, &fbinfo);
178 GrGetWindowFBInfo(SDL_Window, &fbinfo);
181 Dprintf ("leave NX_ResizeImage\n") ;
185 void NX_RefreshDisplay (_THIS)
187 Dprintf ("enter NX_RefreshDisplay\n") ;
189 // Don't refresh a display that doesn't have an image (like GL)
194 #ifdef ENABLE_NANOX_DIRECT_FB
197 char *src, *dest = NULL;
198 int xinc, yinc, rowinc;
200 GrGetWindowFBInfo(SDL_Window, &fbinfo);
202 xinc = this -> screen -> format -> BytesPerPixel ;
203 yinc = this -> screen -> pitch ;
206 if (currently_fullscreen)
207 dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) +
208 (OffsetX * fbinfo.bytespp));
210 dest = fbinfo.winpixels;
211 rowinc = xinc * this -> screen -> w;
213 for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch)
214 SDL_memcpy (dest, src, rowinc) ;
219 if (currently_fullscreen) {
220 GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w,
221 this -> screen -> h, SDL_Image, pixel_type) ;
223 GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w,
224 this -> screen -> h, SDL_Image, pixel_type) ;
229 Dprintf ("leave NX_RefreshDisplay\n") ;