/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Google Inc. * * Simple image thumbnailer */ #include "thumbnailer.h" #include #include #include "libcamera/internal/mapped_framebuffer.h" using namespace libcamera; LOG_DEFINE_CATEGORY(Thumbnailer) Thumbnailer::Thumbnailer() : valid_(false) { } void Thumbnailer::configure(const Size &sourceSize, PixelFormat pixelFormat) { sourceSize_ = sourceSize; pixelFormat_ = pixelFormat; if (pixelFormat_ != formats::NV12) { LOG(Thumbnailer, Error) << "Failed to configure: Pixel Format " << pixelFormat_ << " unsupported."; return; } valid_ = true; } void Thumbnailer::createThumbnail(const FrameBuffer &source, const Size &targetSize, std::vector *destination) { MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read); if (!frame.isValid()) { LOG(Thumbnailer, Error) << "Failed to map FrameBuffer : " << strerror(frame.error()); return; } if (!valid_) { LOG(Thumbnailer, Error) << "Config is unconfigured or invalid."; return; } const unsigned int sw = sourceSize_.width; const unsigned int sh = sourceSize_.height; const unsigned int tw = targetSize.width; const unsigned int th = targetSize.height; ASSERT(frame.planes().size() == 2); ASSERT(tw % 2 == 0 && th % 2 == 0); /* Image scaling block implementing nearest-neighbour algorithm. */ unsigned char *src = frame.planes()[0].data(); unsigned char *srcC = frame.planes()[1].data(); unsigned char *srcCb, *srcCr; unsigned char *dstY, *srcY; size_t dstSize = (th * tw) + ((th / 2) * tw); destination->resize(dstSize); unsigned char *dst = destination->data(); unsigned char *dstC = dst + th * tw; for (unsigned int y = 0; y < th; y += 2) { unsigned int sourceY = (sh * y + th / 2) / th; dstY = dst + y * tw; srcY = src + sw * sourceY; srcCb = srcC + (sourceY / 2) * sw + 0; srcCr = srcC + (sourceY / 2) * sw + 1; for (unsigned int x = 0; x < tw; x += 2) { unsigned int sourceX = (sw * x + tw / 2) / tw; dstY[x] = srcY[sourceX]; dstY[tw + x] = srcY[sw + sourceX]; dstY[x + 1] = srcY[sourceX + 1]; dstY[tw + x + 1] = srcY[sw + sourceX + 1]; dstC[(y / 2) * tw + x + 0] = srcCb[(sourceX / 2) * 2]; dstC[(y / 2) * tw + x + 1] = srcCr[(sourceX / 2) * 2]; } } } a href='/libcamera/libcamera.git/tree/?h=v0.0.5&id=ad2bcbe5b55c8824288cd1752649f39f3a53af38'>root/src/cam/event_loop.cpp
blob: e25784c083cfccc2adbbffcf4c2721243d658a43 (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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * event_loop.cpp - cam - Event loop
 */

#include "event_loop.h"

#include <assert.h>
#include <event2/event.h>
#include <event2/thread.h>
#include <iostream>

EventLoop *EventLoop::instance_ = nullptr;

EventLoop::EventLoop()
{
	assert(!instance_);

	evthread_use_pthreads();
	base_ = event_base_new();
	instance_ = this;
}

EventLoop::~EventLoop()
{
	instance_ = nullptr;