WPF pixel shader with HDR (16-bit) input?

I am trying to create an image viewer for 16 bit PNG images using WPF. My idea was to load images with PngBitmapDecoder, then put them in a control Imageand control the brightness / contrast using a pixel shader.

However, I noticed that the input to the pixel shader seems to have already been converted to 8 bits. Is this a known limitation of WPF or am I mistaken somewhere? (I checked this with a black and white gradient image that I created in Photoshop and which is verified as a 16-bit image)

Here's the code to download the image (to make sure I boot with the full 16-bit range, just writing Source = "test.png" in the Image control loads it as 8-bit)

BitmapSource bitmap;
using (Stream s = File.OpenRead("test.png"))
{
  PngBitmapDecoder decoder = new PngBitmapDecoder(s,BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
  bitmap = decoder.Frames[0];
}

if (bitmap.Format != PixelFormats.Rgba64)
  MessageBox.Show("Pixel format " + bitmap.Format + " is not supported. ");

bitmap.Freeze();
image.Source = bitmap;

Shazzam shader effect.

sampler2D implicitInput : register(s0);

float MinValue : register(c0);
float MaxValue : register(c1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(implicitInput, uv);

 float t = 1.0f / (MaxValue-MinValue);

    float4 result;    
    result.r = (color.r - MinValue) * t;
    result.g = (color.g - MinValue) * t;
    result.b = (color.b - MinValue) * t;
    result.a = color.a;

    return result;
}

XAML :

<Image Name="image" Stretch="Uniform">
  <Image.Effect>
    <shaders:AutoGenShaderEffect x:Name="MinMaxShader" Minvalue="0.0" Maxvalue="1.0>
    </shaders:AutoGenShaderEffect>
  </Image.Effect>
</Image>
+3
1

Microsoft. WPF. D3DImage .

+1

Source: https://habr.com/ru/post/1719704/


All Articles