-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImgItem.h
104 lines (101 loc) · 3.1 KB
/
ImgItem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once
#include "ImgBitmap.h"
#include "ImgBuffer.h"
#include "ImgSettings.h"
#include "FileMapView.h"
#include "3rd-party\Little-CMS\lcms2.h"
#include <Windows.h>
#include <Shlwapi.h>
#include <string>
#include <iomanip>
#include <sstream>
#include <stdexcept>
class ImgItem
{
public:
static constexpr auto kResizePercentThreshold = 0.025l;
static constexpr auto kDefaultICCProfileFilename = L"default.icc";
public:
enum class Format
{
JPEG,
PNG,
Other,
Unsupported
};
enum class Status
{
Queued,
Loading,
Ready,
Error
};
public:
ImgItem(std::wstring filepath, INT targetwidth, INT targetheight)
: filepath_(filepath), targetwidth_(targetwidth), targetheight_(targetheight)
{
loadedevent_ = CreateEvent(NULL, TRUE, FALSE, NULL);
heap_ = GetProcessHeap();
}
virtual ~ImgItem()
{
if (pbitmapinfo_ != nullptr)
{
HeapFree(heap_, 0, pbitmapinfo_);
}
CloseICCProfile();
CloseHandle(loadedevent_);
}
ImgItem(const ImgItem&) = delete;
ImgItem& operator=(const ImgItem&) = delete;
virtual void Load() = 0;
virtual void Unload();
Status status() const { return status_; }
BOOL iccprofileloadfailed() const { return iccprofileloadfailed_; }
std::wstring errormessage() const { return errormessage_; }
INT displaywidth() const { return displaybuffer_.width(); }
INT displayheight() const { return displaybuffer_.height(); }
INT offsetx() const { return offsetx_; }
INT offsety() const { return offsety_; }
HANDLE loadedevent() const { return loadedevent_; }
ImgBitmap GetDisplayBitmap() const;
static void LoadDefaultICCProfile();
static void UnloadDefaultICCProfile();
protected:
std::wstring filepath_;
INT targetwidth_;
INT targetheight_;
INT width_{};
INT height_{};
INT offsetx_{};
INT offsety_{};
ImgBuffer displaybuffer_;
Status status_{ Status::Queued };
std::wstring errormessage_;
HANDLE loadedevent_{ NULL };
HANDLE heap_{ INVALID_HANDLE_VALUE };
protected:
void SetupDisplayParameters() { SetupDisplayParameters(FALSE); }
void SetupDisplayParameters(BOOL topdownbitmap);
void OpenICCProfile(const PBYTE iccprofiledata, UINT iccprofiledatabytecount);
BOOL IsICCProfileLoaded() const { return iccprofile_ != nullptr; }
BOOL TranformCMYK8ColorsToBGR8(INT width, INT height, INT stride, INT newstride, PBYTE* buffer);
void CloseICCProfile();
private:
static cmsHPROFILE DefaultICCProfile;
static CRITICAL_SECTION DefaultICCProfileCriticalSection;
static struct DefaultICCProfileCriticalSectionInitializer
{
DefaultICCProfileCriticalSectionInitializer()
{
if (!InitializeCriticalSectionAndSpinCount(&DefaultICCProfileCriticalSection, 0x00000400))
{
// TODO: handle error
}
}
} defaultICCProfileCriticalSectionInitializer;
private:
PBITMAPINFO pbitmapinfo_{ nullptr };
cmsHPROFILE iccprofile_{ nullptr };
BOOL iccprofileloadfailed_{};
};