src/video/nanox/SDL_nximage.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 769 b8d311d90021
child 1338 604d73db6802
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2004 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         }
    60         else
    61 #endif
    62         {
    63             dest = Image_buff ;
    64             destinc = w * xinc ;
    65         }
    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 * ptrsrc ;
    72             Uint8 * ptrdst ;
    73             int   k ;
    74 
    75             for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
    76                 ptrsrc = src ;
    77                 ptrdst = dest ;
    78                 for (k = w; k > 0; -- k) {
    79                     *ptrdst++ = GammaRamp_B [*ptrsrc++] >> 8;
    80                     *ptrdst++ = GammaRamp_G [*ptrsrc++] >> 8;
    81                     *ptrdst++ = GammaRamp_R [*ptrsrc++] >> 8;
    82                     *ptrdst++ = 0;
    83                     ++ptrsrc;
    84                 }
    85             }
    86         }
    87 #if 1 /* This is needed for microwindows 0.90 or older */
    88         else if (pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) {
    89             Uint8 * ptrsrc ;
    90             Uint8 * ptrdst ;
    91             int   k ;
    92 
    93             for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
    94                 ptrsrc = src ;
    95                 ptrdst = dest ;
    96                 for (k = w; k > 0; -- k) {
    97                     *ptrdst++ = *ptrsrc++;
    98                     *ptrdst++ = *ptrsrc++;
    99                     *ptrdst++ = *ptrsrc++;
   100                     *ptrdst++ = 0;
   101                     ++ptrsrc;
   102                 }
   103             }
   104         }
   105 #endif
   106         else
   107         {
   108             for (j = h; j > 0; -- j, src += yinc, dest += destinc)
   109                 memcpy (dest, src, rowinc) ;
   110         }
   111         if (!Clientfb) {
   112             if (currently_fullscreen) {
   113                 GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, 
   114                     pixel_type) ;
   115             } else {
   116                 GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
   117             }
   118         }
   119     }
   120     GrFlush();
   121 
   122     Dprintf ("leave NX_NormalUpdate\n") ;
   123 }
   124 
   125 int NX_SetupImage (_THIS, SDL_Surface * screen)
   126 {
   127     int size = screen -> h * screen -> pitch ;
   128     
   129     Dprintf ("enter NX_SetupImage\n") ;
   130 
   131     screen -> pixels = (void *) malloc (size) ;
   132 
   133     if (!Clientfb) {
   134         Image_buff = (unsigned char *) malloc (size) ;
   135         if (screen -> pixels == NULL || Image_buff == NULL) {
   136             free (screen -> pixels) ;
   137             free (Image_buff) ;
   138             SDL_OutOfMemory () ;
   139             return -1 ;
   140         }
   141     }
   142 
   143     SDL_Image = (unsigned char *) screen -> pixels ;
   144 
   145     this -> UpdateRects = NX_NormalUpdate ;
   146 
   147     Dprintf ("leave NX_SetupImage\n") ;
   148     return 0 ;
   149 }
   150 
   151 void NX_DestroyImage (_THIS, SDL_Surface * screen)
   152 {
   153     Dprintf ("enter NX_DestroyImage\n") ;
   154     
   155     if (SDL_Image) free (SDL_Image) ;
   156     if (Image_buff) free (Image_buff) ;
   157     if (screen) screen -> pixels = NULL ;
   158     
   159     Dprintf ("leave NX_DestroyImage\n") ;
   160 }
   161 
   162 int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
   163 {
   164     int            retval ;
   165     GR_SCREEN_INFO si ;
   166 
   167     Dprintf ("enter NX_ResizeImage\n") ;
   168 
   169     NX_DestroyImage (this, screen) ;
   170     retval = NX_SetupImage (this, screen) ;
   171 
   172     GrGetScreenInfo (& si) ;
   173     OffsetX = (si.cols - screen -> w) / 2 ;
   174     OffsetY = (si.rows - screen -> h) / 2 ;
   175 
   176 #ifdef ENABLE_NANOX_DIRECT_FB
   177     if (Clientfb) {
   178         /* Get current window position and fb pointer*/
   179         if (currently_fullscreen) 
   180             GrGetWindowFBInfo(FSwindow, &fbinfo);
   181         else
   182             GrGetWindowFBInfo(SDL_Window, &fbinfo);
   183     }
   184 #endif
   185     Dprintf ("leave NX_ResizeImage\n") ;
   186     return retval ;
   187 }
   188 
   189 void NX_RefreshDisplay (_THIS)
   190 {
   191     Dprintf ("enter NX_RefreshDisplay\n") ;
   192 
   193     // Don't refresh a display that doesn't have an image (like GL)
   194     if (! SDL_Image) {
   195         return;
   196     }
   197 
   198 #ifdef ENABLE_NANOX_DIRECT_FB
   199     if (Clientfb) {
   200         int j;
   201         char *src, *dest = NULL;
   202         int xinc, yinc, rowinc;
   203 
   204         GrGetWindowFBInfo(SDL_Window, &fbinfo);
   205 
   206         xinc = this -> screen -> format -> BytesPerPixel ; 
   207         yinc = this -> screen -> pitch ;           
   208 
   209         src = SDL_Image;
   210         if (currently_fullscreen)
   211             dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) +
   212                 (OffsetX * fbinfo.bytespp));
   213         else
   214             dest = fbinfo.winpixels;
   215         rowinc = xinc * this -> screen -> w;
   216 
   217         for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch)
   218             memcpy (dest, src, rowinc) ;
   219     }
   220     else
   221 #endif
   222     {
   223         if (currently_fullscreen) {
   224             GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, 
   225                 this -> screen -> h, SDL_Image, pixel_type) ;
   226         } else {
   227             GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, 
   228                 this -> screen -> h, SDL_Image, pixel_type) ;
   229         }
   230     }
   231     GrFlush();
   232 
   233     Dprintf ("leave NX_RefreshDisplay\n") ;
   234 }