Exemplo n.º 1
0
XnStatus XnSensorImageGenerator::SetPixelFormat(XnPixelFormat Format)
{
	if (GetPixelFormat() == Format)
	{
		return (XN_STATUS_OK);
	}

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	XnStatus nRetVal = XnPropertySetAddModule(&props, m_strModule);
	XN_IS_STATUS_OK(nRetVal);

	XnOutputFormats OutputFormat;
	XnUInt32* anAllowedInputFormats = NULL;
	XnUInt32 nAllowedInputFormats = 0;

	switch (Format)
	{
	case XN_PIXEL_FORMAT_RGB24:
		OutputFormat = XN_OUTPUT_FORMAT_RGB24;
		anAllowedInputFormats = g_anAllowedRGBFormats;
		nAllowedInputFormats = sizeof(g_anAllowedRGBFormats)/sizeof(XnUInt32);
		break;
	case XN_PIXEL_FORMAT_YUV422:
		OutputFormat = XN_OUTPUT_FORMAT_YUV422;
		anAllowedInputFormats = g_anAllowedYUVFormats;
		nAllowedInputFormats = sizeof(g_anAllowedYUVFormats)/sizeof(XnUInt32);
		break;
	case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT:
		OutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8;
		anAllowedInputFormats = g_anAllowedGray8Formats;
		nAllowedInputFormats = sizeof(g_anAllowedGray8Formats)/sizeof(XnUInt32);
		break;
	case XN_PIXEL_FORMAT_MJPEG:
		OutputFormat = XN_OUTPUT_FORMAT_JPEG;
		anAllowedInputFormats = g_anAllowedJPEGFormats;
		nAllowedInputFormats = sizeof(g_anAllowedJPEGFormats)/sizeof(XnUInt32);
		break;
	default:
		return XN_STATUS_INVALID_OPERATION;
	}

	XnUInt32 nInputFormat = FindSupportedInputFormat(anAllowedInputFormats, nAllowedInputFormats);
	if (nInputFormat == INVALID_INPUT_FORMAT)
	{
		XN_LOG_WARNING_RETURN(XN_STATUS_DEVICE_BAD_PARAM, XN_MASK_DEVICE_SENSOR, "Cannot set pixel format to %s - no matching input format.", xnPixelFormatToString(Format));
	}

	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)nInputFormat);
	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_OUTPUT_FORMAT, (XnUInt64)OutputFormat);

	return m_pSensor->BatchConfig(&props);
}
Exemplo n.º 2
0
XN_DDK_API XnStatus XnPropertySetCloneModule(const XnPropertySet* pSource, XnPropertySet* pDest, const XnChar* strModule, const XnChar* strNewName)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnActualPropertiesHash* pModuleProps = NULL;
	nRetVal = pSource->pData->Get(strModule, pModuleProps);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = XnPropertySetAddModule(pDest, strNewName);
	XN_IS_STATUS_OK(nRetVal);

	for (XnActualPropertiesHash::ConstIterator it = pModuleProps->Begin(); it != pModuleProps->End(); ++it)
	{
		XnProperty* pProp = it->Value();
		switch (pProp->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
				nRetVal = XnPropertySetAddIntProperty(pDest, strNewName, pIntProp->GetName(), pIntProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
				nRetVal = XnPropertySetAddRealProperty(pDest, strNewName, pRealProp->GetName(), pRealProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp;
				nRetVal = XnPropertySetAddStringProperty(pDest, strNewName, pStrProp->GetName(), pStrProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp;
				nRetVal = XnPropertySetAddGeneralProperty(pDest, strNewName, pGenProp->GetName(), &pGenProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d", pProp->GetType());
		}
	}

	return (XN_STATUS_OK);
}
Exemplo n.º 3
0
XnStatus XnSensorImageGenerator::SetPixelFormat(XnPixelFormat Format)
{
	if (GetPixelFormat() == Format)
	{
		return (XN_STATUS_OK);
	}

	XnUInt64 nCurrentInputFormat;
	GetIntProperty(XN_STREAM_PROPERTY_INPUT_FORMAT, nCurrentInputFormat);

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	XnStatus nRetVal = XnPropertySetAddModule(&props, m_strModule);
	XN_IS_STATUS_OK(nRetVal);

	XnOutputFormats OutputFormat;

	switch (Format)
	{
	case XN_PIXEL_FORMAT_RGB24:
		OutputFormat = XN_OUTPUT_FORMAT_RGB24;
		break;
	case XN_PIXEL_FORMAT_YUV422:
		OutputFormat = XN_OUTPUT_FORMAT_YUV422;
		break;
	case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT:
		OutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8;
		break;
	case XN_PIXEL_FORMAT_MJPEG:
		OutputFormat = XN_OUTPUT_FORMAT_JPEG;
		break;
	default:
		return XN_STATUS_INVALID_OPERATION;
	}

	if (nCurrentInputFormat != XN_IO_IMAGE_FORMAT_JPEG && OutputFormat == XN_OUTPUT_FORMAT_JPEG)
	{
		XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)XN_IO_IMAGE_FORMAT_JPEG);
	}
	else if (nCurrentInputFormat == XN_IO_IMAGE_FORMAT_JPEG && OutputFormat != XN_OUTPUT_FORMAT_JPEG)
	{
		XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)XN_IMAGE_STREAM_DEFAULT_INPUT_FORMAT);
	}

	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_OUTPUT_FORMAT, (XnUInt64)OutputFormat);

	return m_pSensor->BatchConfig(&props);
}
Exemplo n.º 4
0
XnStatus XnSensorAudioGenerator::SetWaveOutputMode(const XnWaveOutputMode& OutputMode)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (OutputMode.nBitsPerSample != 16)
	{
		return XN_STATUS_INVALID_OPERATION;
	}

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	XnPropertySetAddModule(&props, m_strModule);
	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_SAMPLE_RATE, OutputMode.nSampleRate);
	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS, OutputMode.nChannels);

	nRetVal = m_pSensor->BatchConfig(&props);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
