It is currently Sat Jan 19, 2019 5:04 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: InterpolationPosted: Sun Sep 16, 2007 5:51 pm

Joined: Mon Sep 27, 2004 2:13 pm
Posts: 1668
I would like to add interpolation to my programs, but I don't have the background in math necessary to understand the Wikipedia entries on the various methods. Has anyone else like me here found a good website for reference?

Most algorithms also interpolate in 2D when I only want to interpolate 1D scanlines to just approximately achieve the correct pixel aspect ratio. What would be the easiest method for me to implement in this respect?

I know I don't want nearest neighbor, but I think I've come up with an algorithm for it. Could someone confirm this to be correct:

Code:
outpixel[i] = inpixel[round(numofpixin/numofpixout*i)]

In the meantime I've come up with a "common sense" algorithm which just weighs pixels against their subpixel "bias" which I split between the previous and next pixels:
Code:
scalefactor = numofpixout / numofpixin

pixelout[i] =
(pixelin[((int)(i / scalefactor) - 1) & numofpixin] * ((i / scalefactor) % 1) / 2)) +
(pixelin[(int)(i / scalefactor)     ] * (1 - ((i / scalefactor) % 1))) +
(pixelin[((int)(i / scalefactor)+ 1) & numofpixin] * ((i / scalefactor) % 1) / 2))

Anything like conventional linear interpolation?

Top

 Post subject: Posted: Tue Sep 18, 2007 3:11 am

Joined: Wed Sep 13, 2006 12:45 pm
Posts: 56
A quick-and-dirty example of linear interpolation that works for:
(output_width / input_width) >= 0.5

(There may be a few bugs, at it's untested, but the general concept is good ).

Also, your input pixel buffer should at least have a pitch of (input_width + 1) pixels, and on each line do:

input_line[input_width] = input_line[input_width - 1];

so that the color of the rightmost pixels in the output will be correct.

Code:
uint32_t step = (uint32_t)((uint64_t)65536 * input_width / output_width);
uint32_t pos = 0;

for(unsigned int i = 0; i < output_width; i++)
{
uint32_t r,g,b;

r = pixel[pos >> 16].r * (0x10000 - (pos & 0xFFFF));
r+= pixel[(pos >> 16) + 1].r * (pos & 0xFFFF);

g = pixel[pos >> 16].g * (0x10000 - (pos & 0xFFFF));
g+= pixel[(pos >> 16) + 1].g * (pos & 0xFFFF);

b = pixel[pos >> 16].b * (0x10000 - (pos & 0xFFFF));
b+= pixel[(pos >> 16) + 1].b * (pos & 0xFFFF);

out_pixel[i].r = r >> 16;
out_pixel[i].g = g >> 16;
out_pixel[i].b = b >> 16;

pos += step;
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki