.raw file data loader

Lo all, Anyone know of a place that has a .raw file loader or tutorial on loading .raw files for height maps?

-Mercalli


.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&lt;yres; y++)
{
    for (x=0; x&lt;xres; x++)
    {
        for (z=0; z&lt;bpp; z++)
            infile.get (imagedata[x][y][bpp]);
    }
}
infile.close();

}

hope this helps
-mike

(hmm… it messes my formatting all up… if you hit edit message it’s formatted though

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

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

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.

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.