XnStatus XnDeviceModule::GetAllProperties(XnPropertySet* pSet) const
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// add the module
	nRetVal = XnPropertySetAddModule(pSet, GetName());
	XN_IS_STATUS_OK(nRetVal);

	// now add all properties
	for (XnPropertiesHash::ConstIterator it = m_Properties.Begin(); it != m_Properties.End(); ++it)
	{
		XnProperty* pProperty = it->Value();

		if (pProperty->IsActual())
		{
			nRetVal = pProperty->AddToPropertySet(pSet);
			XN_IS_STATUS_OK(nRetVal);
		}
	}
	
	return (XN_STATUS_OK);
}
Exemplo n.º 6
0
XnStatus XnDataPacker::ReadPropertySetImpl(XnPropertySet* pPropertySet)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XN_VALIDATE_OBJECT_TYPE(XN_PACKED_PROPERTY_SET);

    XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];

    // read property set marker
    MoveToNextObject();

    while (m_pCurrentHeader->nType != XN_PACKED_PROPERTY_SET_MODULES_END_MARKER)
    {
        nRetVal = ReadString(strModule);
        XN_IS_STATUS_OK(nRetVal);

        nRetVal = XnPropertySetAddModule(pPropertySet, strModule);
        XN_IS_STATUS_OK(nRetVal);
    }

    // read properties
    XnChar strName[XN_DEVICE_MAX_STRING_LENGTH];

    // read the modules end marker
    MoveToNextObject();

    while (m_pCurrentHeader->nType != XN_PACKED_PROPERTY_SET_PROPERTIES_END_MARKER)
    {
        // read property and add it to set
        switch (m_pCurrentHeader->nType)
        {
        case XN_PACKED_INT_PROPERTY:
        {
            XnUInt64 nValue;
            nRetVal = ReadPropertyImpl(strModule, strName, &nValue);
            XN_IS_STATUS_OK(nRetVal);
            nRetVal = XnPropertySetAddIntProperty(pPropertySet, strModule, strName, nValue);
            XN_IS_STATUS_OK(nRetVal);
            break;
        }
        case XN_PACKED_REAL_PROPERTY:
        {
            XnDouble dValue;
            nRetVal = ReadPropertyImpl(strModule, strName, &dValue);
            XN_IS_STATUS_OK(nRetVal);
            nRetVal = XnPropertySetAddRealProperty(pPropertySet, strModule, strName, dValue);
            XN_IS_STATUS_OK(nRetVal);
            break;
        }
        case XN_PACKED_STRING_PROPERTY:
        {
            XnChar strValue[XN_DEVICE_MAX_STRING_LENGTH];
            nRetVal = ReadPropertyImpl(strModule, strName, strValue);
            XN_IS_STATUS_OK(nRetVal);
            nRetVal = XnPropertySetAddStringProperty(pPropertySet, strModule, strName, strValue);
            XN_IS_STATUS_OK(nRetVal);
            break;
        }
        case XN_PACKED_GENERAL_PROPERTY:
        {
            XnGeneralBuffer gbValue;
            nRetVal = ReadPropertyImpl(strModule, strName, &gbValue);
            XN_IS_STATUS_OK(nRetVal);
            nRetVal = XnPropertySetAddGeneralProperty(pPropertySet, strModule, strName, &gbValue);
            XN_IS_STATUS_OK(nRetVal);
            break;
        }
        default:
            XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Stream contains an object of type %d in the middle of a property set!", m_pCurrentHeader->nType);
        }
    } // props loop

    // read properties end marker
    MoveToNextObject();

    return (XN_STATUS_OK);
}