process_pipeline.c 15.9 KB
Newer Older
1
2
3
#include "process_pipeline.h"

#include "pipeline.h"
4
#include "zbar_pipeline.h"
5
6
#include "main.h"
#include "config.h"
7
#include "matrix.h"
8
#include "quickpreview.h"
9
#include "wb.h"
10
11
12
13
14
15
16
17
#include <tiffio.h>
#include <assert.h>
#include <math.h>
#include <wordexp.h>
#include <gtk/gtk.h>

#define TIFFTAG_FORWARDMATRIX1 50964

Martijn Braam's avatar
Martijn Braam committed
18
19
static const float colormatrix_srgb[] = { 3.2409, -1.5373, -0.4986, -0.9692, 1.8759,
					  0.0415, 0.0556,  -0.2039, 1.0569 };
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

static MPPipeline *pipeline;

static char burst_dir[23];
static char processing_script[512];

static volatile bool is_capturing = false;
static volatile int frames_processed = 0;
static volatile int frames_received = 0;

static const struct mp_camera_config *camera;

static MPCameraMode mode;

static int burst_length;
static int captures_remaining = 0;

static int preview_width;
static int preview_height;

// static bool gain_is_manual;
static int gain;
static int gain_max;
43
static int gain_min;
44
45
46

static bool exposure_is_manual;
static int exposure;
47
static int exposure_max;
48
static int exposure_min;
49

50
static int wb;
51
static int focus;
52

53
54
static char capture_fname[255];

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
static const char *pixel_format_names[MP_PIXEL_FMT_MAX] = {
    "\002\001\001\000", // fallback
    "\002\001\001\000",//    "BGGR8",
    "\001\002\000\001",//    "GBRG8",
    "\001\000\002\001",//    "GRBG8",
    "\000\001\001\002",//    "RGGB8",
    "\002\001\001\000",//    "BGGR10P",
    "\001\002\000\001",//    "GBRG10P",
    "\001\000\002\001",//    "GRBG10P",
    "\000\001\001\002",//    "RGGB10P",
    "\002\001\001\000",//    "BGGR10",
    "\001\002\000\001",//    "GBRG10",
    "\001\000\002\001",//    "GRBG10",
    "\000\001\001\002",//    "RGGB10",
    "UYVY",//    does not apply
    "YUYV",//    does not apply
};

static const char *
mp_pixel_format_to_cfa_pattern(uint32_t pixel_format)
{
    g_return_val_if_fail(pixel_format < MP_PIXEL_FMT_MAX, "\002\001\001\000");
    return pixel_format_names[pixel_format];
}

80
81
82
static void
register_custom_tiff_tags(TIFF *tif)
{
Martijn Braam's avatar
Martijn Braam committed
83
84
85
86
87
88
89
90
	static const TIFFFieldInfo custom_fields[] = {
		{ TIFFTAG_FORWARDMATRIX1, -1, -1, TIFF_SRATIONAL, FIELD_CUSTOM, 1, 1,
		  "ForwardMatrix1" },
	};

	// Add missing dng fields
	TIFFMergeFieldInfo(tif, custom_fields,
			   sizeof(custom_fields) / sizeof(custom_fields[0]));
91
92
93
94
95
}

static bool
find_processor(char *script)
{
Martijn Braam's avatar
Martijn Braam committed
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
	char *xdg_config_home;
	char filename[] = "postprocess.sh";
	wordexp_t exp_result;

	// Resolve XDG stuff
	if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL) {
		xdg_config_home = "~/.config";
	}
	wordexp(xdg_config_home, &exp_result, 0);
	xdg_config_home = strdup(exp_result.we_wordv[0]);
	wordfree(&exp_result);

	// Check postprocess.h in the current working directory
	sprintf(script, "%s", filename);
	if (access(script, F_OK) != -1) {
		sprintf(script, "./%s", filename);
		printf("Found postprocessor script at %s\n", script);
		return true;
	}

	// Check for a script in XDG_CONFIG_HOME
	sprintf(script, "%s/megapixels/%s", xdg_config_home, filename);
	if (access(script, F_OK) != -1) {
		printf("Found postprocessor script at %s\n", script);
		return true;
	}

	// Check user overridden /etc/megapixels/postprocessor.sh
	sprintf(script, "%s/megapixels/%s", SYSCONFDIR, filename);
	if (access(script, F_OK) != -1) {
		printf("Found postprocessor script at %s\n", script);
		return true;
	}

	// Check packaged /usr/share/megapixels/postprocessor.sh
	sprintf(script, "%s/megapixels/%s", DATADIR, filename);
	if (access(script, F_OK) != -1) {
		printf("Found postprocessor script at %s\n", script);
		return true;
	}

	return false;
