Skip to content

Commit

Permalink
Merge pull request #21 from dekomote/image-controlls
Browse files Browse the repository at this point in the history
Image controls (WIP)
  • Loading branch information
dos1 committed Jul 27, 2014
2 parents a41250e + a79b74c commit bcb521f
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
100 changes: 100 additions & 0 deletions src/capturethread.cpp
Expand Up @@ -41,6 +41,104 @@ CaptureThread::CaptureThread() {
running = false;
}

void CaptureThread::updateImageSettings() {

struct v4l2_queryctrl queryctrl;
struct v4l2_control control;

memset (&queryctrl, 0, sizeof (queryctrl));
memset (&control, 0, sizeof (control));
queryctrl.id = V4L2_CID_BRIGHTNESS;
control.id = V4L2_CID_BRIGHTNESS;

if (-1 == v4l2_ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
if (errno != EINVAL) {
kError() << "VIDIOC_QUERYCTRL";
exit (EXIT_FAILURE);
} else {
kDebug() << "V4L2_CID_BRIGHTNESS is not supported.";
}
} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
kDebug() << "V4L2_CID_BRIGHTNESS is not supported.";
} else {
control.value = (queryctrl.maximum - queryctrl.minimum) * Settings::brightness()/100;
if (-1 == v4l2_ioctl (fd, VIDIOC_S_CTRL, &control)) {
kError() << "VIDIOC_S_CTRL";
exit (EXIT_FAILURE);
}
}

memset (&queryctrl, 0, sizeof (queryctrl));
memset (&control, 0, sizeof (control));
queryctrl.id = V4L2_CID_CONTRAST;
control.id = V4L2_CID_CONTRAST;

if (-1 == v4l2_ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
if (errno != EINVAL) {
kError() << "VIDIOC_QUERYCTRL";
exit (EXIT_FAILURE);
} else {
kDebug() << "V4L2_CID_CONTRAST is not supported.";
}
} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
kDebug() << "V4L2_CID_CONTRAST is not supported.";
} else {
control.value = (queryctrl.maximum - queryctrl.minimum) * Settings::contrast()/100;
if (-1 == v4l2_ioctl (fd, VIDIOC_S_CTRL, &control)) {
kError() << "VIDIOC_S_CTRL";
exit (EXIT_FAILURE);
}
}


memset (&queryctrl, 0, sizeof (queryctrl));
memset (&control, 0, sizeof (control));
queryctrl.id = V4L2_CID_SATURATION;
control.id = V4L2_CID_SATURATION;

if (-1 == v4l2_ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
if (errno != EINVAL) {
kError() << "VIDIOC_QUERYCTRL";
exit (EXIT_FAILURE);
} else {
kDebug() << "V4L2_CID_SATURATION is not supported.";
}
} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
kDebug() << "V4L2_CID_SATURATION is not supported.";
} else {
control.value = (queryctrl.maximum - queryctrl.minimum) * Settings::saturation()/100;
if (-1 == v4l2_ioctl (fd, VIDIOC_S_CTRL, &control)) {
kError() << "VIDIOC_S_CTRL";
exit (EXIT_FAILURE);
}
}


memset (&queryctrl, 0, sizeof (queryctrl));
memset (&control, 0, sizeof (control));
queryctrl.id = V4L2_CID_HUE;
control.id = V4L2_CID_HUE;

if (-1 == v4l2_ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
if (errno != EINVAL) {
kError() << "VIDIOC_QUERYCTRL";
exit (EXIT_FAILURE);
} else {
kDebug() << "V4L2_CID_HUE is not supported.";
}
} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
kDebug() << "V4L2_CID_HUE is not supported.";
} else {
control.value = (queryctrl.maximum - queryctrl.minimum) * Settings::hue()/100;
if (-1 == v4l2_ioctl (fd, VIDIOC_S_CTRL, &control)) {
kError() << "VIDIOC_S_CTRL";
exit (EXIT_FAILURE);
}
}

}


