This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

$hexhex to RGB dump code

$hexhex to RGB dump code
by on (#93374)
Some of you might find this useful. Read the example C code in a libpng source tarball to convert to png. You can also do things like gif2ascii etc.

--------- start of C file hex2image.c -----------

/* compile with 'gcc -c hex2image.c -o hex2image.o; gcc -o hex2image hex2image.o' */

#include <stdio.h>

int main(int argc, char *argv[], char **envp)
{

if (argc < 2) {/* This returns if no argument is provided */
fprintf (stderr, "Usage : hex2image <filename>\n");
return -1;
}

FILE *fp = fopen (argv[1], "r");
unsigned int i = 0;
int n;
for (; (n = fscanf(fp, "$&x", &i)) != EOF;) {
if (n != 0) {
unsigned long int ui = (unsigned long int) i;
fprintf(stdout, "%lu", ui); /* prints RGB value; */
}
}

return 0;

}

---------end of C file hex2image.c------------------