3

I've got a numpy array which represents a bunch of RGB values. I'd like to save them as a RGB 565 png image, which I'll then use as a THREE.js texture. How can I do this using Python?

Do I just need to write out an appropriate 16-bit greyscale image? I.e., convert the R, G and B values to 5, 6 and 5 bit numbers and then add them binary? Is there a better way of doing it? I'v been using pypng so far to write 8 bit RGB pngs.

Jongware
  • 22,200
  • 8
  • 54
  • 100
nrob
  • 861
  • 1
  • 8
  • 22
  • I don't believe PNG supports 565 directly, the only 16bit format I see is 16bit grayscale or 8bit grayscale+alpha. So your solution of 16bit grayscale is probably the way to go. – Mark Ransom May 29 '15 at 17:28
  • 1
    If png does not support this pixel format, how would you use it then? The file you produce will not be recognised by any program. If you want to use it from other program, you need to know how this program reads the file. – Mikhail V May 29 '15 at 18:55
  • 1
    You can use the PNG sBIT chunk to record the fact that the sample precision is 5-6-5 even though image is stored as 8-8-8. See http://www.w3.org/TR/PNG/#11sBIT – Glenn Randers-Pehrson Jul 08 '15 at 20:13

0 Answers0