comparison src/video/nanox/SDL_nximage.c @ 1895:c121d94672cb

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