Skip to content

Instantly share code, notes, and snippets.

@art-den
Created April 26, 2023 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save art-den/e32eed7791cfd1f29db1bbcdadf5920c to your computer and use it in GitHub Desktop.
Save art-den/e32eed7791cfd1f29db1bbcdadf5920c to your computer and use it in GitHub Desktop.
bool ToupBase::SetCaptureFormat(uint8_t index)
{
m_Channels = 1;
bool format_changed = m_CurrentVideoFormat != index;
if (m_MonoCamera)
{
// We need to stop camera first
if (format_changed)
{
FP(Stop(m_Handle));
}
HRESULT rc = FP(put_Option(m_Handle, CP(OPTION_BITDEPTH), index));
if (FAILED(rc))
{
LOGF_ERROR("Failed to set high bit depth. %s", errorCodes(rc).c_str());
// Restart Capture
if (format_changed)
{
rc = FP(StartPullModeWithCallback(m_Handle, &ToupBase::eventCB, this));
if (FAILED(rc))
LOGF_ERROR("Failed to start camera. %s", errorCodes(rc).c_str());
}
return false;
}
m_BitsPerPixel = (index ? 8 : 16);
}
else// Color
{
// We need to stop camera first
if (format_changed)
{
FP(Stop(m_Handle));
}
HRESULT rc = FP(put_Option(m_Handle, CP(OPTION_RAW), index));
if (FAILED(rc))
{
LOGF_ERROR("Failed to set raw mode. %s", errorCodes(rc).c_str());
// Restart Capture
if (format_changed)
{
rc = FP(StartPullModeWithCallback(m_Handle, &ToupBase::eventCB, this));
if (FAILED(rc))
LOGF_ERROR("Failed to start camera. %s", errorCodes(rc).c_str());
}
return false;
}
if (0 == index)
{
m_Channels = 3;
m_BitsPerPixel = 8;
SetCCDCapability(GetCCDCapability() & ~CCD_HAS_BAYER);
}
else
{
SetCCDCapability(GetCCDCapability() | CCD_HAS_BAYER);
IUSaveText(&BayerT[2], getBayerString());
IDSetText(&BayerTP, nullptr);
m_BitsPerPixel = (m_maxBitDepth > 8) ? 16 : 8;
}
}
m_CurrentVideoFormat = index;
int bLevelStep = 1;
if (m_BitsPerPixel > 8)
bLevelStep = 1 << (m_maxBitDepth - 8);
m_OffsetN[0].max = CP(BLACKLEVEL8_MAX) * bLevelStep;
IUUpdateMinMax(&m_OffsetNP);
LOGF_DEBUG("Video Format: %d, BitsPerPixel: %d", index, m_BitsPerPixel);
allocateFrameBuffer();// Allocate memory
// Restart Capture
if (format_changed)
{
HRESULT rc = FP(StartPullModeWithCallback(m_Handle, &ToupBase::eventCB, this));
if (FAILED(rc))
LOGF_ERROR("Failed to start camera. %s", errorCodes(rc).c_str());
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment