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 <math.h>
19
20 #include "waveimg.h"
21 #include "pixel.h"
22 #include "ticks.h"
23 #include "settings.h"
24
setWaving(wavingImage_t * wi,SDL_Surface * screen,SDL_Surface * img,int x,int y,int rots,int amount,int speed)25 void setWaving(wavingImage_t* wi, SDL_Surface* screen, SDL_Surface* img, int x, int y, int rots, int amount, int speed)
26 {
27 wi->screen=screen;
28 wi->img=img;
29 wi->x=x;
30 wi->y=y;
31 wi->rotations=rots;
32 wi->amount=amount;
33 wi->speed=speed;
34
35 wi->useOverlay=0;
36 wi->jumpPos=0;
37 }
38
39 //void waveImg(SDL_Surface* screen, SDL_Surface* img, int xx, int yy, int rots, int amount, int speed)
waveImg(wavingImage_t * wi)40 void waveImg(wavingImage_t* wi)
41 {
42
43 int x, y,ox=0; //In the source image
44 int nx, ny; //new x/y value for px
45 uint32_t col; //Color of pixel
46 int r,g,b;
47
48 float pxInc = (6.28318531/wi->img->w)*wi->rotations;
49
50 float yInc;
51
52 wi->privRotAmount -=(float)getTicks()/wi->speed;
53
54 //If we use overlay, move it
55 if( wi->useOverlay )
56 {
57 wi->overlayPos += wi->overlaySpeed;
58 wi->jumpPos = wi->overlay->h/4 + cos(wi->privRotAmount/2)*wi->overlay->h/4;
59
60 }
61
62 for(x=0; x < wi->img->w; x++)
63 {
64 yInc = round( cos(wi->privRotAmount+x*pxInc)*wi->amount );
65
66 if(wi->useOverlay)
67 {
68 ox=(wi->overlayPos-x)%wi->overlay->w;
69 }
70
71 for(y=0; y < wi->img->h; y++)
72 {
73 col = freadPixel(wi->img, x, y);
74
75 //Do expensive colorkeying
76 r = ((col & wi->img->format->Rmask) >> wi->img->format->Rshift);
77 g = ((col & wi->img->format->Gmask) >> wi->img->format->Gshift);
78 b = ((col & wi->img->format->Bmask) >> wi->img->format->Bshift);
79
80 if( !isAlpha(r,g,b) )
81 {
82 nx = x;
83 ny = y+yInc;
84 //Cheap colorkey, basically, if the green component of the mask is = then we use the pixel.
85 if( wi->useOverlay && ( (freadPixel(wi->mask, x, y) & wi->mask->format->Gmask) >> wi->mask->format->Gshift == 0 ) )
86 {
87 col = freadPixel(wi->overlay, ox, wi->jumpPos+y);
88 }
89
90 plotPixel(wi->screen, nx+wi->x,ny+wi->y, col);
91 }
92 }
93 }
94 }
95
96