On Friday 17 March 2006 15:28, giovanniparodi7 9@yahoo.it opined (in
<1142609304.893 761.195710@v46g 2000cwv.googleg roups.com>):[color=blue]
> Hello everybody is there some utility to convert a raw image in an
> header file?[/color]
I don't think I understand exactly what you want. You may want to
clarify. However, I have a sneaky suspicion that what you're asking is
off-topic (unless you're asking for a portable way to implement this in
a C header file, in which case you still want to be more specific).
--
BR, Vladimir
He walks as if balancing the family tree on his nose.
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.
giovanniparodi7 9@yahoo.it writes:
[color=blue]
> 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.[/color]
On Friday 17 March 2006 16:18, giovanniparodi7 9@yahoo.it opined (in
<1142612338.416 396.143550@i39g 2000cwa.googleg roups.com>):
[color=blue]
> 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.[/color]
Well, I don't know of any such utility, but I believe that, quite
recently, it was mentioned in this group that there exists image format
that is already close to what you require. Search the group with Google
and you may strike lucky. (BTW, it is OT).
--
BR, Vladimir
WHERE CAN THE MATTER BE
Oh, dear, where can the matter be
When it's converted to energy?
There is a slight loss of parity.
Johnny's so long at the fair.
giovanniparodi7 9@yahoo.it said:
[color=blue]
> 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.[/color]
<OT>
Have a look at the xpm file format.
</OT>
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
giovanniparodi7 9@yahoo.it a écrit :[color=blue]
> Hello everybody is there some utility to convert a raw image in an
> header file?
> Thanks everybody
> Gio
>[/color]
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;
Groovy hepcat giovanniparodi7 9@yahoo.it 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!
[color=blue]
>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.[/color]
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. 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.)
void instruct(void)
{
const char *const helptext =
"c-embed\n\n"
"Use:\n"
"c-embed <output_prefi x> <file_1> [<file_2> [<file_3>"
" [...<file_n>]]] > <output_file>\n \n"
"c-embed takes one or more filenames on the command line,\n"
"reads in those files, converts them to C (or C++) arrays\n"
"then outputs each array to <output_prefix> .c and puts extern\n"
"declaratio ns of these arrays in <output_prefix> .h, thus enabling"
" you\n"
"to embed files within programs written in C (or C++) as"
" arrays.\n"
"<output_prefix > may be a dash, in which case arrays will be"
" output\n"
"to standard output and no header will be created.\n"
"The arrays will be called embed_N, where N is the number of"
" the\n"
"file. For example, the first file will be embedded as embed_1,"
" the\n"
"second as embed_2, the third as embed_3, etc.\n";
Using this program is quite simple. Suppose you want to embed a file
named image.jpg in a C file named image.c. You do this:
c-embed image image.jpg
This creates image.c and puts an array of const unsigned char called
embed_1 in it, initialised with the contents of image.jpg. It also
creates image.h, and puts an extern declaration of the array in there.
You can embed any file this way, even multiple files.
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Groovy hepcat jacob navia was jivin' on Fri, 17 Mar 2006 19:28:08
+0100 in comp.lang.c.
Re: Raw image in header file's a cool scene! Dig it!
[color=blue]
>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[/color]
[color=blue]
>#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[/color]
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.
[color=blue]
> int c,col=0;
>
> fprintf(outfile ,"unsigned char myimage[] = {\n");
> while ((c=fgetc(infil e)) != EOF) {
> fprintf(outfile ,"0x%02x,",c );
> col += 5;
> if (col > 70) {[/color]
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Peter Shaggy Haywood wrote:[color=blue]
> Groovy hepcat giovanniparodi7 9@yahoo.it wrote:
>[/color]
.... snip ...[color=blue]
>
> 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.)
>[/color]
.... snip ...
FYI, I get the following errors:
c-embed.c: In function `instruct':
c-embed.c:56: warning: string length `702' is greater than the
length `509' ISO C89 compilers are required to support
c-embed.c: In function `main':
c-embed.c:99: warning: comparison between signed and unsigned
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
Peter Shaggy Haywood a écrit :[color=blue]
> Groovy hepcat jacob navia was jivin' on Fri, 17 Mar 2006 19:28:08
> +0100 in comp.lang.c.[color=green]
>>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[/color]
>
> 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.
>
>[/color]
jacob navia <jacob@jacob.re mcomp.fr> writes:
[color=blue]
> Peter Shaggy Haywood a écrit :[color=green]
> > Groovy hepcat jacob navia was jivin' on Fri, 17 Mar 2006 19:28:08
> > +0100 in comp.lang.c.[color=darkred]
> >>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[/color]
> > 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.
> >[/color]
>
> Can you read?
>
> I wrote that there is no error checking!
>
> It is just an outline, not production code[/color]
And so somehow that means we shouldn't post improvements upon finding flaws?
phaywood@alphal ink.com.au.NO.S PAM (Peter "Shaggy" Haywood) writes:
[color=blue]
> Groovy hepcat giovanniparodi7 9@yahoo.it 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!
>[color=green]
> >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.[/color]
>
> 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.[/color]
Or, you could use a file format that, itself, is C code. X pixel map
(.xpm) files come to mind. You could use GIMP to output these.
Of course, this is an indexed color format, and would still require an
interpreter of some sort to convert it to a more native format
(assuming you don't use Xlib). You can get a library at http://koala.ilog.fr/lehors/xpm.html . Note that there was a security
vulnerability in this library at some point, and I do not know whether
it had been addressed. You'll have to download it and check the
release notes (or better, the source code).
A more readable, C-code image format, you'd be quite
hard-pressed to find. Here is the complete contents of an .xpm file,
which consists of a white box with an X in it: one stroke black and
the other blue.
Comment