Hi Jonnin
I have modified the code, but got strange errors. It might be something stupid, but I need your help to make the code to work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <fstream>
#include <iostream>
typedef unsigned char UCHAR;
typedef signed char SCHAR;
typedef unsigned short int USINT;
struct targa{
header h;
UCHAR* image_data; // here the data stored differently depending on bitrate and colormap etc.
};
class TARGA
{
public:
TARGA();
UCHAR idLength; // no. of chars in id field.
UCHAR colorMapType; // 1 = map 0 = no map
UCHAR imageType; // 1 = color mapped, 2 = rgb, 3 = b&w. All uncompressed
USINT colorMapStart; // index of first entry (lo-hi)
USINT colorMapNumEntries; // no. of color map entries (lo-hi)
UCHAR bitPerEntry; // 16 for 16bit, 24 for 24bit...
USINT xOrigin; // lower left corner (lo-hi)
USINT yOrigin; // lower left corner (lo-hi)
USINT width; // width of image (lo-hi)
USINT height; // height of image (lo-hi)
UCHAR bitsPerPixel; // 16 for 16bit, 24 for 24bit...
UCHAR pixelData;
// The footer is ignored
};
TARGA::TARGA()
{
idLength = 0;
colorMapType = 0;
imageType = 2; // truecolor
colorMapStart = 0;
colorMapNumEntries = 0;
bitPerEntry = 24; // 24 bit
xOrigin = 0;
yOrigin = 0;
width = 2; // width
height = 2; // height
bitsPerPixel = 24; // 24 bit
pixelData = 0;
image_data = new UCHAR[width*height*3];
for (int n=0; n<width*height*3; n++)
{
image_data[n]= 128; // should make all pixels gray
}
}
int main(int argc, char** argv)
{
fstream file;
TARGA targa;
char outfile[] = "outtest.tga";
file.open(outfile, std::ios::out | std::ios::binary);
if (!file)
{
std::cout << "Error in opening " << outfile << " for writing tga" << std::endl;
return 1;
}
file.write((UCHAR *)&targa.h,sizeof(targa.h));
file.write((UCHAR *)targa.image_data, w*h*3);
file.close();
file.open(outfile, std::ios::in | std::ios::binary);
if (!file)
{
std::cout << "Error in opening " << outfile << " for reading tga" << std::endl;
return 1;
}
char c;
int n=0;
while (true)
{
file.get(c);
std::cout << n << ": " << int(c) << std::endl;
if (file.eof()) { break; }
n++;
}
file.read((UCHAR *)&targa,sizeof(targa));
file.close();
return 0;
}
|
9:1: error: 'header' does not name a type
In constructor 'TARGA::TARGA()':
47:1: error: 'image_data' was not declared in this scope
In function 'int main(int, char**)':
57:1: error: 'fstream' was not declared in this scope
57:1: note: suggested alternative:
In file included from /usr/include/c++/4.9/ios:38:0,
from /usr/include/c++/4.9/istream:38,
from /usr/include/c++/4.9/fstream:38,
from 1:
/usr/include/c++/4.9/iosfwd:163:33: note: 'std::fstream'
typedef basic_fstream<char> fstream;
^
62:1: error: 'file' was not declared in this scope
69:28: error: 'class TARGA' has no member named 'h'
69:43: error: 'class TARGA' has no member named 'h'
70:27: error: 'class TARGA' has no member named 'image_data'
70:39: error: 'w' was not declared in this scope
70:41: error: 'h' was not declared in this scope