1 /************************************************************************
2 * This file is part of Wizznic. *
3 * Copyright 2009-2015 Jimmy Christensen <dusted@dusted.dk> *
4 * Wizznic is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * Wizznic is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with Wizznic. If not, see <http://www.gnu.org/licenses/>. *
16 ************************************************************************/
17
18 #include "swscale.h"
19 #include "settings.h"
20 #include "defs.h"
21 #include "pixel.h"
22
23 static SDL_Surface* scale;
24
swScaleInit(int sdlVideoModeFlags,int doScale)25 SDL_Surface* swScaleInit( int sdlVideoModeFlags, int doScale )
26 {
27 scale = SDL_SetVideoMode(SCREENW*doScale,SCREENH*doScale,16, sdlVideoModeFlags);
28 SDL_Surface* screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 320,240,16, scale->format->Rmask,scale->format->Gmask,scale->format->Bmask,0xff000000);
29
30 //Set scaling
31 setting()->scaleFactor= (float)scale->h/240.0;
32
33 return( screen );
34 }
35
swScale(SDL_Surface * screen,int doScale)36 void swScale( SDL_Surface* screen, int doScale )
37 {
38 if(doScale==2)
39 {
40 int x,xx,y,yy;
41 for(y=0; y< SCREENH; y++)
42 {
43 for(x=0; x < SCREENW; x++)
44 {
45 uint16_t c = freadPixel(screen,x,y);/*SDL_MapRGB(scale->format,r,g,b);*/
46 xx=x*2;
47 yy=y*2;
48 plotPixelu(scale, xx,yy, c);
49 plotPixelu(scale, xx+1,yy, c);
50 plotPixelu(scale, xx,yy+1, c);
51 plotPixelu(scale, xx+1,yy+1, c);
52 }
53 }
54 } else if(doScale>2)
55 {
56 int x,y;
57 SDL_Rect r;
58 for(y=0; y< SCREENH; y++)
59 {
60 for(x=0; x < SCREENW; x++)
61 {
62 r.x=x*doScale;
63 r.y=y*doScale;
64 r.w=doScale;
65 r.h=doScale;
66 SDL_FillRect(scale, &r, freadPixel(screen,x,y));
67 }
68 }
69 }
70
71 if( doScale > -1 )
72 {
73 SDL_Flip(scale);
74 }
75 }
76