XNA 是否有 BGRA/BGRX 表面格式?

发布于 2024-12-04 03:24:58 字数 675 浏览 1 评论 0原文

我有一个来自 Kinect 的视频流。其数据以 32 位 BGRX 格式打包。我想将这些数据直接移动到Texture2d中,但我找不到匹配的SurfaceFormat。我能找到的最接近的是 SurfaceFormat.Color,它看起来是 32 位 RGBX。

假设没有兼容的格式。将数据转换并推送到纹理 2d 的最快方法是什么

我认为这样的方法会很好,但它似乎会减慢帧速率:

编辑:我稍微改变了算法,它现在似乎运行得很好。

    void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
    {
        byte x;
        for (int i = 0; i < e.ImageFrame.Image.Bits.Length; i += 4)
        {
            x = e.ImageFrame.Image.Bits[i];
            e.ImageFrame.Image.Bits[i] = e.ImageFrame.Image.Bits[i + 2];
            e.ImageFrame.Image.Bits[i + 2] = x;
        }
        canvas.SetData(e.ImageFrame.Image.Bits);
    }

I have a video stream coming in from the Kinect. It's data is packed in a 32bit BGRX format. I would like to move this data directly into a Texture2d but I cant find a matching SurfaceFormat. The closest thing I can find is SurfaceFormat.Color which looks to be 32bit RGBX.

Assuming that there is not a compatible format. What is the quickest way to convert and push the data to a texture 2d

I was thinking something like this would be good, but it seems to slow down the framerate:

Edit: I changed the algorithm a bit and it seems to be running decently now.

    void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
    {
        byte x;
        for (int i = 0; i < e.ImageFrame.Image.Bits.Length; i += 4)
        {
            x = e.ImageFrame.Image.Bits[i];
            e.ImageFrame.Image.Bits[i] = e.ImageFrame.Image.Bits[i + 2];
            e.ImageFrame.Image.Bits[i + 2] = x;
        }
        canvas.SetData(e.ImageFrame.Image.Bits);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-12-11 03:24:58

这是我能想到的最快的事情:

    void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
    {
        byte[] bits = e.ImageFrame.Image.Bits;
        for (int i = 0; i < bits.Length; i += 4)
        {
            frameBuffer[i] = bits[i + 2];
            frameBuffer[i + 1] = bits[i + 1];
            frameBuffer[i + 2] = bits[i];
        }
        canvas.SetData(frameBuffer);
    }

完全不涉及 kinect,我得到的帧率为 4200

将字节直接移动到texture2d而不纠正格式差异 产量:3100

如果你给自己一个局部变量e.ImageFrame.Image.Bits 并将字节复制到预先分配的缓冲区中,修复字节,我得到:2700

我在原始问题中列出的算法,您可以在其中交换位,然后发送到texture2d 产量约为 750

因此,回顾一下对该算法的更改,帧速率从 750 提高到 2700

This is the fastest thing I have been able to come up with:

    void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
    {
        byte[] bits = e.ImageFrame.Image.Bits;
        for (int i = 0; i < bits.Length; i += 4)
        {
            frameBuffer[i] = bits[i + 2];
            frameBuffer[i + 1] = bits[i + 1];
            frameBuffer[i + 2] = bits[i];
        }
        canvas.SetData(frameBuffer);
    }

Without the kinect involved at all I get a framerate of 4200

Moving the bytes directly to the texture2d without correcting the format difference yield: 3100

If you give your self a local variable with e.ImageFrame.Image.Bits and copy the bytes into a preallocated buffer fixing the bytes as you go I get: 2700

The algorithm i have listed in my original question where you swap the bits in place and then send to texture2d yield about 750

So to recap changing to this algorithm bumped the framerate to 2700 up from 750

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文