Skip to content

Commit

Permalink
Merge pull request #18 from trcwm/master
Browse files Browse the repository at this point in the history
 Implemented brightness/contrast/saturation/gamma controls for windows.
  • Loading branch information
trcwm authored Sep 28, 2017
2 parents 654debe + b9db8fc commit 36bfef4
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 151 deletions.
259 changes: 108 additions & 151 deletions win/platformstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ Stream* createPlatformStream()
return new PlatformStream();
}

// **********************************************************************
// Property translation data
// **********************************************************************

struct property_t
{
uint32_t dsProp; // Directshow CameraControlProperty or VideoProcAmpProperty
bool isCameraControl; // if true dsProp is CameraControlProperty
};

// the order must be the same as the CAPPROPID indeces!
static const property_t gs_properties[] =
{
{0, true}, // dummy
{CameraControl_Exposure, true}, // exposure
{CameraControl_Focus, true},
{CameraControl_Zoom, true},
{VideoProcAmp_WhiteBalance, false},
{VideoProcAmp_Gain, false},
{VideoProcAmp_Brightness, false},
{VideoProcAmp_Contrast, false},
{VideoProcAmp_Saturation, false},
{VideoProcAmp_Gamma, false}
};


// **********************************************************************
// StreamCallbackHandler
// **********************************************************************
Expand Down Expand Up @@ -553,57 +579,35 @@ bool PlatformStream::getPropertyLimits(CapPropertyID propID, int32_t *emin, int3
return false;
}

long prop = 0;
switch(propID)
{
case CAPPROPID_EXPOSURE:
prop = CameraControl_Exposure;
break;
case CAPPROPID_FOCUS:
prop = CameraControl_Focus;
break;
case CAPPROPID_ZOOM:
prop = CameraControl_Zoom;
break;
case CAPPROPID_WHITEBALANCE:
prop = VideoProcAmp_WhiteBalance;
break;
case CAPPROPID_GAIN:
prop = VideoProcAmp_Gain;
break;
default:
return false;
}

//query exposure
long flags, mmin, mmax, delta, defaultValue;
if ((propID != CAPPROPID_WHITEBALANCE) && (propID != CAPPROPID_GAIN))
if (propID < CAPPROPID_LAST)
{
if (m_camControl->GetRange(prop, &mmin, &mmax,
&delta, &defaultValue, &flags) == S_OK)
{
*emin = mmin;
*emax = mmax;
return true;
}
}
else
{
//note: m_videoProcAmp only exists if the camera
// supports hardware accelleration of
// video frame processing, such as
// white balance etc.
if (m_videoProcAmp == nullptr)
long flags, mmin, mmax, delta, defaultValue;
if (gs_properties[propID].isCameraControl)
{
return false;
// use Camera control
if (m_camControl->GetRange(gs_properties[propID].dsProp,
&mmin, &mmax, &delta, &defaultValue, &flags) == S_OK)
{
*emin = mmin;
*emax = mmax;
return true;
}
}
else
{
// use VideoProcAmp
if (m_videoProcAmp == nullptr)
{
return false; // no VideoProcAmp on board camera
}

if (m_videoProcAmp->GetRange(prop, &mmin, &mmax,
&delta, &defaultValue, &flags) == S_OK)
{
*emin = mmin;
*emax = mmax;
return true;
if (m_videoProcAmp->GetRange(gs_properties[propID].dsProp,
&mmin, &mmax, &delta, &defaultValue, &flags) == S_OK)
{
*emin = mmin;
*emax = mmax;
return true;
}
}
}

Expand All @@ -619,69 +623,48 @@ bool PlatformStream::setProperty(uint32_t propID, int32_t value)
return false;
}

long prop = 0;
switch(propID)
{
case CAPPROPID_EXPOSURE:
prop = CameraControl_Exposure;
break;
case CAPPROPID_FOCUS:
prop = CameraControl_Focus;
break;
case CAPPROPID_ZOOM:
prop = CameraControl_Zoom;
break;
case CAPPROPID_WHITEBALANCE:
prop = VideoProcAmp_WhiteBalance;
break;
case CAPPROPID_GAIN:
prop = VideoProcAmp_Gain;
break;
default:
return false;
}

