--- osmo-fl2k/src/fl2k_file.c.orig	2020-08-31 15:24:35.530961212 +0200
+++ osmo-fl2k/src/fl2k_file.c	2020-09-02 11:24:44.520488872 +0200
@@ -43,8 +43,15 @@
 
 static volatile int do_exit = 0;
 static volatile int repeat = 1;
+int tricolor = 0;
 FILE *file;
 char *txbuf = NULL;
+// If tricolor is set, txbuf holds interleaved RGB frames not
+// just a single frame, and txbuf_r, txbuf_b, and txbuf_g are
+// allocated for the separated frames.
+char *txbuf_r = NULL;
+char *txbuf_b = NULL;
+char *txbuf_g = NULL;
 
 void usage(void)
 {
@@ -54,6 +61,7 @@
 		"\t[-d device_index (default: 0)]\n"
 		"\t[-r repeat file (default: 1)]\n"
 		"\t[-s samplerate (default: 100 MS/s)]\n"
+		"\t[-3] treat input as 3 interleaved channels\n"
 		"\tfilename (use '-' to read from stdin)\n\n"
 	);
 	exit(1);
@@ -80,9 +88,22 @@
 }
 #endif
 
+void deinterleave(void)
+{
+	char *ptr = txbuf;
+	for (int i = 0; i < FL2K_BUF_LEN; i++) {
+		txbuf_r[i] = *ptr++;
+		txbuf_g[i] = *ptr++;
+		txbuf_b[i] = *ptr++;
+	}
+	if (ptr != txbuf + FL2K_BUF_LEN * 3)
+		abort();
+}
+
 void fl2k_callback(fl2k_data_info_t *data_info)
 {
-	int r, left = FL2K_BUF_LEN;
+  	int buf_size = FL2K_BUF_LEN * (tricolor ? 3 : 1);
+	int r, left = buf_size;
 	static uint32_t repeat_cnt = 0;
 
 	if (data_info->device_error) {
@@ -92,10 +113,16 @@
 	}
 
 	data_info->sampletype_signed = 1;
-	data_info->r_buf = txbuf;
+	if (!tricolor)
+		data_info->r_buf = txbuf;
+	else {
+	  	data_info->r_buf = txbuf_r;
+	  	data_info->g_buf = txbuf_g;
+	  	data_info->b_buf = txbuf_b;
+	}
 
 	while (!do_exit && (left > 0)) {
-		r = fread(txbuf + (FL2K_BUF_LEN - left), 1, left, file);
+		r = fread(txbuf + (buf_size - left), 1, left, file);
 
 		if (ferror(file))
 			fprintf(stderr, "File Error\n");
@@ -114,6 +141,8 @@
 		if (r > 0)
 			left -= r;
 	}
+	if (tricolor)
+		deinterleave();
 }
 
 int main(int argc, char **argv)
@@ -128,7 +157,7 @@
 	void *status;
 	char *filename = NULL;
 
-	while ((opt = getopt(argc, argv, "d:r:s:")) != -1) {
+	while ((opt = getopt(argc, argv, "d:r:s:3")) != -1) {
 		switch (opt) {
 		case 'd':
 			dev_index = (uint32_t)atoi(optarg);
@@ -139,6 +168,9 @@
 		case 's':
 			samp_rate = (uint32_t)atof(optarg);
 			break;
+		case '3':
+			tricolor = 1;
+			break;
 		default:
 			usage();
 			break;
@@ -166,10 +198,21 @@
 		}
 	}
 
-	txbuf = malloc(FL2K_BUF_LEN);
-	if (!txbuf) {
-		fprintf(stderr, "malloc error!\n");
-		goto out;
+	if (!tricolor) {
+		txbuf = malloc(FL2K_BUF_LEN);
+		if (!txbuf) {
+			fprintf(stderr, "malloc error!\n");
+			goto out;
+		}
+	} else {
+		txbuf = malloc(FL2K_BUF_LEN * 3);
+		txbuf_r = malloc(FL2K_BUF_LEN);
+		txbuf_g = malloc(FL2K_BUF_LEN);
+		txbuf_b = malloc(FL2K_BUF_LEN);
+		if (!txbuf || !txbuf_r || !txbuf_g || !txbuf_b) {
+			fprintf(stderr, "malloc error!\n");
+			goto out;
+		}
 	}
 
 	fl2k_open(&dev, (uint32_t)dev_index);
@@ -207,6 +250,12 @@
 out:
 	if (txbuf)
 		free(txbuf);
+	if (txbuf_r)
+		free(txbuf_r);
+	if (txbuf_g)
+		free(txbuf_g);
+	if (txbuf_b)
+		free(txbuf_b);
 
 	if (file && (file != stdin))
 		fclose(file);
