Adding more channels/data to an image?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
arundel
Prole
Posts: 31
Joined: Tue Sep 21, 2010 8:49 pm
Location: The Netherlands

Adding more channels/data to an image?

Post by arundel »

Is it possible in löve to add more channels than the only r,g,b,a one's? Like a 5th channel that can accept any number, decimal, negative etc. which isn't contrained to a range of 0-255.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Adding more channels/data to an image?

Post by raidho36 »

You can store data to VRAM the same way as in RAM (not exactly, but still), so if you can write appropriate shader to use it, you can. You'd have to handle memory manually though.
arundel
Prole
Posts: 31
Joined: Tue Sep 21, 2010 8:49 pm
Location: The Netherlands

Re: Adding more channels/data to an image?

Post by arundel »

Thanks for the suggestion raidho36, but think I'll go for an easier solution.. if there is any. I thought of something like:
I store the value I want over the 4 channels, in that way I will get a number limit of 255^4=4228250625, which I think is a reasonable limit for my purpose.
Kindof like: (r=205,g=4,b=1,a=1) equals the number: 4*255+205=1255. It's like a counter; when 'r' reaches 255, 'g' adds 1 to itself, and so on. I can't use decimals though. Would this idea work?
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Adding more channels/data to an image?

Post by slime »

If you want to pack a float value in 4 unsigned bytes (which is what each pixel in an ImageData is), you can do something like this http://aras-p.info/blog/2009/07/30/enco ... the-final/ , although if you use it outside a shader you'll have to either modify it to work in the 0-255 range instead of 0-1, or convert your numbers to 0-1 instead of 0-255 and convert back to 0-255 from 0-1 when reading from the function.

ImageData always stores 4-component RGBA data at 1 byte per component (32 bits total) per pixel, you can't change that.
In LÖVE 0.9.0, you will be able to create "HDR" Canvases (but not ImageData or Images) which store data at 64 bits per pixel (2 bytes per component and 4 color components per pixel) whose values can range from -infinity to +infinity. You'll need to use shaders to do anything useful with that, though.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests