Jump to content
  • Advertisement
Sign in to follow this  
Side Winder

Converting a .RAW image into RGB values

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Side Winder
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?
"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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by rozz666
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by Side Winder
Quote:
Original post by rozz666
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.


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 this post


Link to post
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 this post


Link to post
Share on other sites
Pointer to char type.

Quote:
Original post by alvaro
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.


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

Share this post


Link to post
Share on other sites
Little update: when I said I was trying to display it, I was wrong... I was trying to draw it on something else. I've just tried to draw the texture itself and it's come out... roughly to what it should be. It's very purple. Which it shouldn't be.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!