138
139
}

Martijn Braam's avatar
Martijn Braam committed
140
141
static void
setup(MPPipeline *pipeline, const void *data)
142
{
Martijn Braam's avatar
Martijn Braam committed
143
	TIFFSetTagExtender(register_custom_tiff_tags);
144

Martijn Braam's avatar
Martijn Braam committed
145
146
147
148
	if (!find_processor(processing_script)) {
		g_printerr("Could not find any post-process script\n");
		exit(1);
	}
149
150
}

Martijn Braam's avatar
Martijn Braam committed
151
152
void
mp_process_pipeline_start()
153
{
Martijn Braam's avatar
Martijn Braam committed
154
	pipeline = mp_pipeline_new();
155

Martijn Braam's avatar
Martijn Braam committed
156
	mp_pipeline_invoke(pipeline, setup, NULL, 0);
157
158
159


	mp_zbar_pipeline_start();
160
161
}

Martijn Braam's avatar
Martijn Braam committed
162
163
void
mp_process_pipeline_stop()
164
{
Martijn Braam's avatar
Martijn Braam committed
165
	mp_pipeline_free(pipeline);
166
167

	mp_zbar_pipeline_stop();
168
169
}

170
static cairo_surface_t *
171
172
process_image_for_preview(const MPImage *image)
{
Martijn Braam's avatar
Martijn Braam committed
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
	uint32_t surface_width, surface_height, skip;
	quick_preview_size(&surface_width, &surface_height, &skip, preview_width,
			   preview_height, image->width, image->height,
			   image->pixel_format, camera->rotate);

	cairo_surface_t *surface = cairo_image_surface_create(
		CAIRO_FORMAT_RGB24, surface_width, surface_height);

	uint8_t *pixels = cairo_image_surface_get_data(surface);

	quick_preview((uint32_t *)pixels, surface_width, surface_height, image->data,
		      image->width, image->height, image->pixel_format,
		      camera->rotate, camera->mirrored,
		      camera->previewmatrix[0] == 0 ? NULL : camera->previewmatrix,
		      camera->blacklevel, skip);

189
190
191
192
193
194
195
196
197
198
199
200
201
	// Create a thumbnail from the preview for the last capture
	cairo_surface_t *thumb = NULL;
	if (captures_remaining == 1) {
		printf("Making thumbnail\n");
		thumb = cairo_image_surface_create(
			CAIRO_FORMAT_ARGB32, MP_MAIN_THUMB_SIZE, MP_MAIN_THUMB_SIZE);

		cairo_t *cr = cairo_create(thumb);
		draw_surface_scaled_centered(
			cr, MP_MAIN_THUMB_SIZE, MP_MAIN_THUMB_SIZE, surface);
		cairo_destroy(cr);
	}

202
203
	// Pass processed preview to main and zbar
	mp_zbar_pipeline_process_image(cairo_surface_reference(surface));
Martijn Braam's avatar
Martijn Braam committed
204
	mp_main_set_preview(surface);
205
206

	return thumb;
207
208
209
210
211
}

static void
process_image_for_capture(const MPImage *image, int count)
{
Martijn Braam's avatar
Martijn Braam committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
	time_t rawtime;
	time(&rawtime);
	struct tm tim = *(localtime(&rawtime));

	char datetime[20] = { 0 };
	strftime(datetime, 20, "%Y:%m:%d %H:%M:%S", &tim);

	char fname[255];
	sprintf(fname, "%s/%d.dng", burst_dir, count);

	TIFF *tif = TIFFOpen(fname, "w");
	if (!tif) {
		printf("Could not open tiff\n");
	}

	// Define TIFF thumbnail
228
229
	int thumbnail_width = image->width >> 4;
	int thumbnail_height = image->height >> 4;
Martijn Braam's avatar
Martijn Braam committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
	TIFFSetField(tif, TIFFTAG_SUBFILETYPE, 1);
	TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
	TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
	TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
	TIFFSetField(tif, TIFFTAG_MAKE, mp_get_device_make());
	TIFFSetField(tif, TIFFTAG_MODEL, mp_get_device_model());
	uint16_t orientation;
	if (camera->rotate == 0) {
		orientation = camera->mirrored ? ORIENTATION_TOPRIGHT :
						 ORIENTATION_TOPLEFT;
	} else if (camera->rotate == 90) {
		orientation = camera->mirrored ? ORIENTATION_RIGHTBOT :
						 ORIENTATION_LEFTBOT;
	} else if (camera->rotate == 180) {
		orientation = camera->mirrored ? ORIENTATION_BOTLEFT :
						 ORIENTATION_BOTRIGHT;
	} else {
		orientation = camera->mirrored ? ORIENTATION_LEFTTOP :
						 ORIENTATION_RIGHTTOP;
	}
	TIFFSetField(tif, TIFFTAG_ORIENTATION, orientation);
	TIFFSetField(tif, TIFFTAG_DATETIME, datetime);
252
253
254
	TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
	int extrasamples = EXTRASAMPLE_UNSPECIFIED;
	TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, &extrasamples);
Martijn Braam's avatar
Martijn Braam committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
	TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
	TIFFSetField(tif, TIFFTAG_SOFTWARE, "Megapixels");
	long sub_offset = 0;
	TIFFSetField(tif, TIFFTAG_SUBIFD, 1, &sub_offset);
	TIFFSetField(tif, TIFFTAG_DNGVERSION, "\001\001\0\0");
	TIFFSetField(tif, TIFFTAG_DNGBACKWARDVERSION, "\001\0\0\0");
	char uniquecameramodel[255];
	sprintf(uniquecameramodel, "%s %s", mp_get_device_make(),
		mp_get_device_model());
	TIFFSetField(tif, TIFFTAG_UNIQUECAMERAMODEL, uniquecameramodel);
	if (camera->colormatrix[0]) {
		TIFFSetField(tif, TIFFTAG_COLORMATRIX1, 9, camera->colormatrix);
	} else {
		TIFFSetField(tif, TIFFTAG_COLORMATRIX1, 9, colormatrix_srgb);
	}
	if (camera->forwardmatrix[0]) {
		TIFFSetField(tif, TIFFTAG_FORWARDMATRIX1, 9, camera->forwardmatrix);
	}
273
274
275
276
277
278
279
280
	if (camera->colormatrix[0] && camera->forwardmatrix[0]) {
		float neutral[3];
		matrix_white_point(camera->previewmatrix, neutral);
		TIFFSetField(tif, TIFFTAG_ASSHOTNEUTRAL, 3, neutral);
	} else {
		TIFFSetField(tif, TIFFTAG_ASSHOTNEUTRAL, 3, WB_WHITEPOINTS[wb]);
	}
	TIFFSetField(tif, TIFFTAG_CALIBRATIONILLUMINANT1, 21); // D65
Martijn Braam's avatar
Martijn Braam committed
281
	{
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
		uint32_t surface_width, surface_height, skip;
		quick_preview_size(&surface_width, &surface_height, &skip, thumbnail_width,
				thumbnail_height, image->width, image->height,
				image->pixel_format, 0);

		TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, surface_width);
		TIFFSetField(tif, TIFFTAG_IMAGELENGTH, surface_height);

		uint8_t *pixels = malloc(surface_width * 4 * surface_height);
		quick_preview((uint32_t *)pixels, surface_width, surface_height, image->data,
			image->width, image->height, image->pixel_format,
			0, false,
			camera->previewmatrix[0] == 0 ? NULL : camera->previewmatrix,
			camera->blacklevel, skip);

		for (int row = 0; row < thumbnail_height; row++) {
			TIFFWriteScanline(tif, pixels + surface_width * 4 * row, row, 0);
Martijn Braam's avatar
Martijn Braam committed
299
		}
300
		free(pixels);
Martijn Braam's avatar
Martijn Braam committed
301
302
303
304
305
306
307
	}
	TIFFWriteDirectory(tif);

	// Define main photo
	TIFFSetField(tif, TIFFTAG_SUBFILETYPE, 0);
	TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, image->width);
	TIFFSetField(tif, TIFFTAG_IMAGELENGTH, image->height);
