2010-11-27 19:53:23 +00:00
|
|
|
/*
|
2012-01-23 06:36:15 +00:00
|
|
|
Copyright (C) 2010 Kimmo Pekkola, Matt King, spx
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-11-27 19:53:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TINTEDIMAGE_H__
|
|
|
|
#define __TINTEDIMAGE_H__
|
|
|
|
|
2011-02-07 08:02:12 +00:00
|
|
|
#include <windows.h>
|
2013-12-24 11:20:19 +00:00
|
|
|
#include <ole2.h> // For Gdiplus.h.
|
2011-02-07 08:02:12 +00:00
|
|
|
#include <gdiplus.h>
|
|
|
|
#include <string>
|
2013-06-07 19:35:36 +00:00
|
|
|
#include "MeterWindow.h"
|
2011-02-07 08:02:12 +00:00
|
|
|
|
2011-02-07 09:38:27 +00:00
|
|
|
/*
|
2012-06-01 13:06:36 +00:00
|
|
|
** Helper macro to define an array of option names. A prefix must be given.
|
2011-02-07 09:38:27 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
#define TintedImageHelper_DefineOptionArray(name, prefix) \
|
|
|
|
const WCHAR* (name)[TintedImage::OptionCount] = { \
|
2011-02-07 09:38:27 +00:00
|
|
|
prefix L"ImageCrop", \
|
|
|
|
prefix L"Greyscale", \
|
|
|
|
prefix L"ImageTint", \
|
|
|
|
prefix L"ImageAlpha", \
|
|
|
|
prefix L"ColorMatrix1", \
|
|
|
|
prefix L"ColorMatrix2", \
|
|
|
|
prefix L"ColorMatrix3", \
|
|
|
|
prefix L"ColorMatrix4", \
|
|
|
|
prefix L"ColorMatrix5", \
|
|
|
|
prefix L"ImageFlip", \
|
2013-05-10 19:33:26 +00:00
|
|
|
prefix L"ImageRotate", \
|
2013-06-07 19:35:36 +00:00
|
|
|
prefix L"UseExifOrientation", \
|
|
|
|
prefix L"ImagePath" \
|
2011-02-07 09:38:27 +00:00
|
|
|
};
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
class ConfigParser;
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
class TintedImage
|
2010-11-27 19:53:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-05-30 18:51:06 +00:00
|
|
|
enum OptionIndex
|
2011-02-07 09:38:27 +00:00
|
|
|
{
|
2012-05-30 18:51:06 +00:00
|
|
|
OptionIndexImageCrop = 0,
|
|
|
|
OptionIndexGreyscale,
|
|
|
|
OptionIndexImageTint,
|
|
|
|
OptionIndexImageAlpha,
|
|
|
|
OptionIndexColorMatrix1,
|
|
|
|
OptionIndexColorMatrix2,
|
|
|
|
OptionIndexColorMatrix3,
|
|
|
|
OptionIndexColorMatrix4,
|
|
|
|
OptionIndexColorMatrix5,
|
|
|
|
OptionIndexImageFlip,
|
|
|
|
OptionIndexImageRotate,
|
2013-05-10 19:33:26 +00:00
|
|
|
OptionIndexUseExifOrientation,
|
2013-06-07 19:35:36 +00:00
|
|
|
OptionIndexImagePath,
|
2011-02-07 09:38:27 +00:00
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
OptionCount
|
2011-02-07 09:38:27 +00:00
|
|
|
};
|
|
|
|
|
2013-06-07 19:35:36 +00:00
|
|
|
TintedImage(const WCHAR* name = L"ImageName", const WCHAR** optionArray = c_DefaultOptionArray, bool disableTransform = false, MeterWindow* meterWindow = nullptr);
|
2013-05-31 14:18:52 +00:00
|
|
|
~TintedImage();
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2013-06-07 19:35:36 +00:00
|
|
|
void ReadOptions(ConfigParser& parser, const WCHAR* section, const WCHAR* imagePath = L"");
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
bool IsLoaded() { return (m_Bitmap != nullptr); }
|
|
|
|
bool IsTinted() { return (m_BitmapTint != nullptr); }
|
2013-06-08 05:45:28 +00:00
|
|
|
bool IsOptionsChanged() { return m_NeedsCrop || m_NeedsTinting || m_NeedsTransform || m_HasPathChanged; }
|
|
|
|
void ClearOptionFlags() { m_NeedsCrop = m_NeedsTinting = m_NeedsTransform = m_HasPathChanged = false; }
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
Gdiplus::Bitmap* GetOriginalImage() { return m_Bitmap; }
|
|
|
|
Gdiplus::Bitmap* GetTintedImage() { return m_BitmapTint; }
|
|
|
|
Gdiplus::Bitmap* GetImage() { return (m_BitmapTint) ? m_BitmapTint : m_Bitmap; }
|
|
|
|
|
|
|
|
void DisposeImage();
|
|
|
|
void LoadImage(const std::wstring& imageName, bool bLoadAlways);
|
|
|
|
|
|
|
|
protected:
|
2010-12-06 08:59:55 +00:00
|
|
|
enum CROPMODE
|
|
|
|
{
|
|
|
|
CROPMODE_TL = 1,
|
|
|
|
CROPMODE_TR,
|
|
|
|
CROPMODE_BR,
|
|
|
|
CROPMODE_BL,
|
|
|
|
CROPMODE_C
|
|
|
|
};
|
|
|
|
|
2010-12-04 15:07:28 +00:00
|
|
|
void ApplyCrop();
|
2010-11-27 19:53:23 +00:00
|
|
|
void ApplyTint();
|
|
|
|
void ApplyTransform();
|
|
|
|
|
2012-01-09 18:13:22 +00:00
|
|
|
Gdiplus::Bitmap* LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize, HGLOBAL* phBuffer);
|
2011-01-29 00:11:01 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
static Gdiplus::Bitmap* TurnGreyscale(Gdiplus::Bitmap* source);
|
2011-02-07 09:38:27 +00:00
|
|
|
static bool CompareColorMatrix(const Gdiplus::ColorMatrix* a, const Gdiplus::ColorMatrix* b);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2012-05-20 17:57:12 +00:00
|
|
|
Gdiplus::Bitmap* m_Bitmap;
|
|
|
|
Gdiplus::Bitmap* m_BitmapTint; // Tinted bitmap
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2012-05-30 18:51:06 +00:00
|
|
|
const WCHAR* m_Name;
|
|
|
|
const WCHAR** m_OptionArray;
|
2010-11-27 19:53:23 +00:00
|
|
|
const bool m_DisableTransform;
|
|
|
|
|
2010-12-04 15:07:28 +00:00
|
|
|
bool m_NeedsCrop;
|
2010-11-27 19:53:23 +00:00
|
|
|
bool m_NeedsTinting;
|
|
|
|
bool m_NeedsTransform;
|
|
|
|
|
2010-12-04 15:07:28 +00:00
|
|
|
Gdiplus::Rect m_Crop;
|
2010-12-05 15:34:37 +00:00
|
|
|
CROPMODE m_CropMode;
|
2010-11-27 19:53:23 +00:00
|
|
|
bool m_GreyScale;
|
2011-02-07 09:38:27 +00:00
|
|
|
Gdiplus::ColorMatrix* m_ColorMatrix;
|
2010-11-27 19:53:23 +00:00
|
|
|
Gdiplus::RotateFlipType m_Flip;
|
|
|
|
Gdiplus::REAL m_Rotate;
|
2013-05-10 19:33:26 +00:00
|
|
|
bool m_UseExifOrientation;
|
2013-06-08 05:45:28 +00:00
|
|
|
|
2013-06-07 19:35:36 +00:00
|
|
|
std::wstring m_Path;
|
2013-06-08 05:45:28 +00:00
|
|
|
bool m_HasPathChanged;
|
2010-11-27 19:53:23 +00:00
|
|
|
|
2011-03-08 19:39:04 +00:00
|
|
|
std::wstring m_CacheKey;
|
|
|
|
|
2013-06-07 19:35:36 +00:00
|
|
|
MeterWindow* m_MeterWindow;
|
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
static const Gdiplus::ColorMatrix c_GreyScaleMatrix;
|
2011-11-01 04:56:46 +00:00
|
|
|
static const Gdiplus::ColorMatrix c_IdentityMatrix;
|
2011-02-07 09:38:27 +00:00
|
|
|
|
2012-06-01 13:06:36 +00:00
|
|
|
static const WCHAR* c_DefaultOptionArray[OptionCount];
|
2010-11-27 19:53:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|