Skip to content

Commit

Permalink
Implement sf::Image::saveToMemory
Browse files Browse the repository at this point in the history
SFML/SFML#1669

Co-authored-by: Chris Thrasher <[email protected]>
  • Loading branch information
2 people authored and eXpl0it3r committed Sep 9, 2023
1 parent 39dd578 commit 725811b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/SFML/Graphics/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <SFML/Graphics/Color.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/Types.h>
#include <SFML/System/Buffer.h>
#include <SFML/System/InputStream.h>
#include <SFML/System/Vector2.h>
#include <stddef.h>
Expand Down Expand Up @@ -156,9 +157,30 @@ CSFML_GRAPHICS_API void sfImage_destroy(sfImage* image);
///
/// \return sfTrue if saving was successful
///
/// \see sfImage_saveToMemory
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfBool sfImage_saveToFile(const sfImage* image, const char* filename);

////////////////////////////////////////////////////////////
/// \brief Save the image to a buffer in memory
///
/// The format of the image must be specified.
/// The supported image formats are bmp, png, tga and jpg.
/// This function fails if the image is empty, or if
/// the format was invalid.
///
/// \param image Image object
/// \param output Buffer to fill with encoded data
/// \param format Encoding format to use
///
/// \return sfTrue if saving was successful
///
/// \see sfImage_saveToFile
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfBool sfImage_saveToMemory(const sfImage* image, sfBuffer* output, const char* format);

////////////////////////////////////////////////////////////
/// \brief Return the size of an image
///
Expand Down
10 changes: 10 additions & 0 deletions src/SFML/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/System/BufferStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>


////////////////////////////////////////////////////////////
sfImage* sfImage_create(unsigned int width, unsigned int height)
{
Expand Down Expand Up @@ -131,6 +133,14 @@ sfBool sfImage_saveToFile(const sfImage* image, const char* filename)
}


////////////////////////////////////////////////////////////
sfBool sfImage_saveToMemory(const sfImage* image, sfBuffer* output, const char* format)
{
CSFML_CHECK_RETURN(output, sfFalse);
CSFML_CALL_RETURN(image, saveToMemory(output->buffer, format), sfFalse);
}


////////////////////////////////////////////////////////////
void sfImage_createMaskFromColor(sfImage* image, sfColor colorKey, sfUint8 alpha)
{
Expand Down

0 comments on commit 725811b

Please sign in to comment.