2009-10-09 54 views
3

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

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

下面是加载图像的代码(以确保我加载了完整的16位范围,只是写源=“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

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