summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/controller/dpc_status.h
blob: a3ec2762573bffeafe2eb810bc3eb7177a23ea44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (C) 2019, Raspberry Pi (Trading) Limited
 *
 * dpc_status.h - DPC (defective pixel correction) control algorithm status
 */
#pragma once

// The "DPC" algorithm sets defective pixel correction strength.

#ifdef __cplusplus
extern "C" {
#endif

struct DpcStatus {
	int strength; // 0 = "off", 1 = "normal", 2 = "strong"
};

#ifdef __cplusplus
}
#endif
a id='n23' href='#n23'>23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t@gmail.com>
 *
 * cam_select_dialog.cpp - qcam - Camera Selection dialog
 */

#include "cam_select_dialog.h"

#include <memory>

#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>

#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLabel>
#include <QString>

CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManager,
					   QWidget *parent)
	: QDialog(parent), cm_(cameraManager)
{
	/* Use a QFormLayout for the dialog. */
	QFormLayout *layout = new QFormLayout(this);

	/* Setup the camera id combo-box. */
	cameraIdComboBox_ = new QComboBox;
	for (const auto &cam : cm_->cameras())
		cameraIdComboBox_->addItem(QString::fromStdString(cam->id()));

	/* Set camera information labels. */
	cameraLocation_ = new QLabel;
	cameraModel_ = new QLabel;

	updateCameraInfo(cameraIdComboBox_->currentText());
	connect(cameraIdComboBox_, &QComboBox::currentTextChanged,
		this, &CameraSelectorDialog::updateCameraInfo);

	/* Setup the QDialogButton Box */
	QDialogButtonBox *buttonBox =
		new QDialogButtonBox(QDialogButtonBox::Ok |
				     QDialogButtonBox::Cancel);

	connect(buttonBox, &QDialogButtonBox::accepted,
		this, &QDialog::accept);
	connect(buttonBox, &QDialogButtonBox::rejected,
		this, &QDialog::reject);

	/* Set the layout. */
	layout->addRow("Camera:", cameraIdComboBox_);
	layout->addRow("Location:", cameraLocation_);
	layout->addRow("Model:", cameraModel_);
	layout->addWidget(buttonBox);
}

CameraSelectorDialog::~CameraSelectorDialog() = default;

std::string CameraSelectorDialog::getCameraId()
{
	return cameraIdComboBox_->currentText().toStdString();
}

/* Hotplug / Unplug Support. */
void CameraSelectorDialog::addCamera(QString cameraId)
{
	cameraIdComboBox_->addItem(cameraId);
}

void CameraSelectorDialog::removeCamera(QString cameraId)
{
	int cameraIndex = cameraIdComboBox_->findText(cameraId);
	cameraIdComboBox_->removeItem(cameraIndex);
}

/* Camera Information */
void CameraSelectorDialog::updateCameraInfo(QString cameraId)
{
	const std::shared_ptr<libcamera::Camera> &camera =
		cm_->get(cameraId.toStdString());

	if (!camera)
		return;

	const libcamera::ControlList &properties = camera->properties();

	const auto &location = properties.get(libcamera::properties::Location);
	if (location) {
		switch (*location) {
		case libcamera::properties::CameraLocationFront:
			cameraLocation_->setText("Internal front camera");
			break;
		case libcamera::properties::CameraLocationBack:
			cameraLocation_->setText("Internal back camera");
			break;
		case libcamera::properties::CameraLocationExternal:
			cameraLocation_->setText("External camera");
			break;
		default:
			cameraLocation_->setText("Unknown");
		}
	} else {
		cameraLocation_->setText("Unknown");
	}

	const auto &model = properties.get(libcamera::properties::Model)
				    .value_or("Unknown");

	cameraModel_->setText(QString::fromStdString(model));
}