• 9
• 9
• 10
• 10
• 9

# Converting a .RAW image into RGB values

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

## Recommended Posts

I have a 256x256 texture with a bit-depth of 3, but it's stored in a .RAW file. I've opened it with notepad and it's ~195,000 chars on one line (which confirms the 3x256x256) but every attempt I've had at converting it has failed. I have a struct that contains three integers (one for each R, G, B). Right now I'm doing:
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
Colour.r = int(imageData[value]);
Colour.g = int(imageData[value+1]);
Colour.b = int(imageData[value+2]);
value += 3;
}
}

imageData is a pointer array that contains all ~195,000 characters and value is obviously the specified point in that array. Am I even going about this the right way? Or is there something I'm missing here... Cheers.

##### Share on other sites
First of all, a bit depth of three means a grand total of eight colors. Perhaps you meant 24?

Second of all, .RAW is an extension which has been used to indicate several formats. The most popular one is the raw output of a digital camera, but at that resolution I don't think that's the one you've got here. Where did this file come from? What was used to generate it?

##### Share on other sites
Sorry. Yes. 24 bit colour. I meant the "3" to be one character for each R, G and B.

I don't know the answers to your other questions. All I know is that it's supposed to be a 256x256 texture of a wall. I was given this as a small task to do by a friend. Is there no way to do this without knowing how it was generated in the first place?

##### Share on other sites
Quote:
 Original post by Side WinderI don't know the answers to your other questions. All I know is that it's supposed to be a 256x256 texture of a wall. I was given this as a small task to do by a friend. Is there no way to do this without knowing how it was generated in the first place?
"How it was generated" isn't as important as "what the format is", though knowing one will give you the other. Why not just ask your friend where the file came from?

##### Share on other sites
Is your imageData an array of char? Then you have numbers from -128 to 127 which you convert to int. Try changinh imageData type to unsigned char.

##### Share on other sites
Quote:
 Original post by rozz666Is your imageData an array of char? Then you have numbers from -128 to 127 which you convert to int. Try changinh imageData type to unsigned char.

It's a pointer with a size set to (3*256*256) (using malloc()). And then I read in from the file. I've debugged it and it seems to work ok.

And I would ask my friend if he was available. Which he isn't, until tomorrow, and I want to get this out of the way so I can start on other things.

##### Share on other sites
Quote:
Original post by Side Winder
Quote:
 Original post by rozz666Is your imageData an array of char? Then you have numbers from -128 to 127 which you convert to int. Try changinh imageData type to unsigned char.

It's a pointer with a size set to (3*256*256) (using malloc()). And then I read in from the file. I've debugged it and it seems to work ok.

And I would ask my friend if he was available. Which he isn't, until tomorrow, and I want to get this out of the way so I can start on other things.

But pointer to what type?

##### Share on other sites
Is the size of the file exactly 196,608 bytes? If it is, then it is very likely that you are going the right way.

I would usually figure out if I am reading it correctly by trying to display it and seeing what seems wrong with it. If there is a header, the first few pixels won't make sense. If there is some sort of alignment at the end of each row, the image will be skewed. And so on.

##### Share on other sites
Pointer to char type.

Quote:
 Original post by alvaroIs the size of the file exactly 196,608 bytes? If it is, then it is very likely that you are going the right way.I would usually figure out if I am reading it correctly by trying to display it and seeing what seems wrong with it. If there is a header, the first few pixels won't make sense. If there is some sort of alignment at the end of each row, the image will be skewed. And so on.

Yeah, exactly 196,608 bytes. I've tried displaying it and it comes out really fuzzy... Sort of like if a small texture is stretched an incredibly large amount...