hyperion.ng/libsrc/grabber/osx/OsxFrameGrabber.cpp
redPanther 569e59110e implement set videomode via json api (#457)
* implement set videomode via json api

* refactor grabbers:
- new base class
- move shared code to base class

* fix osx

* rework all cmakelist files with auto file collection. except leddevices (need further restructuring)

* store current video and grabbing mode

* add json stuff

* remove grabbingmode - we do not want to expose it
2017-08-04 23:08:15 +02:00

75 lines
1.9 KiB
C++
Executable File

// STL includes
#include <cassert>
#include <iostream>
// Local includes
#include <grabber/OsxFrameGrabber.h>
OsxFrameGrabber::OsxFrameGrabber(const unsigned display, const unsigned width, const unsigned height)
: Grabber("OSXGRABBER", width, height)
, _screenIndex(display)
{
CGImageRef image;
CGDisplayCount displayCount;
CGDirectDisplayID displays[8];
// get list of displays
CGGetActiveDisplayList(8, displays, &displayCount);
if (_screenIndex + 1 > displayCount)
{
Error(_log, "Display with index %d is not available. Using main display", _screenIndex);
_display = kCGDirectMainDisplay;
} else {
_display = displays[_screenIndex];
}
image = CGDisplayCreateImage(_display);
assert(image != NULL);
Info(_log, "Display opened with resolution: %dx%d@%dbit", CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerPixel(image));
CGImageRelease(image);
}
OsxFrameGrabber::~OsxFrameGrabber()
{
}
void OsxFrameGrabber::grabFrame(Image<ColorRgb> & image)
{
CGImageRef dispImage;
CFDataRef imgData;
unsigned char * pImgData;
unsigned dspWidth, dspHeight;
dispImage = CGDisplayCreateImage(_display);
// display lost, use main
if (dispImage == NULL && _display)
{
dispImage = CGDisplayCreateImage(kCGDirectMainDisplay);
// no displays connected, return
if (dispImage == NULL)
{
Error(_log, "No display connected...");
return;
}
}
imgData = CGDataProviderCopyData(CGImageGetDataProvider(dispImage));
pImgData = (unsigned char*) CFDataGetBytePtr(imgData);
dspWidth = CGImageGetWidth(dispImage);
dspHeight = CGImageGetHeight(dispImage);
_imageResampler.setHorizontalPixelDecimation(dspWidth/_width);
_imageResampler.setVerticalPixelDecimation(dspHeight/_height);
_imageResampler.processImage( pImgData,
dspWidth,
dspHeight,
CGImageGetBytesPerRow(dispImage),
PIXELFORMAT_BGR32,
image);
CFRelease(imgData);
CGImageRelease(dispImage);
}