nesdev.com
http://forums.nesdev.com/

$hexhex to RGB dump code
http://forums.nesdev.com/viewtopic.php?f=21&t=8871
Page 1 of 1

Author:  erana [ Sat May 05, 2012 10:52 am ]
Post subject:  $hexhex to RGB dump code

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.

---------8<---- start of C file hex2image.c -------->8---

/* 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;

}

-----8<--------end of C file hex2image.c----------->8-------

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/