Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
1139bbd0
Commit
1139bbd0
authored
Mar 14, 2012
by
Janis Born
Browse files
add function that writes TextureData to a PPM file
parent
90049b9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Data/TextureDataPPMWriter.hh
0 → 100644
View file @
1139bbd0
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_DATA_TEXTUREDATAPPMWRITER_HH
#define ACGL_OPENGL_DATA_TEXTUREDATAPPMWRITER_HH
/**
* Helper function for writing the contents of a TextureData object into a PPM file.
* Expects 8 bit RGBA texture data (as can be provided by Texture::getImageData)
*/
#include
<ACGL/ACGL.hh>
#include
<ACGL/OpenGL/Data/TextureData.hh>
#include
<string>
namespace
ACGL
{
namespace
OpenGL
{
bool
saveTextureDataToPPM
(
const
ConstSharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
);
}
// OpenGL
}
// ACGL
#endif // ACGL_OPENGL_DATA_TEXTUREDATAPPMWRITER_HH
src/ACGL/OpenGL/Data/TextureDataPPMWriter.cc
0 → 100644
View file @
1139bbd0
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include
<ACGL/OpenGL/Data/TextureDataPPMWriter.hh>
#include
<ACGL/OpenGL/Tools.hh>
#include
<fstream>
using
namespace
ACGL
;
using
namespace
ACGL
::
OpenGL
;
using
namespace
ACGL
::
Utils
;
bool
ACGL
::
OpenGL
::
saveTextureDataToPPM
(
const
ConstSharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
)
{
std
::
ofstream
outFileStream
(
_filename
.
c_str
(),
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
);
if
(
!
outFileStream
.
good
())
{
error
()
<<
"saveTextureDataToPPM: Could not open file "
<<
_filename
<<
std
::
endl
;
return
false
;
}
// Use the binary-encoded RGB texture format
outFileStream
<<
"P6"
<<
std
::
endl
;
// Width and height
outFileStream
<<
_textureData
->
getWidth
()
<<
" "
<<
_textureData
->
getHeight
()
<<
std
::
endl
;
// Maximum value
uint_t
maxValue
;
if
(
_textureData
->
getType
()
==
GL_UNSIGNED_BYTE
)
{
maxValue
=
255
;
}
else
{
error
()
<<
"saveTextureDataToPPM: Unsupported data format"
<<
std
::
endl
;
return
false
;
}
outFileStream
<<
maxValue
;
// Single whitespace as a delimiter
outFileStream
<<
"
\n
"
;
// Now, write the image data in binary format
for
(
uint_t
y
=
_textureData
->
getHeight
()
-
1
;
y
>
0
;
--
y
)
{
for
(
uint_t
x
=
0
;
x
<
_textureData
->
getWidth
();
++
x
)
{
uint_t
i
=
(
y
*
_textureData
->
getWidth
())
+
x
;
outFileStream
.
put
(
_textureData
->
getData
()[(
4
*
i
+
0
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
outFileStream
.
put
(
_textureData
->
getData
()[(
4
*
i
+
1
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
outFileStream
.
put
(
_textureData
->
getData
()[(
4
*
i
+
2
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
}
}
outFileStream
.
close
();
return
true
;
}
Write
Preview
Supports
Markdown
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