summaryrefslogtreecommitdiff
path: root/src/android/jpeg/encoder_libjpeg.h
blob: 1e8df05a90e1aa7f04e9e9d81fdf8b2e256aa128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * encoder_libjpeg.h - JPEG encoding using libjpeg
 */
#ifndef __ANDROID_JPEG_ENCODER_LIBJPEG_H__
#define __ANDROID_JPEG_ENCODER_LIBJPEG_H__

#include "encoder.h"

#include "libcamera/internal/buffer.h"
#include "libcamera/internal/formats.h"

#include <jpeglib.h>

class EncoderLibJpeg : public Encoder
{
public:
	EncoderLibJpeg();
	~EncoderLibJpeg();

	int configure(const libcamera::StreamConfiguration &cfg) override;
	int encode(const libcamera::FrameBuffer *source,
		   const libcamera::Span<uint8_t> &destination,
		   const libcamera::Span<const uint8_t> &exifData) override;

private:
	void compressRGB(const libcamera::MappedBuffer *frame);
	void compressNV(const libcamera::MappedBuffer *frame);

	struct jpeg_compress_struct compress_;
	struct jpeg_error_mgr jerr_;

	unsigned int quality_;

	const libcamera::PixelFormatInfo *pixelFormatInfo_;

	bool nv_;
	bool nvSwap_;
};

#endif /* __ANDROID_JPEG_ENCODER_LIBJPEG_H__ */