Page 1 of 1

Adding more channels/data to an image?

Posted: Tue Aug 20, 2013 5:42 pm
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.

Re: Adding more channels/data to an image?

Posted: Tue Aug 20, 2013 7:53 pm
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.

Re: Adding more channels/data to an image?

Posted: Tue Aug 20, 2013 8:35 pm
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?

Re: Adding more channels/data to an image?

Posted: Tue Aug 20, 2013 8:38 pm
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.