comparison src/video/nanox/SDL_nximage.c @ 30:57bf11a5efd7

Added initial support for Nano-X (thanks Hsieh-Fu!)
author Sam Lantinga <slouken@lokigames.com>
date Fri, 11 May 2001 01:13:35 +0000
parents
children e8157fcb3114
comparison
equal deleted inserted replaced
29:a8360daed17d 30:57bf11a5efd7
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4 Copyright (C) 2001 Hsieh-Fu Tsai
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with this library; if not, write to the Free
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 Sam Lantinga
21 slouken@devolution.com
22
23 Hsieh-Fu Tsai
24 clare@setabox.com
25 */
26
27 #include <stdlib.h>
28
29 #include "SDL_error.h"
30
31 #include "SDL_nximage_c.h"
32
33 void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
34 {
35 int i, j, xinc, yinc, destinc ;
36 int x, y, w, h ;
37 unsigned char * src = NULL, * dest = NULL ;
38
39 Dprintf ("enter NX_NormalUpdate\n") ;
40
41 xinc = this -> screen -> format -> BytesPerPixel ;
42 yinc = this -> screen -> pitch ;
43
44 for (i = 0; i < numrects; ++ i) {
45 x = rects [i].x, y = rects [i].y ;
46 w = rects [i].w, h = rects [i].h ;
47 src = SDL_Image + y * yinc + x * xinc ;
48 dest = Image_buff ;
49 destinc = w * xinc ;
50
51 // apply GammaRamp table
52 #if (defined (NANOX_PIXEL_RGB) || defined (NANOX_PIXEL_0888) || \
53 defined (NANOX_PIXEL_888))
54 if (GammaRamp_R && GammaRamp_G && GammaRamp_B) {
55 Uint8 * ptr ;
56 int k ;
57
58 for (j = h; j > 0; -- j, src += yinc) {
59 ptr = src - 1 ;
60 for (k = w; k > 0; -- k) {
61 #ifdef NANOX_PIXEL_RGB
62 ptr += 2 ;
63 #endif
64 #ifdef NANOX_PIXEL_0888
65 ptr += 2 ;
66 #endif
67 #ifdef NANOX_PIXEL_888
68 ++ ptr ;
69 #endif
70 (* ptr) = GammaRamp_B [(* ptr)] ;
71 ++ ptr ;
72 (* ptr) = GammaRamp_G [(* ptr)] ;
73 ++ ptr ;
74 (* ptr) = GammaRamp_R [(* ptr)] ;
75 }
76 }
77 src = SDL_Image + y * yinc + x * xinc ;
78 }
79 #endif // apply Gamma table
80
81 for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
82 memcpy (dest, src, destinc) ;
83 }
84
85 if (currently_fullscreen) {
86 GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff,
87 pixel_type) ;
88 } else {
89 GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
90 }
91 }
92
93 Dprintf ("leave NX_NormalUpdate\n") ;
94 }
95
96 int NX_SetupImage (_THIS, SDL_Surface * screen)
97 {
98 int size = screen -> h * screen -> pitch ;
99
100 Dprintf ("enter NX_SetupImage\n") ;
101
102 screen -> pixels = (void *) malloc (size) ;
103 Image_buff = (unsigned char *) malloc (size) ;
104 if (screen -> pixels == NULL || Image_buff == NULL) {
105 free (screen -> pixels) ;
106 free (Image_buff) ;
107 SDL_OutOfMemory () ;
108 return -1 ;
109 }
110
111 SDL_Image = (unsigned char *) screen -> pixels ;
112
113 this -> UpdateRects = NX_NormalUpdate ;
114
115 Dprintf ("leave NX_SetupImage\n") ;
116 return 0 ;
117 }
118
119 void NX_DestroyImage (_THIS, SDL_Surface * screen)
120 {
121 Dprintf ("enter NX_DestroyImage\n") ;
122
123 if (SDL_Image) free (SDL_Image) ;
124 if (Image_buff) free (Image_buff) ;
125 if (screen) screen -> pixels = NULL ;
126
127 Dprintf ("leave NX_DestroyImage\n") ;
128 }
129
130 int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
131 {
132 int retval ;
133 GR_SCREEN_INFO si ;
134
135 Dprintf ("enter NX_ResizeImage\n") ;
136
137 NX_DestroyImage (this, screen) ;
138 retval = NX_SetupImage (this, screen) ;
139
140 GrGetScreenInfo (& si) ;
141 OffsetX = (si.cols - screen -> w) / 2 ;
142 OffsetY = (si.rows - screen -> h) / 2 ;
143
144 Dprintf ("leave NX_ResizeImage\n") ;
145 return retval ;
146 }
147
148 void NX_RefreshDisplay (_THIS)
149 {
150 Dprintf ("enter NX_RefreshDisplay\n") ;
151
152 // Don't refresh a display that doesn't have an image (like GL)
153 if (! SDL_Image) {
154 return;
155 }
156
157 if (currently_fullscreen) {
158 GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w,
159 this -> screen -> h, SDL_Image, pixel_type) ;
160 } else {
161 GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w,
162 this -> screen -> h, SDL_Image, pixel_type) ;
163 }
164
165 Dprintf ("leave NX_RefreshDisplay\n") ;
166 }