It is currently Tue Jul 17, 2018 5:02 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Pixel interpolation?Posted: Thu Dec 29, 2016 6:17 am
 Formerly Fx3

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3127
Location: Brazil
I use a RGB palette. Any other way of interpolating the pixels than arithmetic mean in each component?

Top

 Post subject: Re: Pixel interpolation?Posted: Thu Dec 29, 2016 7:50 am

Joined: Sun Mar 19, 2006 9:44 pm
Posts: 953
Location: Japan
There are many ways. You could calculate the path from one colour to the other using quadratic formulas, or splines. Also, use HSV, CMYK, HSL, etc. colour spaces when interpolating. Each colour space will give different intermediate colours, each more or less artistically suited to what you want.

 This page looks like an obvious good place to start: https://en.wikipedia.org/wiki/HSL_and_HSV

_________________
http://www.chrismcovell.com

Top

 Post subject: Re: Pixel interpolation?Posted: Thu Dec 29, 2016 4:55 pm

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4055
You need to convert from SRGB (your usual 8-bit RGB format) into Linear RGB, then do componentwise interpolation there, then convert back to SRGB.

Here's a common example image that gets ruined with typical SRGB algorithms. If you downscale by 50% by adding 4 pixels then dividing by 4, you get solid gray. Just try resizing this down to 50% size in a common image editor, you'll see it happen.
But in the Linear RGB color space, you get correct results.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Top

 Post subject: Re: Pixel interpolation?Posted: Fri Dec 30, 2016 9:33 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20255
Location: NE Indiana, USA (NTSC)
If you're trying to do this in a pixel shader, and doing the full conversion between linear and sRGB in real time is hard, you can use approximate sRGB as gamma 2. To convert to linear power, square it (power = value*value), and then to convert back, take the square root (value = power * rsqrt(power)). This is fast on GPUs because they have a dedicated instruction for reciprocal square root (rsqrt(x) = x-1/2) for use in lighting and other calculations that use unit normal vectors. If you want to prototype your algorithm in a well-known image editor before you write code, the equivalent operation in GIMP or Photoshop is applying Levels with gamma 0.5, doing your blurring or scaling, and then applying Levels with gamma 2.

Top

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

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 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