16-bit per channel image processing?

Is it possible to throw 16-bits/channel image data back and forth to a shader and then save it as a 48-bit PNG in Processing? Has anyone done anything like this?

Tagged:

Answers

  • Answer ✓

    For the adventurers who find their way to this question, looking for an answer, this should theoretically work.

    In your shader, pack the result

    vec4 pack (float depth)
        {
            const vec4 bitSh = vec4(256 * 256 * 256,
                                    256 * 256,
                                    256,
                                    1.0);
            const vec4 bitMsk = vec4(0,
                                     1.0 / 256.0,
                                     1.0 / 256.0,
                                     1.0 / 256.0);
            vec4 comp = fract(depth * bitSh);
            comp -= comp.xxyz * bitMsk;
            return comp;
        }
    

    And in your sketch, unpack it

        float unpack (vec4 colour)
        {
            const vec4 bitShifts = vec4(1.0 / (256.0 * 256.0 * 256.0),
                                        1.0 / (256.0 * 256.0),
                                        1.0 / 256.0,
                                        1);
            return dot(colour , bitShifts);
        }
    

    Credit for this goes to stackoverflow (I .. think), I lost the original source. : (

Sign In or Register to comment.