-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCameraRenderer.qml
More file actions
236 lines (201 loc) · 6.02 KB
/
CameraRenderer.qml
File metadata and controls
236 lines (201 loc) · 6.02 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import QtQuick
import QtMultimedia
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
import QtQuick.Layouts
import BackgroundFilter
import CaptureProcessor
import GPhotoCamera
Item {
id: renderer
signal savedPhoto(string filename)
signal failed
property bool photoProcessing: (state === "snapshot")
property bool mirrored: true
property string cameraName: ""
property alias backgroundFilter: backgroundFilter
property bool backgroundFilterEnabled: false
property url backgroundImage: ""
property var libcamera
onCameraNameChanged:
{
print("Camera changed to " + cameraName)
}
CaptureProcessor
{
id: captureProcessor
rotation: applicationSettings.cameraOrientation
onCaptureSaved: fileName =>
{
if(backgroundFilterEnabled)
{
console.log("Process file: " + fileName)
backgroundFilter.processCapture(fileName)
}
else
{
renderer.state = "preview"
savedPhoto("file:" + fileName)
console.log("Saved: " + fileName)
}
}
}
CameraSource
{
id: cameraSource
anchors.fill: parent
cameraName: renderer.cameraName
libcamera: renderer.libcamera
onImageCaptured: function(image) {
whiteOverlay.state = "released"
renderer.state = "store"
console.log("Captured: " + image)
console.log(applicationSettings.foldername.toString())
var path = applicationSettings.foldername.toString()
if(backgroundFilterEnabled)
{
path = path + "/raw"
}
path = path.replace(/^(file:\/{2})/, "")
var cleanPath = decodeURIComponent(path)
console.log(cleanPath)
captureProcessor.saveCapture(image, cleanPath + "/Pict_" + new Date().toLocaleString(
locale, "dd_MM_yyyy_hh_mm_ss") + ".jpg")
}
onErrorOccurred: function(errorString) {
renderer.state = "preview"
console.log("Camera error: " + errorString)
failed()
}
}
ReplaceBackgroundVideoFilter {
id: backgroundFilter
videoSink: cameraSource.output.videoSink
background: backgroundImage
onCaptureProcessingFinished: fileName =>
{
console.log("Capture processing finished")
if (backgroundFilterEnabled) {
renderer.state = "preview"
savedPhoto("file:" + fileName)
console.log("Saved: " + fileName)
}
}
}
VideoOutput {
id: output
anchors.fill: parent
visible: false
//focus: visible // to receive focus and capture key events when visible
}
CaptureSession
{
id: maskSession
videoFrameInput: backgroundFilter
videoOutput: maskOutput
}
VideoOutput {
id: maskOutput
visible: cameraSource.state !== "noCamera" && cameraSource.state !== "Error"
rotation: applicationSettings.cameraOrientation
anchors.fill: parent
onContentRectChanged: {
console.log("Content rect changed: " + Qt.rect(contentRect.x / width, contentRect.y /height, contentRect.width / width, contentRect.height / height))
}
layer.enabled: true
layer.effect: ShaderEffect {
id: mirrorEffect
property variant source: ShaderEffectSource {
sourceItem: maskOutput
hideSource: true
}
property variant bgSource : Image {
id: bgImage
source: backgroundImage
fillMode: Image.PreserveAspectCrop
}
property bool mirrored: renderer.mirrored
property bool enableMask: true
property rect contentRect: Qt.rect(maskOutput.contentRect.x / maskOutput.width, maskOutput.contentRect.y / maskOutput.height, maskOutput.contentRect.width / maskOutput.width, maskOutput.contentRect.height / maskOutput.height)
anchors.fill: maskOutput
fragmentShader: "qrc:/shaders/previewshader.frag.qsb"
}
}
WhiteOverlay {
id: whiteOverlay
x: output.x
y: output.y
width: output.width
height: output.height
}
function takePhoto() {
if (cameraSource.readyForCapture) {
state = "snapshot"
cameraSource.captureImage()
} else {
renderer.state = "preview"
failed()
}
}
BusyIndicator {
id: busyIndicator
anchors.centerIn: parent
visible: false
}
states: [
State {
name: "idle"
},
State {
name: "preview"
PropertyChanges {
target: whiteOverlay
state: "released"
}
PropertyChanges {
target: shutterButton
state: "idle"
}
PropertyChanges {
target: busyIndicator
visible: false
}
StateChangeScript {
script: {
cameraSource.start()
}
}
},
State {
name: "snapshot"
PropertyChanges {
target: whiteOverlay
state: "triggered"
}
},
State {
name: "store"
PropertyChanges {
target: whiteOverlay
state: "processing"
}
PropertyChanges {
target: busyIndicator
visible: true
}
}
]
transitions: Transition {
to: "idle"
SequentialAnimation {
NumberAnimation {
duration: 2000
}
ScriptAction {
script: {
cameraSource.stop()
}
}
}
}
}