1 |
bearsoft |
1.1 |
#include "SGI.h"
|
2 |
|
|
#include "../System/SystemDefine.h"
|
3 |
|
|
#include "../Files/FileTools.h"
|
4 |
|
|
#include "../System/System.h"
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
SGI::SGI(char *fileName)
|
8 |
|
|
{
|
9 |
|
|
setup(fileName);
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
SGI::SGI(String &fileName)
|
13 |
|
|
{
|
14 |
|
|
setup(fileName.buffer);
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
SGI::~SGI()
|
18 |
|
|
{
|
19 |
|
|
if (buffer!=0)
|
20 |
|
|
{
|
21 |
|
|
free(buffer);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
if (binaryInput!=0)
|
25 |
|
|
{
|
26 |
|
|
delete binaryInput;
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
void SGI::setup(char *fileName)
|
31 |
|
|
{
|
32 |
|
|
binaryInput = new BinaryInput();
|
33 |
|
|
buffer=0;
|
34 |
|
|
width=0;
|
35 |
|
|
height=0;
|
36 |
|
|
readFileAndConvertToRaw32(fileName);
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
int SGI::readFileAndConvertToRaw32(char *fileName)
|
41 |
|
|
{
|
42 |
|
|
if ( buffer != 0 )
|
43 |
|
|
{
|
44 |
|
|
free(buffer);
|
45 |
|
|
buffer=0;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
binaryInput->readFile(fileName);
|
49 |
|
|
|
50 |
|
|
if (binaryInput->getFileStatus()==FileExist)
|
51 |
|
|
{
|
52 |
|
|
convertSgiToRaw32(binaryInput);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
return binaryInput->getBinaryStatus();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
void SGI::convertSgiToRaw32(BinaryInput *binaryInput, char *rawBuffer)
|
59 |
|
|
{
|
60 |
|
|
int size=(binaryInput->getInternBufferSize()-512)/4;
|
61 |
|
|
|
62 |
|
|
int k=512;
|
63 |
|
|
int red=k+size;
|
64 |
|
|
int green=k+(size*2);
|
65 |
|
|
int blue=k+(size*3);
|
66 |
|
|
int alpha=k+(size*4);
|
67 |
|
|
|
68 |
|
|
for ( int y=0 ; y<height ; y++ )
|
69 |
|
|
{
|
70 |
|
|
int d3l=width*4;
|
71 |
|
|
|
72 |
|
|
for ( int x=0 ; x<width ; x++ )
|
73 |
|
|
{
|
74 |
|
|
d3l=d3l-4;
|
75 |
|
|
|
76 |
|
|
--alpha;
|
77 |
|
|
binaryInput->setInternBufferPosition(alpha);
|
78 |
|
|
rawBuffer[d3l+3]=binaryInput->getChar(); //alpha
|
79 |
|
|
|
80 |
|
|
--red;
|
81 |
|
|
binaryInput->setInternBufferPosition(red);
|
82 |
|
|
rawBuffer[d3l+2]=binaryInput->getChar(); //red
|
83 |
|
|
|
84 |
|
|
--green;
|
85 |
|
|
binaryInput->setInternBufferPosition(green);
|
86 |
|
|
rawBuffer[d3l+1]=binaryInput->getChar(); //green
|
87 |
|
|
|
88 |
|
|
--blue;
|
89 |
|
|
binaryInput->setInternBufferPosition(blue);
|
90 |
|
|
rawBuffer[d3l]=binaryInput->getChar(); //blue
|
91 |
|
|
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
rawBuffer+=(width*4);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
void SGI::readHeader(BinaryInput *binaryInput)
|
100 |
|
|
{
|
101 |
|
|
binaryInput->setBigEndian(true);
|
102 |
|
|
binaryInput->setInternBufferPosition(3*sizeof(short));
|
103 |
|
|
width=(int)binaryInput->getShort();
|
104 |
|
|
binaryInput->setInternBufferPosition(4*sizeof(short));
|
105 |
|
|
height=(int)binaryInput->getShort();
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
void SGI::convertSgiToRaw32(BinaryInput *binaryInput)
|
109 |
|
|
{
|
110 |
|
|
readHeader(binaryInput);
|
111 |
|
|
|
112 |
|
|
buffer = (int*)malloc(binaryInput->getInternBufferSize()*sizeof(int));
|
113 |
|
|
|
114 |
|
|
convertSgiToRaw32(binaryInput,(char*)buffer);
|
115 |
|
|
|
116 |
|
|
// resize32(int *buffer, int *rawBuffer, int resizeWidth, int resizeHeight)
|
117 |
|
|
}
|
118 |
|
|
/*
|
119 |
|
|
void SGI::resize32(int *buffer, int *rawBuffer, int resizeWidth, int resizeHeight)
|
120 |
|
|
{
|
121 |
|
|
float ustep=(float)width/(float)resizeWidth;
|
122 |
|
|
float vstep=(float)height/(float)resizeHeight;
|
123 |
|
|
|
124 |
|
|
float v=0;
|
125 |
|
|
|
126 |
|
|
for ( int y=0 ; y<resizeHeight ; y++ )
|
127 |
|
|
{
|
128 |
|
|
float u=0;
|
129 |
|
|
|
130 |
|
|
for ( int x=0 ; x<resizeWidth ; x++ )
|
131 |
|
|
{
|
132 |
|
|
int tempu=(int)u;
|
133 |
|
|
int tempv=(int)v;
|
134 |
|
|
buffer[x+y*resizeWidth]=rawBuffer[tempu+tempv*width];
|
135 |
|
|
u+=ustep;
|
136 |
|
|
}
|
137 |
|
|
v+=vstep;
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
*/
|
141 |
|
|
|
142 |
|
|
int SGI::getWidth()
|
143 |
|
|
{
|
144 |
|
|
return width;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
int SGI::getHeight()
|
148 |
|
|
{
|
149 |
|
|
return height;
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
int *SGI::getBuffer()
|
153 |
|
|
{
|
154 |
|
|
return buffer;
|
155 |
|
|
}
|