Feat: ROI screen capture with remote control support via COMMAND_SCREEN_ROI
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,11 +25,12 @@ private:
|
||||
BYTE* m_NextBuffer = nullptr;
|
||||
|
||||
public:
|
||||
ScreenCapturerDXGI(BYTE algo, int gop = DEFAULT_GOP, BOOL all = FALSE, int level = LEVEL_H264_SOFT)
|
||||
: ScreenCapture(32, algo, all, level)
|
||||
ScreenCapturerDXGI(BYTE algo, int gop = DEFAULT_GOP, BOOL all = FALSE, int level = LEVEL_H264_SOFT,
|
||||
RECT rc = {0}, BOOL switchScreen = TRUE)
|
||||
: ScreenCapture(32, algo, all, level, rc, switchScreen)
|
||||
{
|
||||
m_GOP = gop;
|
||||
InitDXGI(all);
|
||||
InitDXGI(all, switchScreen);
|
||||
Mprintf("Capture screen with DXGI: GOP= %d\n", m_GOP);
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ public:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void InitDXGI(BOOL all)
|
||||
void InitDXGI(BOOL all, BOOL switchScreen)
|
||||
{
|
||||
m_iScreenX = 0;
|
||||
m_iScreenY = 0;
|
||||
@@ -72,7 +73,7 @@ public:
|
||||
|
||||
// 4. 获取 DXGI 输出(屏幕)
|
||||
static UINT screen = 0;
|
||||
HRESULT r = dxgiAdapter->EnumOutputs(screen++, &dxgiOutput);
|
||||
HRESULT r = dxgiAdapter->EnumOutputs(switchScreen ? screen++ : screen, &dxgiOutput);
|
||||
if (r == DXGI_ERROR_NOT_FOUND && all) {
|
||||
screen = 0;
|
||||
idx ++;
|
||||
@@ -148,6 +149,15 @@ public:
|
||||
m_BmpZoomBuffer = new BYTE[m_BitmapInfor_Send->bmiHeader.biSizeImage * 2 + 12];
|
||||
m_BmpZoomFirst = nullptr;
|
||||
|
||||
// ROI
|
||||
int w = m_ROI.right - m_ROI.left, h = m_ROI.bottom - m_ROI.top;
|
||||
if (w > 0 && h > 0) {
|
||||
m_nScaleSendWidth = m_BitmapInfor_Send->bmiHeader.biWidth;
|
||||
m_nScaleSendHeight = m_BitmapInfor_Send->bmiHeader.biHeight;
|
||||
m_BitmapInfor_Send->bmiHeader.biWidth = w;
|
||||
m_BitmapInfor_Send->bmiHeader.biHeight = h;
|
||||
m_BitmapInfor_Send->bmiHeader.biSizeImage = w * h * 4;
|
||||
}
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
@@ -173,12 +183,15 @@ public:
|
||||
|
||||
virtual LPBYTE scaleBitmap(LPBYTE target, LPBYTE bitmap) override
|
||||
{
|
||||
if (m_ulFullWidth == m_BitmapInfor_Send->bmiHeader.biWidth && m_ulFullHeight == m_BitmapInfor_Send->bmiHeader.biHeight) {
|
||||
memcpy(target, bitmap, m_BitmapInfor_Send->bmiHeader.biSizeImage);
|
||||
return bitmap;
|
||||
}
|
||||
return ScaleBitmap(target, (uint8_t*)bitmap, m_ulFullWidth, m_ulFullHeight, m_BitmapInfor_Send->bmiHeader.biWidth,
|
||||
m_BitmapInfor_Send->bmiHeader.biHeight, m_nInstructionSet);
|
||||
int scaledW = m_nScaleSendWidth ? m_nScaleSendWidth : (int)m_BitmapInfor_Send->bmiHeader.biWidth;
|
||||
int scaledH = m_nScaleSendHeight ? m_nScaleSendHeight : (int)m_BitmapInfor_Send->bmiHeader.biHeight;
|
||||
if ((ULONG)scaledW == m_ulFullWidth && (ULONG)scaledH == m_ulFullHeight)
|
||||
memcpy(target, bitmap, scaledW * scaledH * 4);
|
||||
else
|
||||
ScaleBitmap(target, (uint8_t*)bitmap, m_ulFullWidth, m_ulFullHeight, scaledW, scaledH, m_nInstructionSet);
|
||||
if (m_nScaleSendWidth)
|
||||
applyROICrop(target, target, scaledW, scaledH);
|
||||
return target;
|
||||
}
|
||||
|
||||
LPBYTE GetFirstScreenData(ULONG* ulFirstScreenLength) override
|
||||
|
||||
Reference in New Issue
Block a user