Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
53728384
Commit
53728384
authored
Feb 02, 2017
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further performance improvement
parent
a14229aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
31 deletions
+16
-31
QtMeshViewer/Header/tga.h
QtMeshViewer/Header/tga.h
+16
-31
No files found.
QtMeshViewer/Header/tga.h
View file @
53728384
#pragma once
#include
<fstream>
#include
"OutputDevice.h"
#include <QImage>
#include <QColor>
#include <QVector>
#include <QFile>
#include "Profiler.h"
QImage
loadTga
(
QString
filePath
,
bool
&
success
)
{
TIC
(
"start"
);
QImage
img
;
success
=
true
;
...
...
@@ -50,34 +48,23 @@ QImage loadTga(QString filePath, bool &success)
// jump to the data block
file
.
seek
(
ui32IDLength
+
ui32PaletteLength
+
18
);
img
=
QImage
(
ui32Width
,
ui32Height
,
QImage
::
Format_RGBA8888
);
// uncompressed
if
(
ui32PicType
==
2
&&
(
ui32BpP
==
24
||
ui32BpP
==
32
))
{
QVector
<
quint8
>
vui8Pixels
;
vui8Pixels
.
resize
(
ui32Size
);
file
.
read
(
reinterpret_cast
<
char
*>
(
vui8Pixels
.
data
()),
ui32Size
);
for
(
unsigned
int
y
=
0
;
y
<
ui32Height
;
y
++
)
{
QRgb
*
imgLine
=
reinterpret_cast
<
QRgb
*>
(
img
.
scanLine
(
ui32Height
-
y
-
1
));
for
(
unsigned
int
x
=
0
;
x
<
ui32Width
;
x
++
)
{
int
valr
=
vui8Pixels
.
at
(
y
*
ui32Width
*
ui32BpP
/
8
+
x
*
ui32BpP
/
8
);
int
valg
=
vui8Pixels
.
at
(
y
*
ui32Width
*
ui32BpP
/
8
+
x
*
ui32BpP
/
8
+
1
);
int
valb
=
vui8Pixels
.
at
(
y
*
ui32Width
*
ui32BpP
/
8
+
x
*
ui32BpP
/
8
+
2
);
int
vala
=
255
;
if
(
ui32BpP
==
32
)
vala
=
vui8Pixels
.
at
(
y
*
ui32Width
*
ui32BpP
/
8
+
x
*
ui32BpP
/
8
+
3
);
imgLine
[
x
]
=
QColor
(
valr
,
valg
,
valb
,
vala
).
rgba
();
}
}
img
=
QImage
(
ui32Width
,
ui32Height
,
ui32BpP
==
32
?
QImage
::
Format_RGBA8888
:
QImage
::
Format_RGB888
);
int
lineWidth
=
ui32Width
*
ui32BpP
/
8
;
for
(
int
i
=
ui32Height
-
1
;
i
>=
0
;
--
i
)
file
.
read
(
reinterpret_cast
<
char
*>
(
img
.
scanLine
(
i
)),
lineWidth
);
}
// else if compressed 24 or 32 bit
else
if
(
ui32PicType
==
10
&&
(
ui32BpP
==
24
||
ui32BpP
==
32
))
// compressed
{
OutputDevice
::
getInstance
()
->
print
(
"compressed tga is not supported by SWBF"
,
1
);
img
=
QImage
(
ui32Width
,
ui32Height
,
QImage
::
Format_RGBA8888
);
quint8
tempChunkHeader
;
quint8
tempData
[
5
];
unsigned
int
tmp_pixelIndex
=
0
;
...
...
@@ -97,9 +84,9 @@ QImage loadTga(QString filePath, bool &success)
QColor
color
;
if
(
ui32BpP
==
32
)
color
.
setRgba
(
qRgba
(
tempData
[
2
],
tempData
[
1
],
tempData
[
0
],
tempData
[
3
]));
color
.
setRgba
(
qRgba
(
tempData
[
0
],
tempData
[
1
],
tempData
[
2
],
tempData
[
3
]));
else
color
.
setRgba
(
qRgba
(
tempData
[
2
],
tempData
[
1
],
tempData
[
0
],
255
));
color
.
setRgba
(
qRgba
(
tempData
[
0
],
tempData
[
1
],
tempData
[
2
],
255
));
img
.
setPixel
(
tmp_pixelIndex
%
ui32Width
,
ui32Height
-
1
-
(
tmp_pixelIndex
/
ui32Width
),
color
.
rgba
());
tmp_pixelIndex
++
;
...
...
@@ -117,9 +104,9 @@ QImage loadTga(QString filePath, bool &success)
QColor
color
;
if
(
ui32BpP
==
32
)
color
.
setRgba
(
qRgba
(
tempData
[
2
],
tempData
[
1
],
tempData
[
0
],
tempData
[
3
]));
color
.
setRgba
(
qRgba
(
tempData
[
0
],
tempData
[
1
],
tempData
[
2
],
tempData
[
3
]));
else
color
.
setRgba
(
qRgba
(
tempData
[
2
],
tempData
[
1
],
tempData
[
0
],
255
));
color
.
setRgba
(
qRgba
(
tempData
[
0
],
tempData
[
1
],
tempData
[
2
],
255
));
img
.
setPixel
(
tmp_pixelIndex
%
ui32Width
,
ui32Height
-
1
-
(
tmp_pixelIndex
/
ui32Width
),
color
.
rgba
());
tmp_pixelIndex
++
;
...
...
@@ -134,10 +121,8 @@ QImage loadTga(QString filePath, bool &success)
}
}
TOC
(
"end"
);
if
(
file
.
isOpen
())
file
.
close
();
return
img
;
return
qMove
(
img
).
rgbSwapped
()
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment