PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

resizing Pictures

Hi all, I've a picture that I want to resize on the fly.

What I'm doing is talking at std 24x24px picture and copying it into a larger buffer (a screen), I'd like to be able to resize the picture, smaller and larger etc, does anyone have a simple algothum for resizing at source image (buffer) into another (buffer)?, somthing based an a magnification factor?

-any code would really be appreciated!
You should be able to find ample examples of image-scaling algorithms on Google or in books...

In any case, it's not that hard to figure it out :P
brendan:if you know what's fixedpoint math.. just think for a while.. if you don't.. learn about it and then think.. it's pretty straightforward
Yes, It seems straight forward etc, and I could learn it.... but I was just hoping I wouldent have to re-invent the wheel again, anyhows..... google here we come...
PocketFrog has source code that do what you want. It is using fixed point maths, so take a look at it.
I'll have a look:

for the time being this is my working function, without fixed maths, it's very slow (ish):

it also has other factors like referenceing a tile in the src gfx as well....

Code:

void place_item_scale_trans(int destsizex, int xpos, int ypos, int xsize, int ysize, int number_itemsx, int item, int transcolor, PIXEL* src, PIXEL* dest, float scale)
{
unsigned int dest_loc = (destsizex * ypos) + xpos;
unsigned int source_width = number_itemsx * xsize;
unsigned int source_loc = ((item / number_itemsx) * source_width * ysize) +
((item % number_itemsx) * xsize);
int calc;
for (int y = 0; y < (ysize * scale); y++)
{
for (int x = 0; x < (xsize * scale); x++)
{
calc = (round(x / scale) + round(y / scale) * source_width);
if (src[calc] != transcolor)
dest[dest_loc + x] = src[calc];
}
dest_loc += destsizex; // move down a row in dest
//source_loc += source_width; // move down a row in source
}
}