Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 7e4013f

Browse files
committed
Individual cropping values aded for all sides
1 parent e3f5ad7 commit 7e4013f

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

src/hyperion-v4l2/V4L2Grabber.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,33 @@ static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, u
3636
}
3737

3838

39-
V4L2Grabber::V4L2Grabber(const std::string &device, int input, VideoStandard videoStandard, int width, int height, int cropHorizontal, int cropVertical, int frameDecimation, int pixelDecimation) :
39+
V4L2Grabber::V4L2Grabber(
40+
const std::string & device,
41+
int input,
42+
VideoStandard videoStandard,
43+
int width,
44+
int height,
45+
int cropLeft,
46+
int cropRight,
47+
int cropTop,
48+
int cropBottom,
49+
int frameDecimation,
50+
int horizontalPixelDecimation,
51+
int verticalPixelDecimation) :
4052
_deviceName(device),
4153
_ioMethod(IO_METHOD_MMAP),
4254
_fileDescriptor(-1),
4355
_buffers(),
4456
_pixelFormat(0),
4557
_width(width),
4658
_height(height),
47-
_cropWidth(cropHorizontal),
48-
_cropHeight(cropVertical),
59+
_cropLeft(cropLeft),
60+
_cropRight(cropRight),
61+
_cropTop(cropTop),
62+
_cropBottom(cropBottom),
4963
_frameDecimation(std::max(1, frameDecimation)),
50-
_pixelDecimation(std::max(1, pixelDecimation)),
64+
_horizontalPixelDecimation(std::max(1, horizontalPixelDecimation)),
65+
_verticalPixelDecimation(std::max(1, verticalPixelDecimation)),
5166
_currentFrame(0),
5267
_callback(nullptr),
5368
_callbackArg(nullptr)
@@ -644,14 +659,14 @@ bool V4L2Grabber::process_image(const void *p, int size)
644659

645660
void V4L2Grabber::process_image(const uint8_t * data)
646661
{
647-
int width = (_width - 2 * _cropWidth + _pixelDecimation/2) / _pixelDecimation;
648-
int height = (_height - 2 * _cropHeight + _pixelDecimation/2) / _pixelDecimation;
662+
int width = (_width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
663+
int height = (_height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
649664

650665
Image<ColorRgb> image(width, height);
651666

652-
for (int ySource = _cropHeight + _pixelDecimation/2, yDest = 0; ySource < _height - _cropHeight; ySource += _pixelDecimation, ++yDest)
667+
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < _height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
653668
{
654-
for (int xSource = _cropWidth + _pixelDecimation/2, xDest = 0; xSource < _width - _cropWidth; xSource += _pixelDecimation, ++xDest)
669+
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < _width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
655670
{
656671
int index = (_width * ySource + xSource) * 2;
657672
uint8_t y = 0;

src/hyperion-v4l2/V4L2Grabber.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ class V4L2Grabber
2121
};
2222

2323
public:
24-
V4L2Grabber(const std::string & device, int input, VideoStandard videoStandard, int width, int height, int cropHorizontal, int cropVertical, int frameDecimation, int pixelDecimation);
24+
V4L2Grabber(
25+
const std::string & device,
26+
int input,
27+
VideoStandard videoStandard,
28+
int width,
29+
int height,
30+
int cropLeft,
31+
int cropRight,
32+
int cropTop,
33+
int cropBottom,
34+
int frameDecimation,
35+
int horizontalPixelDecimation,
36+
int verticalPixelDecimation);
2537
virtual ~V4L2Grabber();
2638

2739
void setCallback(ImageCallback callback, void * arg);
@@ -84,10 +96,13 @@ class V4L2Grabber
8496
uint32_t _pixelFormat;
8597
int _width;
8698
int _height;
87-
const int _cropWidth;
88-
const int _cropHeight;
99+
const int _cropLeft;
100+
const int _cropRight;
101+
const int _cropTop;
102+
const int _cropBottom;
89103
const int _frameDecimation;
90-
const int _pixelDecimation;
104+
const int _horizontalPixelDecimation;
105+
const int _verticalPixelDecimation;
91106

92107
int _currentFrame;
93108

src/hyperion-v4l2/hyperion-v4l2.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ int main(int argc, char** argv)
4444
IntParameter & argInput = parameters.add<IntParameter> (0x0, "input", "Input channel (optional)");
4545
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Try to set the width of the video input (optional)");
4646
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Try to set the height of the video input (optional)");
47-
IntParameter & argCropWidth = parameters.add<IntParameter> (0x0, "crop-width", "Number of pixels to crop from the left and right sides in the picture before decimation [default=0]");
48-
IntParameter & argCropHeight = parameters.add<IntParameter> (0x0, "crop-height", "Number of pixels to crop from the top and the bottom in the picture before decimation [default=0]");
47+
IntParameter & argCropWidth = parameters.add<IntParameter> (0x0, "crop-width", "Number of pixels to crop from the left and right sides of the picture before decimation [default=0]");
48+
IntParameter & argCropHeight = parameters.add<IntParameter> (0x0, "crop-height", "Number of pixels to crop from the top and the bottom of the picture before decimation [default=0]");
49+
IntParameter & argCropLeft = parameters.add<IntParameter> (0x0, "crop-left", "Number of pixels to crop from the left of the picture before decimation (overrides --crop-width)");
50+
IntParameter & argCropRight = parameters.add<IntParameter> (0x0, "crop-right", "Number of pixels to crop from the right of the picture before decimation (overrides --crop-width)");
51+
IntParameter & argCropTop = parameters.add<IntParameter> (0x0, "crop-top", "Number of pixels to crop from the top of the picture before decimation (overrides --crop-height)");
52+
IntParameter & argCropBottom = parameters.add<IntParameter> (0x0, "crop-bottom", "Number of pixels to crop from the bottom of the picture before decimation (overrides --crop-height)");
4953
IntParameter & argSizeDecimation = parameters.add<IntParameter> ('s', "size-decimator", "Decimation factor for the output size [default=1]");
5054
IntParameter & argFrameDecimation = parameters.add<IntParameter> ('f', "frame-decimator", "Decimation factor for the video frames [default=1]");
5155
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
@@ -79,15 +83,23 @@ int main(int argc, char** argv)
7983
return 0;
8084
}
8185

86+
if (!argCropLeft.isSet()) argCropLeft.setDefault(argCropWidth.getValue());
87+
if (!argCropRight.isSet()) argCropRight.setDefault(argCropWidth.getValue());
88+
if (!argCropTop.isSet()) argCropTop.setDefault(argCropHeight.getValue());
89+
if (!argCropBottom.isSet()) argCropBottom.setDefault(argCropHeight.getValue());
90+
8291
V4L2Grabber grabber(
8392
argDevice.getValue(),
8493
argInput.getValue(),
8594
argVideoStandard.getValue(),
8695
argWidth.getValue(),
8796
argHeight.getValue(),
88-
std::max(0, argCropWidth.getValue()),
89-
std::max(0, argCropHeight.getValue()),
97+
std::max(0, argCropLeft.getValue()),
98+
std::max(0, argCropRight.getValue()),
99+
std::max(0, argCropTop.getValue()),
100+
std::max(0, argCropBottom.getValue()),
90101
std::max(1, argFrameDecimation.getValue()),
102+
std::max(1, argSizeDecimation.getValue()),
91103
std::max(1, argSizeDecimation.getValue()));
92104

93105
grabber.start();

0 commit comments

Comments
 (0)