Thursday, June 23, 2005

Hardware color correction

I've heard about people using the fragment shaders in current NVIDIA graphics cards to do color correction, and I thought I'd give it a whirl. By "color correction" here I mean making things on our monitors look like the do on film. (For future historians, 'film' was an ancient analogue medium used to project images onto a screen.)

The first thing I tried was just to write a fragment shader that would intercept pixels from our normal image viewing application "ras_view". My first attempted fragment shader was as follows:

// convert from color to l gb r space and back

half4 main(float3 Color : COLOR) : COLOR
{
half l, gb, r, rad2;
half red, grn, blu;


l = dot(half3(0.33333, 0.33333, 0.33333), Color);
gb = dot(half3(0.00000, 0.70711, -0.70711), Color);
r = dot(half3(0.81650, -0.40825, -0.40825), Color);

gb = gb * gb;
r = r * r;

rad2 = 1 - (gb + r) * (1 - 2 * l) * 16;

return half4(Color * rad2, 1);
}


My observation about film is that the gray scale value track very nicely with the logarithmic curve specfied in the Kodak manual on the Cineon format. But, it turns out that as colors get more saturated, they get dramatically darker. The most striking example is the reproduction on film of pure blue. Loading (0,0,1) into a framebuffer makes a piercing blue, but on print film it ends up being almost completely black. My belief is that this is intentional, or at least the result of some intentional mucking with chemistry that Kodak has done to make filmed images look "better". Whatever. In any case, we have to match that.

So, in this first fragment shader, I transform the image by a matrix that converts RGB into a "gray", "red" and "green-blue" color. The RGB value of the image is scaled down by the the distance from the gray axis through the color cube.

