Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

c - What is the simplest RGB image format?

I am working in C on a physics experiment, Young's interference experiment and i made a program who prints to file a huge bunch of pixels :

for (i=0; i < width*width; i++)
{
    fwrite(hue(raster_matrix[i]), 1, 3, file);
}

Where hue, when given a value [0..255], gives back a char * with 3 bytes, R,G,B.

I would like to put a minimal header in my image file in order to make this raw file a valid image file.

More concise : Switching from :

offset
0000 : height * width : data } my data, 24bit RGB pixels

to

offset
0000 : dword : magic        
     : /* ?? */              
0012 : dword : height         } Header <--> common image file
0016 : dword : width         /
     : /* ?? */             /
0040 : height * width : data  } my data, 24bit RGB pixels

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You probably want to use the PPM format which is what you're looking for: a minimal header followed by raw RGB.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...