308
	TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, mp_pixel_format_bits_per_pixel(image->pixel_format));
Martijn Braam's avatar
Martijn Braam committed
309
310
311
312
313
	TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CFA);
	TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
	TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
	static const short cfapatterndim[] = { 2, 2 };
	TIFFSetField(tif, TIFFTAG_CFAREPEATPATTERNDIM, cfapatterndim);
314
315

    const char *cfa_pattern = mp_pixel_format_to_cfa_pattern(image->pixel_format);
316
#if (TIFFLIB_VERSION < 20201219) && !LIBTIFF_CFA_PATTERN
317
    TIFFSetField(tif, TIFFTAG_CFAPATTERN, cfa_pattern);
318
#else
319
    TIFFSetField(tif, TIFFTAG_CFAPATTERN, 4, cfa_pattern);
320
#endif
321
	printf("TIFF version %d\n", TIFFLIB_VERSION);
322
323
324
	int whitelevel = camera->whitelevel;
	if (!whitelevel) {
		whitelevel = (1 << mp_pixel_format_pixel_depth(image->pixel_format)) - 1;
Martijn Braam's avatar
Martijn Braam committed
325
	}
326
	TIFFSetField(tif, TIFFTAG_WHITELEVEL, 1, &whitelevel);
Martijn Braam's avatar
Martijn Braam committed
327
	if (camera->blacklevel) {
328
329
		const float blacklevel = camera->blacklevel;
		TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 1, &blacklevel);
Martijn Braam's avatar
Martijn Braam committed
330
331
332
333
334
	}
	TIFFCheckpointDirectory(tif);
	printf("Writing frame to %s\n", fname);

	for (int row = 0; row < image->height; row++) {
335
		TIFFWriteScanline(tif, image->data + (row * mp_pixel_format_width_to_bytes(image->pixel_format, image->width)), row, 0);
Martijn Braam's avatar
Martijn Braam committed
336
337
338
339
340
341
342
343
344
345
346
347
	}
	TIFFWriteDirectory(tif);

	// Add an EXIF block to the tiff
	TIFFCreateEXIFDirectory(tif);
	// 1 = manual, 2 = full auto, 3 = aperture priority, 4 = shutter priority
	if (!exposure_is_manual) {
		TIFFSetField(tif, EXIFTAG_EXPOSUREPROGRAM, 2);
	} else {
		TIFFSetField(tif, EXIFTAG_EXPOSUREPROGRAM, 1);
	}

348
349
350
351
	//TIFFSetField(tif, EXIFTAG_EXPOSURETIME,
	//	     (mode.frame_interval.numerator /
	//	      (float)mode.frame_interval.denominator) /
	//		     ((float)image->height / (float)exposure));
352
353
354
355
356
	if (camera->iso_min && camera->iso_max) {
		uint16_t isospeed = remap(gain - 1, gain_min, gain_max, camera->iso_min,
					  camera->iso_max);
		TIFFSetField(tif, EXIFTAG_ISOSPEEDRATINGS, 1, &isospeed);
	}
Martijn Braam's avatar
Martijn Braam committed
357
	TIFFSetField(tif, EXIFTAG_FLASH, 0);
358
	TIFFSetField(tif, EXIFTAG_WHITEBALANCE, 1);
Martijn Braam's avatar
Martijn Braam committed
359
360
361
362
363
364
365
366
367
368
369
370
371

	TIFFSetField(tif, EXIFTAG_DATETIMEORIGINAL, datetime);
	TIFFSetField(tif, EXIFTAG_DATETIMEDIGITIZED, datetime);
	if (camera->fnumber) {
		TIFFSetField(tif, EXIFTAG_FNUMBER, camera->fnumber);
	}
	if (camera->focallength) {
		TIFFSetField(tif, EXIFTAG_FOCALLENGTH, camera->focallength);
	}
	if (camera->focallength && camera->cropfactor) {
		TIFFSetField(tif, EXIFTAG_FOCALLENGTHIN35MMFILM,
			     (short)(camera->focallength * camera->cropfactor));
	}
372
373
374
	char makernote[255] = {};
	snprintf(makernote, 255, "L5MP Gain: %d; Exposure: %d; Focus: %d; Balance: %s", gain, exposure, focus, WB_ILLUMINANTS[wb]);
	TIFFSetField(tif, EXIFTAG_MAKERNOTE, strlen(makernote) + 1, makernote);
