diff --git a/SDL2pp/Surface.cc b/SDL2pp/Surface.cc index 877efbd..a87de0f 100644 --- a/SDL2pp/Surface.cc +++ b/SDL2pp/Surface.cc @@ -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 diff --git a/SDL2pp/Surface.hh b/SDL2pp/Surface.hh index 7ab9dc5..ddcfdd2 100644 --- a/SDL2pp/Surface.hh +++ b/SDL2pp/Surface.hh @@ -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