RAW Image data reading ERROR

J

Joan

I read RAW image data from a binary file stream. I have to read just
bytes one by one and put them into a matrix of structs of unsigned
chars.
I have to use unsigned chars because their rangs go from 0 to 255. If
I use chars then a value of 129 will be -128 :(

The problem:

infile.get(ImageDATA[j].R);

Reads only chars... Ok, it works fine with chars, but when I access to
the matrix the value is read like char... but i want rang from 0 -
255...

Help meeeeee

The source is something like that:

#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>

using namespace std;

struct structRGB {
unsigned char R;
unsigned char G;
unsigned char B;
};

structRGB ImageDATA[576][720];



int main(int argc, char *argv[]) {

int i,j;
ifstream infile;
ofstream outfile;



infile.open("image.raw", ios::binary);
for(i=0; i<576; i++) {
for(j=0; j<720; j++) {
infile.get(ImageDATA[j].R);
infile.get(ImageDATA[j].G);
infile.get(ImageDATA[j].B);
}
}
infile.close();


outfile.open("copy.raw", ios::binary);
for(i=0; i<576; i++) {
for(j=0; j<720; j++) {
outfile.put(ImageDATA[j].R);
outfile.put(ImageDATA[j].G);
outfile.put(ImageDATA[j].B);
}
}

outfile.close();


system("PAUSE");
return 0;
}
 
J

Jonathan Mcdougall

Joan said:
I read RAW image data from a binary file stream. I have to read just
bytes one by one and put them into a matrix of structs of unsigned
chars.
I have to use unsigned chars because their rangs go from 0 to 255. If
I use chars then a value of 129 will be -128 :(

The problem:

infile.get(ImageDATA[j].R);

Reads only chars...


How about

ImageData[j].R = infile.get();

istream::get() returns an int, which is plenty.

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top