mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 13:36:12 +01:00
Add functions for creating sRGB enabled textures from file, memory, etc. (#177)
* Add functions for creating sRGB enabled textures from file / memory / stream / image * Remove unused functions * Remove redundant sfTexture_createFromFile declaration
This commit is contained in:
1 parent
8d14b53047
commit
e40235ffb0
2 files changed
+140
-33
No files matched your search
@@ -68,6 +68,29 @@ CSFML_GRAPHICS_API sfTexture* sfTexture_create(unsigned int width, unsigned int
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area);
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Create a new sRGB-enabled texture from a file
|
||||||
|
///
|
||||||
|
/// When providing texture data from an image file or memory, it can
|
||||||
|
/// either be stored in a linear color space or an sRGB color space.
|
||||||
|
/// Most digital images account for gamma correction already, so they
|
||||||
|
/// would need to be "uncorrected" back to linear color space before
|
||||||
|
/// being processed by the hardware. The hardware can automatically
|
||||||
|
/// convert it from the sRGB color space to a linear color space when
|
||||||
|
/// it gets sampled. When the rendered image gets output to the final
|
||||||
|
/// framebuffer, it gets converted back to sRGB.
|
||||||
|
///
|
||||||
|
/// This load option is only useful in conjunction with an sRGB capable
|
||||||
|
/// framebuffer. This can be requested during window creation.
|
||||||
|
///
|
||||||
|
/// \param filename Path of the image file to load
|
||||||
|
/// \param area Area of the source image to load (NULL to load the entire image)
|
||||||
|
///
|
||||||
|
/// \return A new sfTexture object, or NULL if it failed
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* area);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create a new texture from a file in memory
|
/// \brief Create a new texture from a file in memory
|
||||||
///
|
///
|
||||||
@@ -80,6 +103,18 @@ CSFML_GRAPHICS_API sfTexture* sfTexture_createFromFile(const char* filename, con
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area);
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Create a new sRGB-enabled texture from a file in memory
|
||||||
|
///
|
||||||
|
/// \param data Pointer to the file data in memory
|
||||||
|
/// \param sizeInBytes Size of the data to load, in bytes
|
||||||
|
/// \param area Area of the source image to load (NULL to load the entire image)
|
||||||
|
///
|
||||||
|
/// \return A new sfTexture object, or NULL if it failed
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create a new texture from a custom stream
|
/// \brief Create a new texture from a custom stream
|
||||||
///
|
///
|
||||||
@@ -91,6 +126,17 @@ CSFML_GRAPHICS_API sfTexture* sfTexture_createFromMemory(const void* data, size_
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* area);
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* area);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Create a new sRGB-enabled texture from a custom stream
|
||||||
|
///
|
||||||
|
/// \param stream Source stream to read from
|
||||||
|
/// \param area Area of the source image to load (NULL to load the entire image)
|
||||||
|
///
|
||||||
|
/// \return A new sfTexture object, or NULL if it failed
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect* area);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create a new texture from an image
|
/// \brief Create a new texture from an image
|
||||||
///
|
///
|
||||||
@@ -102,6 +148,17 @@ CSFML_GRAPHICS_API sfTexture* sfTexture_createFromStream(sfInputStream* stream,
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area);
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Create a new sRGB-enabled texture from an image
|
||||||
|
///
|
||||||
|
/// \param image Image to upload to the texture
|
||||||
|
/// \param area Area of the source image to load (NULL to load the entire image)
|
||||||
|
///
|
||||||
|
/// \return A new sfTexture object, or NULL if it failed
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect* area);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy an existing texture
|
/// \brief Copy an existing texture
|
||||||
///
|
///
|
||||||
@@ -223,31 +280,6 @@ CSFML_GRAPHICS_API void sfTexture_setSmooth(sfTexture* texture, sfBool smooth);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
CSFML_GRAPHICS_API sfBool sfTexture_isSmooth(const sfTexture* texture);
|
CSFML_GRAPHICS_API sfBool sfTexture_isSmooth(const sfTexture* texture);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Enable or disable conversion from sRGB
|
|
||||||
///
|
|
||||||
/// When providing texture data from an image file or memory, it can
|
|
||||||
/// either be stored in a linear color space or an sRGB color space.
|
|
||||||
/// Most digital images account for gamma correction already, so they
|
|
||||||
/// would need to be "uncorrected" back to linear color space before
|
|
||||||
/// being processed by the hardware. The hardware can automatically
|
|
||||||
/// convert it from the sRGB color space to a linear color space when
|
|
||||||
/// it gets sampled. When the rendered image gets output to the final
|
|
||||||
/// framebuffer, it gets converted back to sRGB.
|
|
||||||
///
|
|
||||||
/// After enabling or disabling sRGB conversion, make sure to reload
|
|
||||||
/// the texture data in order for the setting to take effect.
|
|
||||||
///
|
|
||||||
/// This option is only useful in conjunction with an sRGB capable
|
|
||||||
/// framebuffer. This can be requested during window creation.
|
|
||||||
///
|
|
||||||
/// \param sRgb True to enable sRGB conversion, false to disable it
|
|
||||||
///
|
|
||||||
/// \see sfTexture_isSrgb
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CSFML_GRAPHICS_API void sfTexture_setSrgb(sfTexture* texture, sfBool sRgb);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether the texture source is converted from sRGB or not
|
/// \brief Tell whether the texture source is converted from sRGB or not
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -67,6 +67,25 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* area)
|
||||||
|
{
|
||||||
|
sfTexture* texture = new sfTexture;
|
||||||
|
|
||||||
|
sf::IntRect rect;
|
||||||
|
if (area)
|
||||||
|
rect = sf::IntRect(area->left, area->top, area->width, area->height);
|
||||||
|
|
||||||
|
texture->This->setSrgb(true);
|
||||||
|
|
||||||
|
if (!texture->This->loadFromFile(filename, rect))
|
||||||
|
{
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
||||||
@@ -86,6 +105,26 @@ sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, cons
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
||||||
|
{
|
||||||
|
sfTexture* texture = new sfTexture;
|
||||||
|
|
||||||
|
sf::IntRect rect;
|
||||||
|
if (area)
|
||||||
|
rect = sf::IntRect(area->left, area->top, area->width, area->height);
|
||||||
|
|
||||||
|
texture->This->setSrgb(true);
|
||||||
|
|
||||||
|
if (!texture->This->loadFromMemory(data, sizeInBytes, rect))
|
||||||
|
{
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* area)
|
sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* area)
|
||||||
@@ -108,6 +147,29 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect* area)
|
||||||
|
{
|
||||||
|
CSFML_CHECK_RETURN(stream, NULL);
|
||||||
|
|
||||||
|
sfTexture* texture = new sfTexture;
|
||||||
|
|
||||||
|
sf::IntRect rect;
|
||||||
|
if (area)
|
||||||
|
rect = sf::IntRect(area->left, area->top, area->width, area->height);
|
||||||
|
|
||||||
|
texture->This->setSrgb(true);
|
||||||
|
|
||||||
|
CallbackStream sfmlStream(stream);
|
||||||
|
if (!texture->This->loadFromStream(sfmlStream, rect))
|
||||||
|
{
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area)
|
sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area)
|
||||||
@@ -129,6 +191,27 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect* area)
|
||||||
|
{
|
||||||
|
CSFML_CHECK_RETURN(image, NULL);
|
||||||
|
|
||||||
|
sfTexture* texture = new sfTexture;
|
||||||
|
|
||||||
|
sf::IntRect rect;
|
||||||
|
if (area)
|
||||||
|
rect = sf::IntRect(area->left, area->top, area->width, area->height);
|
||||||
|
|
||||||
|
texture->This->setSrgb(true);
|
||||||
|
|
||||||
|
if (!texture->This->loadFromImage(image->This, rect))
|
||||||
|
{
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_copy(const sfTexture* texture)
|
sfTexture* sfTexture_copy(const sfTexture* texture)
|
||||||
@@ -234,14 +317,6 @@ sfBool sfTexture_isSmooth(const sfTexture* texture)
|
|||||||
return texture->This->isSmooth();
|
return texture->This->isSmooth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void sfTexture_setSrgb(sfTexture* texture, sfBool sRgb)
|
|
||||||
{
|
|
||||||
CSFML_CALL_PTR(texture, setSrgb(sRgb == sfTrue));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfBool sfTexture_isSrgb(const sfTexture* texture)
|
sfBool sfTexture_isSrgb(const sfTexture* texture)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user