summaryrefslogtreecommitdiff
path: root/src/util.c
blob: 4e496a479ee8f2bbc78dfcc1baf2b518d35bf71c (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
#include <stdio.h>

#include "video_decode.h"
#include "util.h"

void
pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename)
{
	FILE *f;
	int i;

	f = fopen(filename, "w");
	fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);
	for(i=0; i < ysize; i++)
		fwrite(buf + i * wrap, 1, xsize, f);
	fclose(f);
}

void
frame_mix_pgm_save(struct video_frame *frame_a, struct video_frame *frame_b,
	char *filename)
{
        uint8_t *row_a = frame_a->data, *col_a = NULL;
        uint8_t *row_b = frame_b->data, *col_b = NULL;

        for (int y = 0; y < frame_a->height; ++y) {
                col_a = row_a;
                col_b = row_b;
                for (int x = 0; x < frame_a->width; ++x) {
			if (x > frame_a->width / 2)
	                        *col_a = *col_b;
                        col_a++;
                        col_b++;
                }
                row_a += frame_a->stride;
                row_b += frame_b->stride;
        }

	FILE *f = fopen(filename, "w");
	fprintf(f, "P5\n%d %d\n%d\n", frame_a->width, frame_a->height, 255);
	for (int i = 0; i < frame_a->height; i++)
		fwrite(frame_a->data+i*frame_a->stride, 1, frame_a->width, f);
	fclose(f);
}