lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
28.91k stars 1.29k forks source link

Support for 16 bit color depth PNG #3988

Closed gillesboisson closed 6 months ago

gillesboisson commented 7 months ago

Feature request

What are you trying to achieve?

From 16 bits (ushort) pngs I would to keep color depth when it saved

When you searched for similar feature requests, what did you find that might be related?

I didn't any option in PngOptions

const image = sharp('./my-image.png');

image.png({
   // color depth doesn't need to be supported if imagesource was ushort already
   colorDepth: 'ushort' // or 16 but it seams that specifying type seems to make sens, png support ubyte ushort 
});

What alternatives have you considered?

No alternative apart from switching library

Please provide sample image(s) that help explain this feature

My use case is mainly for GLTF export optimisation as I need to resize and compress texture, normal map and high quality require 16 bits color depth texture. In order to be used as it is, or compressed again in GPU texture format

eg. Books_Oil_Lamps_and_Props_Normal

lovell commented 7 months ago

Did you see https://sharp.pixelplumbing.com/api-colour#tocolourspace ?

await sharp(input)
 .toColourspace('rgb16')
 .toFile('16-bpp.png');

In addition, if you hadn't seen it, https://github.com/donmccurdy/glTF-Transform uses sharp under the hood and may be of interest.

gillesboisson commented 7 months ago

Thanks for your reply, Sorry I have been lazy on not getting deeper enough into the doc

Is it a normal behaviour that the sharp object doesn't takes source color depth by default and use 8 bits,but takes srgb / rgb source colour space into account when it is exported.

lovell commented 7 months ago

I've added some clarification and a further example to the docs via commit https://github.com/lovell/sharp/commit/0eb57698ec4b47cc9d67f8ec25d70bb4d3930fb5

lovell commented 6 months ago

I hope this information helped. Please feel free to re-open with more details if further assistance is required.