What's a good interface for sRGB colours?

I'm writing a ray-tracer, which uses Python to define its scene files.  The ray-tracer itself handles sRGB gamma correctly, but I'm having a hard time coming up with an interface that exposes that functionality clearly to the user.  I'll explain with an example:
Intuitively, one would expect Color(1, 1, 1)/2 to equal Color(0.5, 0.5, 0.5).  But because of sRGB gamma, that's not a half-intensity white.  So two lights with Color(1, 1, 1)/2 would not look the same as one full-brightness light, which would be confusing.
My current idea is to have two different types for colours: "Color" for colours in the linear space, and "sRGB" for colours in the sRGB space.  Is there a better way, that would hide more of the complexity of sRGB gamma from users?

I couldn't get the link to work to examine the code, so I'm just working off of assumptions.
If the Color object stores channel information in a list, iterators might be a natural fit:
color_1 = Color(1, 1, 1)
# one-liner using list comprehensions and parameter expansion
color_2 = Color(*[channel / 2 for channel in color_1.channels])
# slightly more verbose using an extra variable
channels = [channel / 2 for channel in color_1.channels]
color_3 = Color(*channels)
# using a for loop
channels = []
for channel in color_1.channels:
channels.append(channel)
color_4 = Color(*channels)
You might also try having a of_ratio (forgive unintuitive naming class method (alternate constructor) in your Color class:
# This code is untested, but the general idea should hopefully be obvious enough
class Color
def __init__(self, r, g, b):
self.r = r
self.g = g
self.b = b
@classmethod
def of_ratio(cls, ratio):
return Color(*[channel * ratio for channel in cls.channels])
@property
def channels(self):
return [self.r, self.g, self.b]
# example usage
color_1 = Color(1, 1, 1)
color_2 = Color.of_ratiof(color_1, 0.5)
edit:
I just remembered, you could do operator overloading.
Just implement __add__ __sub__ __div__ __mul__, etc respectively.
Last edited by aspidites (2011-12-04 05:59:26)

Similar Messages

  • What is a good interface to get LE's max # of tracks?

    I have heard goo things from folks using the FirePod, but what is a good interface for LE to get the max tracks it is capable of?

    Hey tele-player! LTNS!
    Well, I am still leaning towards the FirePod, but since I have no immediate plans to buy anything, maybe something new will come out by the time I get to a position that I can actually make a purchase.
    My day gig is being outsourced to India, and at my age, i really don't want to go out and look for another job. So I plan to do whatever else I can from home to try to make a living. Plus I am gonna get to play out again And I thought maybe I might offer my services to some of the young bands locally to help them record demos. So, this is a "down the road" situation for now. For that, I'll need to get Tiger as well as the FirePod, and a handful more mics than I have for starters.

  • What's a good book for getting started?

    I've been doing web design in HTML and ColdFusion for almost 3 years. It's clear that ColdFusion is on it's way out and I need to learn J2EE/Java/JSP etc. I have a few questions:
    Java is a term I've heard associated with C++ and other types of programming as well as Web design. Are the Java/C++ Java and the Web Java basically the same type of language? Is the Web Java and JavaScript the same thing? I'm very confused!
    What is a good book for getting these types of questions answered and getting started in J2EE/Java/JSP? There are quite a few variations of script languages out there and I want to make sure I learn the right stuff, ie the stuff that employers are going to be needing.
    Thanks!

    Here is a free online version of a good book:
    http://pdf.coreservlets.com/Core-Servlets-and-JSP.pdf
    Print it off or read from the screen. Otherwise, there are several good Java books out there. What I would do is go to the bookstore and thumb through a few books. Depending on what type of book you want (example based or theory) find the books that you think would satisfy your learning style. Write down the names and authors, go home and buy them used online at Amazon for tremendous discounts. This way you can buy several versus just one.

  • What is a good strategy for keeping the OEM GRID up and running?

    Hi,
    What is a good strategy for keeping OEM GRID up and running? Currently, we have grid installed on one linux64bit box with 4 cpus and 8 gigs of RAM, oms 10204, repdb 10204, agent 10204. In addition to using this oem grid for notifications and performance monitring, we are also using this oem grid for scheduling over 700 jobs running over 30 targets.
    What is a good strategy to have to backup the grid so that when this box goes down, we can restore and then recover the grid? Please lead to white papers or documentations. Thank you.

    Take a look at Oracle Maximum Availability Architecture, a set of architectural recommendation on setting Oracle software up for high availability.
    The information is available on this page:
    http://www.oracle.com/technology/deploy/availability/htdocs/maa.htm
    Look under HA Best Practices for Grid Control.
    Chung Wu
    [Application Management Blog|http://www.appmanagementblog.com/]

  • What is a good replacement for the Adobe Flash Player for my iPad?

    What is a good substitute for Adobe Flash Player for my iPad? I would like to download a flash player for games but not sure what to get. Any suggestions, please?

    <http://store.apple.com/us/product/MC742ZM/A/ati-radeon-hd-5770-graphics-upgrade- kit-for-mac-pro-(mid-2010)>

  • What's a good interface to record voice/guitar tracks in Logic Pro

    Hello - could you tell me what would be a good interface to record voice/guitar into a Logic Pro project please?  Thanks.

    planetCAS wrote:
    re the firmware update - there is talk that this should only be done if you are going to use USB - and also that it needs to be done via Windows.........I am confused re this?
    I don't know about that, I don't own a Phonic, but if you only have to do it for USB, well, then there's no problem and you don't have to do anything, so...
    Also when you say DAW (what does that stand for?
    Digital Audio Workstation; Logic, Cubase, Protools etc are all DAWs. You'll probably encounter this term once in a while...
    I just want to make sure and sorry if i sound silly but I should be able to use Phonic as my interface with Logic Pro without using Cubase?
    Yes.

  • Analog to Digital Converter-- What's A Good Product For My System?

    What would be a good analog to digital converter for Final Cut Express HD 3.5 on a Mac OSX 10.4 system? I've used a Canopus on a MacPro with Final Cut Pro before and liked it, but wasn't sure what would be a good product for my macbook. I've looked at the Canopus advc-110 and 55 but am not clear on the difference and if it would work with what I have.

    The ADVC-55 is capture only. It includes composite & s-video inputs and stereo audio inputs. Firewire output.
    The ADVC-110 is bidirectional (meaning you can both capture and output through it - this is a very good way to monitor your video during production as you can see the actual quality on a monitor/TV rather than just your computer screen, which has limited capability to show you the actual video quality.) It includes composite & s-video inputs and outputs; stereo audio inputs & outputs; Firewire input & output.
    The ADVC-300 is also bidirectional and includes composite, s-video and component video i/o (D1 connector) inputs & outputs; stereo audio inputs & outputs; Firewire input & output; and software that enables you to tweak its video settings. Helpful in cleaning up particularly bad analog videos.
    I've used these things for years and they all work great. I do not believe there is any difference in the internal conversion hardware ... The primary differences are support for one-way vs. bidirectional conversion; input/output connectors; and the software that comes with the ADVC-300.
    If you have basically clean analog video, any of these units will be fine. You can use any analog source (VHS deck, camcorder, DVD player, etc.) and would typically use iMovie or Final Cut Express to capture your video on a Mac.

  • What is a good extenstion for pop up menus?

    I recently created a site in Fireworks that used pop up menus
    but then found out later that they don't work on Internet Explorer
    (you can view the site at www.caspre.com it is the very last menu
    item at the end called "about cascade"). What I need to know is if
    there is a good extension for dreamweaver (or fireworks) that won't
    cause problems in ie. It should be noted that the pop up menu works
    great in Firefox.

    "Paevo Kelley" <[email protected]> wrote in
    message
    news:fl1dh0$ck5$[email protected]..
    > Or Plugin Lab (much better in my opinion)...
    Mind to qualify your opinion in terms of code quality,
    accessibility, and
    support? I'm sure that would be quite helpful information for
    lots of folks.
    Al Sparber - PVII
    http://www.projectseven.com
    Extending Dreamweaver - Nav Systems | Galleries | Widgets
    Authors: "42nd Street: Mastering the Art of CSS Design"

  • What is a good design for remote Views?

    Hi All,
    I am thinking how would I design my process for performance consideration in retrieving dynamic values of table/view data.
    The requirement is like this:
    1. We have 50 databases residing on each own server counterpart (50 servers).
    2. Each database has table Patch_LeveL (apps_name, patch_level), which contains  just one row only to reflect the latest patch level applied for the apps on this database. Note that are we constantly on applying service packs for this apps.
    3. On our central monitoring server (db). I create 50 database LINKS for each of the 50 databases.
    4. I created 50 views over these links to make  it centralized to represent  the 50 Patch_Level tables. As   patch_level_view1, 2, 3.....patch_level_view50.
    5. I then create a central view as .... as  union of the 50 individual views Actually I am just planning to do the above activity.
    My question is....is this a good design for performance? Can you share be a better approach?
    Is there a limitation of joining "union" of 50 views?
    Thanks a lot,

    Is there a limitation of joining "union" of 50 views?What can happen is if the connection to one of these servers is interrupted, the big "union" view will not work. As said by above poster MV, with lets say an hourly refresh, helps with this situation as you have the data that was gathered last time (and most likely it is still valid).

  • Looking for clip art pictures for birthday invitation. What is a good spot for that?

    Looking for clip art pictures for Birthday invitations. What is a good spot to find these or how do I acess this on my mac.  New to mac.
    Thanks

    Do a search for clip art using your favorite search engine - Google or Bing are good places to start. 

  • What are some good cases for the ipad 2?

    what are good cases for the ipad 2?

    I bought an Adesso case/keyboard model WKB-2000CD http://www.adesso.com/en/component/content/article/49-coming-soon/455-wkb-2000cd .html Works great & looks good. Do a Google search using the model number to get the best price.
     Cheers, Tom

  • What's a good codec for working with Sony HDCAM 24P  How much storage space

    cutting a short film shot with Sony HDCAM 24P Is there a sequence setting foe 24P and should I keep it 24P? What's the storage requirements for this or where can I look it up? Thanks!

    dvcProHD is also a great offline low demand codec and you can maintain 23.98 frame rate

  • What's a good solution for cataloging DNG raw photo files for creative teams?

    Does anyone know of a good solution for cataloging DNG raw photo files for creative teams? I'm looking for something that will extract previews as well as be searchable by category and keywords?

    Does anyone know of a good solution for cataloging DNG raw photo files for creative teams? I'm looking for something that will extract previews as well as be searchable by category and keywords?

  • What's a good fit for me?

    I want to know which SAP module is the best fit for me. I have a masters in IT and an MBA in finance. I am currently working in BI (for a while now) and I like it. But I want to better utilize my MBA and stay in SAP. Finance interests me a lot. However I did not find the FICO module interesting, it seemed more Accounting. Any other modules that are a good fit for finanace graduates? Thanks.

    figured it myself.

  • What are some good apps for changing the pitch of my music? I currently use djay. Is there anything better?

    I like shifting the pitch of songs, it makes it sound new to me. what are some good apps that can do this? right now I use djay

    I like shifting the pitch of songs, it makes it sound new to me. what are some good apps that can do this? right now I use djay

Maybe you are looking for