Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to multiply Pixels on a PNG Loaded SDL Surface?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 DarkHorseKnight   Members   -  Reputation: 143

Like
0Likes
Like

Posted 05 October 2012 - 07:30 PM

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);

}
}

Edited by DarkHorseKnight, 05 October 2012 - 07:31 PM.


Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 6881

Like
0Likes
Like

Posted 08 October 2012 - 05:06 AM

Two things which I would like to clarify first Posted Image.

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.

Edited by Ashaman73, 08 October 2012 - 05:08 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS