-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageRequest.h
More file actions
112 lines (103 loc) · 3.4 KB
/
Copy pathImageRequest.h
File metadata and controls
112 lines (103 loc) · 3.4 KB
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
105
106
107
108
109
110
111
112
#pragma once
#include <cstdint>
#include <string>
namespace ImageCore
{
// Size struct (removes dependency on FD2D Layout.h)
struct Size
{
float w, h;
};
enum class ImagePurpose
{
Thumbnail, // Thumbnail (small size)
Preview, // Preview (medium size)
FullResolution // Original resolution
};
struct ImageRequest
{
std::wstring source; // File path
ImagePurpose purpose; // Loading purpose
Size targetSize; // Target size for thumbnail/preview
bool srgb; // Whether to use sRGB color space
// If true, allow returning GPU-compressed DDS blocks (BCn) for GPU-native rendering.
// If false (e.g., D2D-only renderer), the decode pipeline returns CPU-displayable BGRA8 pixels.
bool allowGpuCompressedDDS;
uint32_t mipLevel; // Source mip to decode (DDS only)
ImageRequest()
: purpose(ImagePurpose::FullResolution)
, targetSize{ 0.0f, 0.0f }
, srgb(true)
, allowGpuCompressedDDS(true)
, mipLevel(0)
{
}
ImageRequest(const std::wstring& path, ImagePurpose p = ImagePurpose::FullResolution)
: source(path)
, purpose(p)
, targetSize{ 0.0f, 0.0f }
, srgb(true)
, allowGpuCompressedDDS(true)
, mipLevel(0)
{
}
};
// For cache key generation
inline bool operator==(const ImageRequest& a, const ImageRequest& b)
{
return a.source == b.source &&
a.purpose == b.purpose &&
a.targetSize.w == b.targetSize.w &&
a.targetSize.h == b.targetSize.h &&
a.srgb == b.srgb &&
a.allowGpuCompressedDDS == b.allowGpuCompressedDDS &&
a.mipLevel == b.mipLevel;
}
inline bool operator<(const ImageRequest& a, const ImageRequest& b)
{
if (a.source != b.source)
{
return a.source < b.source;
}
if (a.purpose != b.purpose)
{
return static_cast<int>(a.purpose) < static_cast<int>(b.purpose);
}
if (a.targetSize.w != b.targetSize.w)
{
return a.targetSize.w < b.targetSize.w;
}
if (a.targetSize.h != b.targetSize.h)
{
return a.targetSize.h < b.targetSize.h;
}
if (a.srgb != b.srgb)
{
return a.srgb < b.srgb;
}
if (a.allowGpuCompressedDDS != b.allowGpuCompressedDDS)
{
return a.allowGpuCompressedDDS < b.allowGpuCompressedDDS;
}
return a.mipLevel < b.mipLevel;
}
}
// Hash function for ImageRequest (specialization in std namespace)
namespace std
{
template<>
struct hash<ImageCore::ImageRequest>
{
size_t operator()(const ImageCore::ImageRequest& req) const
{
size_t h1 = hash<wstring>{}(req.source);
size_t h2 = static_cast<size_t>(req.purpose);
size_t h3 = hash<float>{}(req.targetSize.w);
size_t h4 = hash<float>{}(req.targetSize.h);
size_t h5 = hash<bool>{}(req.srgb);
size_t h6 = hash<bool>{}(req.allowGpuCompressedDDS);
size_t h7 = hash<uint32_t>{}(req.mipLevel);
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3) ^ (h5 << 4) ^ (h6 << 5) ^ (h7 << 6);
}
};
}