fast 2x image scaling algorithm

Started by
10 comments, last by samgzman 20 years, 3 months ago
Ever heard of 2xSaI? Nica algo for image scaling.

Check it here:
http://elektron.its.tudelft.nl/~dalikifa/
Advertisement
quote:Original post by Anonymous Poster
the code u posted RPGeezus didnt make much sense to me in following it logically, but it did it anyhow and here is what i got

My code as it is:
	m_ucTest1 = new unsigned char[32*32];m_ucTest2 = new unsigned char[64*64];// m_ucTest1 is filled hereunsigned char* srcPtr  = &m_ucTest1[0];unsigned char* dstRowPtrA  = &m_ucTest2[0];	unsigned char color;for (int y = 0; y < 32; y++){     for (int x = 0; x < 32; x++)     {          color = *srcPtr;          *dstRowPtrA = color;          *(dstRowPtrA + 64) = color;          dstRowPtrA++;          srcPtr++;     }     dstRowPtrA += 64;}   


My bad. Sorry, I wrote this code off the top of my head. I was trying to give you an idea as to how it might be done, not code to actually do it.

In any case, I left out two lines: in the main loop, where we set the color in the destination, were setting x,y and x,y+1. We also need to set x+1,y and x+1,y+1. In doing this, you'll also need to increment dstRowPtrA not by one (++) but by two (+= 2). This 'should' fix your problem.

unsigned char color;for (int y = 0; y < 32; y++){     for (int x = 0; x < 32; x++)     {          color = *srcPtr;          *dstRowPtrA = color;          *(dstRowPtrA + 64) = color;          *(dstRowPtrA +1) = color;          *(dstRowPtrA + 64 + 1) = color;          dstRowPtrA += 2;          srcPtr++;     }     dstRowPtrA += 64;}   



In doing this you might notice that we could actually replace the four *setPixel lines with TWO lines by chainging:

char *dstRowPtrA
to
short *dstRowPtrA

and

unsigned char color
to
short color

then

color = *srcData // Same as before
color += color << 8; // This effectivley duplicates the color byte (0x00aa will become 0xaaaa).

then revert the += 2 in dstRowPtrA back to ++ (because a short is two bytes).

Then, outside of the for ( x= loop, change the dstRowPtrA += 64 to dstRowPtrA += 32; This is because when you increment a pointer, it increments to the next record-- that is, if you had a long *ta, and said ta++, ta would actually increment four bytes (the length of a long).

This might speed up the code a bit.

Sorry for the snafu. I was tryping off the top of my head.

Will

[edited by - RPGeezus on January 8, 2004 12:10:54 PM]
------------------http://www.nentari.com

This topic is closed to new replies.

Advertisement