Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: .raw file data loader

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2000
    Posts
    6

    .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

  2. #2
    Intern Newbie
    Join Date
    Apr 2000
    Posts
    44

    Re: .raw file data loader


    .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
    -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).]

  3. #3
    Intern Newbie
    Join Date
    Apr 2000
    Posts
    44

    Re: .raw file data loader

    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

  4. #4
    Guest

    Re: .raw file data loader

    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.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: .raw file data loader

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •