src/video/nanox/SDL_nximage.c
author Sam Lantinga
Sat, 30 Aug 2003 06:27:01 +0000
changeset 698 31d9be995d5c
parent 471 26dafefeebb2
child 699 d3b2e93629eb
permissions -rw-r--r--
*** empty log message ***
     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     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.
    11 
    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.
    16 
    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
    20 
    21     Sam Lantinga
    22     slouken@libsdl.org
    23     
    24     Hsieh-Fu Tsai
    25     clare@setabox.com
    26 */
    27 
    28 #include <stdlib.h>
    29 #include <string.h>
    30 
    31 #include "SDL_error.h"
    32 
    33 #include "SDL_nximage_c.h"
    34 
    35 void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
    36 {
    37     int           i, j, xinc, yinc, destinc, rowinc ;
    38     int           x, y, w, h ;
    39     unsigned char * src = NULL, * dest = NULL ;
    40 
    41     Dprintf ("enter NX_NormalUpdate\n") ;
    42     
    43     /* These are the values for the incoming image */
    44     xinc = this -> screen -> format -> BytesPerPixel ;
    45     yinc = this -> screen -> pitch ;
    46         
    47     for (i = 0; i < numrects; ++ i) {
    48         x = rects [i].x, y = rects [i].y ;
    49         w = rects [i].w, h = rects [i].h ;
    50         src = SDL_Image + y * yinc + x * xinc ;
    51 #ifdef ENABLE_NANOX_DIRECT_FB
    52 	if (Clientfb) {
    53 	    if (currently_fullscreen)
    54 	        dest = fbinfo.winpixels + (((y+OffsetY) * fbinfo.pitch) +
    55 		    ((x+OffsetX) * fbinfo.bytespp));
    56 	    else
    57 	        dest = fbinfo.winpixels + ((y * fbinfo.pitch) + (x * fbinfo.bytespp));
    58 	    destinc = fbinfo.pitch;
    59 	} else {
    60 #endif
    61             dest = Image_buff ;
    62             destinc = w * xinc ;
    63 #ifdef ENABLE_NANOX_DIRECT_FB
    64 	}
    65 #endif
    66 	rowinc = w * xinc;
    67 
    68         // apply GammaRamp table
    69         if ((pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888)
    70 	  && GammaRamp_R && GammaRamp_G && GammaRamp_B) {
    71             Uint8 * ptr ;
    72             int   k ;
    73 
    74             for (j = h; j > 0; -- j, src += yinc) {
    75                 ptr = src - 1 ;
    76                 for (k = w; k > 0; -- k) {
    77 		    if (pixel_type == MWPF_TRUECOLOR0888)
    78                         ptr += 2 ;
    79                     else
    80                         ++ ptr ;
    81                     (* ptr) = GammaRamp_B [(* ptr)] ;
    82                     ++ ptr ;
    83                     (* ptr) = GammaRamp_G [(* ptr)] ;
    84                     ++ ptr ;
    85                     (* ptr) = GammaRamp_R [(* ptr)] ;
    86                 }
    87             }
    88             src = SDL_Image + y * yinc + x * xinc ;
    89         }
    90 
    91         for (j = h; j > 0; -- j, src += yinc, dest += destinc)
    92             memcpy (dest, src, rowinc) ;
    93 	if (!Clientfb) {
    94             if (currently_fullscreen) {
    95                 GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, 
    96                     pixel_type) ;
    97             } else {
    98                 GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
    99             }
   100 	}
   101     }
   102     GrFlush();
   103 
   104     Dprintf ("leave NX_NormalUpdate\n") ;
   105 }
   106 
   107 int NX_SetupImage (_THIS, SDL_Surface * screen)
   108 {
   109     int size = screen -> h * screen -> pitch ;
   110     
   111     Dprintf ("enter NX_SetupImage\n") ;
   112 
   113     screen -> pixels = (void *) malloc (size) ;
   114 
   115     if (!Clientfb) {
   116         Image_buff = (unsigned char *) malloc (size) ;
   117         if (screen -> pixels == NULL || Image_buff == NULL) {
   118             free (screen -> pixels) ;
   119             free (Image_buff) ;
   120             SDL_OutOfMemory () ;
   121             return -1 ;
   122         }
   123     }
   124 
   125     SDL_Image = (unsigned char *) screen -> pixels ;
   126 
   127     this -> UpdateRects = NX_NormalUpdate ;
   128 
   129     Dprintf ("leave NX_SetupImage\n") ;
   130     return 0 ;
   131 }
   132 
   133 void NX_DestroyImage (_THIS, SDL_Surface * screen)
   134 {
   135     Dprintf ("enter NX_DestroyImage\n") ;
   136     
   137     if (SDL_Image) free (SDL_Image) ;
   138     if (Image_buff) free (Image_buff) ;
   139     if (screen) screen -> pixels = NULL ;
   140     
   141     Dprintf ("leave NX_DestroyImage\n") ;
   142 }
   143 
   144 int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
   145 {
   146     int            retval ;
   147     GR_SCREEN_INFO si ;
   148 
   149     Dprintf ("enter NX_ResizeImage\n") ;
   150 
   151     NX_DestroyImage (this, screen) ;
   152     retval = NX_SetupImage (this, screen) ;
   153 
   154     GrGetScreenInfo (& si) ;
   155     OffsetX = (si.cols - screen -> w) / 2 ;
   156     OffsetY = (si.rows - screen -> h) / 2 ;
   157 
   158 #ifdef ENABLE_NANOX_DIRECT_FB
   159     if (Clientfb) {
   160         /* Get current window position and fb pointer*/
   161         if (currently_fullscreen) 
   162             GrGetWindowFBInfo(FSwindow, &fbinfo);
   163         else
   164             GrGetWindowFBInfo(SDL_Window, &fbinfo);
   165     }
   166 #endif
   167     Dprintf ("leave NX_ResizeImage\n") ;
   168     return retval ;
   169 }
   170 
   171 void NX_RefreshDisplay (_THIS)
   172 {
   173     Dprintf ("enter NX_RefreshDisplay\n") ;
   174 
   175     // Don't refresh a display that doesn't have an image (like GL)
   176     if (! SDL_Image) {
   177         return;
   178     }
   179 
   180 #ifdef ENABLE_NANOX_DIRECT_FB
   181     if (Clientfb) {
   182         int j;
   183         char *src, *dest = NULL;
   184         int xinc, yinc, rowinc;
   185 
   186 	GrGetWindowFBInfo(SDL_Window, &fbinfo);
   187 
   188 	xinc = this -> screen -> format -> BytesPerPixel ; 
   189 	yinc = this -> screen -> pitch ;           
   190 
   191 	src = SDL_Image;
   192 	if (currently_fullscreen)
   193 	    dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) +
   194 	        (OffsetX * fbinfo.bytespp));
   195 	else
   196 	    dest = fbinfo.winpixels;
   197 	rowinc = xinc * this -> screen -> w;
   198 
   199 	for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch)
   200 	    memcpy (dest, src, rowinc) ;
   201     } else {
   202 #endif
   203         if (currently_fullscreen) {
   204             GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, 
   205                 this -> screen -> h, SDL_Image, pixel_type) ;
   206 	} else {
   207             GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, 
   208                 this -> screen -> h, SDL_Image, pixel_type) ;
   209 	}
   210 #ifdef ENABLE_NANOX_DIRECT_FB
   211     }
   212 #endif
   213     GrFlush();
   214 
   215     Dprintf ("leave NX_RefreshDisplay\n") ;
   216 }