• 13
• 18
• 19
• 27
• 10

# raw files, channels and heightmaps

This topic is 3893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everybody, I want to load a .raw file as a picture in my aplicaction. My function works fine with a 3-channel raw image. The problem is that one of the images i want to load is a 1024x1024 1-channel heightmap, and if i use the same function that i have to load raw files, i only get my picture smaller and repeated 3 times instead of the original one. Could someone please give me a clua about what i have to do with my channels problem ? Any help would be very appreciated Thank you very much

##### Share on other sites
well, what's that loading function? we can only guess if we don't know ;-)

you might also consider just using a "proper" image format instead of raw, like .bmp
there are many free examples of implementations of loaders for such formats out there, often you can just use the code without having to modify it at all.

this has the advantage that you can check after loading whether the image has the correct format and resolution, to prevent surprises ;-)

##### Share on other sites
It's also worth noting that if you mean RAW as in the unprocessed data straight from a digital camera's sensor, then not all the formats are the same (i.e. Nikon's NEF isn't the same as whatever Canon uses, etc.)

##### Share on other sites
Sorry , i forgot to include the function i use, i got it from a tutorial, so it's not very original:

void cTHTViewer::loadRawFile( const char * filename, int width, int height )  GLuint texture;  FILE * file;  BYTE * data;  // open texture data  file = fopen( filename, "rb" );  if ( file == NULL ) printf("Can't find the height map!");  data = malloc( width * height * 3 );  // read texture data  fread( data, width * height * 3, 1, file );  fclose( file );}

Quote:
 you might also consider just using a "proper" image format instead of raw, like .bmpthere are many free examples of implementations of loaders for such formats out there, often you can just use the code without having to modify it at all.

Believe me, i'd love to use a "proper" format image, but i need the raw format because once loaded the image in 2D, i need to generate a 3d terrain with it, and i need a .raw file to do that

Quote:
 It's also worth noting that if you mean RAW as in the unprocessed data straight from a digital camera's sensor, then not all the formats are the same (i.e. Nikon's NEF isn't the same as whatever Canon uses, etc.)

The image doesn't come from any kind of camera, it's only a generated .raw file repsesenting a heightmap, and i can assume is correctly created, because the terrain generates properly from it.

Thanks both for your help anyway !

##### Share on other sites

I was assuming that he meant header-less files, when he said "raw files".
just the pure data, without any file format info in the file.

you can create such files ie. in paintshop pro. if you have an image, like 128x128x24bpp, and store it as ".raw", the resulting file contains nothing more than just a sequence of r,g,b bytes of row after row of that image.

##### Share on other sites

void cTHTViewer::loadRawFile(const char *filename, int width, int height, int channelSize){  GLuint texture;  FILE * file;  BYTE * data;  // open texture data  file = fopen( filename, "rb" );  if ( file == NULL ) printf("Can't find the height map!");  data = malloc( width * height * channelSize );  // read texture data  fread( data, width * height * channelSize, 1, file );  fclose( file );}

##### Share on other sites
Quote:
Original post by DaniCat
Sorry , i forgot to include the function i use, i got it from a tutorial, so it's not very original:

*** Source Snippet Removed ***

Quote:
 you might also consider just using a "proper" image format instead of raw, like .bmpthere are many free examples of implementations of loaders for such formats out there, often you can just use the code without having to modify it at all.

Believe me, i'd love to use a "proper" format image, but i need the raw format because once loaded the image in 2D, i need to generate a 3d terrain with it, and i need a .raw file to do that

Quote:
 It's also worth noting that if you mean RAW as in the unprocessed data straight from a digital camera's sensor, then not all the formats are the same (i.e. Nikon's NEF isn't the same as whatever Canon uses, etc.)

The image doesn't come from any kind of camera, it's only a generated .raw file repsesenting a heightmap, and i can assume is correctly created, because the terrain generates properly from it.

Thanks both for your help anyway !

ah, ok, looks like you always multiply the size of the image, and the index when accessing the data by 3, which is only correct if you hav a raw file that has three channels of each 8 bits.
If you have only one channel of 8 bits, you should not do this multiplying.

But still, you do not nee raw files, really.
If you find some free, say, .bmp reader class source code on the net, and this class is not crap, it will provide a function for you to access the bare pixels or color component values of the image.
So, this is more save than raw files, will be more convenient *once it's working* ;-) and mor flexible.

##### Share on other sites
Just in case you chose to use a "proper file format",
and there can't be found image reader classes that support extracting the color components of a pixel (which might be stored just in a 32bit int), we can show you how to do this manually, no problem :-)
But I think there should be stuff around that already supports this.

Maybe somebody can even recommend a free, not too complicated to use image loading library?
(I don't know one ATM, sorry)

##### Share on other sites
just found this (bu I dont know how good/reliable this is)

click