Skip to content

Commit b25a7f6

Browse files
committed
HDR10Capture Drag Drop support
1 parent 178ddbe commit b25a7f6

18 files changed

+150
-90
lines changed

AviToExrSequence/Main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ Process(const wchar_t* inAviPath, const char* outExrPrefix, const bool PQ) {
2525
return false;
2626
}
2727

28+
MLConverter::ColorSpace cs = MLConverter::CS_Rec709;
2829
MLColorGamutType gamut = ML_CG_Rec709;
2930
MLImage::GammaType gamma = MLImage::MLG_G22;
3031
if (PQ) {
32+
cs = MLConverter::CS_Rec2020;
3133
gamut = ML_CG_Rec2020;
3234
gamma = MLImage::MLG_ST2084;
3335
}
@@ -70,6 +72,7 @@ Process(const wchar_t* inAviPath, const char* outExrPrefix, const bool PQ) {
7072

7173
if (imgFmt.biCompression == MLStringToFourCC("v210")) {
7274
conv.Yuv422_10bitToR10G10B10A2(
75+
cs,
7376
(const uint32_t*)buf1,
7477
(uint32_t*)buf2,
7578
imgFmt.biWidth, imgFmt.biHeight, 0xff);

HDR10Capture2019/MLBmpReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
/// BMPファイルを読む。
99
/// </summary>
1010
/// <returns>0:成功。負の数:失敗。1:BMPファイルでは無かった。</returns>
11-
int MLBmpRead(const char* filePath, MLImage& img_return) {
11+
int MLBmpRead(const wchar_t* filePath, MLImage& img_return) {
1212
FILE* fp = nullptr;
1313

14-
int ercd = fopen_s(&fp, filePath, "rb");
14+
int ercd = _wfopen_s(&fp, filePath, L"rb");
1515
if (ercd != 0 || fp == nullptr) {
1616
return E_FAIL;
1717
}

HDR10Capture2019/MLBmpReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
/// BMPファイルを読む。
77
/// </summary>
88
/// <returns>0:成功。負の数:失敗。1:BMPファイルでは無かった。</returns>
9-
int MLBmpRead(const char* filePath, MLImage& img_return);
9+
int MLBmpRead(const wchar_t* filePath, MLImage& img_return);

PngToBmp/MLBmpWriter.cpp renamed to HDR10Capture2019/MLBmpWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ FloatToUint16(float v) {
1818
/// 24bit BMP または 48bit BMPファイルを書き込む。
1919
/// </summary>
2020
/// <returns>0:成功。負の数:失敗。</returns>
21-
int MLBmpWrite(const char* filePath, MLImage& img)
21+
int MLBmpWrite(const wchar_t* filePath, MLImage& img)
2222
{
2323
FILE* fp = nullptr;
24-
int ercd = fopen_s(&fp, filePath, "wb");
24+
int ercd = _wfopen_s(&fp, filePath, L"wb");
2525
if (ercd != 0 || fp == nullptr) {
26-
printf("Error: MLBmpWrite fopen failed. %s\n", filePath);
26+
printf("Error: MLBmpWrite fopen failed. %S\n", filePath);
2727
return E_FAIL;
2828
}
2929

3030
int64_t imgBytes = 0;
3131
uint8_t* imgTo = nullptr;
3232
int biBitCount = 0;
33-
if (img.bitFormat == MLImage::BFT_UInt8) {
33+
if (img.bitFormat == MLImage::BFT_UIntR8G8B8A8) {
3434
// 24bit BGR画像データ作成。
3535
biBitCount = 24;
3636
imgBytes = (int64_t)img.width * img.height * 3 * sizeof(uint8_t); // 3==書き込みデータのnumCh

PngToBmp/MLBmpWriter.h renamed to HDR10Capture2019/MLBmpWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/// 48bit BMPファイルを書き込む。
77
/// </summary>
88
/// <returns>0:成功。負の数:失敗。</returns>
9-
int MLBmpWrite(const char* filePath, MLImage& img);
9+
int MLBmpWrite(const wchar_t* filePath, MLImage& img);
1010

HDR10Capture2019/MLDX12.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44
#include "Common.h"
55
#include "d3dx12.h"
6+
#include <shellapi.h> //< HDROP
67

78
class MLDX12 {
89
public:
@@ -15,6 +16,7 @@ class MLDX12 {
1516
virtual void OnDestroy(void) = 0;
1617
virtual void OnKeyDown(int key) = 0;
1718
virtual void OnKeyUp(int key) = 0;
19+
virtual void OnDropFiles(HDROP hDrop) = 0;
1820
virtual void OnSizeChanged(int width, int height, bool minimized) = 0;
1921
void SetWindowBounds(int left, int top, int right, int bottom);
2022

HDR10Capture2019/MLDX12App.cpp

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ MLDX12App::MLDX12App(UINT width, UINT height, UINT options)
4747
// 設定を読み出します。
4848
std::string imgPath = mSettings.LoadStringA("ImgFilePath");
4949
if (imgPath.empty()) {
50-
strcpy_s(mImgFilePath, "c:/data/OpenEXR_HDR10_test1.exr");
50+
wcscpy_s(mImgFilePath, L"c:/data/OpenEXR_HDR10_test1.exr");
5151
} else {
52-
strcpy_s(mImgFilePath, imgPath.c_str());
52+
memset(mImgFilePath, 0, sizeof mImgFilePath);
53+
MultiByteToWideChar(CP_UTF8, 0, imgPath.c_str(), -1, mImgFilePath, _countof(mImgFilePath)-1);
5354
}
5455
std::string aviPath = mSettings.LoadStringA("AviFilePath");
5556
if (aviPath.empty()) {
56-
strcpy_s(mAviFilePath, "D:/test.avi");
57+
wcscpy_s(mAviFilePath, L"D:/test.avi");
5758
} else {
58-
strcpy_s(mAviFilePath, aviPath.c_str());
59+
memset(mAviFilePath, 0, sizeof mAviFilePath);
60+
MultiByteToWideChar(CP_UTF8, 0, aviPath.c_str(), -1, mAviFilePath, _countof(mAviFilePath) - 1);
5961
}
6062

6163
int outOfRangeR = mSettings.LoadInt("OutOfRangeR", 0);
@@ -75,8 +77,17 @@ MLDX12App::MLDX12App(UINT width, UINT height, UINT options)
7577

7678
MLDX12App::~MLDX12App(void)
7779
{
78-
mSettings.SaveStringA("ImgFilePath", mImgFilePath);
79-
mSettings.SaveStringA("AviFilePath", mAviFilePath);
80+
// WriteToFile()まで消えないバッファーを作る。
81+
char imgPath[MAX_PATH * 3];
82+
memset(imgPath, 0, sizeof imgPath);
83+
WideCharToMultiByte(CP_UTF8, 0, mImgFilePath, -1, imgPath, sizeof imgPath - 1, nullptr, nullptr);
84+
mSettings.SaveStringA("ImgFilePath", imgPath);
85+
86+
// WriteToFile()まで消えないバッファーを作る。
87+
char aviPath[MAX_PATH * 3];
88+
memset(aviPath, 0, sizeof aviPath);
89+
WideCharToMultiByte(CP_UTF8, 0, mAviFilePath, -1, aviPath, sizeof aviPath - 1, nullptr, nullptr);
90+
mSettings.SaveStringA("AviFilePath", aviPath);
8091

8192
int outOfRangeR = (int)(mShaderConsts.outOfRangeColor.x * 255.0f);
8293
int outOfRangeG = (int)(mShaderConsts.outOfRangeColor.y * 255.0f);
@@ -127,7 +138,7 @@ MLDX12App::OnInit(void)
127138

128139
if (argc == 2) {
129140
wchar_t* pathW = argv[1];
130-
WideCharToMultiByte(CP_UTF8, 0, pathW, -1, mImgFilePath, sizeof(mImgFilePath) - 1, nullptr, nullptr);
141+
wcscpy_s(mImgFilePath, pathW);
131142
ReadImg();
132143
}
133144
}
@@ -807,6 +818,15 @@ MLDX12App::OnKeyUp(int key)
807818
}
808819
}
809820

821+
void
822+
MLDX12App::OnDropFiles(HDROP hDrop)
823+
{
824+
UINT rv = DragQueryFile(hDrop, 0, mImgFilePath, _countof(mImgFilePath) - 1);
825+
if (0 < rv) {
826+
mRequestReadImg = true;
827+
}
828+
}
829+
810830
void
811831
MLDX12App::OnSizeChanged(int width, int height, bool minimized)
812832
{
@@ -1070,6 +1090,8 @@ void
10701090
MLDX12App::ShowVideoCaptureWindow(void)
10711091
{
10721092
HRESULT hr = S_OK;
1093+
char s[MAX_PATH * 3];
1094+
memset(s, 0, sizeof s);
10731095

10741096
ImGui::Begin("Video Capture Settings ##VCS");
10751097

@@ -1162,25 +1184,26 @@ MLDX12App::ShowVideoCaptureWindow(void)
11621184
MLAviImageFormat aviIF = BMDPixelFormatToMLAviImageFormat(fmt.pixelFormat);
11631185

11641186
if (MLIF_Unknown != aviIF) {
1165-
ImGui::InputText("Record AVI filename ##VCS", mAviFilePath, sizeof mAviFilePath - 1);
1187+
WideCharToMultiByte(CP_UTF8, 0, mAviFilePath, -1, s, sizeof s - 1, nullptr, nullptr);
1188+
if (ImGui::InputText("Record AVI filename ##VCS", s, sizeof s - 1)) {
1189+
// text Updated.
1190+
MultiByteToWideChar(CP_UTF8, 0, s, -1, mAviFilePath, _countof(mAviFilePath));
1191+
}
1192+
11661193
if (ImGui::Button("Record ## VCS", ImVec2(256, 48))) {
1167-
if (PathFileExistsA(mAviFilePath)) {
1168-
sprintf_s(mErrorVCMsg, "Error: File exists.\nPlease input different file name. %s", mAviFilePath);
1194+
if (PathFileExists(mAviFilePath)) {
1195+
sprintf_s(mErrorVCMsg, "Error: File exists.\nPlease input different file name.");
11691196
ImGui::OpenPopup("ErrorVCPopup");
11701197
} else {
1171-
wchar_t path[512];
1172-
memset(path, 0, sizeof path);
1173-
MultiByteToWideChar(CP_UTF8, 0, mAviFilePath, sizeof mAviFilePath, path, 511);
1174-
11751198
bool bRv = mVCU.AviWriter().Start(
1176-
path, fmt.width, fmt.height,
1199+
mAviFilePath, fmt.width, fmt.height,
11771200
(double)fmt.frameRateTS/fmt.frameRateTV,
11781201
aviIF, true);
11791202
if (bRv) {
11801203
mVCState = VCS_Recording;
11811204
mErrorVCMsg[0] = 0;
11821205
} else {
1183-
sprintf_s(mErrorVCMsg, "Error: Record Failed.\nFile open error : %s", mAviFilePath);
1206+
sprintf_s(mErrorVCMsg, "Error: Record Failed.\nFile open error.");
11841207
ImGui::OpenPopup("ErrorVCPopup");
11851208
}
11861209
}
@@ -1193,7 +1216,7 @@ MLDX12App::ShowVideoCaptureWindow(void)
11931216
break;
11941217
case VCS_Recording:
11951218
ImGui::Text("Now Recording...");
1196-
ImGui::Text("Record filename : %s", mAviFilePath);
1219+
ImGui::Text("Record filename : %S", mAviFilePath);
11971220
{
11981221
// hour:min:sec:frameを算出。
11991222
auto vt = MLFrameNrToTime((int)(mVCU.AviWriter().FramesPerSec()+0.5), mVCU.AviWriter().TotalVideoFrames());
@@ -1406,22 +1429,22 @@ enum ExtensionType {
14061429
};
14071430

14081431
static ExtensionType
1409-
PathNameToExtensionType(const char* path)
1432+
PathNameToExtensionType(const wchar_t* path)
14101433
{
14111434
assert(path);
14121435

1413-
int len = (int)strlen(path);
1436+
int len = (int)wcslen(path);
14141437
if (len < 5) {
14151438
return ET_Other;
14161439
}
14171440

1418-
if (0 == _stricmp(&path[len - 4], ".PNG")) {
1441+
if (0 == _wcsicmp(&path[len - 4], L".PNG")) {
14191442
return ET_PNG;
14201443
}
1421-
if (0 == _stricmp(&path[len - 4], ".EXR")) {
1444+
if (0 == _wcsicmp(&path[len - 4], L".EXR")) {
14221445
return ET_EXR;
14231446
}
1424-
if (0 == _stricmp(&path[len - 4], ".BMP")) {
1447+
if (0 == _wcsicmp(&path[len - 4], L".BMP")) {
14251448
return ET_BMP;
14261449
}
14271450
return ET_Other;
@@ -1432,20 +1455,29 @@ MLDX12App::ReadImg(void)
14321455
{
14331456
HRESULT hr = 0;
14341457

1458+
if (ET_Other == PathNameToExtensionType(mImgFilePath)) {
1459+
sprintf_s(mErrorFileReadMsg, "Error: Unsupported Image format.");
1460+
ImGui::OpenPopup("ErrorImageFileRWPopup");
1461+
return E_FAIL;
1462+
}
1463+
14351464
mMutex.lock();
14361465
hr = MLBmpRead(mImgFilePath, mRenderImg);
14371466
if (hr == 1) {
14381467
// ファイルは存在するがBMPではなかった場合。
14391468
hr = MLPngRead(mImgFilePath, mRenderImg);
14401469
if (hr == 1) {
14411470
// ファイルは存在するがPNGではなかった場合。
1442-
hr = MLExrRead(mImgFilePath, mRenderImg);
1471+
char s[MAX_PATH * 3];
1472+
memset(s, 0, sizeof s);
1473+
WideCharToMultiByte(CP_UTF8, 0, mImgFilePath, -1, s, sizeof s - 1, nullptr, nullptr);
1474+
hr = MLExrRead(s, mRenderImg);
14431475
}
14441476
}
14451477
mMutex.unlock();
14461478

14471479
if (hr < 0) {
1448-
sprintf_s(mErrorFileReadMsg, "Error: Read Image Failed.\nFile open error : %s", mImgFilePath);
1480+
sprintf_s(mErrorFileReadMsg, "Error: Read Image Failed.");
14491481
ImGui::OpenPopup("ErrorImageFileRWPopup");
14501482
} else {
14511483
mState = S_ImageViewing;
@@ -1458,6 +1490,9 @@ MLDX12App::ReadImg(void)
14581490
void
14591491
MLDX12App::ShowImageFileRWWindow(void)
14601492
{
1493+
char path[MAX_PATH];
1494+
memset(path, 0, sizeof path);
1495+
14611496
int hr = S_OK;
14621497
ImGui::Begin("File Read / Write");
14631498

@@ -1472,7 +1507,12 @@ MLDX12App::ShowImageFileRWWindow(void)
14721507

14731508
if (mState == S_Capturing) {
14741509
// キャプチャー中。
1475-
ImGui::InputText("PNG / EXR Image Filename to Write", mImgFilePath, sizeof mImgFilePath - 1);
1510+
memset(path, 0, sizeof path);
1511+
WideCharToMultiByte(CP_UTF8, 0, mImgFilePath, -1, path, sizeof path - 1, nullptr, nullptr);
1512+
if (ImGui::InputText("PNG / EXR Image Filename to Write", path, sizeof path - 1)) {
1513+
// text has changed. update mImgFilePath.
1514+
MultiByteToWideChar(CP_UTF8, 0, path, -1, mImgFilePath, _countof(mImgFilePath) - 1);
1515+
}
14761516

14771517
if (mWriteImg.data != nullptr) {
14781518
// 静止画をファイルに保存する。
@@ -1481,29 +1521,30 @@ MLDX12App::ShowImageFileRWWindow(void)
14811521
switch (et) {
14821522
case ET_PNG:
14831523
if (ImGui::Button("Write PNG Image ##RF0", ImVec2(256, 48))) {
1484-
if (PathFileExistsA(mImgFilePath)) {
1485-
sprintf_s(mErrorFileReadMsg, "Error: File exists.\nPlease input different file name. %s", mImgFilePath);
1524+
if (PathFileExists(mImgFilePath)) {
1525+
sprintf_s(mErrorFileReadMsg, "Error: File exists.\nPlease input different file name.");
14861526
ImGui::OpenPopup("ErrorImageFileRWPopup");
14871527
} else {
14881528
hr = MLPngWrite(mImgFilePath, mWriteImg);
14891529

14901530
if (FAILED(hr)) {
1491-
sprintf_s(mErrorFileReadMsg, "Error: Write Image Failed.\nFile Write error : %s", mImgFilePath);
1531+
sprintf_s(mErrorFileReadMsg, "Error: Write Image Failed.\nFile Write error.");
14921532
ImGui::OpenPopup("ErrorImageFileRWPopup");
14931533
}
14941534
}
14951535
}
14961536
break;
14971537
case ET_EXR:
14981538
if (ImGui::Button("Write EXR Image ##RF0", ImVec2(256, 48))) {
1499-
if (PathFileExistsA(mImgFilePath)) {
1500-
sprintf_s(mErrorFileReadMsg, "Error: File exists.\nPlease input different file name. %s", mImgFilePath);
1539+
if (PathFileExists(mImgFilePath)) {
1540+
sprintf_s(mErrorFileReadMsg, "Error: File exists.\nPlease input different file name.");
15011541

15021542
ImGui::OpenPopup("ErrorImageFileRWPopup");
15031543
} else {
1504-
hr = mExrWriter.Write(mImgFilePath, mWriteImg);
1544+
WideCharToMultiByte(CP_UTF8, 0, mImgFilePath, -1, path, sizeof path - 1, nullptr, nullptr);
1545+
hr = mExrWriter.Write(path, mWriteImg);
15051546
if (FAILED(hr)) {
1506-
sprintf_s(mErrorFileReadMsg, "Error: Write Image Failed.\nFile Write error : %s", mImgFilePath);
1547+
sprintf_s(mErrorFileReadMsg, "Error: Write Image Failed.\nFile Write error.");
15071548
ImGui::OpenPopup("ErrorImageFileRWPopup");
15081549
}
15091550
}
@@ -1515,10 +1556,17 @@ MLDX12App::ShowImageFileRWWindow(void)
15151556
}
15161557
}
15171558
} else {
1518-
ImGui::InputText("EXR/PNG/BMP Image Filename to Read", mImgFilePath, sizeof mImgFilePath - 1);
1559+
memset(path, 0, sizeof path);
1560+
WideCharToMultiByte(CP_UTF8, 0, mImgFilePath, -1, path, sizeof path - 1, nullptr, nullptr);
1561+
1562+
if (ImGui::InputText("EXR/PNG/BMP Image Filename to Read", path, sizeof path - 1)) {
1563+
// text has changed. update mImgFilePath.
1564+
MultiByteToWideChar(CP_UTF8, 0, path, -1, mImgFilePath, _countof(mImgFilePath) - 1);
1565+
}
15191566

1520-
if (ImGui::Button("Read Image ##RF0", ImVec2(256, 48))) {
1567+
if (mRequestReadImg || ImGui::Button("Read Image ##RF0", ImVec2(256, 48))) {
15211568
ReadImg();
1569+
mRequestReadImg = false;
15221570
}
15231571
}
15241572

HDR10Capture2019/MLDX12App.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MLDX12App : public MLDX12, IMLVideoCapUserCallback {
3939
virtual void OnDestroy(void);
4040
virtual void OnKeyDown(int key) { }
4141
virtual void OnKeyUp(int key);
42+
virtual void OnDropFiles(HDROP hDrop);
4243
virtual void OnSizeChanged(int width, int height, bool minimized);
4344

4445
enum OptionsEnum {
@@ -147,7 +148,8 @@ class MLDX12App : public MLDX12, IMLVideoCapUserCallback {
147148
char mErrorSettingsMsg[512] = {};
148149
char mErrorFileReadMsg[512] = {};
149150

150-
char mImgFilePath[512] = {};
151+
wchar_t mImgFilePath[512] = {};
152+
bool mRequestReadImg = false;
151153

152154
ComPtr<ID3D12GraphicsCommandList> mCmdListTexUpload;
153155
ComPtr<ID3D12CommandAllocator> mCmdAllocatorTexUpload;
@@ -207,7 +209,7 @@ class MLDX12App : public MLDX12, IMLVideoCapUserCallback {
207209
};
208210
VideoCaptureState mVCState = VCS_PreInit;
209211
char mErrorVCMsg[512] = {};
210-
char mAviFilePath[512] = {};
212+
wchar_t mAviFilePath[512] = {};
211213
MLImage::GammaType mCaptureImgGamma = MLImage::MLG_G22;
212214
void MLVideoCapUserCallback_VideoInputFormatChanged(const MLVideoCaptureVideoFormat & vFmt);
213215

0 commit comments

Comments
 (0)