【问题标题】:WPF pixel shader with HDR (16-bit) input?具有 HDR(16 位)输入的 WPF 像素着色器?
【发布时间】:2010-12-05 07:11:15
【问题描述】:

我正在尝试使用 WPF 为 16 位 PNG 图像构建图像查看器。我的想法是使用PngBitmapDecoder 加载图像,然后将它们放入Image 控件中,并使用像素着色器控制亮度/对比度。

但是,我注意到像素着色器的输入似乎已经转换为 8 位。这是 WPF 的已知限制还是我在某处犯了错误? (我用我在 Photoshop 中创建并验证为 16 位图像的黑白渐变图像进行了检查)

这是加载图像的代码(以确保我加载完整的 16 位范围,只需在 Image 控件中写入 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>

【问题讨论】:

    标签: wpf shader bits-per-pixel


    【解决方案1】:

    我刚收到 Microsoft 的回复。这确实是 WPF 渲染系统的一个限制。我会尝试D3DImage 作为解决方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      相关资源
      最近更新 更多