Skip to content

Commit 8c58f73

Browse files
committed
1.6.0.0
1 parent 311953e commit 8c58f73

File tree

6 files changed

+136
-145
lines changed

6 files changed

+136
-145
lines changed

Visual Studio 2022/ps-image/Source/app.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99

1010
std::unique_ptr<Global_Application> G = std::make_unique<Global_Application>();
1111

12-
std::function<void()> CreateModalFunc = []() {};
13-
14-
std::function<void()> SearchModalFunc = []() {};
15-
16-
std::function<void(float, bool&)> SearchModalCb = [](float, bool&) {};
17-
18-
std::function<void()> SaveAllFunc = []() {};
19-
20-
static String ImGuiIniFilename = "";
21-
22-
static ImGuiContext* Context = nullptr;
23-
2412
void Global_Application::About(void) const
2513
{
2614
Standard_String Str;
@@ -226,7 +214,8 @@ void Global_Application::Shutdown(void)
226214
do { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } while (b_Searching);
227215
}
228216

229-
if (ToolbarIcons) { ToolbarIcons->Release(); ToolbarIcons = nullptr; }
217+
b_ToolbarIconsOnBoot = false;
218+
m_ToolbarIcons.reset();
230219

231220
Render->Shutdown();
232221

@@ -239,7 +228,7 @@ void Global_Application::Shutdown(void)
239228
//ImGui_ImplDX9_Shutdown();
240229
//ImGui_ImplWin32_Shutdown();
241230

242-
//ImGui::DestroyContext(Context);
231+
//ImGui::DestroyContext(Context.get());
243232

244233
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
245234

@@ -250,6 +239,8 @@ void Global_Application::Shutdown(void)
250239

251240
void Global_Application::DragAndDrop(StrVecW Files)
252241
{
242+
Window->ClearDroppedFiles();
243+
253244
/*for (std::size_t i = 0; i < Files.size(); i++)
254245
{
255246
StringW FileExtension = FS.GetFileExtension(Files[i]).wstring();
@@ -263,8 +254,6 @@ void Global_Application::DragAndDrop(StrVecW Files)
263254
}*/
264255

265256
if (!Files.empty()) { TextureIO(Files[0], ImageIO::All); }
266-
267-
Window->ClearDroppedFiles();
268257
}
269258

270259
void Global_Application::Commandline(StrVecW Args)
@@ -312,10 +301,10 @@ int Global_Application::Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWST
312301
Commandline(Window->GetCommandline(lpCmdLine));
313302
}
314303
{
315-
ImGuiIniFilename = GetImGuiConfigFilename().string();
304+
m_ConfigStr = GetImGuiConfigFilename().string();
316305

317306
IMGUI_CHECKVERSION();
318-
Context = ImGui::CreateContext();
307+
Context.reset(ImGui::CreateContext());
319308
ImGui::StyleColorsDark();
320309

321310
{
@@ -347,7 +336,7 @@ int Global_Application::Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWST
347336
}
348337

349338
ImGuiIO& io = ImGui::GetIO();
350-
io.IniFilename = ImGuiIniFilename.c_str();
339+
io.IniFilename = m_ConfigStr.c_str();
351340
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
352341
io.Fonts->Clear();
353342
io.Fonts->AddFontFromFileTTF(Window->GetFont().string().c_str(), Window->FontSize());
@@ -423,6 +412,8 @@ int Global_Application::Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWST
423412

424413
D3DXIMAGE_INFO ImageInfo{};
425414

415+
IDirect3DTexture9* ToolbarIcons = nullptr;
416+
426417
if (FS.Exists(GetToolbarIconFilename()))
427418
{
428419
if (!FAILED(D3DXCreateTextureFromFileExW(Render->Device(),
@@ -436,6 +427,7 @@ int Global_Application::Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWST
436427
D3DX_DEFAULT,
437428
D3DCOLOR_XRGB(255, 255, 255), &ImageInfo, NULL, &ToolbarIcons)))
438429
{
430+
m_ToolbarIcons.reset(ToolbarIcons);
439431
b_ToolbarIconsOnBoot = true;
440432
}
441433
}
@@ -452,6 +444,7 @@ int Global_Application::Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWST
452444
D3DX_DEFAULT,
453445
D3DCOLOR_XRGB(255, 255, 255), &ImageInfo, NULL, &ToolbarIcons)))
454446
{
447+
m_ToolbarIcons.reset(ToolbarIcons);
455448
b_ToolbarIconsOnBoot = true;
456449
}
457450
}

Visual Studio 2022/ps-image/Source/app.h

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ typedef class Global_Application Global;
2525

2626
extern std::unique_ptr<Global_Application> G;
2727

