mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-02-17 20:52:38 +01:00
texturec: Added --linear option.
This commit is contained in:
@@ -314,6 +314,9 @@ namespace bimg
|
||||
, const void* _src
|
||||
);
|
||||
|
||||
///
|
||||
void imageRgba32fToLinear(ImageContainer* _imageContainer);
|
||||
|
||||
///
|
||||
void imageRgba32fToGamma(
|
||||
void* _dst
|
||||
@@ -324,6 +327,9 @@ namespace bimg
|
||||
, const void* _src
|
||||
);
|
||||
|
||||
///
|
||||
void imageRgba32fToGamma(ImageContainer* _imageContainer);
|
||||
|
||||
///
|
||||
void imageRgba32fLinearDownsample2x2(
|
||||
void* _dst
|
||||
|
||||
@@ -560,6 +560,28 @@ namespace bimg
|
||||
}
|
||||
}
|
||||
|
||||
void imageRgba32fToLinear(ImageContainer* _imageContainer)
|
||||
{
|
||||
const uint16_t numSides = _imageContainer->m_numLayers * (_imageContainer->m_cubeMap ? 6 : 1);
|
||||
|
||||
for (uint16_t side = 0; side < numSides; ++side)
|
||||
{
|
||||
bimg::ImageMip mip;
|
||||
bimg::imageGetRawData(*_imageContainer, side, 0, _imageContainer->m_data, _imageContainer->m_size, mip);
|
||||
|
||||
const uint32_t pitch = _imageContainer->m_width*16;
|
||||
const uint32_t slice = _imageContainer->m_height*pitch;
|
||||
|
||||
for (uint32_t zz = 0, depth = _imageContainer->m_depth; zz < depth; ++zz)
|
||||
{
|
||||
const uint32_t srcDataStep = uint32_t(bx::floor(zz * _imageContainer->m_depth / float(depth) ) );
|
||||
const uint8_t* srcData = &mip.m_data[srcDataStep*slice];
|
||||
|
||||
imageRgba32fToLinear(const_cast<uint8_t*>(srcData), mip.m_width, mip.m_height, 1, pitch, srcData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void imageRgba32fToGamma(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src)
|
||||
{
|
||||
uint8_t* dst = ( uint8_t*)_dst;
|
||||
@@ -584,6 +606,28 @@ namespace bimg
|
||||
}
|
||||
}
|
||||
|
||||
void imageRgba32fToGamma(ImageContainer* _imageContainer)
|
||||
{
|
||||
const uint16_t numSides = _imageContainer->m_numLayers * (_imageContainer->m_cubeMap ? 6 : 1);
|
||||
|
||||
for (uint16_t side = 0; side < numSides; ++side)
|
||||
{
|
||||
bimg::ImageMip mip;
|
||||
bimg::imageGetRawData(*_imageContainer, side, 0, _imageContainer->m_data, _imageContainer->m_size, mip);
|
||||
|
||||
const uint32_t pitch = _imageContainer->m_width*16;
|
||||
const uint32_t slice = _imageContainer->m_height*pitch;
|
||||
|
||||
for (uint32_t zz = 0, depth = _imageContainer->m_depth; zz < depth; ++zz)
|
||||
{
|
||||
const uint32_t srcDataStep = uint32_t(bx::floor(zz * _imageContainer->m_depth / float(depth) ) );
|
||||
const uint8_t* srcData = &mip.m_data[srcDataStep*slice];
|
||||
|
||||
imageRgba32fToGamma(const_cast<uint8_t*>(srcData), mip.m_width, mip.m_height, 1, pitch, srcData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void imageRgba32fLinearDownsample2x2Ref(void* _dst, uint32_t _width, uint32_t _height, uint32_t _depth, uint32_t _srcPitch, const void* _src)
|
||||
{
|
||||
const uint32_t dstWidth = _width/2;
|
||||
|
||||
@@ -467,7 +467,7 @@ namespace bimg
|
||||
, 4, 3
|
||||
, STBIR_FLAG_ALPHA_PREMULTIPLIED
|
||||
, STBIR_EDGE_CLAMP
|
||||
, STBIR_FILTER_CUBICBSPLINE
|
||||
, STBIR_FILTER_BOX
|
||||
, STBIR_COLORSPACE_LINEAR
|
||||
, NULL
|
||||
);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <string>
|
||||
|
||||
#define BIMG_TEXTUREC_VERSION_MAJOR 1
|
||||
#define BIMG_TEXTUREC_VERSION_MINOR 17
|
||||
#define BIMG_TEXTUREC_VERSION_MINOR 18
|
||||
|
||||
BX_ERROR_RESULT(TEXTRUREC_ERROR, BX_MAKEFOURCC('t', 'c', 0, 0) );
|
||||
|
||||
@@ -46,6 +46,7 @@ struct Options
|
||||
"\t radiance: %s\n"
|
||||
"\t equirect: %s\n"
|
||||
"\t strip: %s\n"
|
||||
"\t linear: %s\n"
|
||||
, maxSize
|
||||
, mipSkip
|
||||
, edge
|
||||
@@ -58,6 +59,7 @@ struct Options
|
||||
, radiance ? "true" : "false"
|
||||
, equirect ? "true" : "false"
|
||||
, strip ? "true" : "false"
|
||||
, linear ? "true" : "false"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,6 +77,7 @@ struct Options
|
||||
bool pma = false;
|
||||
bool sdf = false;
|
||||
bool alphaTest = false;
|
||||
bool linear = false;
|
||||
};
|
||||
|
||||
void imageRgba32fNormalize(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src)
|
||||
@@ -272,8 +275,18 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
, false
|
||||
);
|
||||
|
||||
if (!_options.linear)
|
||||
{
|
||||
bimg::imageRgba32fToLinear(src);
|
||||
}
|
||||
|
||||
bimg::imageResizeRgba32fLinear(dst, src);
|
||||
|
||||
if (!_options.linear)
|
||||
{
|
||||
bimg::imageRgba32fToGamma(dst);
|
||||
}
|
||||
|
||||
bimg::imageFree(src);
|
||||
bimg::imageFree(input);
|
||||
|
||||
@@ -852,6 +865,7 @@ void help(const char* _error = NULL, bool _showHelp = true)
|
||||
" --ref <alpha> Alpha reference value.\n"
|
||||
" --iqa Image Quality Assessment\n"
|
||||
" --pma Premultiply alpha into RGB channel.\n"
|
||||
" --linear Input and output texture is linear color space (gamma correction won't be applied).\n"
|
||||
" --max <max size> Maximum width/height (image will be scaled down and\n"
|
||||
" aspect ratio will be preserved.\n"
|
||||
" --radiance <model> Radiance cubemap filter. (Lighting model: Phong, PhongBrdf, Blinn, BlinnBrdf, GGX)\n"
|
||||
@@ -987,6 +1001,7 @@ int main(int _argc, const char* _argv[])
|
||||
options.strip = cmdLine.hasArg("strip");
|
||||
options.iqa = cmdLine.hasArg("iqa");
|
||||
options.pma = cmdLine.hasArg("pma");
|
||||
options.linear = cmdLine.hasArg("linear");
|
||||
|
||||
if (options.equirect
|
||||
&& options.strip)
|
||||
|
||||
Reference in New Issue
Block a user