Martijn Braam's avatar
Martijn Braam committed
375
376
377
378
379
380
381
382
383
384
	uint64_t exif_offset = 0;
	TIFFWriteCustomDirectory(tif, &exif_offset);
	TIFFFreeDirectory(tif);

	// Update exif pointer
	TIFFSetDirectory(tif, 0);
	TIFFSetField(tif, TIFFTAG_EXIFIFD, exif_offset);
	TIFFRewriteDirectory(tif);

	TIFFClose(tif);
385
386
}

387
static void
388
post_process_finished(GSubprocess *proc, GAsyncResult *res, cairo_surface_t *thumb)
389
390
391
392
393
394
395
396
397
398
399
400
{
	char *stdout;
	g_subprocess_communicate_utf8_finish(proc, res, &stdout, NULL, NULL);

	// The last line contains the file name
	int end = strlen(stdout);
	// Skip the newline at the end
	stdout[--end] = '\0';

	char *path = path = stdout + end - 1;
	do {
		if (*path == '\n') {
401
			path++;
402
403
404
405
406
			break;
		}
		--path;
	} while (path > stdout);

407
	mp_main_capture_completed(thumb, path);
408
409
}

410
static void
411
process_capture_burst(cairo_surface_t *thumb)
412
{
Martijn Braam's avatar
Martijn Braam committed
413
414
415
	time_t rawtime;
	time(&rawtime);
	struct tm tim = *(localtime(&rawtime));
416

Martijn Braam's avatar
Martijn Braam committed
417
418
	char timestamp[30];
	strftime(timestamp, 30, "%Y%m%d%H%M%S", &tim);
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
	if (g_get_user_special_dir(G_USER_DIRECTORY_PICTURES) != NULL) {
		sprintf(capture_fname,
			"%s/IMG%s",
			g_get_user_special_dir(G_USER_DIRECTORY_PICTURES),
			timestamp);
	} else if (getenv("XDG_PICTURES_DIR") != NULL) {
		sprintf(capture_fname,
			"%s/IMG%s",
			getenv("XDG_PICTURES_DIR"),
			timestamp);
	} else {
		sprintf(capture_fname,
			"%s/Pictures/IMG%s",
			getenv("HOME"),
			timestamp);
	}

437

Martijn Braam's avatar
Martijn Braam committed
438
439
	// Start post-processing the captured burst
	g_print("Post process %s to %s.ext\n", burst_dir, capture_fname);
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
	GError *error = NULL;
	GSubprocess *proc = g_subprocess_new(
		G_SUBPROCESS_FLAGS_STDOUT_PIPE,
		&error,
		processing_script,
		burst_dir,
		capture_fname,
		NULL);

	if (!proc) {
		g_printerr("Failed to spawn postprocess process: %s\n",
			   error->message);
		return;
	}

	g_subprocess_communicate_utf8_async(
		proc,
		NULL,
		NULL,
		(GAsyncReadyCallback)post_process_finished,
460
		thumb);
461
462
463
464
465
}

static void
process_image(MPPipeline *pipeline, const MPImage *image)
{
Martijn Braam's avatar
Martijn Braam committed
466
	assert(image->width == mode.width && image->height == mode.height);
467

468
	cairo_surface_t *thumb = process_image_for_preview(image);
469

Martijn Braam's avatar
Martijn Braam committed
470
471
472
	if (captures_remaining > 0) {
		int count = burst_length - captures_remaining;
		--captures_remaining;
473

Martijn Braam's avatar
Martijn Braam committed
474
		process_image_for_capture(image, count);
475

Martijn Braam's avatar
Martijn Braam committed
476
		if (captures_remaining == 0) {
477
478
479
480
			assert(thumb);
			process_capture_burst(thumb);
		} else {
			assert(!thumb);
Martijn Braam's avatar
Martijn Braam committed
481
		}
482
483
	} else {
		assert(!thumb);
Martijn Braam's avatar
Martijn Braam committed
484
	}
485

Martijn Braam's avatar
Martijn Braam committed
486
	free(image->data);
487

Martijn Braam's avatar
Martijn Braam committed
488
489
490
491
	++frames_processed;
	if (captures_remaining == 0) {
		is_capturing = false;
	}
492
493
}

