Sign in to follow this  
Side Winder

Converting a .RAW image into RGB values

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


Then try using unsigned char. Or use Paint Shop Pro or other program to open it and see whats inside.

Share this post


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


Then try using unsigned char. Or use Paint Shop Pro or other program to open it and see whats inside.


Clever :) Why didnt I think of that earlier... Haha. Oh well. And yeah, the unsigned char thing worked too and it's showing just about right now. Only thing is, when I try and display the texture, it displays rotated and oddly skewed. It's rotated 90 degrees to the right with the Y direction much longer than the X direction (ie its coming out at about 100x300 instead of 256x256)

EDIT: nevermind, wasn't resetting the array values when I was drawing it :) Now I've just got to figure out how to get it to draw on the damn walls... Thoughts anyone? :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this