Added "ImageAlpha" option to the IMAGE meter.

Changed the interpolation mode in AntiAlias=1 to Default from Bicubic. There is a possibility that this change will be changed again in the future.
This commit is contained in:
spx 2010-02-20 00:39:08 +00:00
parent 0bcd8c30fc
commit 16b1918af3
3 changed files with 32 additions and 3 deletions

View File

@ -419,7 +419,8 @@ bool CMeter::Draw(Graphics& graphics)
if (m_AntiAlias)
{
graphics.SetInterpolationMode(InterpolationModeBicubic);
//graphics.SetInterpolationMode(InterpolationModeBicubic); // Bicubic is not suitable for shrinking an image.
graphics.SetInterpolationMode(InterpolationModeDefault);
graphics.SetSmoothingMode(SmoothingModeHighQuality);
graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality);
}

View File

@ -39,6 +39,7 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow)
m_WidthDefined = false;
m_HeightDefined = false;
m_PreserveAspectRatio = false;
m_ImageAlpha = 255;
m_hBuffer = NULL;
m_Modified.dwHighDateTime = 0;
m_Modified.dwLowDateTime = 0;
@ -205,7 +206,7 @@ void CMeterImage::ReadConfig(const WCHAR* section)
}
}
if (!m_Measure)
if (!m_Initialized || !m_Measure)
{
std::wstring oldImageName = m_ImageName;
@ -220,6 +221,10 @@ void CMeterImage::ReadConfig(const WCHAR* section)
m_PreserveAspectRatio = 0!=parser.ReadInt(section, L"PreserveAspectRatio", 0);
m_ImageAlpha = parser.ReadInt(section, L"ImageAlpha", 255);
m_ImageAlpha = min(255, m_ImageAlpha);
m_ImageAlpha = max(0, m_ImageAlpha);
if (-1 != (int)parser.ReadFormula(section, L"W", -1))
{
m_WidthDefined = true;
@ -316,7 +321,29 @@ bool CMeterImage::Draw(Graphics& graphics)
}
Rect r(x, y, drawW, drawH);
graphics.DrawImage(m_Bitmap, r, 0, 0, imageW, imageH, UnitPixel);
if (m_ImageAlpha == 255)
{
graphics.DrawImage(m_Bitmap, r, 0, 0, imageW, imageH, UnitPixel);
}
else if (m_ImageAlpha > 0)
{
REAL alp = m_ImageAlpha / 255.0f;
// Initialize the color matrix
ColorMatrix colorMatrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, alp, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
// Create an ImageAttributes object and set its color matrix
ImageAttributes imageAtt;
imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
// Draw the semi-transparent bitmap image
graphics.DrawImage(m_Bitmap, r, 0, 0, imageW, imageH, UnitPixel, &imageAtt);
}
}
return true;

View File

@ -49,6 +49,7 @@ private:
bool m_WidthDefined;
bool m_HeightDefined;
bool m_PreserveAspectRatio; // If true, aspect ratio of the image is preserved when the image is scaled
int m_ImageAlpha; // Transparency value 0 - 255
HGLOBAL m_hBuffer;
FILETIME m_Modified;
};