双线性插值 - DirectX 与 GDI+ [英] Bilinear interpolation - DirectX vs. GDI+

查看:40
本文介绍了双线性插值 - DirectX 与 GDI+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# 应用程序,我为它编写了 GDI+ 代码,该代码使用位图/TextureBrush 渲染来呈现 2D 图像,可以应用各种图像处理功能.此代码是模仿现有 DX9 代码的应用程序中的新路径,它们共享一个公共库来执行所有向量和矩阵(例如 ViewToWorld/WorldToView)操作.我的测试台包含 DX9 输出图像,我将这些图像与新 GDI+ 代码的输出进行比较.

I have a C# app for which I've written GDI+ code that uses Bitmap/TextureBrush rendering to present 2D images, which can have various image processing functions applied. This code is a new path in an application that mimics existing DX9 code, and they share a common library to perform all vector and matrix (e.g. ViewToWorld/WorldToView) operations. My test bed consists of DX9 output images that I compare against the output of the new GDI+ code.

一个简单的测试用例,渲染到与位图尺寸匹配的视口(即没有缩放或平移)确实匹配像素完美(没有二进制差异) - 但一旦图像被缩放向上(放大),我在 5-10% 的像素中得到了非常小的差异.差异的大小为 1(有时为 2)/256.我怀疑这是由于插值差异造成的.

A simple test case that renders to a viewport that matches the Bitmap dimensions (i.e. no zoom or pan) does match pixel-perfect (no binary diff) - but as soon as the image is zoomed up (magnified), I get very minor differences in 5-10% of the pixels. The magnitude of the difference is 1 (occasionally 2)/256. I suspect this is due to interpolation differences.

问题:对于 DX9 正射投影(和身份世界空间),相机垂直并以纹理四边形为中心,期望 DirectX.Direct3D.TextureFilter.Linear 在使用 System.Drawing.Drawing2D.InterpolationMode.Bilinear设置?

Question: For a DX9 ortho projection (and identity world space), with a camera perpendicular and centered on a textured quad, is it reasonable to expect DirectX.Direct3D.TextureFilter.Linear to generate identical output to a GDI+ TextureBrush filled rectangle/polygon when using the System.Drawing.Drawing2D.InterpolationMode.Bilinear setting?

对于这种(放大)情况,DX9 代码使用了这个(MinFilter,MipFilter 设置类似):
Device.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Linear);

For this (magnification) case, the DX9 code is using this (MinFilter,MipFilter set similarly):
Device.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Linear);

并且 GDI+ 路径正在使用:g.InterpolationMode = InterpolationMode.Bilinear;

and the GDI+ path is using: g.InterpolationMode = InterpolationMode.Bilinear;

我认为双线性插值"是一个相当具体的过滤器定义,但后来我注意到 GDI+ 中有另一个用于HighQualityBilinear"的选项(我已经尝试过,没有区别 - 鉴于描述"添加了用于收缩的预过滤")

I thought that "Bilinear Interpolation" was a fairly specific filter definition, but then I noticed that there is another option in GDI+ for "HighQualityBilinear" (which I've tried, with no difference - which makes sense given the description of "added prefiltering for shrinking")

后续问题: 期望 DirectX 和 GDI+ 之间像素完美的输出匹配是否合理(假设传入的所有外部坐标都相等)?如果没有,为什么不呢?

Followup Question: Is it reasonable to expect pixel-perfect output matching between DirectX and GDI+ (assuming all external coordinates passed in are equal)? If not, why not?

澄清:我使用的图像是不透明灰度(R=G=B,A=1),使用 Format32bppPArgb.

Clarification: The images I'm using are opaque grayscale (R=G=B, A=1) using Format32bppPArgb.

最后,我可以使用许多其他 API(Direct2D、WPF、GDI 等)——这个问题通常适用于比较其中任意两个等效"双线性插值输出图像的输出.谢谢!

Finally, there are a number of other APIs I could be using (Direct2D, WPF, GDI, etc.) - and this question generally applies to comparing the output of "equivalent" bilinear interpolated output images across any two of these. Thanks!

推荐答案

DirectX 主要在 GPU 中运行,而 DX9 可能正在运行着色器.GDI+ 运行在完全不同的算法上.我认为期望两者提供精确的像素匹配输出是不合理的.

DirectX runs mostly in the GPU and DX9 may be running shaders. GDI+ runs on completely different algorithms. I don't think it is reasonable to expect the two to come up with exactly pixel-matching outputs.

我希望 DX9 具有比 GDI+ 更好的质量,这是对旧 GDI 的一步改进,但并不多.长期以来,人们一直认为 GDI+ 在抗锯齿线和保持图像缩放质量方面存在问题(这似乎是您的问题).为了获得与最新一代 GPU 纹理处理类似的质量,您需要转向 WPF 图形.这提供了类似于 DX 的质量.

I'd expect DX9 to have better quality than GDI+, which is a step improvement over the old GDI but not much. GDI+ is long understood to have trouble with anti-aliasing lines and also with preserving quality in image scaling (which seems to be your problem). In order to have something similar in quality than latest-generation GPU texture processing, you'll need to move to WPF graphics. This gives quality similar to DX.

WPF 也使用 GPU(如果可用)并回退到软件渲染(如果没有 GPU),因此 GPU 和软件渲染之间的输出相当接近.

WPF also uses the GPU (if available) and falls back to software rendering (if no GPU), therefore the output between GPU and software rendering are reasonably close.

虽然这已被选为答案,但这只是早期的解释尝试,并没有真正解决真正的原因.读者可以参考问题的评论和答案中的讨论.

这篇关于双线性插值 - DirectX 与 GDI+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