|
Author Topic:   What's up with 26 for color??
binaryz
Member
posted January 10, 2001 06:05 PM            
Hi guys,
Here's a really strange problem. Why is it that if I read any kind of bitmap (I've tried RAW & BMP) as soon as it hits a byte that contains 26 for either R, G, or B, or even all 3, it stops reading? I know something in fread() fails, because I get a 0 back for amount read. But all the other colors work except 26?? This doesn't make much sense.
This is the code sample I used:

#define MAP_SIZE 5
int main()
{
FILE* filePtr;
unsigned char* HeightFields;

filePtr = fopen("map.raw", "r");

HeightFields = new unsigned char[MAP_SIZE*MAP_SIZE];

memset(HeightFields, 0, (MAP_SIZE*MAP_SIZE));

fread(HeightFields, (MAP_SIZE*MAP_SIZE), 1, filePtr);


fclose(filePtr);
delete [] HeightFields;

return 0;
}

Any ideas?? Thanks again.

IP:

Lithium
Member
posted January 10, 2001 10:00 PM         
Can't say for sure, but try using a read flag and a binary flag for fopen:

filePtr = fopen("map.raw", "rb");

I don't know what r by itself defaults to. You don't want text.

Basically, test all return values from function calls and test all
pointers for NULL. The code you listed doesn't even test if FilePtr
or HeightFields is valid or not before you use them.

And a .RAW file is not the same as a .BMP file. .RAW files are
just single byte values (0-255). If your heightmap is 5x5, then
your raw file size better be exactly 25 bytes. You can use programs
like Photoshop or Paint Shop Pro to save and edit them.

Also, if you don't have a hex editor, then I recommend you get one.
There are hundreds of free ones on the net.

IP:

binaryz
Member
posted January 11, 2001 07:48 AM            
Lith,
First off a big THANK YOU!
The problem was exactly what you said. I was reading the file with the "r" switch only. As soon as I switched to "rb" 26 values came in correctly.

I know I wasn't doing error checking, but I just whipped that up quick to test things with. My original function did more error checking.

At first I had BMP instead of RAW with the header structure and everything, but I was getting sick of the padding it did when a file wasn't 2^n size, so I switched to RAW.

Thanks again!!

IP: