代码之家  ›  专栏  ›  技术社区  ›  chris166

带HDR(16位)输入的WPF像素着色?

  •  3
  • chris166  · 技术社区  · 15 年前

    我正在尝试用WPF构建一个16位PNG图像的图像查看器。我的想法是用 PngBitmapDecoder ,然后将它们放入 Image 控制,并使用像素明暗器控制亮度/对比度。

    但是,我注意到像素着色程序的输入似乎已经转换为8位了。这是已知的WPF限制还是我在某个地方犯了错误?(我用我在photoshop中创建的黑/白渐变图像检查了这一点,并将其验证为16位图像)

    下面是加载图像的代码(为了确保我以完整的16位范围加载,只需在图像控件中编写source=“test.png”将其加载为8位)

    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 tool .

    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>
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   chris166    15 年前

    我刚收到微软的回复。这实际上是WPF渲染系统中的一个限制。我会尝试 D3DImage 作为解决方案。