28-
extern std::function<void()> CreateModalFunc;
29-
30-
extern std::function<void()> SearchModalFunc;
31-
extern std::function<void(float, bool&)> SearchModalCb;
32-
33-
extern std::function<void()> SaveAllFunc;
34-
3528
extern LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
3629
extern LRESULT CALLBACK RenderProc(HWND, UINT, WPARAM, LPARAM);
3730

@@ -42,10 +35,19 @@ class Global_Application final {
4235

4336
Standard_FileSystem FS;
4437

45-
std::unique_ptr<Sony_PlayStation_Texture> m_Texture;
38+
String m_ConfigStr;
39+
40+
std::function<void()> CreateModalFunc;
41+
42+
std::function<void()> SearchModalFunc;
43+
std::function<void(float, bool&)> SearchModalCb;
44+
45+
std::function<void()> SaveAllFunc;
4646

47-
IDirect3DTexture9* ToolbarIcons;
48-
IDirect3DTexture9* DXTexture;
47+
std::unique_ptr<ImGuiContext, decltype(&ImGui::DestroyContext)> Context;
48+
49+
std::unique_ptr<IDirect3DTexture9, IDirect3DTexture9Delete> m_DXTexture;
50+
std::unique_ptr<IDirect3DTexture9, IDirect3DTexture9Delete> m_ToolbarIcons;
4951
D3DSURFACE_DESC m_TextureDesc;
5052
D3DTEXTUREFILTERTYPE m_TextureFilter;
5153

@@ -54,10 +56,12 @@ class Global_Application final {
5456
std::size_t m_SelectedFile;
5557
std::size_t m_PostSearchSelectedFile;
5658

59+
std::unique_ptr<Sony_PlayStation_Texture> m_Texture;
60+
5761
Sony_Texture_Create_Ex m_CreateInfo;
5862

59-
DWORD ClipboardColor;
60-
std::vector<Sony_Texture_16bpp> ClipboardPalette;
63+
std::vector<Sony_Pixel_16bpp> m_ClipboardPalette;
64+
DWORD m_ClipboardColor;
6165

6266
std::uint16_t m_Palette;
6367

@@ -73,22 +77,17 @@ class Global_Application final {
7377
std::uint16_t m_LastKnownPaletteCount;
7478
std::size_t m_LastKnownFileCount;
7579

76-
float m_ProgressBar;
77-
bool b_Searching;
78-
79-
bool b_ImageOnDisk;
80+
int m_BootWidth;
81+
int m_BootHeight;
82+
bool b_BootMaximized;
83+
bool b_BootFullscreen;
84+
bool b_ToolbarIconsOnBoot;
85+
bool b_OpenLastFileOnBoot;
8086

8187
bool b_RequestTextureReset;
8288
bool b_RequestFontChange;
83-
84-
float m_FontSizeMin;
85-
float m_FontSizeMax;
86-
87-
float m_ImageZoomMin;
88-
float m_ImageZoomMax;
89-
float m_ImageZoom;
90-
91-
bool b_Dithering;
89+
bool b_Shutdown;
90+
bool b_ForceShutdown;
9291

9392
bool b_ViewToolbar;
9493
bool b_ViewStatusbar;
@@ -99,16 +98,19 @@ class Global_Application final {
9998
bool b_ViewImageOptions;
10099
bool b_ViewVRAMWindow;
101100

102-
bool b_ToolbarIconsOnBoot;
103-
bool b_OpenLastFileOnBoot;
101+
float m_FontSizeMin;
102+
float m_FontSizeMax;
104103

105-
int m_BootWidth;
106-
int m_BootHeight;
107-
bool b_BootMaximized;
108-
bool b_BootFullscreen;
104+
float m_ImageZoomMin;
105+
float m_ImageZoomMax;
106+
float m_ImageZoom;
109107

110-
bool b_Shutdown;
111-
bool b_ForceShutdown;
108+
bool b_ImageOnDisk;
109+
110+
float m_ProgressBar;
111+
bool b_Searching;
112+
113+
bool b_Dithering;
112114

113115
[[nodiscard]] constexpr auto Texture() noexcept -> Sony_PlayStation_Texture&
114116
{
@@ -190,9 +192,10 @@ class Global_Application final {
190192
Render(std::make_unique<Standard_DirectX_9>()),
191193
Str(),
192194
FS(),
195+
m_ConfigStr(),
193196
m_Texture(nullptr),
194-
ToolbarIcons(nullptr),
195-
DXTexture(nullptr),
197+
m_ToolbarIcons(nullptr),
198+
m_DXTexture(nullptr),
196199
m_TextureDesc(),
197200
m_TextureFilter(D3DTEXF_NONE),
198201
m_Filename(),
@@ -205,8 +208,8 @@ class Global_Application final {
205208
b_RequestFontChange(false),
206209
b_RequestTextureReset(false),
207210
m_CreateInfo(),
208-
ClipboardColor(0),
209-
ClipboardPalette(),
211+
m_ClipboardColor(0),
212+
m_ClipboardPalette(),
210213
m_LastKnownBitsPerPixel(16),
211214
m_LastKnownWidth(1024),
212215
m_LastKnownHeight(512),
@@ -238,8 +241,13 @@ class Global_Application final {
238241
b_BootMaximized(false),
239242
b_BootFullscreen(false),
240243
b_Shutdown(false),
241-
b_ForceShutdown(false)
244+
b_ForceShutdown(false),
245+
Context(nullptr, &ImGui::DestroyContext)
242246
{
247+
CreateModalFunc = []() {};
248+
SearchModalFunc = []() {};
249+
SearchModalCb = [](float, bool&) {};
250+
SaveAllFunc = []() {};
243251
}
244252
~Global_Application(void) = default;
245253

Visual Studio 2022/ps-image/Source/app_file.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void Global_Application::Close(void)
1313

1414
if (m_Texture) { m_Texture.reset(); m_Texture = nullptr; }
1515

16-
if (Render->NormalState() && DXTexture) { DXTexture->Release(); DXTexture = nullptr; }
16+
if (Render->NormalState() && m_DXTexture) { m_DXTexture.reset(); }
1717

1818
m_Palette = 0;
1919

@@ -57,11 +57,9 @@ void Global_Application::ResetTexture(void)
5757

5858
if (Render->NormalState())
5959
{
60-
if (DXTexture) { DXTexture->Release(); }
60+
m_DXTexture.reset(Render->CreateTexture(m_Texture, m_Palette, Texture().TransparencyFlags(), Texture().TransparencyColor()));
6161

62-
DXTexture = Render->CreateTexture(m_Texture, m_Palette, Texture().TransparencyFlags(), Texture().TransparencyColor());
63-
64-
DXTexture->GetLevelDesc(0, &m_TextureDesc);
62+
m_DXTexture->GetLevelDesc(0, &m_TextureDesc);
6563
}
6664
}
6765
else { Close(); }
@@ -106,7 +104,7 @@ void Global_Application::Search(std::filesystem::path Filename)
106104
This->m_ProgressBar = 0.0f;
107105
This->b_Searching = true;
108106

109-
SearchModalCb = [&](float Progress, bool& b_Status) -> void
107+
This->SearchModalCb = [&](float Progress, bool& b_Status) -> void
110108
{
111109
This->m_ProgressBar = Progress;
112110
b_Status = This->b_Searching;
@@ -122,7 +120,7 @@ void Global_Application::Search(std::filesystem::path Filename)
122120

123121
External->Str.hWnd = This->Window->Get();
124122

125-
External->Search(Filename, 0, SearchModalCb, OnSearchCompleteCb);
123+
External->Search(Filename, 0, This->SearchModalCb, OnSearchCompleteCb);
126124
});
127125

128126
SearchModalFunc = [This]() -> void { This->SearchModal(); };
@@ -190,13 +188,13 @@ void Global_Application::MovePalette(std::uint16_t iPalette, bool Right)
190188
void Global_Application::CopyPalette(void)
191189
{
192190
if (!m_Texture) { return; }
193-
Texture().CopyPalette(ClipboardPalette, m_Palette);
191+
Texture().CopyPalette(m_ClipboardPalette, m_Palette);
194192
}
195193

196194
void Global_Application::PastePalette(void)
197195
{
198-
if (!m_Texture || ClipboardPalette.empty()) { return; }
199-
if (Texture().PastePalette(ClipboardPalette, m_Palette)) { b_RequestTextureReset = true; }
196+
if (!m_Texture || m_ClipboardPalette.empty()) { return; }
197+
if (Texture().PastePalette(m_ClipboardPalette, m_Palette)) { b_RequestTextureReset = true; }
200198
}
201199

202200
void Global_Application::AddPalette(void)
@@ -378,6 +376,7 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
378376
#endif
379377

380378
bool b_KnownFileExt = false;
379+
!b_KnownFileExt ? b_KnownFileExt = (m_FileExt == L".TM2") ? true : false : false;
381380
!b_KnownFileExt ? b_KnownFileExt = (m_FileExt == L".TIM") ? true : false : false;
382381
!b_KnownFileExt ? b_KnownFileExt = (m_FileExt == L".CLT") ? true : false : false;
383382
!b_KnownFileExt ? b_KnownFileExt = (m_FileExt == L".PXL") ? true : false : false;
@@ -391,6 +390,8 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
391390

392391
if ((!b_KnownFileExt || b_DefaultFileType) && !b_Import && !b_Write && !b_SaveAs && !b_SaveAll) { m_PostSearchSelectedFile = 0; Search(Filename); return; }
393392

393+
if ((m_FileExt == L".TM2") && b_SaveAs) { Str.Message(L"I/O Error: TIM2 output is not yet supported"); return; }
394+
394395
if (b_SaveAll)
395396
{
396397
if (!b_SupportedSaveType) { Str.Message(L"I/O Error: cannot save all as unknown file type"); return; }
@@ -444,7 +445,7 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
444445
#ifdef LIB_JPEG
445446
if (std::to_underlying(SaveAllType) & std::to_underlying(ImageType::JPG))
446447
{
447-
std::make_unique<Sony_PlayStation_Texture>(This->m_Filename, (size_t)This->File()[iCnt].first)->SaveJPG(
448+
std::make_unique<Sony_PlayStation_Texture>(This->m_Filename, (size_t)This->File()[iCnt].first)->SaveJPEG(
448449
Directory / This->Str.FormatCStyle(L"%ws_%04d_0x%08llx.jpg", This->m_Filename.stem().wstring().c_str(), iCnt, This->File()[iCnt].first), NULL, iPalette, b_Truncate);
449450
}
450451
#endif
@@ -493,7 +494,7 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
493494
if (m_FileExt == L".PNG" && !External->SavePNG(Filename, pSource, iPalette, b_Truncate)) { return; }
494495
#endif
495496
#ifdef LIB_JPEG
496-
if ((m_FileExt == L".JPG" || m_FileExt == L".JPEG") && !External->SaveJPG(Filename, pSource, iPalette, b_Truncate)) { return; }
497+
if ((m_FileExt == L".JPG" || m_FileExt == L".JPEG") && !External->SaveJPEG(Filename, pSource, iPalette, b_Truncate)) { return; }
497498
#endif
498499

499500
if (b_OpenOnComplete)
@@ -517,6 +518,7 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
517518

518519
External->Str.hWnd = Window->Get();
519520

521+
if (m_FileExt == L".TM2" && !External->OpenTIM2(Filename, pSource, b_Palette, b_Pixel)) { return; }
520522
if (m_FileExt == L".TIM" && !External->OpenTIM(Filename, pSource, b_Palette, b_Pixel)) { return; }
521523
if (m_FileExt == L".CLT" && !External->OpenCLT(Filename, pSource)) { return; }
522524
if (m_FileExt == L".PXL" && !External->OpenPXL(Filename, pSource)) { return; }
@@ -527,7 +529,7 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
527529
if (m_FileExt == L".PNG" && !External->OpenPNG(Filename, pSource)) { return; }
528530
#endif
529531
#ifdef LIB_JPEG
530-
if ((m_FileExt == L".JPG" || m_FileExt == L".JPEG") && !External->OpenJPG(Filename, pSource)) { return; }
532+
if ((m_FileExt == L".JPG" || m_FileExt == L".JPEG") && !External->OpenJPEG(Filename, pSource)) { return; }
531533
#endif
532534

533535
if (!b_Palette) { External->DeletePalette(NULL, true); }
@@ -581,7 +583,7 @@ void Global_Application::TextureIO(std::filesystem::path Filename, ImageIO Flags
581583
return;
582584
}
583585

584-
std::vector<Sony_Texture_16bpp> Palette = Texture().ConvertPalette(External->GetPalette(), External->GetPaletteColorMax(), Texture().GetPaletteColorMax());
586+
std::vector<Sony_Pixel_16bpp> Palette = Texture().ConvertPalette(External->GetPalette(), External->GetPaletteColorMax(), Texture().GetPaletteColorMax());
585587

586588
if (b_PaletteAdd)
587589
{
@@ -688,9 +690,9 @@ void Global_Application::TextureIO(ImageIO Flags, std::uintmax_t pSource, std::u
688690
{
689691
if (auto Filename = Window->GetOpenFilename(
690692
{ L"All files",
691-
L"Sony Texture Image", L"Sony Texture CLUT", L"Sony Texture Pixels", L"Sony Bitstream",
693+
L"Sony Texture Image", L"Sony Texture CLUT", L"Sony Texture Pixels", L"Sony Bitstream", L"Sony Texture Image 2",
692694
L"Bitmap Graphic", L"Microsoft RIFF Palette", L"Portable Network Graphics", L"Joint Photographic Experts Group" },
693-
{ L"*.*", L"*.tim", L"*.clt", L"*.pxl", L"*.bs", L"*.bmp", L"*.pal", L"*.png", L"*.jpg;*.jpeg" }
695+
{ L"*.*", L"*.tim", L"*.clt", L"*.pxl", L"*.bs", L"*.tm2", L"*.bmp", L"*.pal", L"*.png", L"*.jpg;*.jpeg" }
694696
); Filename.has_value())
695697
{ TextureIO(Filename.value(), Flags, pSource, iPalette, SaveAllType); }
696698
}

0 commit comments

Comments
 (0)