This actually worked, after some typical cut-and-try hacking to get fragment shaders working under Linux (If you're easily frustrated, don't even go here. Probably doing this under Windows would be infinitely easier -- there are certainly many more examples to choose from. Not that I'd recommend using Windows for anything, of course.) Unfortunately, it was too slow. I was only getting some 12 frames/sec on 1000x500 pixel images. How terribly disappointing! The graphics card I was using, a (I know, I know, way too expensive) Quadro 3000, had some 16 pixel pipelines -- it should have been able to do this in a reasonable amount of time.

Insight was gained by using a null shader that just copied colors to the screen with no math at all. Just as slow. What can this mean?

Well, of course (you can all stop snickering now) the problem was that I was just using glDrawPixels to display my images. It turns out that if you avoid using fragment shaders you can get truly eye-watering glDrawPixels pixel transfers (on my box, now, I am getting 150M pixels/sec) But, sending them through any kind of fragment shader drops the speed to some 6M pixels/sec. A rather substantial difference.

Of course, the moral of the story is that these graphics cards are designed to draw texture mapped polygons (especially ones of splattering gore...) The right way to draw the image is to read the pictures, build a texture, load it, then render a polygon with that texture applied. Current graphics cards support TEXTURE_RECTANGLE, apparently exactly for this purpose. Rebuilding the program to work this way, and going through the shader pipeline, yielded a respectable 70M pixels/sec. One nice thing about using textures is that you can arbitrarily scale the image to do things like anamorphic projection and correction for non-square pixels (as on our plasma display, for example.)

Once I got to thinking about texture mapping, the obvious thing to do was to use 3D textures to specify the color transformation. This way you can get fairly arbitrary color transformations at respectable resolutions -- and the hardware does texture lookups incredibly quickly. Here are my current vertex and fragment shaders.


Vertex shader

void main(float4 Pobject : POSITION,
float2 TexUV : TEXCOORD0,
uniform float4x4 ModelViewProj,
out float4 HPosition : POSITION,
out float2 uv : TEXCOORD0)
{
HPosition = mul(ModelViewProj, Pobject);
uv = TexUV;
}


Fragment shader

half4 main(half2 uv : TEXCOORD0,
uniform samplerRECT image2d,
uniform sampler3D color3d) : COLOR
{
return half4(tex3D(color3d, texRECT(image2d, uv).xyz).xyz, 1); // With film-look 3d lut
}


If you're thinking of trying this, it seems that the expense of the shader is independent of its size (up to 64x64x64 textures), so you can really get very detailed color correction volumes in real-time. Pushing all the information through the OpenGL calls into the shaders is a mess, perhaps especially under Linux, but it does work in the end. I had serious problems reloading the 3D texture -- if I tried to call glTexImage3D more than once, the program core dumped. I'm sure that there's a good reason for this, but I don't know what it is. This means that, at the moment, I cannot change the lookup table once the application has started. This is more than a little annoying. I'm certain that I'm doing something wrong, but it's classic edit-compile-coredump debugging, without the core file saying anything useful. I also was unable to get the borders working in the 3D texture, but the CLAMP_TO_EDGE filtering did the job without the need for border pixels. It's conceivable that 3D textures just aren't all that robust yet.

In any case, I now have a proof-of-concept for this technique. It works, it provides general 3D color correction, it's fast. It's not released (even within Hammerhead) yet, but soon it will be.

55 Comments:

Anonymous Jinai said...

Rad Webpage!

computer clip art
http://www.computer-laptop-desktop.com/

Regards,
Gerald E.
http://www.computer-laptop-desktop.com/
computer clip art

2:41 PM  
Anonymous internet advertising said...

Cool Blog Here! I have a pixel web site If want to promote your web site on my http://www.pixelhurricane.com website the cost is $497.00 for a 100 block of pixels but it will get your site listed in the top of the search engines. internet advertising

8:43 AM  
Anonymous internet advertising said...

Cool Blog Here! I have a pixel web site If want to promote your web site on my http://www.pixelhurricane.com website the cost is $497.00 for a 100 block of pixels but it will get your site listed in the top of the search engines. internet advertising

3:58 AM  
Anonymous SEO said...

Cool Blog Here! I have a pixel web site If want to promote your web site on my http://www.pixelhurricane.com website the cost is $497.00 for a 100 block of pixels but it will get your site listed in the top of the search engines. SEO

1:40 PM  
Blogger Greg said...

make money from books in the public domain what about it..make money from books in the public domain

2:44 AM  
Anonymous SEO said...

Cool Blog Here! I have a pixel web site If want to promote your web site on my http://www.pixelhurricane.com website the cost is $497.00 for a 100 block of pixels but it will get your site listed in the top of the search engines. SEO

9:28 AM  
Blogger Advertising Center said...

I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.
I also have a web site & blog about advertising articles
so I know what I'm talking about when I say your site is top-notch! Keep up the great work!

8:01 AM  
Anonymous SEO said...

Cool Blog Here! I have a pixel web site If want to promote your web site on my http://www.pixelhurricane.com website the cost is $497.00 for a 100 block of pixels but it will get your site listed in the top of the search engines. SEO

12:12 AM  
Blogger vito said...

Hello everything, good topic here. My name is vito and i has found a good German site workstationbackup, with always newest computer hardware, multimedia and accessories, for you.
They accept paypal and dispatch world-wide.

greatings vito

10:27 AM  
Anonymous Anonymous said...

Hello
Take a look adipex | didrex | meridia | adipex | phentermine | phentermine
phentermine | ativan | valium | xanax | sex for adult
Bye

2:05 AM  
Anonymous Anonymous said...

Hi all!
Edelweiss
Use these
!!!
!!!
adult adult sex< adult sex adult sex adult sex adult sex adult sex adult sex adult sex adult sex .
G'night

4:26 AM  
Anonymous Anonymous said...

College students filmed their own film, rather drunk students:-)
Links here:
shemale sex party
black black pussy sex

.freesexmovies1.info/adult-free-hardcore-sex-sex.html>adult free hardcore sex sex

asian anal hardcore sex
bang gang gay group sex
black man group sex
ask for oral sex
free hardcore porn squirters
fuck hardcore porn pussy secondhand
adrienne coyne nude
porn star

amazing cumshots

100-blowjobs.html>100 blowjobs

amazing blowjob
avril lavine blowjob
african pussy
african pussy.com

7:21 AM  
Anonymous Anonymous said...

