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.
slouken@30
     1
/*
slouken@30
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@30
     4
    Copyright (C) 2001  Hsieh-Fu Tsai
slouken@471
     5
    Copyright (C) 2002  Greg Haerr <greg@censoft.com>
slouken@30
     6
slouken@30
     7
    This library is free software; you can redistribute it and/or
slouken@30
     8
    modify it under the terms of the GNU Library General Public
slouken@30
     9
    License as published by the Free Software Foundation; either
slouken@30
    10
    version 2 of the License, or (at your option) any later version.
slouken@30
    11
slouken@30
    12
    This library is distributed in the hope that it will be useful,
slouken@30
    13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@30
    14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@30
    15
    Library General Public License for more details.
slouken@30
    16
slouken@30
    17
    You should have received a copy of the GNU Library General Public
slouken@30
    18
    License along with this library; if not, write to the Free
slouken@30
    19
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@30
    20
slouken@30
    21
    Sam Lantinga
slouken@252
    22
    slouken@libsdl.org
slouken@30
    23
    
slouken@30
    24
    Hsieh-Fu Tsai
slouken@30
    25
    clare@setabox.com
slouken@30
    26
*/
slouken@30
    27
slouken@30
    28
#include <stdlib.h>
slouken@698
    29
#include <string.h>
slouken@30
    30
slouken@30
    31
#include "SDL_error.h"
slouken@30
    32
slouken@30
    33
#include "SDL_nximage_c.h"
slouken@30
    34
slouken@30
    35
void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
slouken@30
    36
{
slouken@471
    37
    int           i, j, xinc, yinc, destinc, rowinc ;
slouken@30
    38
    int           x, y, w, h ;
slouken@30
    39
    unsigned char * src = NULL, * dest = NULL ;
slouken@471
    40
slouken@30
    41
    Dprintf ("enter NX_NormalUpdate\n") ;
slouken@471
    42
    
slouken@471
    43
    /* These are the values for the incoming image */
slouken@30
    44
    xinc = this -> screen -> format -> BytesPerPixel ;
slouken@30
    45
    yinc = this -> screen -> pitch ;
slouken@30
    46
        
slouken@30
    47
    for (i = 0; i < numrects; ++ i) {
slouken@30
    48
        x = rects [i].x, y = rects [i].y ;
slouken@30
    49
        w = rects [i].w, h = rects [i].h ;
slouken@30
    50
        src = SDL_Image + y * yinc + x * xinc ;
slouken@471
    51
#ifdef ENABLE_NANOX_DIRECT_FB
slouken@699
    52
        if (Clientfb) {
slouken@699
    53
            if (currently_fullscreen)
slouken@699
    54
                dest = fbinfo.winpixels + (((y+OffsetY) * fbinfo.pitch) +
slouken@699
    55
                    ((x+OffsetX) * fbinfo.bytespp));
slouken@699
    56
            else
slouken@699
    57
                dest = fbinfo.winpixels + ((y * fbinfo.pitch) + (x * fbinfo.bytespp));
slouken@699
    58
            destinc = fbinfo.pitch;
slouken@699
    59
        }
slouken@699
    60
        else
slouken@471
    61
#endif
slouken@699
    62
        {
slouken@471
    63
            dest = Image_buff ;
slouken@471
    64
            destinc = w * xinc ;
slouken@699
    65
        }
slouken@699
    66
        rowinc = w * xinc;
slouken@30
    67
slouken@30
    68
        // apply GammaRamp table
slouken@471
    69
        if ((pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888)
slouken@699
    70
          && GammaRamp_R && GammaRamp_G && GammaRamp_B) {
slouken@699
    71
            Uint8 * ptrsrc ;
slouken@699
    72
            Uint8 * ptrdst ;
slouken@30
    73
            int   k ;
slouken@30
    74
slouken@699
    75
            for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
slouken@699
    76
                ptrsrc = src ;
slouken@699
    77
                ptrdst = dest ;
slouken@30
    78
                for (k = w; k > 0; -- k) {
slouken@699
    79
                    *ptrdst++ = GammaRamp_B [*ptrsrc++] >> 8;
slouken@699
    80
                    *ptrdst++ = GammaRamp_G [*ptrsrc++] >> 8;
slouken@699
    81
                    *ptrdst++ = GammaRamp_R [*ptrsrc++] >> 8;
slouken@699
    82
                    *ptrdst++ = 0;
slouken@699
    83
                    ++ptrsrc;
slouken@30
    84
                }
slouken@30
    85
            }
slouken@30
    86
        }
slouken@700
    87
#if 1 /* This is needed for microwindows 0.90 or older */
slouken@699
    88
        else if (pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) {
slouken@699
    89
            Uint8 * ptrsrc ;
slouken@699
    90
            Uint8 * ptrdst ;
slouken@699
    91
            int   k ;
slouken@30
    92
slouken@699
    93
            for (j = h; j > 0; -- j, src += yinc, dest += destinc) {
slouken@699
    94
                ptrsrc = src ;
slouken@699
    95
                ptrdst = dest ;
slouken@699
    96
                for (k = w; k > 0; -- k) {
slouken@699
    97
                    *ptrdst++ = *ptrsrc++;
slouken@699
    98
                    *ptrdst++ = *ptrsrc++;
slouken@699
    99
                    *ptrdst++ = *ptrsrc++;
slouken@699
   100
                    *ptrdst++ = 0;
slouken@699
   101
                    ++ptrsrc;
slouken@699
   102
                }
slouken@699
   103
            }
slouken@699
   104
        }
slouken@699
   105
#endif
slouken@699
   106
        else
slouken@699
   107
        {
slouken@699
   108
            for (j = h; j > 0; -- j, src += yinc, dest += destinc)
slouken@699
   109
                memcpy (dest, src, rowinc) ;
slouken@699
   110
        }
slouken@699
   111
        if (!Clientfb) {
slouken@471
   112
            if (currently_fullscreen) {
slouken@471
   113
                GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, 
slouken@471
   114
                    pixel_type) ;
slouken@471
   115
            } else {
slouken@471
   116
                GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ;
slouken@471
   117
            }
slouken@699
   118
        }
slouken@30
   119
    }
slouken@471
   120
    GrFlush();
slouken@30
   121
slouken@30
   122
    Dprintf ("leave NX_NormalUpdate\n") ;
slouken@30
   123
}
slouken@30
   124
slouken@30
   125
int NX_SetupImage (_THIS, SDL_Surface * screen)
slouken@30
   126
{
slouken@30
   127
    int size = screen -> h * screen -> pitch ;
slouken@30
   128
    
slouken@30
   129
    Dprintf ("enter NX_SetupImage\n") ;
slouken@30
   130
slouken@30
   131
    screen -> pixels = (void *) malloc (size) ;
slouken@471
   132
slouken@471
   133
    if (!Clientfb) {
slouken@471
   134
        Image_buff = (unsigned char *) malloc (size) ;
slouken@471
   135
        if (screen -> pixels == NULL || Image_buff == NULL) {
slouken@471
   136
            free (screen -> pixels) ;
slouken@471
   137
            free (Image_buff) ;
slouken@471
   138
            SDL_OutOfMemory () ;
slouken@471
   139
            return -1 ;
slouken@471
   140
        }
slouken@30
   141
    }
slouken@30
   142
slouken@30
   143
    SDL_Image = (unsigned char *) screen -> pixels ;
slouken@30
   144
slouken@30
   145
    this -> UpdateRects = NX_NormalUpdate ;
slouken@30
   146
slouken@30
   147
    Dprintf ("leave NX_SetupImage\n") ;
slouken@30
   148
    return 0 ;
slouken@30
   149
}
slouken@30
   150
slouken@30
   151
void NX_DestroyImage (_THIS, SDL_Surface * screen)
slouken@30
   152
{
slouken@30
   153
    Dprintf ("enter NX_DestroyImage\n") ;
slouken@30
   154
    
slouken@30
   155
    if (SDL_Image) free (SDL_Image) ;
slouken@30
   156
    if (Image_buff) free (Image_buff) ;
slouken@30
   157
    if (screen) screen -> pixels = NULL ;
slouken@30
   158
    
slouken@30
   159
    Dprintf ("leave NX_DestroyImage\n") ;
slouken@30
   160
}
slouken@30
   161
slouken@30
   162
int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags)
slouken@30
   163
{
slouken@30
   164
    int            retval ;
slouken@30
   165
    GR_SCREEN_INFO si ;
slouken@30
   166
slouken@30
   167
    Dprintf ("enter NX_ResizeImage\n") ;
slouken@30
   168
slouken@30
   169
    NX_DestroyImage (this, screen) ;
slouken@30
   170
    retval = NX_SetupImage (this, screen) ;
slouken@30
   171
slouken@30
   172
    GrGetScreenInfo (& si) ;
slouken@30
   173
    OffsetX = (si.cols - screen -> w) / 2 ;
slouken@30
   174
    OffsetY = (si.rows - screen -> h) / 2 ;
slouken@471
   175
slouken@471
   176
#ifdef ENABLE_NANOX_DIRECT_FB
slouken@471
   177
    if (Clientfb) {
slouken@471
   178
        /* Get current window position and fb pointer*/
slouken@471
   179
        if (currently_fullscreen) 
slouken@471
   180
            GrGetWindowFBInfo(FSwindow, &fbinfo);
slouken@471
   181
        else
slouken@471
   182
            GrGetWindowFBInfo(SDL_Window, &fbinfo);
slouken@471
   183
    }
slouken@471
   184
#endif
slouken@30
   185
    Dprintf ("leave NX_ResizeImage\n") ;
slouken@30
   186
    return retval ;
slouken@30
   187
}
slouken@30
   188
slouken@30
   189
void NX_RefreshDisplay (_THIS)
slouken@30
   190
{
slouken@30
   191
    Dprintf ("enter NX_RefreshDisplay\n") ;
slouken@30
   192
slouken@30
   193
    // Don't refresh a display that doesn't have an image (like GL)
slouken@30
   194
    if (! SDL_Image) {
slouken@30
   195
        return;
slouken@30
   196
    }
slouken@30
   197
slouken@471
   198
#ifdef ENABLE_NANOX_DIRECT_FB
slouken@471
   199
    if (Clientfb) {
slouken@471
   200
        int j;
slouken@471
   201
        char *src, *dest = NULL;
slouken@471
   202
        int xinc, yinc, rowinc;
slouken@471
   203
slouken@699
   204
        GrGetWindowFBInfo(SDL_Window, &fbinfo);
slouken@471
   205
slouken@699
   206
        xinc = this -> screen -> format -> BytesPerPixel ; 
slouken@699
   207
        yinc = this -> screen -> pitch ;           
slouken@471
   208
slouken@699
   209
        src = SDL_Image;
slouken@699
   210
        if (currently_fullscreen)
slouken@699
   211
            dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) +
slouken@699
   212
                (OffsetX * fbinfo.bytespp));
slouken@699
   213
        else
slouken@699
   214
            dest = fbinfo.winpixels;
slouken@699
   215
        rowinc = xinc * this -> screen -> w;
slouken@471
   216
slouken@699
   217
        for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch)
slouken@699
   218
            memcpy (dest, src, rowinc) ;
slouken@699
   219
    }
slouken@699
   220
    else
slouken@471
   221
#endif
slouken@699
   222
    {
slouken@471
   223
        if (currently_fullscreen) {
slouken@471
   224
            GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, 
slouken@471
   225
                this -> screen -> h, SDL_Image, pixel_type) ;
slouken@699
   226
        } else {
slouken@471
   227
            GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, 
slouken@471
   228
                this -> screen -> h, SDL_Image, pixel_type) ;
slouken@699
   229
        }
slouken@30
   230
    }
slouken@471
   231
    GrFlush();
slouken@30
   232
slouken@30
   233
    Dprintf ("leave NX_RefreshDisplay\n") ;
slouken@30
   234
}