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

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

问题描述

我有一个C#应用程序,为此,我已经写了使用位图/的TextureBrush渲染到present 2D图像,都可以应用各种图像处理功能GDI + code。这code是在模仿现有的DX9 code应用程序中的新的路径,他们都有一个共同的库来执行所有的向量和矩阵(如ViewToWorld / WorldToView)操作。我的测试床由DX9,我对新的GDI + code的输出比较输出图像。

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邻投影(和身份世界空间),与垂直摄像头和中心质感的四,它是合理的期待<一个href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(MICROSOFT.DIRECTX.DIRECT3D.TEXTUREFILTER);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV3.5%22);k(DevLang-CSHARP)&rd=true"相对=nofollow> DirectX.Direct3D.TextureFilter.Linear 使用时产生相同的输出到GDI +的TextureBrush填充矩形/多边形的<一个href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.DRAWING.DRAWING2D.INTERPOLATIONMODE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV3.5%22);k(DevLang-CSHARP)&rd=true"相对=nofollow> 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 code就是采用这种(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(我已经试过了,没有区别的另一种选择 - 这是有道理给出的说明补充说:prefiltering缩水)

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第I,可以使用(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 +是早就知道有抗锯齿线的麻烦,也与图像缩放preserving质量(这似乎是你的问题)。为了在质量比最新一代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天全站免登陆