Looking to access 16-bit image data in Javascript/WebGL

后端 未结 3 2241
迷失自我
迷失自我 2021-02-14 23:49

I\'m trying to download 16-bit image data from a server and push it into a WebGL texture without browser plug-ins. texImage2d will work with: ImageData, HTMLImageElement, HTMLCa

3条回答
  •  无人共我
    2021-02-14 23:59

    In case of combining two PNG images, one with the top 8 bits and the second with the low 8 bits, I think it should be:

    highp vec4 texCol = texture2D(tex_low, vec2(vTexCoord.s, vTexCoord.t)) * (1.0 / 257.0);
    texCol += texture2D(tex_up, vec2(vTexCoord.s, vTexCoord.t)) * (256.0 / 257.0);
    

    In 8 bits per channel RGB colors will range from 0 to 255 = 2^8 - 1.
    In 16 bits per channel RGB colors will range from 0 to 65535 = 2^16 - 1 = 255*257.

    Explanation

    WebGL works using colour values from 0 to 1 and makes it by dividing 8 bit color value by 255. So the divided value belongs to the range <0,1>.
    In case of 16 bit per channel we would like to divide it by 65535 to get the proper number from range <0,1>.

    What we want is 16 bit color value reduced to range <0,1>.
    Let low and up be color value from range 0..255. up is top 8 bits and low is low 8 bits.
    To get 16 bit value we can compute: low + up*256. Now we have number in range 0..65535. To get value from range <0,1> we divide it by 65535. Note that WebGL works using color values from range <0,1> , it is Lw=low/255 and Uw=up/255. So, we don't have to multiply it by 255 and divide it by 65535 because 65535 = 255*257. Instead we just divide by 257.

    enter image description here

    Also I could not find any software to split 16 bit / channel image into two 8 bit/channel image, so here is my code, feel free to use it, it splits 16 bit / channel Tiff into two 8 bit/channel PNGs:

    https://github.com/czero69/ImageSplitter

提交回复
热议问题