long flags, dummy;
if ((propID != CAPPROPID_WHITEBALANCE) && (propID != CAPPROPID_GAIN))
if (propID < CAPPROPID_LAST)
{
// first we get the property so we can retain the flag settings
if (m_camControl->Get(prop, &dummy, &flags) != S_OK)
long flags, dummy;
if (gs_properties[propID].isCameraControl)
{
return false;
}
// use Camera control
// first we get the property so we can retain the flag settings
if (m_camControl->Get(gs_properties[propID].dsProp, &dummy, &flags) != S_OK)
{
return false;
}

// now we set the property.
if (m_camControl->Set(prop, value, flags) != S_OK)
{
return false;
}
}
else
{
//note: m_videoProcAmp only exists if the camera
// supports hardware accelleration of
// video frame processing, such as
// white balance etc.
if (m_videoProcAmp == nullptr)
{
return false;
// now we set the property.
if (m_camControl->Set(gs_properties[propID].dsProp, value, flags) != S_OK)
{
return false;
}
}

// first we get the property so we can retain the flag settings
if (m_videoProcAmp->Get(prop, &dummy, &flags) != S_OK)
else
{
return false;
}
// use VideoProcAmp
if (m_videoProcAmp == nullptr)
{
return false; // no VideoProcAmp on board camera
}

// now we set the property.
if (m_videoProcAmp->Set(prop, value, flags) != S_OK)
{
return false;
}
// first we get the property so we can retain the flag settings
if (m_videoProcAmp->Get(gs_properties[propID].dsProp, &dummy, &flags) != S_OK)
{
return false;
}

// now we set the property.
if (m_videoProcAmp->Set(gs_properties[propID].dsProp, value, flags) != S_OK)
{
return false;
}
}
}

return true;
return false;
}


Expand Down Expand Up @@ -759,64 +742,38 @@ bool PlatformStream::getDSProperty(uint32_t propID, long &value, long &flags)
return false;
}

long prop = 0;
switch(propID)
{
case CAPPROPID_EXPOSURE:
prop = CameraControl_Exposure;
break;
case CAPPROPID_FOCUS:
prop = CameraControl_Focus;
break;
case CAPPROPID_ZOOM:
prop = CameraControl_Zoom;
break;
case CAPPROPID_WHITEBALANCE:
prop = VideoProcAmp_WhiteBalance;
break;
case CAPPROPID_GAIN:
prop = VideoProcAmp_Gain;
break;
default:
return false;
}

if ((propID != CAPPROPID_WHITEBALANCE) && (propID != CAPPROPID_GAIN))
if (propID < CAPPROPID_LAST)
{
if (FAILED(m_camControl->Get(prop, &value, &flags)))
if (gs_properties[propID].isCameraControl)
{
return false;
// use Camera control
if (FAILED(m_camControl->Get(gs_properties[propID].dsProp, &value, &flags)))
{
return false;
}
return true;
}
//LOG(LOG_VERBOSE, "PlatformStream::getDSProperty ID=%d\n", propID);
//LOG(LOG_VERBOSE, "Value : %08Xh\n", value);
//LOG(LOG_VERBOSE, "Flags : %08Xh\n", flags);
return true;
}
else
{
//note: m_videoProcAmp only exists if the camera
// supports hardware accelleration of
// video frame processing, such as
// white balance etc.
if (m_videoProcAmp == nullptr)
else
{
return false;
}
//note: m_videoProcAmp only exists if the camera
// supports hardware accelleration of
// video frame processing, such as
// white balance etc.
if (m_videoProcAmp == nullptr)
{
return false;
}

// get the current value so we can just set the auto flag
// but leave the actualy setting itself intact.
if (FAILED(m_videoProcAmp->Get(prop, &value, &flags)))
{
return false;
// get the current value so we can just set the auto flag
// but leave the actualy setting itself intact.
if (FAILED(m_videoProcAmp->Get(gs_properties[propID].dsProp, &value, &flags)))
{
return false;
}
return true;
}

//LOG(LOG_VERBOSE, "PlatformStream::getDSProperty ID=%d\n", propID);
//LOG(LOG_VERBOSE, "Value : %08Xh\n", value);
//LOG(LOG_VERBOSE, "Flags : %08Xh\n", flags);
return true;
}

return false; // we should never reach here..
return false;
}

/** get property (exposure, zoom etc) of camera/stream */
Expand Down
12 changes: 12 additions & 0 deletions win/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ void showProperties(CapContext ctx, int32_t streamID)

printf("Gain : ");
showProperty(ctx, streamID, CAPPROPID_GAIN);

printf("Brightness : ");
showProperty(ctx, streamID, CAPPROPID_BRIGHTNESS);

printf("Contrast : ");
showProperty(ctx, streamID, CAPPROPID_CONTRAST);

printf("Saturation : ");
showProperty(ctx, streamID, CAPPROPID_SATURATION);

printf("Gamma : ");
showProperty(ctx, streamID, CAPPROPID_GAMMA);
}

void estimateFrameRate(CapContext ctx, int32_t streamID)
Expand Down

0 comments on commit 36bfef4

Please sign in to comment.