Added Surface constructor based on SDL_CreateRGBSurfaceWithFormatFrom (issue #80)

This commit is contained in:
Vraiment 2017-07-24 00:29:01 -07:00
parent a668a2dbd5
commit 5cf39322a6
2 changed files with 22 additions and 0 deletions

View File

@ -56,6 +56,11 @@ Surface::Surface(Uint32 flags, int width, int height, int depth, Uint32 format)
if ((surface_ = SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) == nullptr)
throw Exception("SDL_CreateRGBSurfaceWithFormat");
}
Surface::Surface(void* pixels, int width, int height, int depth, int pitch, Uint32 format) {
if ((surface_ = SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format)) == nullptr)
throw Exception("SDL_CreateRGBSurfaceWithFormatFrom");
}
#endif
#ifdef SDL2PP_WITH_IMAGE

View File

@ -228,6 +228,23 @@ public:
///
////////////////////////////////////////////////////////////
Surface(Uint32 flags, int width, int height, int depth, Uint32 format);
////////////////////////////////////////////////////////////
/// \brief Create RGB surface with the given format from the given pixel data
///
/// \param[in] pixels The pixel data to create the surface from
/// \param[in] width Width of the surface
/// \param[in] height Height of the surface
/// \param[in] depth Depth of the surface
/// \param[in] pitch The length of a row of pixels in bytes
/// \param[in] format The pixel format of the surface
///
/// \throws SDL2pp::Exception
///
/// \see https://wiki.libsdl.org/SDL_CreateRGBSurfaceWithFormat
///
////////////////////////////////////////////////////////////
Surface(void* pixels, int width, int height, int depth, int pitch, Uint32 format);
#endif
#ifdef SDL2PP_WITH_IMAGE