G
giovanniparodi79
Hello everybody is there some utility to convert a raw image in an
header file?
Thanks everybody
Gio
header file?
Thanks everybody
Gio
Hello everybody is there some utility to convert a raw image in an
header file?
Sorry I would like to take a raw image file and convert it to an
header file, generating an array that contains in each cell the gray
level that corresponds to the pixel.
It will be useful in order to avoid read from hd that on my target
platform (an embedded system) can become very slow.
Hope this is not ot.
Sorry I would like to take a raw image file and convert it to an header
file, generating an array that contains in each cell the gray level
that corresponds to the pixel.
It will be useful in order to avoid read from hd that on my target
platform (an embedded system) can become very slow.
Hope this is not ot.
Sorry I would like to take a raw image file and convert it to an header
file, generating an array that contains in each cell the gray level
that corresponds to the pixel.
Hello everybody is there some utility to convert a raw image in an
header file?
Thanks everybody
Gio
Sorry I would like to take a raw image file and convert it to an header
file, generating an array that contains in each cell the gray level
that corresponds to the pixel.
It will be useful in order to avoid read from hd that on my target
platform (an embedded system) can become very slow.
Hope this is not ot.
Not tested, no error checking, here is a way to do it:
usage: first arg is name of the image file, second is name of header file
#include <stdio.h>
int main(int argc,char *argv[])
{
FILE *infile = fopen(argv[1],"rb"); // open image
FILE *outfile = fopen(argv[2],"w"); // open header
int c,col=0;
fprintf(outfile,"unsigned char myimage[] = {\n");
while ((c=fgetc(infile)) != EOF) {
fprintf(outfile,"0x%02x,",c);
col += 5;
if (col > 70) {
fprintf(outfile,"\n");
col=0;
}
}
fprintf(outfile,"\n};\n");
.... snip ...Peter said:Groovy hepcat (e-mail address removed) wrote:
.... snip ...
You write one. Yes, that's right. You write your own utility. It's
really quite trivial. But if you feel that such a beastie is beyond
your skills at this time, you can use the following program, which I
wrote and have used. I call it c-embed. (I realise someone already
posted a program like this, but it was untested and not as good. If
you want something that has at least been tried out, use my program.)
Groovy hepcat jacob navia was jivin' on Fri, 17 Mar 2006 19:28:08
+0100 in comp.lang.c.
Not good taking for granted that there will be 2 command line
arguments. Also not good taking for granted that the fopen() calls
will succeed. They may not.
jacob navia said:Peter Shaggy Haywood a écrit :
Can you read?
I wrote that there is no error checking!
It is just an outline, not production code
Groovy hepcat (e-mail address removed) was jivin' on 17 Mar 2006
08:18:58 -0800 in comp.lang.c.
Re: Raw image in header file's a cool scene! Dig it!
Such things don't belong in headers. They belong in the main part of
a translation unit (ie., the .c file). Headers should contain external
declarations of functions and variables, macro definitions and such.
But, to your question, how do you store an image (or other) file in
a C source file? It's really quite easy, believe it or not. All you
have to do is read each byte of the file and use its value as an
initialiser for an array. "Tedious, time consuming and error prone," I
hear you say? Au contraire. It's extremely easy and efficient, if you
let the computer do it. Now I hear you ask, "But how do I do that?"
You use a simple utility that reads a file and outputs C source code
containing an array initialised with the contents of the file. Your
next question: "Where do I get a utility like that?"
You write one. Yes, that's right. You write your own utility. It's
really quite trivial.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.