summaryrefslogtreecommitdiff
path: root/test/v4l2_videodevice/stream_on_off.cpp
AgeCommit message (Expand)Author
2020-10-20test: Omit extra semicolonsHirokazu Honda
2020-03-18libcamera: v4l2_videodevice: Rename exportBuffers() to allocateBuffers()Laurent Pinchart
2020-01-12test: v4l2_videodevice: Switch to FrameBuffer interfaceNiklas Söderlund
2019-06-19libcamera: Rename V4L2Device to V4L2VideoDeviceJacopo Mondi
5' href='#n55'>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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * exif.h - EXIF tag creator using libexif
 */

#pragma once

#include <chrono>
#include <string>
#include <time.h>

#include <libexif/exif-data.h>

#include <libcamera/base/span.h>

#include <libcamera/geometry.h>

class Exif
{
public:
	Exif();
	~Exif();

	enum Compression {
		None = 1,
		JPEG = 6,
	};

	enum Flash {
		/* bit 0 */
		Fired = 0x01,
		/* bits 1 and 2 */
		StrobeDetected = 0x04,
		StrobeNotDetected = 0x06,
		/* bits 3 and 4 */
		ModeCompulsoryFiring = 0x08,
		ModeCompulsorySuppression = 0x10,
		ModeAuto = 0x18,
		/* bit 5 */
		FlashNotPresent = 0x20,
		/* bit 6 */
		RedEye = 0x40,
	};

	enum WhiteBalance {
		Auto = 0,
		Manual = 1,
	};

	enum StringEncoding {
		NoEncoding = 0,
		ASCII = 1,
		Unicode = 2,
	};

	void setMake(const std::string &make);
	void setModel(const std::string &model);

	void setOrientation(int orientation);
	void setSize(const libcamera::Size &size);
	void setThumbnail(libcamera::Span<const unsigned char> thumbnail,
			  Compression compression);
	void setTimestamp(time_t timestamp, std::chrono::milliseconds msec);

	void setGPSDateTimestamp(time_t timestamp);
	void setGPSLocation(const double *coords);
	void setGPSMethod(const std::string &method);

	void setFocalLength(float length);
	void setExposureTime(uint64_t nsec);
	void setAperture(float size);
	void setISO(uint16_t iso);
	void setFlash(Flash flash);
	void setWhiteBalance(WhiteBalance wb);

	libcamera::Span<const uint8_t> data() const { return { exifData_, size_ }; }
	[[nodiscard]] int generate();

private:
	ExifEntry *createEntry(ExifIfd ifd, ExifTag tag);
	ExifEntry *createEntry(ExifIfd ifd, ExifTag tag, ExifFormat format,
			       unsigned long components, unsigned int size);

	void setByte(ExifIfd ifd, ExifTag tag, uint8_t item);
	void setShort(ExifIfd ifd, ExifTag tag, uint16_t item);
	void setLong(ExifIfd ifd, ExifTag tag, uint32_t item);
	void setString(ExifIfd ifd, ExifTag tag, ExifFormat format,
		       const std::string &item,
		       StringEncoding encoding = NoEncoding);
	void setRational(ExifIfd ifd, ExifTag tag, ExifRational item);
	void setRational(ExifIfd ifd, ExifTag tag,
			 libcamera::Span<const ExifRational> items);

	std::tuple<int, int, int> degreesToDMS(double decimalDegrees);
	void setGPSDMS(ExifIfd ifd, ExifTag tag, int deg, int min, int sec);

	std::u16string utf8ToUtf16(const std::string &str);

	bool valid_;

	ExifData *data_;
	ExifMem *mem_;
	ExifByteOrder order_;

	unsigned char *exifData_;
	unsigned int size_;
};