16-bit per channel PNG export

Asked by unfa

I'm using Inkscape to generate heightmaps and bumpmaps that I use in Blender.

The problem I have is that 8 bits per channel gives my very bad quantization (stairstep) on the heightmaps.
The color depth is simply not enough.

Is it possible to export a higher color-depth bitmaps out of innkscape?

16- bit per channel for PNG would totally solve the issue for me, but how do I do this?

In theory I could overcome this limitation by oversampling with dither (like one can do in audio):

1. Add a thin layer of noise overlay in Inkscape that'd produce dithering on the gradients - adding more "sub bit" information.
2. Export to at least 2x resolution - we need more pixels to make use of the dithering.
3. Load in a program that supports higher bit depths (like Krita)
4. Scale down the image, avaraging the pixel values and save to a 16-bit per channel PNG.

This would be very tedious and resource hungry and I would very much love to just be able to export a 16-bit per channel PNG form Inkscape.

An option to export a Grayscale image with higher bitdepth would also be great to save some diskspace.

Question information

Language:
English Edit question
Status:
Invalid
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
johnc
Solved:
Last query:
Last reply:
Revision history for this message
Mc (mc...) said :
#1

Hi,

unfortunately, our rendering library (cairo) only supports at most 32bit per pixel images (8-bit ARGB) https://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t

That said, I implemented for version 0.93 (so, available in devel(trunk)version, but not released) an improvement to allow exporting other png formats [1]. Exporting to ARGB32 will not make much sense in your case (it'll just interpolate #12345678 -> #1212343456567878), but exporting to 16bit gray level will be possible with a 16bit luminance computation using the three 8-bit r,g,b channels

Apart from that, you'll have to oversample

[1] https://launchpadlibrarian.net/286591135/bitmap.png from https://bugs.launchpad.net/inkscape/+bug/170650

Revision history for this message
Ian Bruce (ian-bruce) said :
#3

<unfa> wrote:

> I'm using Inkscape to generate heightmaps and bumpmaps that I use in Blender.
>
> The problem I have is that 8 bits per channel gives me very bad quantization
> (stairstep) on the heightmaps. The color depth is simply not enough.
>
> Is it possible to export a higher color-depth bitmaps out of Inkscape?
>
> 16-bit per channel for PNG would totally solve the issue for me, but how do I do this?

I had exactly the same problem, in exactly the same circumstances.

The solution I came up with is to export your image from Inkscape as a PDF file,
and then use Ghostscript to render it as a 16-bit/channel PNG image:

    gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png48 -r800 -sOutputFile=heightmap.png heightmap.pdf

https://ghostscript.com/doc/current/Devices.htm#PNG

You can adjust the output resolution with the "-r" option; if you set the nominal width
or height of the PDF image to be one inch, then this will directly control the PNG image size.

https://ghostscript.com/doc/current/Use.htm#Output_resolution

***************

<mc> wrote:

> unfortunately, our rendering library (cairo) only supports at most 32bit per pixel images
> (8-bit ARGB)
>
> https://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t

actually, there's a 10-bit/channel image type listed there:

    CAIRO_FORMAT_RGB30 -- like RGB24 but with 10bpc.

> That said, I implemented for version 0.93 (so, available in devel(trunk)version,
> but not released) an improvement to allow exporting other png formats.
> Exporting to ARGB32 will not make much sense in your case
> (it'll just interpolate #12345678 -> #1212343456567878), but exporting
> to 16bit gray level will be possible with a 16bit luminance computation using
> the three 8-bit r,g,b channels

It doesn't seem likely that converting an 8-bit/channel RGB gradient to
a 16-bit grayscale image is going to result in more than 8-bit effective
colour depth, so that doesn't solve the OP's problem.

Can you adjust your patch so that 48-bit PNG output is an option,
and then render to a CAIRO_FORMAT_RGB30 image surface? Then just
shift-left each colour value by six bits before writing the PNG file, and we
get 10-bit effective colour depth.

There is actually a better possibility -- notice this message from the Cairo
mailing-list:

>>> Actually, there is a branch in the pixman repository called
>>> "wide-composite" that has code for 10.10.10.{x,2}.
>>> It is not ready to go in yet, though.
>>
>> What's the use case for 10.10.10.2, out of curiosity?
>
> As I understand it, these formats are supported by nvidia hardware,
> and in order to be able to add those visuals to the X server, software
> fallbacks are needed.
>
> Note that this code is not really specific to the 10.10.10.x formats -
> it works pretty like the existing general compositing code, except
> that it uses an intermediate 16.16.16.16 format instead of 8.8.8.8,
> so that general 16 bits-per-channel formats would be easy to add.

https://lists.cairographics.org/archives/cairo/2007-October/011542.html

That was written almost ten years ago; it seems highly likely that the
pixel format referred to there as "10.10.10.x" is now available as
CAIRO_FORMAT_RGB30. In other words, Cairo can already use
16-bit/channel RGBA internally, and "general 16-bits-per-channel
formats would be easy to add."

Inkscape must be one of the most prominent and successful applications
for Cairo. If a formal request were made by the Inkscape project that Cairo
provide API support for the 16-bit/channel RGBA which they apparently
have already implemented internally, presumably that would motivate
somebody familiar with the Cairo codebase, since it would be "easy to add".

Can this be done? It is really quite shocking that at this late date, with
10-bit/channel monitors and video cards becoming widely available,
free-software vector graphics only supports 8-bit RGB. (Except for
Ghostscript, as above.) GIMP v2.10 is supposed to be released this
year, and will support 16/32-bit colour depth. Can't Inkscape and Cairo
match that?

-- Ian Bruce

Revision history for this message
Mc (mc...) said :
#4

They apparently have it as a proposed student project:
[Medium] Add HDR image surface type to cairo/pixman (CAIRO_FORMAT_ARGB64).

https://www.cairographics.org/todo/