Martijn Braam's avatar
Martijn Braam committed
494
495
void
mp_process_pipeline_process_image(MPImage image)
496
{
Martijn Braam's avatar
Martijn Braam committed
497
498
	// If we haven't processed the previous frame yet, drop this one
	if (frames_received != frames_processed && !is_capturing) {
499
		//printf("Dropped frame at capture\n");
Benjamin Schaaf's avatar
Benjamin Schaaf committed
500
		free(image.data);
Martijn Braam's avatar
Martijn Braam committed
501
502
		return;
	}
503

Martijn Braam's avatar
Martijn Braam committed
504
	++frames_received;
505

Martijn Braam's avatar
Martijn Braam committed
506
507
	mp_pipeline_invoke(pipeline, (MPPipelineCallback)process_image, &image,
			   sizeof(MPImage));
508
509
}

Martijn Braam's avatar
Martijn Braam committed
510
511
static void
capture()
512
{
Martijn Braam's avatar
Martijn Braam committed
513
514
515
	char template[] = "/tmp/megapixels.XXXXXX";
	char *tempdir;
	tempdir = mkdtemp(template);
516

Martijn Braam's avatar
Martijn Braam committed
517
518
519
520
	if (tempdir == NULL) {
		g_printerr("Could not make capture directory %s\n", template);
		exit(EXIT_FAILURE);
	}
521

Martijn Braam's avatar
Martijn Braam committed
522
	strcpy(burst_dir, tempdir);
523

Martijn Braam's avatar
Martijn Braam committed
524
	captures_remaining = burst_length;
525
526
}

Martijn Braam's avatar
Martijn Braam committed
527
528
void
mp_process_pipeline_capture()
529
{
Martijn Braam's avatar
Martijn Braam committed
530
	is_capturing = true;
531

Martijn Braam's avatar
Martijn Braam committed
532
	mp_pipeline_invoke(pipeline, capture, NULL, 0);
533
534
535
536
537
}

static void
update_state(MPPipeline *pipeline, const struct mp_process_pipeline_state *state)
{
Martijn Braam's avatar
Martijn Braam committed
538
539
540
541
542
543
544
545
546
547
548
	camera = state->camera;
	mode = state->mode;

	burst_length = state->burst_length;

	preview_width = state->preview_width;
	preview_height = state->preview_height;

	// gain_is_manual = state->gain_is_manual;
	gain = state->gain;
	gain_max = state->gain_max;
549
	gain_min = state->gain_min;
Martijn Braam's avatar
Martijn Braam committed
550
551
552

	exposure_is_manual = state->exposure_is_manual;
	exposure = state->exposure;
553
	exposure_max = state->exposure_max;
554
	exposure_min = state->exposure_min;
Martijn Braam's avatar
Martijn Braam committed
555

556
	wb = state->wb;
557
	focus = state->focus;
558

Martijn Braam's avatar
Martijn Braam committed
559
560
561
	struct mp_main_state main_state = {
		.camera = camera,
		.mode = mode,
562
        .is_present = state->is_present,
Martijn Braam's avatar
Martijn Braam committed
563
564
565
		.gain_is_manual = state->gain_is_manual,
		.gain = gain,
		.gain_max = gain_max,
566
		.gain_min = gain_min,
Martijn Braam's avatar
Martijn Braam committed
567
568
		.exposure_is_manual = exposure_is_manual,
		.exposure = exposure,
569
		.exposure_max = exposure_max,
570
		.exposure_min = exposure_min,
Martijn Braam's avatar
Martijn Braam committed
571
572
		.has_auto_focus_continuous = state->has_auto_focus_continuous,
		.has_auto_focus_start = state->has_auto_focus_start,
573
		.focus = focus,
Martijn Braam's avatar
Martijn Braam committed
574
575
	};
	mp_main_update_state(&main_state);
576
577
}

Martijn Braam's avatar
Martijn Braam committed
578
579
void
mp_process_pipeline_update_state(const struct mp_process_pipeline_state *new_state)
580
{
Martijn Braam's avatar
Martijn Braam committed
581
582
	mp_pipeline_invoke(pipeline, (MPPipelineCallback)update_state, new_state,
			   sizeof(struct mp_process_pipeline_state));
583
}