[英]WPF pixel shader with HDR (16-bit) input?
我正在嘗試使用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着色器效果工具創建了像素着色器 。
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渲染系統的一個限制。 我將嘗試使用D3DImage
作為解決方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.