Skip to content

Commit b60f44f

Browse files
committed
Fix exr write alpha value
1 parent df65d08 commit b60f44f

File tree

3 files changed

+86
-27
lines changed

3 files changed

+86
-27
lines changed

HDR10Capture2019/MLConverter.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <ctgmath>
33
#include <assert.h>
44
#include <algorithm>
5+
#include <Windows.h>
56

67
static uint32_t
78
NtoHL(uint32_t v)
@@ -36,7 +37,7 @@ static const float pq_c3 = 18.6875f; // ( 2392.0 / 4096.0 ) * 32.0;
3637
static const float pq_C = 10000.0f;
3738

3839
static float
39-
ST2084toLinear(float v) {
40+
ST2084toExrLinear(float v) {
4041
float Np = pow(v, 1.0f / pq_m2);
4142
float L = Np - pq_c1;
4243
if (L < 0.0f) {
@@ -51,13 +52,19 @@ MLConverter::MLConverter(void)
5152
{
5253
// ガンマ変換テーブル作成。
5354
for (int i = 0; i < 1024; ++i) {
54-
float v = (float)i / 1023;
55+
float v = (float)i / 1023.0f;
5556

5657
float g22 = v < 0.04045f ? v / 12.92f : pow(abs(v + 0.055f) / 1.055f, 2.4f);
5758
mGammaInv22_10bit[i] = g22;
5859

59-
float st2084 = ST2084toLinear(v);
60+
float st2084 = ST2084toExrLinear(v);
6061
mGammaInvST2084_10bit[i] = st2084;
62+
63+
/*
64+
char s[256];
65+
sprintf_s(s, "%d, %f, %f\n", i, g22, st2084);
66+
OutputDebugStringA(s);
67+
*/
6168
}
6269
}
6370

@@ -149,10 +156,9 @@ MLConverter::Rgb10bitToR10G10B10A2(const uint32_t* pFrom, uint32_t* pTo, const i
149156
void
150157
MLConverter::R10G10B10A2ToExrHalfFloat(const uint32_t* pFrom, uint16_t* pTo, const int width, const int height, const uint8_t alpha, GammaType gamma)
151158
{
152-
uint32_t a = alpha << 2;
153-
if (alpha == 0xff) {
154-
a = 0x3ff;
155-
}
159+
// アルファチャンネルは別の計算式。
160+
// 0.0~1.0の範囲の値。
161+
half aF = (float)(alpha /255.0f);
156162

157163
int readPos = 0;
158164
int writePos = 0;
@@ -163,17 +169,18 @@ MLConverter::R10G10B10A2ToExrHalfFloat(const uint32_t* pFrom, uint16_t* pTo, con
163169
// XXRRRRRR RRRRGGGG GGGGGGBB BBBBBBBB
164170
// --987654 32109876 54321098 76543210
165171

172+
// 10bit RGB値。
166173
const uint32_t r = (v >> 20) & 0x3ff;
167174
const uint32_t g = (v >> 10) & 0x3ff;
168175
const uint32_t b = (v >> 0) & 0x3ff;
169176

170177
switch (gamma){
171178
case GT_SDR_22:
172179
{
173-
const half rF = mGammaInv22_10bit[r];
174-
const half gF = mGammaInv22_10bit[g];
175-
const half bF = mGammaInv22_10bit[b];
176-
const half aF = mGammaInv22_10bit[a];
180+
const half& rF = mGammaInv22_10bit[r];
181+
const half& gF = mGammaInv22_10bit[g];
182+
const half& bF = mGammaInv22_10bit[b];
183+
// アルファチャンネルは別の計算式。
177184
pTo[writePos + 0] = bF.bits();
178185
pTo[writePos + 1] = gF.bits();
179186
pTo[writePos + 2] = rF.bits();
@@ -182,10 +189,10 @@ MLConverter::R10G10B10A2ToExrHalfFloat(const uint32_t* pFrom, uint16_t* pTo, con
182189
break;
183190
case GT_HDR_PQ:
184191
{
185-
const half rF = mGammaInvST2084_10bit[r];
186-
const half gF = mGammaInvST2084_10bit[g];
187-
const half bF = mGammaInvST2084_10bit[b];
188-
const half aF = mGammaInvST2084_10bit[a];
192+
const half& rF = mGammaInvST2084_10bit[r];
193+
const half& gF = mGammaInvST2084_10bit[g];
194+
const half& bF = mGammaInvST2084_10bit[b];
195+
// アルファチャンネルは別の計算式。
189196
pTo[writePos + 0] = bF.bits();
190197
pTo[writePos + 1] = gF.bits();
191198
pTo[writePos + 2] = rF.bits();

HDR10Capture2019/MLDX12App.cpp

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ MLDX12App::ShowVideoCaptureWindow(void)
10971097

10981098
if (MLIF_Unknown != aviIF) {
10991099
ImGui::InputText("Record AVI filename ##VCS", mAviFilePath, sizeof mAviFilePath - 1);
1100-
if (ImGui::Button("Record ## VCS", ImVec2(256, 64))) {
1100+
if (ImGui::Button("Record ## VCS", ImVec2(256, 48))) {
11011101
wchar_t path[512];
11021102
memset(path, 0, sizeof path);
11031103
MultiByteToWideChar(CP_UTF8, 0, mAviFilePath, sizeof mAviFilePath, path, 511);
@@ -1316,6 +1316,35 @@ MLDX12App::ShowSettingsWindow(void) {
13161316
ImGui::End();
13171317
}
13181318

1319+
enum ExtensionType {
1320+
ET_PNG,
1321+
ET_EXR,
1322+
ET_BMP,
1323+
ET_Other,
1324+
};
1325+
1326+
static ExtensionType
1327+
PathNameToExtensionType(const char* path)
1328+
{
1329+
assert(path);
1330+
1331+
int len = (int)strlen(path);
1332+
if (len < 5) {
1333+
return ET_Other;
1334+
}
1335+
1336+
if (0 == _stricmp(&path[len - 4], ".PNG")) {
1337+
return ET_PNG;
1338+
}
1339+
if (0 == _stricmp(&path[len - 4], ".EXR")) {
1340+
return ET_EXR;
1341+
}
1342+
if (0 == _stricmp(&path[len - 4], ".BMP")) {
1343+
return ET_BMP;
1344+
}
1345+
return ET_Other;
1346+
}
1347+
13191348
void
13201349
MLDX12App::ShowImageFileRWWindow(void) {
13211350
int hr = S_OK;
@@ -1332,21 +1361,43 @@ MLDX12App::ShowImageFileRWWindow(void) {
13321361

13331362
if (mState == S_Capturing) {
13341363
// キャプチャー中。
1335-
ImGui::InputText("OpenEXR Image Filename to Write", mImgFilePath, sizeof mImgFilePath - 1);
1364+
ImGui::InputText("PNG / EXR Image Filename to Write", mImgFilePath, sizeof mImgFilePath - 1);
13361365

13371366
if (mWriteImg.data != nullptr) {
1338-
if (ImGui::Button("Write OpenEXR ##RF0")) {
1339-
hr = MLExrWrite(mImgFilePath, mWriteImg);
1367+
// 静止画をファイルに保存する。
1368+
1369+
ExtensionType et = PathNameToExtensionType(mImgFilePath);
1370+
switch (et) {
1371+
case ET_PNG:
1372+
if (ImGui::Button("Write PNG Image ##RF0", ImVec2(256, 48))) {
1373+
hr = MLPngWrite(mImgFilePath, mWriteImg);
13401374

1341-
if (FAILED(hr)) {
1342-
sprintf_s(mErrorFileReadMsg, "Write Image Failed.\nFile Write error : %s", mImgFilePath);
1343-
ImGui::OpenPopup("ErrorImageFileRWPopup");
1375+
if (FAILED(hr)) {
1376+
sprintf_s(mErrorFileReadMsg, "Write Image Failed.\nFile Write error : %s", mImgFilePath);
1377+
ImGui::OpenPopup("ErrorImageFileRWPopup");
1378+
}
1379+
}
1380+
break;
1381+
case ET_EXR:
1382+
if (ImGui::Button("Write EXR Image ##RF0", ImVec2(256, 48))) {
1383+
hr = MLExrWrite(mImgFilePath, mWriteImg);
1384+
1385+
if (FAILED(hr)) {
1386+
sprintf_s(mErrorFileReadMsg, "Write Image Failed.\nFile Write error : %s", mImgFilePath);
1387+
ImGui::OpenPopup("ErrorImageFileRWPopup");
1388+
}
13441389
}
1390+
break;
1391+
default:
1392+
ImGui::Text("Cannot save image file: Unknown file extension.");
1393+
break;
13451394
}
13461395
}
13471396
} else {
13481397
ImGui::InputText("EXR/PNG/BMP Image Filename to Read", mImgFilePath, sizeof mImgFilePath - 1);
1349-
if (ImGui::Button("Read ##RF0")) {
1398+
1399+
if (ImGui::Button("Read Image ##RF0", ImVec2(256, 48))) {
1400+
13501401
mMutex.lock();
13511402
hr = MLBmpRead(mImgFilePath, mRenderImg);
13521403
if (hr == 1) {
@@ -1374,6 +1425,7 @@ void
13741425
MLDX12App::ImGuiCommands(void) {
13751426
if (mShowImGui) {
13761427
//ImGui::ShowDemoWindow();
1428+
13771429
// 順番が重要。キャプチャー画像を保存するため。
13781430
ShowVideoCaptureWindow();
13791431
ShowImageFileRWWindow();

HDR10Capture2019/Resource.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
6161
//
6262

6363
VS_VERSION_INFO VERSIONINFO
64-
FILEVERSION 1,0,0,1
65-
PRODUCTVERSION 1,0,0,1
64+
FILEVERSION 1,1,0,1
65+
PRODUCTVERSION 1,1,0,1
6666
FILEFLAGSMASK 0x3fL
6767
#ifdef _DEBUG
6868
FILEFLAGS 0x1L
@@ -79,12 +79,12 @@ BEGIN
7979
BEGIN
8080
VALUE "CompanyName", "TODO: <Company name>"
8181
VALUE "FileDescription", "HDR10Capture"
82-
VALUE "FileVersion", "1.0.0.1"
82+
VALUE "FileVersion", "1.1.0.1"
8383
VALUE "InternalName", "HDR10Capture"
8484
VALUE "LegalCopyright", "Copyright (C) 2020"
8585
VALUE "OriginalFilename", "HDR10Capture.exe"
8686
VALUE "ProductName", "HDR10Capture"
87-
VALUE "ProductVersion", "1.0.0.1"
87+
VALUE "ProductVersion", "1.1.0.1"
8888
END
8989
END
9090
BLOCK "VarFileInfo"

0 commit comments

Comments
 (0)