Skip to content

Commit

Permalink
Remove the need for copying the image buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Sep 7, 2023
1 parent 3a6294b commit f5175fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
3 changes: 0 additions & 3 deletions include/SFML/Graphics/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ CSFML_GRAPHICS_API sfBool sfImage_saveToFile(const sfImage* image, const char* f
/// This function fails if the image is empty, or if
/// the format was invalid.
///
/// The array pointed to by \p buffer must be freed to prevent
/// a memory leak.
///
/// \param image Image object
/// \param buffer Address of buffer to fill with encoded data
/// \param size Size of buffer
Expand Down
8 changes: 2 additions & 6 deletions src/SFML/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,10 @@ sfBool sfImage_saveToMemory(const sfImage* image, unsigned char** buffer, size_t
{
CSFML_CHECK_RETURN(image, sfFalse);

std::vector<sf::Uint8> output;
static std::vector<sf::Uint8> output;
if (image->This.saveToMemory(output, format)){
// Create new buffer then return address and size to user
*buffer = reinterpret_cast<unsigned char*>(std::malloc(output.size()));
*buffer = &output[0];
*size = output.size();

// Copy vector contents into buffer
std::memcpy(*buffer, &output[0], output.size());
return sfTrue;
}

Expand Down

0 comments on commit f5175fb

Please sign in to comment.