Skip to content

Instantly share code, notes, and snippets.

@pcercuei
Created December 22, 2023 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcercuei/7913083b03441c37fb2ea1e35f6acdf9 to your computer and use it in GitHub Desktop.
Save pcercuei/7913083b03441c37fb2ea1e35f6acdf9 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *in_f, *out_f;
unsigned int width = 160;
unsigned int height = 120;
unsigned int w, h, len = width * height * 3 / 2;
char out[len], in[len];
memset(out, 0xff, sizeof(out));
in_f = fopen("../frame01.raw", "r");
out_f = fopen("converted.raw", "w");
if (!in_f || !out_f) {
fprintf(stderr, "Cannot open files\n");
return -1;
}
fread(in, 1, len, in_f);
for (h = 0; h < height / 2; h++) {
/* Y data on even lines is stored sequentially */
memcpy(&out[h * 2 * width], &in[h * width * 3], width);
/* Odd lines contain YUYV */
for (w = 0; w < width; w++)
out[(h * 2 + 1) * width + w] = in[(h * 3 + 1) * width + w * 2];
for (w = 0; w < width; w++)
out[(height + h) * width + w] = in[(h * 3 + 1) * width + w * 2 + 1];
}
fwrite(out, 1, len, out_f);
fclose(in_f);
fclose(out_f);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment