Image file in C

A

Afifov

Hello, I am trying to know how I can generate an image file in C. I want to
draw a line on top of a picture (png or JPG), but I don't know where to
start. Any help?
 
P

Philip Paeps

Afifov said:
Hello, I am trying to know how I can generate an image file in C. I want to
draw a line on top of a picture (png or JPG), but I don't know where to
start. Any help?

This is not really a question about the C language itself and hence strictly
speaking off-topic in this group.

On most platforms, you can use the gd library to perform this sort of magic,
you can find all about it using google or on: <http://www.boutell.com/gd/>.

- Philip

--
Philip Paeps Please don't email any replies
(e-mail address removed) I follow the newsgroup.

BOFH Excuse #186:
permission denied
 
A

Afifov

I dont want to use any libraries. I know about the gd, and libpng. This is
not off topic because i am looking for the C struct that defines a png
file and how it is drawn. All i want to do is just take an image and draw
a line over it. But i want to know the struct of the matrix.
Anyway, your reply was noted. Thx
 
A

ashok.s.das

Hi said:
Hello, I am trying to know how I can generate an image file in C. I want to
draw a line on top of a picture (png or JPG), but I don't know where to
start. Any help?

Have you tried www.wotsit.org for file formats??? that is really nice.
Check it and write your own algo ...

Ashok.
 
L

Lawrence Kirby

I dont want to use any libraries. I know about the gd, and libpng. This is
not off topic because i am looking for the C struct that defines a png
file and how it is drawn.

The problem is that the C language doesn't define anything related to png
files. Also there is unlikely to be a single struct definition that
relates to a png file because the layout of a structure and the
representation of individual fields can cary from one C implementation to
another.
All i want to do is just take an image and draw
a line over it. But i want to know the struct of the matrix.
Anyway, your reply was noted. Thx

You will probably need code that reads in a png file and converts it to an
appropriate internal representation, and when you've finished code that
reencodes your internal representation and writes it to a file. In the
middle you will need code to draw a line. A good place to discuss all of
this might be comp.graphics.algorithms.

Lawrence
 
K

Kenneth Brody

Afifov said:
I dont want to use any libraries. I know about the gd, and libpng. This is
not off topic because i am looking for the C struct that defines a png
file

Check www.wotsit.org, which probably has descriptions of the png file
format.
and how it is drawn.

That is system-dependent, and is definitely OT for c.l.c.
All i want to do is just take an image and draw
a line over it.

You can't. At least not without using some non-standard libraries, or
extensions to the C language.
But i want to know the struct of the matrix.
www.wotsit.org

Anyway, your reply was noted. Thx


--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
R

Randy Howard

Afifov wrote
(in article
<[email protected].
com>):
I dont want to use any libraries. I know about the gd, and libpng.

Then you will be rolling it from scratch I suppose.
This is not off topic because i am looking for the C struct that defines a png
file and how it is drawn.

It is off topic. analogy...

Q: "I would like to know how to implement a neural network in C
that implements backprop. I know this is on topic here
since it will be written in C."
A: "There is no coverage for neural networks or backprop in the
C Standard. You would be much better off asking somewhere
that covers such things. If you have an implementation
partly written and can't get it to compile or work properly
in C, post a small snippet that demonstrates the problem
and post it here and you will get lots of help."
All i want to do is just take an image and draw
a line over it. But i want to know the struct of the matrix.

So you better go find a document that describes the .png file
format in detail and read and understand it. Or, you could like
at source for another implementation and figure it out that way.
I'm sure there are other newsgroups where this sort of thing
would be on-topic, and you would get lets of authoritative
answers. This isn't one of them.
 
A

Alexei A. Frounze

Afifov said:
Hello, I am trying to know how I can generate an image file in C. I want to
draw a line on top of a picture (png or JPG), but I don't know where to
start. Any help?

Look for libjpeg, libpng.

Alex
 
S

Simon Biber

Afifov said:
Hello, I am trying to know how I can generate an image file in C. I want to
draw a line on top of a picture (png or JPG), but I don't know where to
start. Any help?

PNG and JPG are not simple formats. There is a LOT of tricky code
involved just to unpack the pixels. This can be done entirely in ANSI C,
but it's a lot of work.

You are much better off using an existing library to read it and convert
it into a simple array in memory. The libpng and libjpeg libraries are
very portable and widely available.

Then, you can use whatever algorithm you want to draw a line onto the
bit-map. Bresenham's line algorithm comes to mind, but that's off-topic
here. Try searching Google for sample code, and if you have questions,
try asking in comp.graphics.algorithms.

Another option is to use a utility like png2pnm or jpeg2pnm to change it
into a much simpler file format that you can more-or-less read straight
into an array.
 
M

Malcolm

Afifov said:
I dont want to use any libraries. I know about the gd, and libpng. This is
not off topic because i am looking for the C struct that defines a png
file and how it is drawn. All i want to do is just take an image and draw
a line over it. But i want to know the struct of the matrix.
Anyway, your reply was noted. Thx
C structs do not specify a given layout in memory. Trying to mirror a binary
file format with a struct is very risky, and will break if you port to
another compiler.

Handle your images internally using a structure something like this

typedef struct
{
int width;
int height;
unsigned char *pixels;
} IMAGE;

Then write code to load and save IMAGEs in as many file formats as you want
to support. Some, like JPEG, are so complex that realistically you will have
to write a wrapper to a third party library. Others are just a matter of
writing out a width and height parameter in the right endianness, and then
getting the rgb channels the right way round.
 
J

Jasen Betts

The problem is that the C language doesn't define anything related to png
files. Also there is unlikely to be a single struct definition that
relates to a png file because the layout of a structure and the
representation of individual fields can cary from one C implementation to
another.

most file structures can be written in a format that is C-portable atleast
on machines that use 8-bit chars. such structs aren't handy to use, (all
integers are broken into 8 bit chunks... etc), but they are portable.


Bye.
Jasen
 
C

Chris Croughton

most file structures can be written in a format that is C-portable atleast
on machines that use 8-bit chars. such structs aren't handy to use, (all
integers are broken into 8 bit chunks... etc), but they are portable.

Well, yes, everything can be read into arrays of unsigned char and then
decoded from there. Indeed, that's how I do it in several pieces of
code. But you can't do it as a "C struct" (unless that struct is only
an array of unsigned chars) portably (many iuseful file formats
compress to a bitstream, so it won't map directly onto a struct at all
in any sensible way).

Chris C
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,915
Members
47,456
Latest member
JavierWalp

Latest Threads

Top