mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 18:46:29 +03:00
Image format configuration is now done by image, and not globally.
--HG-- branch : dev
This commit is contained in:
@@ -64,17 +64,33 @@ class EE_API Image {
|
||||
SAVE_TYPE_JPG = 4
|
||||
};
|
||||
|
||||
/** @return The current Jpeg save quality */
|
||||
static Uint32 jpegQuality();
|
||||
class FormatConfiguration
|
||||
{
|
||||
public:
|
||||
FormatConfiguration() :
|
||||
mSvgScale(1.f),
|
||||
mJpegSaveQuality(85)
|
||||
{}
|
||||
|
||||
/** Set the save quality of Jpeg files ( between 0 and 100 ) */
|
||||
static void jpegQuality( Uint32 level );
|
||||
/** @return The current Jpeg save quality */
|
||||
const Uint32& jpegSaveQuality() const { return mJpegSaveQuality; }
|
||||
|
||||
/** @return The current SVG default scale */
|
||||
static Float svgScale();
|
||||
/** Set the save quality of Jpeg files ( between 0 and 100 ) */
|
||||
void jpegSaveQuality( Uint32 level ) {
|
||||
level = eemin<Uint32>( level, 100 );
|
||||
mJpegSaveQuality = level;
|
||||
}
|
||||
|
||||
/** Set the SVG default scale */
|
||||
static void svgScale( Float scale );
|
||||
/** @return The current SVG default scale */
|
||||
const Float& svgScale() const { return mSvgScale; }
|
||||
|
||||
/** Set the SVG default scale */
|
||||
void svgScale( Float scale ) { mSvgScale = scale; }
|
||||
|
||||
protected:
|
||||
Float mSvgScale;
|
||||
Uint32 mJpegSaveQuality;
|
||||
};
|
||||
|
||||
/** @return The File Extension of a Save Type */
|
||||
static std::string saveTypeToExtension( const Int32& Format );
|
||||
@@ -91,7 +107,7 @@ class EE_API Image {
|
||||
* @param height the var to store the image height
|
||||
* @param channels the var to store the image channels count
|
||||
*/
|
||||
static bool getInfo( const std::string& path, int * width, int * height, int * channels );
|
||||
static bool getInfo( const std::string& path, int * width, int * height, int * channels, const FormatConfiguration& imageFormatConfiguration = FormatConfiguration() );
|
||||
|
||||
/** @return True if the file is a valid image ( reads the file header to know if the file is an image file format supported )
|
||||
* @param path the image path
|
||||
@@ -109,7 +125,7 @@ class EE_API Image {
|
||||
Image();
|
||||
|
||||
/** Copy a image data to create the new image */
|
||||
Image( Graphics::Image * image );
|
||||
explicit Image( Graphics::Image * image );
|
||||
|
||||
/** Use an existing image ( and appropriates the data passed ) */
|
||||
Image( Uint8* data, const unsigned int& width, const unsigned int& height, const unsigned int& channels );
|
||||
@@ -123,28 +139,29 @@ class EE_API Image {
|
||||
/** Load an image from path
|
||||
* @param Path The path to the file.
|
||||
* @param forceChannels Number of channels to use for the image, default 0 means that it use the default image channels.
|
||||
* @param formatConfiguration Set the format configuration if needed
|
||||
*/
|
||||
Image( std::string Path, const unsigned int& forceChannels = 0 );
|
||||
Image( std::string Path, const unsigned int& forceChannels = 0, const FormatConfiguration& formatConfiguration = FormatConfiguration() );
|
||||
|
||||
/** Load a compressed image from memory
|
||||
* @param imageData The image data
|
||||
* @param imageDataSize The image size
|
||||
* @param forceChannels Number of channels to use for the image, default 0 means that it use the default image channels.
|
||||
*/
|
||||
Image( const Uint8* imageData, const unsigned int& imageDataSize, const unsigned int& forceChannels = 0 );
|
||||
Image( const Uint8* imageData, const unsigned int& imageDataSize, const unsigned int& forceChannels = 0, const FormatConfiguration& formatConfiguration = FormatConfiguration() );
|
||||
|
||||
/** Load an image from pack
|
||||
* @param Pack The pack file to use to load the image.
|
||||
* @param FilePackPath The path of the file inside the pack file.
|
||||
* @param forceChannels Number of channels to use for the image, default 0 means that it use the default image channels.
|
||||
*/
|
||||
Image( Pack * Pack, std::string FilePackPath, const unsigned int& forceChannels = 0 );
|
||||
Image( Pack * Pack, std::string FilePackPath, const unsigned int& forceChannels = 0, const FormatConfiguration& formatConfiguration = FormatConfiguration() );
|
||||
|
||||
/** Load an image from stream
|
||||
* @param stream The stream to read the image
|
||||
* @param forceChannels Number of channels to use for the image, default 0 means that it use the default image channels.
|
||||
*/
|
||||
Image( IOStream& stream, const unsigned int& forceChannels = 0 );
|
||||
Image( IOStream& stream, const unsigned int& forceChannels = 0, const FormatConfiguration& formatConfiguration = FormatConfiguration() );
|
||||
|
||||
virtual ~Image();
|
||||
|
||||
@@ -240,10 +257,13 @@ class EE_API Image {
|
||||
|
||||
/** Overload the assigment operator to ensure the image copy */
|
||||
Graphics::Image& operator =(const Image& right);
|
||||
protected:
|
||||
static Uint32 sJpegQuality;
|
||||
static Float sSVGScale;
|
||||
|
||||
/** Set the image format configuration */
|
||||
void setImageFormatConfiguration( const FormatConfiguration& imageFormatConfiguration );
|
||||
|
||||
/** @return The image format configuration */
|
||||
const FormatConfiguration& getImageFormatConfiguration() const;
|
||||
protected:
|
||||
Uint8 * mPixels;
|
||||
unsigned int mWidth;
|
||||
unsigned int mHeight;
|
||||
@@ -251,6 +271,7 @@ class EE_API Image {
|
||||
Uint32 mSize;
|
||||
bool mAvoidFree;
|
||||
bool mLoadedFromStbi;
|
||||
FormatConfiguration mFormatConfiguration;
|
||||
|
||||
void allocate( const Uint32& size, Color DefaultColor = Color(0,0,0,0), bool memsetData = true );
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class EE_API TextureFactory : protected Mutex {
|
||||
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
|
||||
* @return Internal Texture Id
|
||||
*/
|
||||
Uint32 loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
|
||||
Uint32 loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration() );
|
||||
|
||||
/** Load a texture from memory
|
||||
* @param ImagePtr The image data in RAM just as if it were still in a file
|
||||
@@ -64,7 +64,7 @@ class EE_API TextureFactory : protected Mutex {
|
||||
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
|
||||
* @return The internal Texture Id
|
||||
*/
|
||||
Uint32 loadFromMemory( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
|
||||
Uint32 loadFromMemory( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration() );
|
||||
|
||||
/** Load a Texture from stream
|
||||
* @param Stream The IOStream instance
|
||||
@@ -74,7 +74,7 @@ class EE_API TextureFactory : protected Mutex {
|
||||
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
|
||||
* @return The internal Texture Id
|
||||
*/
|
||||
Uint32 loadFromStream( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
|
||||
Uint32 loadFromStream( IOStream& Stream, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration() );
|
||||
|
||||
/** Load a Texture from a file path
|
||||
* @param Filepath The path for the texture
|
||||
@@ -84,7 +84,7 @@ class EE_API TextureFactory : protected Mutex {
|
||||
* @param KeepLocalCopy Keep the array data copy. ( useful if want to reload the texture )
|
||||
* @return The internal Texture Id
|
||||
*/
|
||||
Uint32 loadFromFile( const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
|
||||
Uint32 loadFromFile( const std::string& Filepath, const bool& Mipmap = false, const Texture::ClampMode& ClampMode = Texture::ClampMode::ClampToEdge, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const Image::FormatConfiguration& imageformatConfiguration = Image::FormatConfiguration() );
|
||||
|
||||
/** Remove and Unload the Texture Id
|
||||
* @param TexId
|
||||
@@ -142,11 +142,6 @@ class EE_API TextureFactory : protected Mutex {
|
||||
*/
|
||||
unsigned int getValidTextureSize( const unsigned int& Size );
|
||||
|
||||
/** Saves an image from an array of unsigned chars to disk
|
||||
* @return False if failed, otherwise returns True
|
||||
*/
|
||||
bool saveImage( const std::string& filepath, const Image::SaveType& Format, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, const unsigned char* data );
|
||||
|
||||
/** Determine if the TextureId passed exists */
|
||||
bool existsId( const Uint32& TexId );
|
||||
|
||||
@@ -203,8 +198,6 @@ class EE_API TextureFactory : protected Mutex {
|
||||
|
||||
int mCurrentTexture[ EE_MAX_TEXTURE_UNITS ];
|
||||
|
||||
BlendMode mLastBlend;
|
||||
|
||||
std::vector<Texture*> mTextures;
|
||||
|
||||
unsigned int mMemSize;
|
||||
|
||||
@@ -87,6 +87,10 @@ class EE_API TextureLoader : public ObjectLoader {
|
||||
|
||||
/** @return The texture instance ( if it was loaded ). */
|
||||
Texture * getTexture() const;
|
||||
|
||||
Image::FormatConfiguration getFormatConfiguration() const;
|
||||
|
||||
void setFormatConfiguration(const Image::FormatConfiguration & formatConfiguration);
|
||||
protected:
|
||||
Uint32 mLoadType; // From memory, from path, from pack
|
||||
Uint8 * mPixels; // Texture Info
|
||||
@@ -109,6 +113,7 @@ class EE_API TextureLoader : public ObjectLoader {
|
||||
Uint32 mSize;
|
||||
|
||||
RGB * mColorKey;
|
||||
Image::FormatConfiguration mFormatConfiguration;
|
||||
|
||||
void start();
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class EE_API TextureRegion : public DrawableResource {
|
||||
|
||||
/** Saves the TextureRegion to a file in the file format specified.
|
||||
* This will get the Texture from VRAM ( it will not work with OpenGL ES ) */
|
||||
bool saveToFile( const std::string& filepath, const Image::SaveType& Format );
|
||||
bool saveToFile(const std::string& filepath, const Image::SaveType& Format , const Image::FormatConfiguration& imageFormatConfiguration = Image::FormatConfiguration() );
|
||||
|
||||
/** Sets the Destination Size as the Source Rect Size ( the real size of the TextureRegion ) multiplied by the pixel density. */
|
||||
void resetDestSize();
|
||||
|
||||
@@ -188,27 +188,6 @@ static bool svg_test_from_stream( IOStream& stream ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Uint32 Image::sJpegQuality = 85;
|
||||
|
||||
Uint32 Image::jpegQuality() {
|
||||
return sJpegQuality;
|
||||
}
|
||||
|
||||
void Image::jpegQuality( Uint32 level ) {
|
||||
level = eemin<Uint32>( level, 100 );
|
||||
sJpegQuality = level;
|
||||
}
|
||||
|
||||
Float Image::sSVGScale = 1.0f;
|
||||
|
||||
Float Image::svgScale() {
|
||||
return sSVGScale;
|
||||
}
|
||||
|
||||
void Image::svgScale( Float scale ) {
|
||||
sSVGScale = scale;
|
||||
}
|
||||
|
||||
std::string Image::saveTypeToExtension( const Int32& Format ) {
|
||||
switch( Format ) {
|
||||
case Image::SaveType::SAVE_TYPE_TGA: return "tga";
|
||||
@@ -249,15 +228,15 @@ Image::PixelFormat Image::channelsToPixelFormat( const Uint32& channels ) {
|
||||
return pf;
|
||||
}
|
||||
|
||||
bool Image::getInfo( const std::string& path, int * width, int * height, int * channels ) {
|
||||
bool Image::getInfo( const std::string& path, int * width, int * height, int * channels, const FormatConfiguration& imageFormatConfiguration ) {
|
||||
bool res = stbi_info( path.c_str(), width, height, channels ) != 0;
|
||||
|
||||
if ( !res && svg_test( path ) ) {
|
||||
NSVGimage * image = nsvgParseFromFile( path.c_str(), "px", 96.0f );
|
||||
|
||||
if ( NULL != image ) {
|
||||
*width = image->width * sSVGScale;
|
||||
*height = image->height * sSVGScale;
|
||||
*width = image->width * imageFormatConfiguration.svgScale();
|
||||
*height = image->height * imageFormatConfiguration.svgScale();
|
||||
*channels = 4;
|
||||
|
||||
nsvgDelete( image );
|
||||
@@ -283,8 +262,8 @@ bool Image::getInfo( const std::string& path, int * width, int * height, int * c
|
||||
NSVGimage * image = nsvgParse( (char*)data.data, "px", 96.0f );
|
||||
|
||||
if ( NULL != image ) {
|
||||
*width = image->width * sSVGScale;
|
||||
*height = image->height * sSVGScale;
|
||||
*width = image->width * imageFormatConfiguration.svgScale();
|
||||
*height = image->height * imageFormatConfiguration.svgScale();
|
||||
*channels = 4;
|
||||
|
||||
nsvgDelete( image );
|
||||
@@ -383,14 +362,15 @@ Image::Image( Uint8* data, const unsigned int& Width, const unsigned int& Height
|
||||
{
|
||||
}
|
||||
|
||||
Image::Image( std::string Path, const unsigned int& forceChannels ) :
|
||||
Image::Image( std::string Path, const unsigned int& forceChannels, const FormatConfiguration& formatConfiguration ) :
|
||||
mPixels(NULL),
|
||||
mWidth(0),
|
||||
mHeight(0),
|
||||
mChannels(forceChannels),
|
||||
mSize(0),
|
||||
mAvoidFree(false),
|
||||
mLoadedFromStbi(false)
|
||||
mLoadedFromStbi(false),
|
||||
mFormatConfiguration(formatConfiguration)
|
||||
{
|
||||
int w, h, c;
|
||||
Pack * tPack = NULL;
|
||||
@@ -426,14 +406,15 @@ Image::Image( std::string Path, const unsigned int& forceChannels ) :
|
||||
}
|
||||
}
|
||||
|
||||
Image::Image( const Uint8 * imageData, const unsigned int & imageDataSize, const unsigned int & forceChannels ) :
|
||||
Image::Image( const Uint8 * imageData, const unsigned int & imageDataSize, const unsigned int & forceChannels, const FormatConfiguration& formatConfiguration ) :
|
||||
mPixels(NULL),
|
||||
mWidth(0),
|
||||
mHeight(0),
|
||||
mChannels(forceChannels),
|
||||
mSize(0),
|
||||
mAvoidFree(false),
|
||||
mLoadedFromStbi(false)
|
||||
mLoadedFromStbi(false),
|
||||
mFormatConfiguration(formatConfiguration)
|
||||
{
|
||||
int w, h, c;
|
||||
Uint8 * data = stbi_load_from_memory( imageData, imageDataSize, &w, &h, &c, mChannels );
|
||||
@@ -465,26 +446,28 @@ Image::Image( const Uint8 * imageData, const unsigned int & imageDataSize, const
|
||||
}
|
||||
}
|
||||
|
||||
Image::Image( Pack * Pack, std::string FilePackPath, const unsigned int& forceChannels ) :
|
||||
Image::Image( Pack * Pack, std::string FilePackPath, const unsigned int& forceChannels, const FormatConfiguration& formatConfiguration ) :
|
||||
mPixels(NULL),
|
||||
mWidth(0),
|
||||
mHeight(0),
|
||||
mChannels(forceChannels),
|
||||
mSize(0),
|
||||
mAvoidFree(false),
|
||||
mLoadedFromStbi(false)
|
||||
mLoadedFromStbi(false),
|
||||
mFormatConfiguration(formatConfiguration)
|
||||
{
|
||||
loadFromPack( Pack, FilePackPath );
|
||||
}
|
||||
|
||||
Image::Image( IOStream & stream, const unsigned int& forceChannels ) :
|
||||
Image::Image( IOStream & stream, const unsigned int& forceChannels, const FormatConfiguration& formatConfiguration ) :
|
||||
mPixels(NULL),
|
||||
mWidth(0),
|
||||
mHeight(0),
|
||||
mChannels(forceChannels),
|
||||
mSize(0),
|
||||
mAvoidFree(false),
|
||||
mLoadedFromStbi(false)
|
||||
mLoadedFromStbi(false),
|
||||
mFormatConfiguration(formatConfiguration)
|
||||
{
|
||||
if ( stream.isOpen() ) {
|
||||
stbi_io_callbacks callbacks;
|
||||
@@ -536,8 +519,8 @@ void Image::svgLoad( NSVGimage * image ) {
|
||||
unsigned char* img = NULL;
|
||||
int w, h;
|
||||
|
||||
w = (int)image->width * sSVGScale;
|
||||
h = (int)image->height * sSVGScale;
|
||||
w = (int)image->width * mFormatConfiguration.svgScale();
|
||||
h = (int)image->height * mFormatConfiguration.svgScale();
|
||||
|
||||
rast = nsvgCreateRasterizer();
|
||||
|
||||
@@ -545,7 +528,7 @@ void Image::svgLoad( NSVGimage * image ) {
|
||||
img = (unsigned char*)malloc(w*h*4);
|
||||
|
||||
if (img != NULL) {
|
||||
nsvgRasterize(rast, image, 0, 0, sSVGScale, img, w, h, w * 4);
|
||||
nsvgRasterize(rast, image, 0, 0, mFormatConfiguration.svgScale(), img, w, h, w * 4);
|
||||
|
||||
mPixels = img;
|
||||
mWidth = w;
|
||||
@@ -693,7 +676,7 @@ bool Image::saveToFile(const std::string& filepath, const SaveType & Format ) {
|
||||
Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, (Int32)mWidth, (Int32)mHeight, mChannels, getPixelsPtr() ) );
|
||||
} else {
|
||||
jpge::params params;
|
||||
params.m_quality = jpegQuality();
|
||||
params.m_quality = mFormatConfiguration.jpegSaveQuality();
|
||||
Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), mWidth, mHeight, mChannels, getPixelsPtr(), params);
|
||||
}
|
||||
}
|
||||
@@ -911,4 +894,12 @@ Graphics::Image &Image::operator =(const Image &right) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Image::setImageFormatConfiguration( const Image::FormatConfiguration& imageFormatConfiguration ) {
|
||||
mFormatConfiguration = imageFormatConfiguration;
|
||||
}
|
||||
|
||||
const Image::FormatConfiguration &Image::getImageFormatConfiguration() const {
|
||||
return mFormatConfiguration;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace EE { namespace Graphics {
|
||||
SINGLETON_DECLARE_IMPLEMENTATION(TextureFactory)
|
||||
|
||||
TextureFactory::TextureFactory() :
|
||||
mLastBlend(BlendAlpha),
|
||||
mMemSize(0),
|
||||
mLastCoordinateType( Texture::CoordinateType::Normalized ),
|
||||
mErasing(false)
|
||||
@@ -43,26 +42,30 @@ Uint32 TextureFactory::loadFromPixels( const unsigned char * Pixels, const unsig
|
||||
return myTex.getId();
|
||||
}
|
||||
|
||||
Uint32 TextureFactory::loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
|
||||
Uint32 TextureFactory::loadFromPack( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Image::FormatConfiguration& imageformatConfiguration ) {
|
||||
TextureLoader myTex( Pack, FilePackPath, Mipmap, ClampMode, CompressTexture, KeepLocalCopy );
|
||||
myTex.setFormatConfiguration( imageformatConfiguration );
|
||||
myTex.load();
|
||||
return myTex.getId();
|
||||
}
|
||||
|
||||
Uint32 TextureFactory::loadFromMemory( const unsigned char * ImagePtr, const unsigned int& Size, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
|
||||
Uint32 TextureFactory::loadFromMemory( const unsigned char * ImagePtr, const unsigned int& Size, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Image::FormatConfiguration& imageformatConfiguration ) {
|
||||
TextureLoader myTex( ImagePtr, Size, Mipmap, ClampMode, CompressTexture, KeepLocalCopy );
|
||||
myTex.setFormatConfiguration( imageformatConfiguration );
|
||||
myTex.load();
|
||||
return myTex.getId();
|
||||
}
|
||||
|
||||
Uint32 TextureFactory::loadFromStream( IOStream& Stream, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
|
||||
Uint32 TextureFactory::loadFromStream( IOStream& Stream, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Image::FormatConfiguration& imageformatConfiguration ) {
|
||||
TextureLoader myTex( Stream, Mipmap, ClampMode, CompressTexture, KeepLocalCopy );
|
||||
myTex.setFormatConfiguration( imageformatConfiguration );
|
||||
myTex.load();
|
||||
return myTex.getId();
|
||||
}
|
||||
|
||||
Uint32 TextureFactory::loadFromFile( const std::string& Filepath, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
|
||||
Uint32 TextureFactory::loadFromFile( const std::string& Filepath, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Image::FormatConfiguration& imageformatConfiguration ) {
|
||||
TextureLoader myTex( Filepath, Mipmap, ClampMode, CompressTexture, KeepLocalCopy );
|
||||
myTex.setFormatConfiguration( imageformatConfiguration );
|
||||
myTex.load();
|
||||
return myTex.getId();
|
||||
}
|
||||
@@ -273,20 +276,6 @@ unsigned int TextureFactory::getValidTextureSize( const unsigned int& Size ) {
|
||||
return Math::nextPowOfTwo(Size);
|
||||
}
|
||||
|
||||
bool TextureFactory::saveImage(const std::string& filepath, const Image::SaveType & Format, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, const unsigned char* data ) {
|
||||
bool Res;
|
||||
|
||||
if ( Image::SaveType::SAVE_TYPE_JPG != Format ) {
|
||||
Res = 0 != SOIL_save_image ( filepath.c_str(), Format, Width, Height, Channels, data );
|
||||
} else {
|
||||
jpge::params params;
|
||||
params.m_quality = Image::jpegQuality();
|
||||
Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), Width, Height, Channels, data, params);
|
||||
}
|
||||
|
||||
return Res;
|
||||
}
|
||||
|
||||
bool TextureFactory::existsId( const Uint32& TexId ) {
|
||||
return ( TexId < mTextures.size() && TexId > 0 && NULL != mTextures[ TexId ] );
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ void TextureLoader::loadFromFile() {
|
||||
mSize = FileSystem::fileSize( mFilepath );
|
||||
}
|
||||
|
||||
Image image( mFilepath, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default );
|
||||
Image image( mFilepath, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default, mFormatConfiguration );
|
||||
image.avoidFreeImage( true );
|
||||
mPixels = image.getPixels(); mImgWidth = image.getWidth(); mImgHeight = image.getHeight(); mChannels = image.getChannels();
|
||||
}
|
||||
@@ -289,7 +289,7 @@ void TextureLoader::loadFromMemory() {
|
||||
stbi__pkm_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels );
|
||||
mIsCompressed = mDirectUpload = true;
|
||||
} else {
|
||||
Image image( mImagePtr, mSize, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default );
|
||||
Image image( mImagePtr, mSize, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default, mFormatConfiguration );
|
||||
image.avoidFreeImage( true );
|
||||
mPixels = image.getPixels(); mImgWidth = image.getWidth(); mImgHeight = image.getHeight(); mChannels = image.getChannels();
|
||||
}
|
||||
@@ -337,7 +337,7 @@ void TextureLoader::loadFromStream() {
|
||||
} else {
|
||||
mStream->seek( 0 );
|
||||
|
||||
Image image( *mStream, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default );
|
||||
Image image( *mStream, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default, mFormatConfiguration );
|
||||
image.avoidFreeImage( true );
|
||||
mPixels = image.getPixels(); mImgWidth = image.getWidth(); mImgHeight = image.getHeight(); mChannels = image.getChannels();
|
||||
|
||||
@@ -491,6 +491,14 @@ Texture * TextureLoader::getTexture() const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Image::FormatConfiguration TextureLoader::getFormatConfiguration() const {
|
||||
return mFormatConfiguration;
|
||||
}
|
||||
|
||||
void TextureLoader::setFormatConfiguration(const Image::FormatConfiguration & formatConfiguration ) {
|
||||
mFormatConfiguration = formatConfiguration;
|
||||
}
|
||||
|
||||
void TextureLoader::unload() {
|
||||
if ( mLoaded ) {
|
||||
TextureFactory::instance()->remove( mTexId );
|
||||
|
||||
@@ -465,26 +465,18 @@ bool TexturePacker::addPackerTex( TexturePackerTex * TPack ) {
|
||||
}
|
||||
|
||||
bool TexturePacker::addImage( Image * Img, const std::string& Name ) {
|
||||
Float oldSvgScale( Image::svgScale() );
|
||||
|
||||
Image::svgScale( mScalableSVG ? PixelDensity::toFloat( mPixelDensity ) : 1.f );
|
||||
|
||||
TexturePackerTex * TPack = eeNew( TexturePackerTex, ( Img, Name ) );
|
||||
|
||||
Image::svgScale( oldSvgScale );
|
||||
|
||||
return addPackerTex( TPack );
|
||||
}
|
||||
|
||||
bool TexturePacker::addTexture( const std::string& TexturePath ) {
|
||||
if ( FileSystem::fileExists( TexturePath ) ) {
|
||||
Float oldSvgScale( Image::svgScale() );
|
||||
Image::FormatConfiguration imageFormatConfiguration;
|
||||
|
||||
Image::svgScale( mScalableSVG ? PixelDensity::toFloat( mPixelDensity ) : 1.f );
|
||||
imageFormatConfiguration.svgScale( mScalableSVG ? PixelDensity::toFloat( mPixelDensity ) : 1.f );
|
||||
|
||||
TexturePackerTex * TPack = eeNew( TexturePackerTex, ( TexturePath ) );
|
||||
|
||||
Image::svgScale( oldSvgScale );
|
||||
TexturePackerTex * TPack = eeNew( TexturePackerTex, ( TexturePath, imageFormatConfiguration ) );
|
||||
|
||||
return addPackerTex( TPack );
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace EE { namespace Graphics { namespace Private {
|
||||
|
||||
TexturePackerTex::TexturePackerTex( const std::string& Name ) :
|
||||
TexturePackerTex::TexturePackerTex( const std::string& Name, const Image::FormatConfiguration& imageFormatConfiguration ) :
|
||||
mName(Name),
|
||||
mWidth(0),
|
||||
mHeight(0),
|
||||
@@ -18,7 +18,7 @@ TexturePackerTex::TexturePackerTex( const std::string& Name ) :
|
||||
mDisabled(false),
|
||||
mImg( NULL )
|
||||
{
|
||||
if ( Image::getInfo( Name.c_str(), &mWidth, &mHeight, &mChannels ) ) {
|
||||
if ( Image::getInfo( Name.c_str(), &mWidth, &mHeight, &mChannels, imageFormatConfiguration ) ) {
|
||||
mArea = mWidth * mHeight;
|
||||
mLongestEdge = ( mWidth >= mHeight ) ? mWidth : mHeight;
|
||||
mLoadedInfo = true;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define EE_GRAPHICSPRIVATECTEXTUREPACKERTEX
|
||||
|
||||
#include <eepp/graphics/base.hpp>
|
||||
#include <eepp/graphics/image.hpp>
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
@@ -11,7 +12,7 @@ namespace Private {
|
||||
|
||||
class TexturePackerTex {
|
||||
public:
|
||||
TexturePackerTex( const std::string& name );
|
||||
TexturePackerTex(const std::string& name , const Image::FormatConfiguration& imageFormatConfiguration );
|
||||
|
||||
TexturePackerTex( EE::Graphics::Image * Img, const std::string& name );
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ const Uint8* TextureRegion::getPixelsPtr() {
|
||||
return reinterpret_cast<const Uint8*> (&mPixels[0]);
|
||||
}
|
||||
|
||||
bool TextureRegion::saveToFile(const std::string& filepath, const Image::SaveType & Format) {
|
||||
bool TextureRegion::saveToFile(const std::string& filepath, const Image::SaveType & Format, const Image::FormatConfiguration& imageFormatConfiguration ) {
|
||||
bool Res = false;
|
||||
|
||||
lock();
|
||||
@@ -362,7 +362,7 @@ bool TextureRegion::saveToFile(const std::string& filepath, const Image::SaveTyp
|
||||
Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, getRealSize().getWidth(), getRealSize().getHeight(), mTexture->getChannels(), getPixelsPtr() ) );
|
||||
} else {
|
||||
jpge::params params;
|
||||
params.m_quality = Image::jpegQuality();
|
||||
params.m_quality = imageFormatConfiguration.jpegSaveQuality();
|
||||
Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), getRealSize().getWidth(), getRealSize().getHeight(), mTexture->getChannels(), getPixelsPtr(), params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user