// process video data
void CaptureThread::run() {
while (devam) {
Expand Down Expand Up @@ -147,6 +245,8 @@ int CaptureThread::start() {
return 1;
}

updateImageSettings();

CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = width;
Expand Down
1 change: 1 addition & 0 deletions src/capturethread.h
Expand Up @@ -41,6 +41,7 @@ class CaptureThread : public QThread
int effect;
protected:
void run();
void updateImageSettings();
signals:
void renderedImage(const QImage &image);
void startedCapture(int width, int height);
Expand Down
16 changes: 16 additions & 0 deletions src/kamerka.kcfg
Expand Up @@ -21,6 +21,22 @@
<label>Framerate limit.</label>
<default>0</default>
</entry>
<entry name="brightness" type="Int">
<label>Image brightness.</label>
<default>50</default>
</entry>
<entry name="contrast" type="Int">
<label>Image contrast.</label>
<default>50</default>
</entry>
<entry name="saturation" type="Int">
<label>Image saturation.</label>
<default>30</default>
</entry>
<entry name="hue" type="Int">
<label>Image hue.</label>
<default>50</default>
</entry>
<entry name="mirror" type="Bool">
<label>Mirror output</label>
<default>false</default>
Expand Down
43 changes: 42 additions & 1 deletion src/settingsdialog.cpp
Expand Up @@ -92,6 +92,47 @@ SettingsDialog::SettingsDialog(QWidget *parent, QString name, KConfigSkeleton *c
checkbox->setObjectName("kcfg_flip");
layout->addRow(checkbox);

xdggroupbox = new QGroupBox();
xdggroupbox->setTitle(i18n("Image Settings"));
xdggroupbox->setCheckable(false);
QFormLayout *lay = new QFormLayout(xdggroupbox);
QSlider *slider = new QSlider();
slider->setObjectName("kcfg_brightness");
slider->setMinimum(-100);
slider->setMaximum(100);
slider->setTickInterval(10);
slider->setTickPosition(QSlider::TicksBelow);
slider->setOrientation(Qt::Horizontal);
lay->addRow(i18n("Brightness:"), slider);

slider = new QSlider();
slider->setObjectName("kcfg_contrast");
slider->setMinimum(0);
slider->setMaximum(100);
slider->setTickInterval(10);
slider->setTickPosition(QSlider::TicksBelow);
slider->setOrientation(Qt::Horizontal);
lay->addRow(i18n("Contrast:"), slider);

slider = new QSlider();
slider->setObjectName("kcfg_saturation");
slider->setMinimum(0);
slider->setMaximum(100);
slider->setTickInterval(10);
slider->setTickPosition(QSlider::TicksBelow);
slider->setOrientation(Qt::Horizontal);
lay->addRow(i18n("Saturation:"), slider);

slider = new QSlider();
slider->setObjectName("kcfg_hue");
slider->setMinimum(-100);
slider->setMaximum(100);
slider->setTickInterval(10);
slider->setTickPosition(QSlider::TicksBelow);
slider->setOrientation(Qt::Horizontal);
lay->addRow(i18n("Hue:"), slider);

layout->addRow(xdggroupbox);

this->addPage(page, i18n("Camera"), "camera-web", i18n("Camera settings") );

Expand All @@ -101,7 +142,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, QString name, KConfigSkeleton *c
xdggroupbox = new QGroupBox();
xdggroupbox->setTitle(i18n("Self-timer"));
xdggroupbox->setCheckable(false);
QFormLayout *lay = new QFormLayout(xdggroupbox);
lay = new QFormLayout(xdggroupbox);
spinbox = new QSpinBox();
spinbox->setObjectName("kcfg_selftimer");
spinbox->setSuffix(i18n(" seconds"));
Expand Down

0 comments on commit bcb521f

Please sign in to comment.