summaryrefslogtreecommitdiff
path: root/utils/meson.build
AgeCommit message (Expand)Author
2020-11-11README, meson: Add dependency on ply and jinja2 for IPA interface generationPaul Elder
2020-11-03libcamera: tracing: Implement tracing infrastructurePaul Elder
2020-09-24meson: Define python3 and python3-yaml required dependenciesEzequiel Garcia
2020-09-24libcamera: ipa: Move key generation to utilsKieran Bingham
2020-09-24libcamera: Move Header generation utilities to utilsKieran Bingham
2020-05-13licenses: License all meson files under CC0-1.0Laurent Pinchart
2018-11-20utils: ipu3: Add IPU3 raw capture unpack utilityLaurent Pinchart
='#n74'>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 112
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * EXIF tag creator using libexif
 */

#pragma once

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

#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(std::vector<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_;

	std::vector<unsigned char> thumbnailData_;
};