📄 capprop.c
字号:
}
NTSTATUS
SetRegistryKeyValue(
HANDLE hKey,
PWCHAR pwszEntry,
LONG nValue
)
{
NTSTATUS status;
UNICODE_STRING ustr;
RtlInitUnicodeString(&ustr, pwszEntry);
status =
ZwSetValueKey(
hKey,
&ustr,
0, /* optional */
REG_DWORD,
&nValue,
sizeof(nValue)
);
return status;
}
BOOL
DCamQueryPropertyFeaturesAndSettings(
IN PIRB pIrb,
PDCAM_EXTENSION pDevExt,
ULONG ulFieldOffset,
DCamRegArea * pFeature,
HANDLE hKeySettings,
PWCHAR pwszPropertyName,
ULONG ulPropertyNameLen,
DCamRegArea * pPropertySettings,
PWCHAR pwszPropertyNameDef,
ULONG ulPropertyNameDefLen,
LONG * plValueDef
)
{
NTSTATUS Status = STATUS_SUCCESS;
ULONG ulLength;
DCamRegArea RegDefault;
// Reset settings.
pFeature->AsULONG = 0;
pPropertySettings->AsULONG = 0;
// Read feature of this property
Status = DCamReadRegister(pIrb, pDevExt, ulFieldOffset-QUERY_ADDR_OFFSET, &(pFeature->AsULONG));
if(NT_SUCCESS(Status)) {
pFeature->AsULONG = bswap(pFeature->AsULONG);
if(pFeature->Feature.PresenceInq == 0) {
ERROR_LOG(("\'%S not supported; Reset property settings\n", pwszPropertyName));
return FALSE;
}
} else {
ERROR_LOG(("\'ST:%x reading register\n", Status));
return FALSE;
}
// Get persisted settings saved in the registry; (if it not defined, it is initialize to 0).
ulLength = sizeof(LONG);
Status = GetRegistryKeyValue(
hKeySettings,
pwszPropertyName,
ulPropertyNameLen,
(PVOID) pPropertySettings,
&ulLength
);
if(NT_SUCCESS(Status)) {
// Detect if AutoMode was mistakenly set by the registry.
if(pPropertySettings->Brightness.AutoMode == 1 && pFeature->Feature.AutoMode == 0) {
ERROR_LOG(("\'Detect %s AutoMode mistakenly set\n", pwszPropertyName));
pPropertySettings->Brightness.AutoMode = 0;
}
// Detect out of range and set it to mid range.
if(pPropertySettings->Brightness.Value < pFeature->Feature.MIN_Value ||
pFeature->Feature.MAX_Value < pPropertySettings->Brightness.Value) {
ERROR_LOG(("\'Detect %S out of range %d not within (%d,%d)\n",
pwszPropertyName,
pPropertySettings->Brightness.Value,
pFeature->Feature.MIN_Value,
pFeature->Feature.MAX_Value));
pPropertySettings->Brightness.Value = (pFeature->Feature.MIN_Value + pFeature->Feature.MAX_Value)/2;
}
// Query default value
ulLength = sizeof(LONG);
RegDefault.AsULONG = 0;
*plValueDef = 0;
Status = GetRegistryKeyValue(
hKeySettings,
pwszPropertyNameDef,
ulPropertyNameDefLen,
(PVOID) &RegDefault,
&ulLength
);
if(NT_SUCCESS(Status)) {
// Make sure that the default is within the range
if(RegDefault.Brightness.Value < pFeature->Feature.MIN_Value ||
pFeature->Feature.MAX_Value < RegDefault.Brightness.Value) {
ERROR_LOG(("\'%S %d out of range (%d, %d), set to midrange.\n",
pwszPropertyNameDef,
RegDefault.Brightness.Value,
pFeature->Feature.MIN_Value,
pFeature->Feature.MAX_Value));
*plValueDef = (LONG) (pFeature->Feature.MIN_Value + pFeature->Feature.MAX_Value)/2;
} else {
*plValueDef = (LONG) RegDefault.Brightness.Value;
}
} else {
ERROR_LOG(("\'Read Registry failed! ST:%x; %S; Offset:%d\n", Status, pwszPropertyNameDef, ulFieldOffset));
*plValueDef = (LONG) (pFeature->Feature.MIN_Value + pFeature->Feature.MAX_Value)/2;
// Set default so return success too.
Status = STATUS_SUCCESS;
}
} else {
// If registry key is not in the registry key, we will initialize it to
// always use the auto mode, and its value (and the default) in midrange.
ERROR_LOG(("\'Read Registry failed! ST:%x; %S; Offset:%d\n", Status, pwszPropertyName, ulFieldOffset));
pPropertySettings->Brightness.AutoMode = pFeature->Feature.AutoMode;
pPropertySettings->Brightness.Value = (pFeature->Feature.MIN_Value + pFeature->Feature.MAX_Value)/2;
*plValueDef = (LONG) (pFeature->Feature.MIN_Value + pFeature->Feature.MAX_Value)/2;
// Set default so return success too.
Status = STATUS_SUCCESS;
}
#if DBG
// Print out a summary of this property setting, include:
// Features, current setting, and persisted values.
DCamReadRegister(pIrb, pDevExt, ulFieldOffset, &(pDevExt->RegArea.AsULONG));
pDevExt->RegArea.AsULONG = bswap(pDevExt->RegArea.AsULONG);
DbgMsg1(("\'***** St:%x; %S (offset:%d)\n", Status, pwszPropertyName, ulFieldOffset));
DbgMsg1(("\'Feature: %x; Pres:%d; OnePush:%d; ReadOut:%d; OnOff;%d; (A:%d; M:%d); (%d..%d)\n",
pFeature->AsULONG,
pFeature->Feature.PresenceInq,
pFeature->Feature.OnePush,
pFeature->Feature.ReadOut_Inq,
pFeature->Feature.OnOff,
pFeature->Feature.AutoMode,
pFeature->Feature.ManualMode,
pFeature->Feature.MIN_Value,
pFeature->Feature.MAX_Value
));
DbgMsg1(("\'Setting: %.8x; Pres:%d; OnePush:%d; OnOff;%d; Auto:%d; (%d;%d)\n",
pDevExt->RegArea.AsULONG,
pDevExt->RegArea.WhiteBalance.PresenceInq,
pDevExt->RegArea.WhiteBalance.OnePush,
pDevExt->RegArea.WhiteBalance.OnOff,
pDevExt->RegArea.WhiteBalance.AutoMode,
pDevExt->RegArea.WhiteBalance.UValue,
pDevExt->RegArea.WhiteBalance.VValue
));
DbgMsg1(("\'Registry:%.8x; Pres:%d; OnePush:%d; OnOff;%d; Auto:%d; (%d;%d)\n\n",
pPropertySettings->AsULONG,
pPropertySettings->WhiteBalance.PresenceInq,
pPropertySettings->WhiteBalance.OnePush,
pPropertySettings->WhiteBalance.OnOff,
pPropertySettings->WhiteBalance.AutoMode,
pPropertySettings->WhiteBalance.UValue,
pPropertySettings->WhiteBalance.VValue
));
#endif
return NT_SUCCESS(Status);
}
BOOL
DCamGetPropertyValuesFromRegistry(
PDCAM_EXTENSION pDevExt
)
{
NTSTATUS Status;
HANDLE hPDOKey, hKeySettings;
PIRB pIrb;
ULONG ulLength;
DbgMsg2(("\'GetPropertyValuesFromRegistry: pDevExt=%x; pDevExt->BusDeviceObject=%x\n", pDevExt, pDevExt->BusDeviceObject));
pIrb = ExAllocatePoolWithTag(NonPagedPool, sizeof(IRB), 'macd');
if(!pIrb)
return FALSE;
//
// Registry key:
// Windows 2000:
// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\
// {6BDD1FC6-810F-11D0-BEC7-08002BE2092F\000x
//
// Win98:
// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Class\Image\000x
//
Status =
IoOpenDeviceRegistryKey(
pDevExt->PhysicalDeviceObject,
PLUGPLAY_REGKEY_DRIVER,
STANDARD_RIGHTS_READ,
&hPDOKey);
// Can fail only if PDO might be deleted due to device removal.
ASSERT(!pDevExt->bDevRemoved && Status == STATUS_SUCCESS);
//
// loop through our table of strings,
// reading the registry for each.
//
if(!NT_SUCCESS(Status)) {
ERROR_LOG(("\'GetPropertyValuesFromRegistry: IoOpenDeviceRegistryKey failed with Status=%x\n", Status));
ExFreePool(pIrb); pIrb = NULL;
return FALSE;
}
//
// Create or open the settings key
//
Status =
CreateRegistrySubKey(
hPDOKey,
KEY_ALL_ACCESS,
wszSettings,
&hKeySettings
);
if(!NT_SUCCESS(Status)) {
ERROR_LOG(("\'GetPropertyValuesFromRegistry: CreateRegistrySubKey failed with Status=%x\n", Status));
ZwClose(hPDOKey);
return FALSE;
}
// Get persisted settings saved in the registry; (if it not defined, it is initialize to 0).
//
// Read from registry to find out what compression formats are supported
// by the decoder installed on this system. This registry key can be altered
// if IHV/ISV add additional decoder. Currently, Microsft's MSYUV supports
// only UYVY format.
//
pDevExt->DecoderDCamVModeInq0.AsULONG = 0;
ulLength = sizeof(LONG);
Status = GetRegistryKeyValue(
hKeySettings,
wszVModeInq0,
sizeof(wszVModeInq0),
(PVOID) &pDevExt->DecoderDCamVModeInq0,
&ulLength
);
if(NT_SUCCESS(Status)) {
pDevExt->DecoderDCamVModeInq0.AsULONG = bswap(pDevExt->DecoderDCamVModeInq0.AsULONG);
DbgMsg1(("\'Modes supported by the decoder: %x\n [0]:%d\n [1]:%d\n [2]:%d\n [3]:%d\n [4]:%d\n [5]:%d\n",
pDevExt->DecoderDCamVModeInq0.AsULONG,
pDevExt->DecoderDCamVModeInq0.VMode.Mode0,
pDevExt->DecoderDCamVModeInq0.VMode.Mode1,
pDevExt->DecoderDCamVModeInq0.VMode.Mode2,
pDevExt->DecoderDCamVModeInq0.VMode.Mode3,
pDevExt->DecoderDCamVModeInq0.VMode.Mode4,
pDevExt->DecoderDCamVModeInq0.VMode.Mode5
));
} else {
ERROR_LOG(("\'Failed to read VModeInq0 registery: %x\n", Status));
}
// MSYUV supports these modes; always turn them on.
pDevExt->DecoderDCamVModeInq0.VMode.Mode1 = 1; // MSYUV.dll:(UYVY:320x480)
pDevExt->DecoderDCamVModeInq0.VMode.Mode3 = 1; // MSYUV.dll:(UYVY:640x480)
#ifdef SUPPORT_RGB24
pDevExt->DecoderDCamVModeInq0.VMode.Mode4 = 1; // MSYUV.dll:(RGB24:640x480)
#endif
#if DBG
pDevExt->DevFeature1.AsULONG = 0;
Status = DCamReadRegister(pIrb, pDevExt, FIELDOFFSET(CAMERA_REGISTER_MAP, FeaturePresent1), &pDevExt->DevFeature1.AsULONG);
if(NT_SUCCESS(Status)) {
pDevExt->DevFeature1.AsULONG = bswap(pDevExt->DevFeature1.AsULONG);
DbgMsg1(("\'Features1: %x:\n Brightness:%d;\n Exposure:%d\n Sharpness:%d\n WhiteBalance:%d\n Hue:%d;\n Saturation:%d;\n Gamma:%d\n Shutter:%d\n Gain:%d\n Iris:%d\n Focus:%d\n",
pDevExt->DevFeature1.AsULONG,
pDevExt->DevFeature1.CameraCap1.Brightness,
pDevExt->DevFeature1.CameraCap1.Exposure,
pDevExt->DevFeature1.CameraCap1.Sharpness,
pDevExt->DevFeature1.CameraCap1.White_Balance,
pDevExt->DevFeature1.CameraCap1.Hue,
pDevExt->DevFeature1.CameraCap1.Saturation,
pDevExt->DevFeature1.CameraCap1.Gamma,
pDevExt->DevFeature1.CameraCap1.Shutter,
pDevExt->DevFeature1.CameraCap1.Gain,
pDevExt->DevFeature1.CameraCap1.Iris,
pDevExt->DevFeature1.CameraCap1.Focus
));
} else {
ERROR_LOG(("\'Failed to read Feature1 register: %x\n", Status));
}
pDevExt->DevFeature2.AsULONG = 0;
Status = DCamReadRegister(pIrb, pDevExt, FIELDOFFSET(CAMERA_REGISTER_MAP, FeaturePresent2), &pDevExt->DevFeature1.AsULONG);
if(NT_SUCCESS(Status)) {
pDevExt->DevFeature2.AsULONG = bswap(pDevExt->DevFeature2.AsULONG);
DbgMsg1(("\'Features2: %x\n Zoom:%d\n Pan:%d\n Tile:%d\n",
pDevExt->DevFeature2.AsULONG,
pDevExt->DevFeature2.CameraCap2.Zoom,
pDevExt->DevFeature2.CameraCap2.Pan,
pDevExt->DevFeature1.CameraCap2.Tile
));
} else {
ERROR_LOG(("\'Failed to read Feature2 register: %x\n", Status));
}
#endif
// Brightness
if(DCamQueryPropertyFeaturesAndSettings(
pIrb,
pDevExt,
FIELDOFFSET(CAMERA_REGISTER_MAP, Brightness),
&pDevExt->DevProperty[ENUM_BRIGHTNESS].Feature,
hKeySettings,
wszBrightness,
sizeof(wszBrightness),
&pDevExt->DevProperty[ENUM_BRIGHTNESS].StatusNControl,
wszBrightnessDef,
sizeof(wszBrightnessDef),
&pDevExt->DevProperty[ENUM_BRIGHTNESS].DefaultValue
)) {
pDevExt->DevProperty[ENUM_BRIGHTNESS].RangeNStep.Bounds.SignedMinimum = pDevExt->DevProperty[ENUM_BRIGHTNESS].Feature.Feature.MIN_Value;
pDevExt->DevProperty[ENUM_BRIGHTNESS].RangeNStep.Bounds.SignedMaximum = pDevExt->DevProperty[ENUM_BRIGHTNESS].Feature.Feature.MAX_Value;
pDevExt->DevPropDefine[ENUM_BRIGHTNESS].Range.Members = (VOID*) &pDevExt->DevProperty[ENUM_BRIGHTNESS].RangeNStep;
pDevExt->DevPropDefine[ENUM_BRIGHTNESS].Default.Members = (VOID*) &pDevExt->DevProperty[ENUM_BRIGHTNESS].DefaultValue;
} else {
pDevExt->VideoProcAmpItems[ENUM_BRIGHTNESS].GetSupported = FALSE;
pDevExt->VideoProcAmpItems[ENUM_BRIGHTNESS].SetSupported = FALSE;
}
// Saturation
if(DCamQueryPropertyFeaturesAndSettings(
pIrb,
pDevExt,
FIELDOFFSET(CAMERA_REGISTER_MAP, Saturation),
&pDevExt->DevProperty[ENUM_SATURATION].Feature,
hKeySettings,
wszSaturation,
sizeof(wszSaturation),
&pDevExt->DevProperty[ENUM_SATURATION].StatusNControl,
wszSaturationDef,
sizeof(wszSaturationDef),
&pDevExt->DevProperty[ENUM_SATURATION].DefaultValue
)) {
pDevExt->DevProperty[ENUM_SATURATION].RangeNStep.Bounds.SignedMinimum = pDevExt->DevProperty[ENUM_SATURATION].Feature.Feature.MIN_Value;
pDevExt->DevProperty[ENUM_SATURATION].RangeNStep.Bounds.SignedMaximum = pDevExt->DevProperty[ENUM_SATURATION].Feature.Feature.MAX_Value;
pDevExt->DevPropDefine[ENUM_SATURATION].Range.Members = (VOID*) &pDevExt->DevProperty[ENUM_SATURATION].RangeNStep;
pDevExt->DevPropDefine[ENUM_SATURATION].Default.Members = (VOID*) &pDevExt->DevProperty[ENUM_SATURATION].DefaultValue;
} else {
pDevExt->VideoProcAmpItems[ENUM_SATURATION].GetSupported = FALSE;
pDevExt->VideoProcAmpItems[ENUM_SATURATION].SetSupported = FALSE;
}
// Hue
if(DCamQueryPropertyFeaturesAndSettings(
pIrb,
pDevExt,
FIELDOFFSET(CAMERA_REGISTER_MAP, Hue),
&pDevExt->DevProperty[ENUM_HUE].Feature,
hKeySettings,
wszHue,
sizeof(wszHue),
&pDevExt->DevProperty[ENUM_HUE].StatusNControl,
wszHueDef,
sizeof(wszHueDef),
&pDevExt->DevProperty[ENUM_HUE].DefaultValue
)) {
pDevExt->DevProperty[ENUM_HUE].RangeNStep.Bounds.SignedMinimum = pDevExt->DevProperty[ENUM_HUE].Feature.Feature.MIN_Value;
pDevExt->DevProperty[ENUM_HUE].RangeNStep.Bounds.SignedMaximum = pDevExt->DevProperty[ENUM_HUE].Feature.Feature.MAX_Value;
pDevExt->DevPropDefine[ENUM_HUE].Range.Members = (VOID*) &pDevExt->DevProperty[ENUM_HUE].RangeNStep;
pDevExt->DevPropDefine[ENUM_HUE].Default.Members = (VOID*) &pDevExt->DevProperty[ENUM_HUE].DefaultValue;
} else {
pDevExt->VideoProcAmpItems[ENUM_HUE].GetSupported = FALSE;
pDevExt->VideoProcAmpItems[ENUM_HUE].SetSupported = FALSE;
}
// Sharpness
if(DCamQueryPropertyFeaturesAndSettings(
pIrb,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -