为什么sizeof(NUI_DEPTH_IMAGE_PIXEL)4而不是2? [英] Why is sizeof(NUI_DEPTH_IMAGE_PIXEL) 4 and not 2?

查看:44
本文介绍了为什么sizeof(NUI_DEPTH_IMAGE_PIXEL)4而不是2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

深度像素的大小应该是16位吗?玩家索引为3位,深度信息为13位。但似乎并非如此。我有一个以下函数将深度转换为rgb,基于深度基础知识来自SDK的c ++示例:

So the size of a depth pixel should be 16 bits right? 3 bits for player index and 13 for depth information. But it doesn't seem to be the case. I have a following function to convert depth to rgb, based on depth basics c++ sample from SDK:

void DepthConverter::process(unsigned char* frameData, unsigned char* outBuffer)
{    
    if (frameData != NULL)
    {
        unsigned char* rgbRun = outBuffer;

        unsigned short* bufferRun = reinterpret_cast<unsigned short *>(frameData);

        // end pixel is start + width*height - 1
        unsigned short* bufferEnd = bufferRun + (width_ * height_);

        while (bufferRun < bufferEnd)
        {
            // discard player index
            unsigned short depth = *bufferRun >> 3;

            unsigned char intensity = depthToIntensity_[depth];

            // blue byte
            *(rgbRun++) = intensity;

            // green byte
            *(rgbRun++) = intensity;

            // red byte
            *(rgbRun++) = intensity;

            // alpha (skip)
            ++rgbRun;

            // Increment buffer index
            ++bufferRun;
        }
    }
}

这显然不起作用,因为单个像素是4个字节。我传递的frameData是lockedRect.pBits。 depthToIntensity []是一个查找表。如果我将bufferRun更改为unsigned int,我会得到一些结果,但看起来不行。我缺少什么?

This doesn't work obviously, because single pixel is 4 bytes. frameData I'm passing is lockedRect.pBits. depthToIntensity[] is a lookup table. If I change bufferRun to unsigned int I get some results, but they don't look ok. What am I missing?




推荐答案

您没有为您提供的代码提供足够的数据。你的frameData只是深度数据吗?深度数据是16位,但如果您正在关注DepthBasics-D2D示例,您将注意到LockedRect.pBits不仅仅是深度数据。

You have not provided enough data with the code you provided. Is your frameData just the depth data? Depth data is 16bits, but if you are following the DepthBasics-D2D sample, you will note that the LockedRect.pBits is not just the depth data.

        const NUI_DEPTH_IMAGE_PIXEL * pBufferRun = reinterpret_cast<const NUI_DEPTH_IMAGE_PIXEL *>(LockedRect.pBits);

        // end pixel is start + width*height - 1
        const NUI_DEPTH_IMAGE_PIXEL * pBufferEnd = pBufferRun + (cDepthWidth * cDepthHeight);

NUI_DEPTH_IMAGE_PIXEL是¥b $ b

NUI_DEPTH_IMAGE_PIXEL is

typedef struct _NUI_DEPTH_IMAGE_PIXEL
    {
    USHORT playerIndex;
    USHORT depth;
    } 	NUI_DEPTH_IMAGE_PIXEL;

所以要获得深度值,你应该使用这个:

So to get just the depth value, you should be using this:

            // discard the portion of the depth that contains only the player index
            USHORT depth = pBufferRun->depth;




我希望这样明确了。


I hope this clear that up.


这篇关于为什么sizeof(NUI_DEPTH_IMAGE_PIXEL)4而不是2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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