-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
66 lines (50 loc) · 1.36 KB
/
main.cpp
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
#include "TGA.h"
#include "TGAFile.h"
#include <stdio.h>
class TGAFileImpl : public ITGAStream
{
FILE* m_hFile;
size_t m_size;
public:
TGAFileImpl(const char* file)
: m_hFile(0)
{
m_hFile = fopen(file, "r");
}
int read(void* pBuffer, int sizeBlock)
{
return fread(pBuffer, sizeof(unsigned __int8), sizeBlock, m_hFile);
}
int seek(__int64 offset, TGAStremOrigin SeekMethod)
{
return _fseeki64(m_hFile, offset, SeekMethod);
}
unsigned __int64 tell()
{
return _ftelli64(m_hFile);
}
unsigned __int64 size() const
{
return m_size;
}
};
int main(int argc, char *argv[])
{
if (argc != 2)
return 0;
TGAFileImpl tgaFile(argv[1]);
TGA tga(&tgaFile);
tga.read();
const TGAHeader& hdr = tga.header();
const TGAField& field = hdr.field();
const ColorMapSpecification& cmap = hdr.color_map_specification();
const ImageSpecification& image_spec = hdr.image_specification();
auto sizeHeader = hdr.size();
std::vector<unsigned __int8> vImageID; vImageID.resize((int)tga.image_id_size());
std::vector<unsigned __int8> vColorMapData; vColorMapData.resize((int)tga.color_map_data_size());
std::vector<unsigned __int8> vImageData; vImageData.resize((int)tga.image_data_size());
tga.image_id(vImageID.data());
tga.color_map_data(vColorMapData.data());
tga.image_data(vImageData.data());
return 0;
}