how to load a raw file

Started by
6 comments, last by the origin 22 years, 1 month ago
how can i load a raw file (not nehes code) and the result should be an array world [256][256] ps how can i create a rawfile?
Advertisement
A raw file is the actual color data for the bitmap. Open the file, read it as binary, parse out the bytes accordingly - RGBRGBRGBRGB...
Conversely, open a file for binary writing, write out the color data to a binary file RGBRGBRGBRGB... or use your favorite graphics editor, Paint Shop Pro handles them on Windows, Gimp likely does so on Linux.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
may somebody give/post a simple code or function for interpreting raw files
It''s not that simple if you don''t know the size of the image and the way the colors are laid out ahead of time. For example, when I open a raw file in psp it greets me with a dialog box asking me for parameters:
image size in pixels: width, height [edits]
color channels: grayscale, rgb, cmy, cmyk [radios]
file structure:
header size (in bytes) [edit box]
planar (rrr,ggg, bbb ... [radio 1]
interleaved (rgb,rgb,rgb...[radio 2]
order rgb [radio 1]
order bgr [radio 2]
flipped (bottom up) [check]

Sort of illustrates why graphic file headers were invented.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Note that a raw file can contain anything.. it means a file without any header information (unlike bmp and all other formats.. so it can store RGB values or height map, or anything else.. you can think it as a bag of binary data.. so you have to know the size of the data (width, height) and format of the data a priori.. here is a code snipplet to load a height map from a raw file..

  // you can pass these as parameters as well as filename (when it is a function)int width = 256;int height = 256;int worldsize = 256;// I gues you are trying to load a height map with integer valuesint ** world = new int* world[worldsize];for (int i = 0; i < worldsize; ++i)   world[i] = new int[worldsize];FILE*fp = fopen("yourfile.raw", "rb");for(int x = 0; x < worldsize; ++x){   for(int y = 0; y < worldsize; ++y)   {        fread(world[x][y], sizeof(int), 1, fp);   }}fclose(fp);  


note that if the file doesn't contain the data in the correct order that you requested, you crash! what i try to say is that "raw" is not a file format like bmp, jpg, etc.. you have to know what's inside exactly to be able to read them.. i guess this helps..

Edited by - mentat on February 20, 2002 7:53:13 AM
-----------my quote is under construction
hi can i load frim bmp s too ??

if yes why raw?


and how can i create a raw file and how can i read one with a program (iphoto+)



Edited by - the origin on February 20, 2002 9:10:09 AM
for loading from bmp, you need to read the info about the file from the header by messing with lots of structures.. as far as I remember there is an example in MSDN. I could post as well but it is quite long..

and that''s the main reason for using raw.. raw is simple.. but if you are writing for public, supporting bmp is a better idea.. it is not that difficult (as compared to jpg).. no maths involved.. read the info, load the data..

you can create a raw file from almost all paint programs (at least photoshop and PSPro). But don''t forget to note down the width, height and colour depth info somewhere, because those programs will ask for it (photoshop makes a guess which is generally correct)..

cheers..

-----------
my quote is under construction
-----------my quote is under construction
ok want to go another way

  void LoadRawFile(LPSTR strName, int nSize, BYTE *pHeightMap){	FILE *pFile = NULL;	pFile = fopen( strName, "rb" );	fread( pHeightMap, 1, nSize, pFile );	int result = ferror( pFile );	fclose(pFile);}int InitGL(GLvoid)										{	....	...	LoadRawFile("Data/Terrain.raw", MAP_SIZE * MAP_SIZE, g_HeightMap);	....									}  





what must i do to get the raw datas in the array

world[256][256]


thanks

This topic is closed to new replies.

Advertisement