It is currently Tue Oct 17, 2017 8:09 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: $hexhex to RGB dump code
PostPosted: Sat May 05, 2012 10:52 am 
Offline
User avatar

Joined: Thu Jan 27, 2011 3:08 am
Posts: 33
Location: Europe
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-------


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group