diff --git a/StShared/StAVImage.cpp b/StShared/StAVImage.cpp index 830632d8..31bed4d6 100644 --- a/StShared/StAVImage.cpp +++ b/StShared/StAVImage.cpp @@ -701,7 +701,13 @@ bool StAVImage::save(const StString& theFilePath, myCodecCtx->height = (int )anImage.getSizeY(); myCodecCtx->time_base.num = 1; myCodecCtx->time_base.den = 1; - myCodecCtx->compression_level = 9; // 0..9 + + // PNG compression level is within [0..9] range + static const int PNG_QLOWER = 0; + static const int PNG_QUPPER = 9; + const float aRatio = stClamp(theParams.Compression >= 0.0f ? theParams.Compression : 1.0f, 0.0f, 1.0f); + int aQLevel = stRound(stLerp(float(PNG_QLOWER), float(PNG_QUPPER), aRatio)); + myCodecCtx->compression_level = aQLevel; break; } case ST_TYPE_JPEG: @@ -746,7 +752,13 @@ bool StAVImage::save(const StString& theFilePath, myCodecCtx->height = (int )anImage.getSizeY(); myCodecCtx->time_base.num = 1; myCodecCtx->time_base.den = 1; - myCodecCtx->qmin = myCodecCtx->qmax = 5; // quality factor - lesser is better + + // quantizer factor within 1..31 range, lesser is better + static const int JPEG_QLOWER = 1; + static const int JPEG_QUPPER = 31; + const float aRatio = stClamp(theParams.Compression >= 0.0f ? theParams.Compression : 0.10f, 0.0f, 1.0f); + int aQFactor = stRound(stLerp(float(JPEG_QLOWER), float(JPEG_QUPPER), aRatio)); + myCodecCtx->qmin = myCodecCtx->qmax = aQFactor; break; } case ST_TYPE_NONE: diff --git a/include/StImage/StImageFile.h b/include/StImage/StImageFile.h index 148b5512..0f530061 100644 --- a/include/StImage/StImageFile.h +++ b/include/StImage/StImageFile.h @@ -58,8 +58,10 @@ class StImageFile : public StImage { ImageType SaveImageType; /** Stereo format to be stored as metadata. */ StFormat StereoFormat; + /** Compression level within [0..1] range (0 minimal compression, 1 maximum, -1 default). */ + float Compression; - SaveImageParams() : SaveImageType(ST_TYPE_NONE), StereoFormat(StFormat_AUTO) {} + SaveImageParams() : SaveImageType(ST_TYPE_NONE), StereoFormat(StFormat_AUTO), Compression(-1.0) {} }; public: diff --git a/include/StTemplates/StTemplates.h b/include/StTemplates/StTemplates.h index 5e4ce488..ca635872 100644 --- a/include/StTemplates/StTemplates.h +++ b/include/StTemplates/StTemplates.h @@ -76,4 +76,14 @@ inline Type stClamp(const Type theValue, return theValue; } +/** + * Compute linear interpolation between two values. + * @param theT interpolation coefficient 0..1 + * @return interpolation result + */ +template +inline Type stLerp(const Type& theFrom, const Type& theTo, const ElemType theT) { + return theFrom * (ElemType(1) - theT) + theTo * theT; +} + #endif //__StTemplates_H__ diff --git a/include/StTemplates/StVec3.h b/include/StTemplates/StVec3.h index 02fcf45e..41b5d580 100644 --- a/include/StTemplates/StVec3.h +++ b/include/StTemplates/StVec3.h @@ -345,7 +345,7 @@ class StVec3 { } /** - * Compute linear interpolation between to vectors. + * Compute linear interpolation between two vectors. * @param theT (const Element_t ) - interpolation coefficient 0..1; * @return interpolation result. */