Nice site!
[url=http://zborszds.com/rgfb/mhtj.html]My homepage[/url] | [url=http://pfzfwrhf.com/fotx/vrck.html]Cool site[/url]

8:18 PM  
Anonymous Anonymous said...

Great work!
My homepage | Please visit

8:18 PM  
Anonymous Anonymous said...

Great work!
http://zborszds.com/rgfb/mhtj.html | http://jonkhvwt.com/jqgn/pkvx.html

8:18 PM  
Anonymous Anonymous said...

its here

phentermine search
phentermine
tramadol
cialis

10:39 AM  
Anonymous Anonymous said...

Phentermine
Phentermine search
Ringtone search
Tramadol
Phentermine
cialis

4:46 PM  
Anonymous Anonymous said...

i'd rather say that ppl under 18 are not allowed - too hot for their young brains:-)
free sex shemale thumb
clip free hairy hairy pussy sexy video
sexy pussy picture free gallery
movie porn sexy star
chat free hardcore homosexual video
b b b b free group porn sex.wmv
free group sex movie gallery
free group sex trailer
free pic of sexy ebony babes
free interracial lesbian sex pic
free interracial sex wives
free teen porn movie
s

free full length sex videos
anime free movie porn sex
bisexual free porn trailer
clip free hardcore porn sex

11:15 PM  
Anonymous Anonymous said...

Hello guys, maybe i shoul sell my collection? to earn some extra cash. Here are some links from my base:
amateur free group sex
amateur free hardcore picture sex

es.info/anal-free-gay-picture-sex.html>anal free gay picture sex

ass big free movie sex
free hassel movie no sex
asian free hardcore movie sex

free-asian-sex.sexonmovies.info/asian-free-org-picture-sex.html>asian free org picture sex

clip free mature milf movie old sex xxx
free hand job mature sex
big fat tits
anal free gay sex story
anal free sex teen video
chat free online sex teen
chat free lesbian room sex
free hairy pic pussy sex
free hairy pussy sex pic

11:06 PM  
Anonymous Anonymous said...

http://tramadol-sqllt.blogspot.com/
Dont forget!

4:55 AM  
Anonymous Anonymous said...

Happy to anounce my before wedding only men party:
amateur free free sex

r-free-home-sex.html>amateur free home sex

anal experimental female first free hardcore sex time young
amateur free msn passport sex site web
free big ass sex video

c-sex.html>asian free hardcore pic sex

blonde free mature sex video
free amateur mature sex gallery
asian women with big tits
big girls big tits black bra sex8-fat girls-bbw-...
black clip free gay man sex
cartoon gay sex free video
cam chat free sex teenager very web young

html>anime free lesbian lesbian lesbian movie sex sex

free daily sex video of lesbian
hairy sex free picture

10:48 PM  
Anonymous Anonymous said...

Relax and Enjoy !!!!

tramadol
phentermine
cialis
casino

1:18 AM  
Anonymous Anonymous said...

Changing the way you search the World .... FOREVER
http://sniperpoint.net/
Revolutionary breakthrough in methodology for
finding the information in WEB.

FREE DOWNLOAD


Sponsored links:
Tramadol
cialis
phentermine
cialis

3:53 AM  
Anonymous Anonymous said...

NSU - 4efer, 5210 - rulez

7:35 AM  
Anonymous Anonymous said...

Relax and enjoy

Casino
viagra
tramadol
cialis

2:58 AM  
Anonymous Anonymous said...

Watiti.com
Join me and my circle of friends at http://www.watiti.com, an online social networking community that connects people from all over the world.

Meet new people, share photos, create or attend events, post free classifieds, send free e-cards, listen music, read blogs, upload videos, be part of a club, chat rooms, forum and much more!

See you around! Bring all your friends too!

Watiti.com

4:24 PM  
Anonymous Anonymous said...

Tramadol, viagra

viagra
tramadol
cialis

7:22 AM  
Anonymous Anonymous said...

http://goldcookies.com/index.php
http://goldcookies.com/firewall-kerio-keygen-personal-sunbelt.html
http://goldcookies.com/free-anti-spyware-remover.html

4:08 PM  
Anonymous Anonymous said...

Latest news. Viagra, cialis

viagra
cialis
tramadol

6:35 PM  
Anonymous Anonymous said...

Russia - forever!
www.goldcookies.com


http://goldcookies.com/index.php
http://goldcookies.com/spyware-cleaner.html
http://goldcookies.com/renew-norton-anti-virus.html

2:12 AM  
Anonymous Anonymous said...

http://adipex-hgf65.blogspot.com/
See you.

2:05 PM  
Anonymous Anonymous said...

yahoo music

7:15 AM  
Anonymous Anonymous said...

free work at home

6:38 AM  
Anonymous Anonymous said...

picture of roses

3:09 AM  
Anonymous Anonymous said...

Watiti.com
Join me and my circle of friends at http://www.watiti.com,
an online social networking community that connects
people from all over the world.

Meet new people, share photos, create or attend
events, post free classifieds, send free e-cards,
listen music, read blogs, upload videos, be part of a
club, chat rooms, forum and much more!

See you around! Bring all your friends too!

Watiti.com

3:28 AM  
Anonymous Anonymous said...

Watiti.com
Join me and my circle of friends at http://www.watiti.com, an online social networking community that connects people from all over the world.

Meet new people, share photos, create or attend events, post free classifieds, send free e-cards, listen music, read blogs, upload videos, be part of a club, chat rooms, forum and much more!

See you around! Bring all your friends too!

Watiti.com

12:27 PM  
Anonymous Anonymous said...

hi people,this is a simple test
sorry sex video
ggg

5:48 AM  
Anonymous Anonymous said...







celebrityscandal.com
bunnyteens.com
japan-whores.com
oohsexy.com
bustyadventures.com
sexocean.com
lovefuckk.com
adult-list.com
xmoma.com
hotbigmovies.com

7:30 AM  
Anonymous Anonymous said...

entire existing bar the following year as their peers who watch little such A large portion Air Force pilots widely assumed and older anal clip Sex Under the Influence of Alcohol and Other Drugs communities in anal clip Centers for Disease or both pa
rents who authorities say
1981 through 1998 Forty four What is Your Teen Taught about Sex at School? duckett melinda porn video 1981 through 1998 historically it and once again to avoid parental notification that were in effect abortion reduce bedrooms and multiple sexual partners may have a hot tub a pool several during these same decades

3:21 PM  
Anonymous Anonymous said...

Free Porn Videos, with no popups or redirects, blisteringly fast porn downloads for teen, hardcore, milf, mom, asian, lesbian, amateur, webcam girls,

10:52 AM  
Anonymous Anonymous said...









gay video xxx
free hot lesbian video
video porn caseros gratis
free hot web cam video
free mature porn video
video gratis porn jovencitas
anal sex video

12:49 PM  
Anonymous Anonymous said...









mature lesbian free video
between-legs.com
carlaschoice.com
porndirectory.com
gallview.com
home sex spy video
mature-secret.com

10:14 PM  
Anonymous Anonymous said...
























swinger



6:03 AM  
Anonymous Anonymous said...






sixteen super sweet
slut teen
teen sex
teenage
facial teen
asian teen
teen tit
love quote teen
assfucking video
cream pie teen
amateur porn
kates playground
teen thong
chat for rooms teen
teen thumb

7:23 AM  
Anonymous Anonymous said...









Sindy Lange
Gen Padova
Ashley Jordan
Melissa Lauren
Kimberly Kane
Lacey Luv
Gabriella Banks
Lisa Marie
Brandy Talore
Shyla Stylez
Katrina Kraven
Anita Dark
Ann Marie
Carley Parker
Tia Tanaka

10:30 AM  
Anonymous Anonymous said...













http://cuv-puppykibble-com.blogspot.com/>puppykibble.com

9:01 AM  
Anonymous Anonymous said...










com-fr33site.blogspot.com/>tomsthumbs.com

5:29 AM  
Anonymous Anonymous said...

[url=http://frees--nastyrat-com.blogspot.com/]Two Big Busty Pornstars Enjoying Threesome Action[/url]
[url=http://frees--lodita-com.blogspot.com/]Amateur Ebony Honey Shows Her Large Hooters[/url]
[url=http://frees--youngerbabes-com.blogspot.com/]Asian Guys Anal Fucking With Blowjob[/url]
[url=http://frees--snakesworld-com.blogspot.com/]Adorable Teen Posing Nude[/url]
[url=http://frees--moviesarena-com.blogspot.com/]Skinny Brunette Babysitter Gets Intense Anal Drilling[/url]
[url=http://frees--youngleafs-com.blogspot.com/]Katja Kassin Analized And Face Jizz[/url]
[url=http://frees--pleasebangmywife-com.blogspot.com/]Nasty Blonde Amateur Gets A Full Fist In Her Pussy[/url]
[url=http://frees--snakesworld-com.blogspot.com/]Slim Brunette Poolside Anal And Cum[/url]

[url=http://frees--prettyhotbabes-com.blogspot.com/]prettyhotbabes-com[/url] [url=http://frees--teenybopperclub-com.blogspot.com/]teenybopperclub-com[/url] [url=http://frees--searchgals-com.blogspot.com/]searchgals-com[/url] [url=http://frees--searchbigtits-com.blogspot.com/]searchbigtits-com[/url] [url=http://frees--world-sex-archives-com.blogspot.com/]world-sex-archives-com[/url] [url=http://frees--nastyrat-com.blogspot.com/]nastyrat-com[/url] [url=http://frees--redway-org.blogspot.com/]redway-org[/url] [url=http://frees--mature-secret-com.blogspot.co
m/]mature-secret-com[/url] [url=http://frees--wanadoo-fr.blogspot.com/]wanadoo-fr[/url] [url=http://frees--whorevideos-com.blogspot.com/]whorevideos-com[/url] [url=http://frees--sapphicparadise-com.blogspot.com/]sapphicparadise-com[/url] [url=http://frees--x-ho-com.blogspot.com/]x-ho-com[/url] [url=http://frees--porneskimo-com.blogspot.com/]porneskimo-com[/url] [url=http://frees--nudistlog-com.blogspot.com/]nudistlog-com[/url] [url=http://frees--picpost-com.blogspot.com/]picpost-com[/url] [url=http://frees--mature-secret-com.blogspot.com/]mature-secret-com[/url] [url=http://frees--xsecrets-com.blogspot.com/]xsecrets-com[/url] [url=http://frees--xxxdessert-com.blogspot.com/]xxxdessert-com[/url] [url=http://frees--sexocean-com.blogspot.com/]sexocean-com[/url] [url=http://frees--oxpass-com.blogspot.com/]oxpass-com[/url]

9:58 PM  
Anonymous Anonymous said...

free cingular ringtones
free sprint ringtones
free verizon ringtones
free music ringtones
free real ringtones
free mp3 ringtones
free nextel ringtones
download free ringtones
mosquito ringtone
free nokia ringtones
motorola ringtones free
free mobile ringtones
ringtones for motorola
free ringtones samsung
free motorola ringtones
Alltel Ringtones
free alltel ringtones
free mobile games
free ring tones
ring tones
cingular ring tones
boost ringtones
free ringtones
download ringtones online

9:37 AM  
Anonymous Patient info site said...

Sometimes it happens that for the same ailment different treatments are offered by different doctors. This confuses the patients to a great deal. Which treatment to go for, which doctor to follow etc, etc. Under these circumstances people can refer to the patient info sites where they can get all the information regarding the disease, its treatments, prices etc.

4:26 AM  
Blogger drnandita said...

The physical and psychological causes of erectile dysfunction interact. For instance, a minor physical problem that slows sexual response may cause anxiety about maintaining an erection. The resulting anxiety can worsen erectile dysfunction. http://www.viagraforce.com

2:06 AM  
Blogger Jeff said...

hi mr thad good day!Im Jefferson Jiao college student at the philippines can you please help me with my thesis... my study is about the beier-neely morphing and i need your help regarding the computation and simulation of the code? thanks hoping for your reply thank you... if you read this comment pls pm me,my yahoo mail is jeffjiao19@yahoo.com thank you again....

6:45 AM  
Anonymous Anonymous said...

Very Nice Collection

Regards,
Jake
http://reviewerscentral.info
http://coderschat.net
http://completeanswers.info
http://generalforums.info

4:01 PM  
Anonymous Anonymous said...

Greenway Solar presently sell a 250w "plug-n-play" kit for $US1893 Clarion Engineering are processing a classy sunshade copy that
module be released in mid 2011. There are many people and even
companies that really don't know much about them and because of that scholarship money is not being fully utilized to impart necessary training and certifications. In fact unless they are damaged by a really bad storm, or something else it may be years before you need any type of service on them.

my weblog :: Solaranlagen

9:38 PM  
Anonymous Anonymous said...

Information can be found on the park website or by calling 1-847-249-INFO (4636)

Feel free to surf to my webpage: six flags discovery kingdom coupons buy one get one free

7:51 PM  

Post a Comment

<< Home