How to multiply Pixels on a PNG Loaded SDL Surface?

Started by
0 comments, last by Ashaman73 11 years, 6 months ago
Hi!

I was hoping someone could tell me what is required to multiply the pixels on an PNG Loaded Surface

"What I mean is zoom the png file so its bigger then its orginal PNG Loaded size on a SDL Surface"

I'm able to manipulate just normal pixels and put them on the screen and make gradient rectangles with them

but I really don't understand how to do the multiplication on the PNG loaded Surface pixels

my thought was too :

get the surface->pixels member and then get the width and height store them all in separate variables then multiply them then load them back into surface->pixels member if that's even possible am I correct?
probably wrong ;/


any solutions? ;/


#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>
#include <iostream>
#include <math.h>
#undef main

using namespace std;

SDL_Surface *Screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
void pixeltest(int x, int y , int color)
{
unsigned int *poo = static_cast <unsigned int *> (Screen->pixels);
int offset = y * (Screen->pitch / sizeof(unsigned int));

for(x = 0; x <= 1000; x++)
poo[offset + x] = color;
}
int main(int argc, char *argv[])
{
SDL_Surface *PNG , *Imagetest;

SDL_Color WhiteColor={255,255,255};

PNG = IMG_Load("ChocoLeft1.png");
Uint8* keystate;

keystate = SDL_GetKeyState(NULL);
//SDL_LockSurface(PNG);
int pngy = 0;
int pngx = 0;
int pngcolor = 0;

unsigned int *pngptr = static_cast <unsigned int *> (PNG->pixels);
int pngoffset = pngy * (PNG->pitch / sizeof(unsigned int));
bool done = false;

SDL_Event event;

keystate = SDL_GetKeyState(0);
while(!done)
{
SDL_FillRect(Screen,NULL,0xffff26);

SDL_BlitSurface(PNG,NULL,Screen,NULL);

for(pngx = 0; pngx <= 100; pngx++)
pngptr[pngoffset + pngx] = pngcolor;

while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
return 0;
break;

}

}

SDL_Flip(Screen);

}
}
Advertisement
Two things which I would like to clarify first smile.png.

First off, it is called scaling, multipling in conjunction with pixels is often used when we talk about shaders/blending or even photoshop layers. The second point is, that png is just a fileformat, once it is loaded, it doesn't matter any longer.

To scale your image with sdl take a look here.

This topic is closed to new replies.

Advertisement