PDA

View Full Version : .raw file data loader



Mercalli
12-14-2000, 07:44 AM
Lo all, Anyone know of a place that has a .raw file loader or tutorial on loading .raw files for height maps?

-Mercalli

Thr33d
12-15-2000, 03:14 PM
http://www.opengl.org/discussion_boards/ubb/smile.gif
.raw files are only image data, you must know the bits per pixel (color depth) and resolution to load the image correctly.

if you're using c though, it's very simple -
example for loading 256x256 res raw in 24 bit color :

#include <fstream.h>

main(int)
{
const int xres = 256;
const int yres = 256;
const int bpp = 3;
int x, y, z;
unsigned char imagedata[xres][yres][bpp];

ifstream infile;
infile.open ("image.raw");
for (y=0; y<yres; y++)
{
for (x=0; x<xres; x++)
{
for (z=0; z<bpp; z++)
infile.get (imagedata[x][y][bpp]);
}
}
infile.close();
}

hope this helps http://www.opengl.org/discussion_boards/ubb/smile.gif
-mike

(hmm... it messes my formatting all up... if you hit edit message it's formatted though http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Thr33d (edited 12-15-2000).]

Thr33d
12-15-2000, 03:25 PM
Btw raw files come in several formats;
if it's a greyscale image it's just in the file as a stream of left to right, top to bottom (unless it's flipped bottom up)

in rgb the rgb can be in the format
rgb or bgr, per pixel or can be stored as the entire images' red, green then blue, or blue, green, red...

-mike

12-21-2000, 10:20 AM
In c you can use the fread command to read in the entire data set without the for loops. Actually it will work with c++ too, but you would have to include stdlib. I'm sure there is a way to do it with streams though.

Deiussum
12-21-2000, 11:59 AM
Originally posted by Nick **&&*$*%^:
In c you can use the fread command to read in the entire data set without the for loops. Actually it will work with c++ too, but you would have to include stdlib. I'm sure there is a way to do it with streams though.

From MSDN:

istream::read
istream& read( char* pch, int nCount );

istream& read( unsigned char* puch, int nCount );

istream& read( signed char* psch, int nCount );

Parameters

pch, puch, psch

A pointer to a character array.

nCount

The maximum number of characters to read.

Remarks

Extracts bytes from the stream until the limit nCount is reached or until the end of file is reached. The read function is useful for binary stream input.