Skip to content

Commit 01b340e

Browse files
authored
Add support for the IPropertyStore interface for .jls files (#70)
1 parent 7f0729a commit 01b340e

38 files changed

+878
-276
lines changed

Directory.Build.props

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
<!-- Build to a folder outside the source folders, making it easier to clean. -->
99
<OutDir>$(MSBuildThisFileDirectory)build\bin\$(Platform)\$(Configuration)\</OutDir>
1010
<OutDir Condition="'$(Platform)'=='Win32'">$(MSBuildThisFileDirectory)build\bin\x86\$(Configuration)\</OutDir>
11-
12-
<!-- C++ temp files can be redirected. -->
13-
<IntDir>$(MSBuildThisFileDirectory)build\intermediate\$(MSBuildProjectName)\$(Platform)\$(Configuration)\</IntDir>
14-
<IntDir Condition="'$(Platform)'=='Win32'">$(MSBuildThisFileDirectory)build\intermediate\$(MSBuildProjectName)\x86\$(Configuration)\</IntDir>
11+
<IntDir>$(MSBuildThisFileDirectory)build\intermediate\$(Platform)\$(Configuration)\$(MSBuildProjectName)\</IntDir>
12+
<IntDir Condition="'$(Platform)'=='Win32'">$(MSBuildThisFileDirectory)build\intermediate\x86\$(Configuration)\$(MSBuildProjectName)\</IntDir>
1513

1614
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
1715

@@ -178,6 +176,7 @@
178176
<Optimization>MaxSpeed</Optimization>
179177
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
180178
<EnablePREfast>true</EnablePREfast> <!-- For release builds, enable the MS static analyzer build into the C++ compiler. -->
179+
<DisableAnalyzeExternal>true</DisableAnalyzeExternal>
181180
</ClCompile>
182181
<Link>
183182
<EnableCOMDATFolding>true</EnableCOMDATFolding>

jpegls-wic-codec.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyBugproneBranchClone/@EntryIndexedValue">DO_NOT_SHOW</s:String>
3+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyBugproneEmptyCatch/@EntryIndexedValue">DO_NOT_SHOW</s:String>
34
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyBugproneMisplacedWideningCast/@EntryIndexedValue">DO_NOT_SHOW</s:String>
45
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyClangDiagnosticMicrosoftCast/@EntryIndexedValue">DO_NOT_SHOW</s:String>
56
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyClangDiagnosticReservedMacroIdentifier/@EntryIndexedValue">DO_NOT_SHOW</s:String>
@@ -11,6 +12,7 @@
1112
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyHicppAvoidCArrays/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1213
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyHicppMultiwayPathsCovered/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1314
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyMiscUnusedParameters/@EntryIndexedValue">ERROR</s:String>
15+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyMiscUseInternalLinkage/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1416
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyModernizeAvoidCArrays/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1517
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyReadabilityMagicNumbers/@EntryIndexedValue">DO_NOT_SHOW</s:String>
1618
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClangTidyReadabilityNonConstParameter/@EntryIndexedValue">DO_NOT_SHOW</s:String>

spelling.dic

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
jlsfile
2727
fccd
2828
bugprone
29+
anymap

src/class_factory.ixx

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
export module class_factory;
55

6-
import <win.hpp>;
76
import winrt;
7+
import <win.hpp>;
88

99
import hresults;
10+
import util;
1011

1112
export template<typename Class>
1213
struct class_factory : winrt::implements<class_factory<Class>, IClassFactory>
@@ -27,7 +28,7 @@ struct class_factory : winrt::implements<class_factory<Class>, IClassFactory>
2728
}
2829
catch (...)
2930
{
30-
return winrt::to_hresult();
31+
return to_hresult();
3132
}
3233
}
3334

src/dll_main.cpp

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
// Copyright (c) Team CharLS.
1+
// SPDX-FileCopyrightText: © 2018 Team CharLS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
#include "macros.hpp"
54
#include "intellisense.hpp"
65
#include "version.hpp"
76

87
import std;
8+
import winrt;
99
import <win.hpp>;
1010

1111
import guids;
1212
import util;
1313
import hresults;
1414
import jpegls_bitmap_decoder;
1515
import jpegls_bitmap_encoder;
16+
import property_store;
17+
import "macros.hpp";
1618

1719
using std::array;
1820
using std::wstring;
@@ -104,6 +106,38 @@ void register_encoder()
104106
register_general_decoder_encoder_settings(id::jpegls_encoder, CATID_WICBitmapEncoders, L"JPEG-LS Encoder", formats);
105107
}
106108

109+
void register_property_store_file_extension(const wchar_t* file_extension)
110+
{
111+
registry::set_value(LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers\)"s + file_extension,
112+
L"", guid_to_string(id::property_store_class).c_str());
113+
114+
const auto sub_key = LR"(SOFTWARE\Classes\SystemFileAssociations\)"s + file_extension;
115+
registry::set_value(sub_key, L"ExtendedTileInfo", L"prop:System.ItemType;*System.DateModified;*System.Image.Dimensions");
116+
registry::set_value(
117+
sub_key, L"FullDetails",
118+
L"prop:System.PropGroup.Image;System.Image.Dimensions;System.Image.HorizontalSize;System.Image.VerticalSize;System."
119+
L"Image.BitDepth;System.PropGroup.FileSystem;System.ItemNameDisplay;System.ItemType;System.ItemFolderPathDisplay;"
120+
L"System.DateCreated;System.DateModified;System.Size;System.FileAttributes;System.OfflineAvailability;System."
121+
L"OfflineStatus;System.SharedWith;System.FileOwner;System.ComputerName");
122+
registry::set_value(sub_key, L"InfoTip",
123+
L"prop:System.ItemType;*System.DateModified;*System.Image.Dimensions;*System.Size");
124+
registry::set_value(sub_key, L"PreviewDetails",
125+
L"prop:*System.DateModified;*System.Image.Dimensions;*System.Size;*System.OfflineAvailability;"
126+
"*System.OfflineStatus;*System.DateCreated;*System.SharedWith");
127+
}
128+
129+
void register_property_store()
130+
{
131+
const wstring sub_key{LR"(SOFTWARE\Classes\CLSID\)" + guid_to_string(id::property_store_class)};
132+
133+
// COM co-create registration.
134+
const wstring inproc_server_sub_key{sub_key + LR"(\InprocServer32\)"};
135+
registry::set_value(inproc_server_sub_key, L"", get_module_path().c_str());
136+
registry::set_value(inproc_server_sub_key, L"ThreadingModel", L"Both");
137+
138+
register_property_store_file_extension(L".jls");
139+
}
140+
107141
HRESULT unregister(const GUID& class_id, const GUID& wic_category_id)
108142
{
109143
const wstring sub_key{LR"(SOFTWARE\Classes\CLSID\)" + guid_to_string(class_id)};
@@ -160,18 +194,22 @@ try
160194
if (class_id == id::jpegls_encoder)
161195
return create_jpegls_bitmap_encoder_factory(interface_id, result);
162196

163-
return CLASS_E_CLASSNOTAVAILABLE;
197+
if (class_id == id::property_store_class)
198+
return create_property_store_class_factory(interface_id, result);
199+
200+
return error_class_not_available;
164201
}
165202
catch (...)
166203
{
167-
return winrt::to_hresult();
204+
return to_hresult();
168205
}
169206

170207
HRESULT __stdcall DllRegisterServer()
171208
try
172209
{
173210
register_decoder();
174211
register_encoder();
212+
register_property_store();
175213

176214
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
177215

@@ -194,7 +232,7 @@ try
194232
}
195233
catch (...)
196234
{
197-
return winrt::to_hresult();
235+
return to_hresult();
198236
}
199237

200238
// ReSharper restore CppParameterNamesMismatch

src/guids.ixx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Team CharLS.
1+
// SPDX-FileCopyrightText: © 2019 Team CharLS
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
export module guids;
@@ -19,4 +19,7 @@ inline constexpr GUID jpegls_encoder{0x70a823ea, 0x9f, 0x402f, {0x9b, 0xda, 0xe9
1919
// {8adbe21c-a720-424e-b238-45ad1052b98c}
2020
inline constexpr GUID vendor_team_charls{0x8adbe21c, 0xa720, 0x424e, {0xb2, 0x38, 0x45, 0xad, 0x10, 0x52, 0xb9, 0x8c}};
2121

22+
// {9505939A-CDB9-4090-AAD4-7DA7032101BD}
23+
inline constexpr GUID property_store_class{0x9505939a, 0xcdb9, 0x4090, {0xaa, 0xd4, 0x7d, 0xa7, 0x3, 0x21, 0x1, 0xbd}};
24+
2225
} // namespace id

src/hresults.ixx

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ module;
88
export module hresults;
99

1010
import <win.hpp>;
11-
import winrt;
1211

1312
export {
1413

1514
inline constexpr HRESULT success_ok{S_OK};
15+
inline constexpr HRESULT success_false{S_FALSE};
1616
inline constexpr HRESULT error_fail{E_FAIL};
1717
inline constexpr HRESULT error_pointer{E_POINTER};
18+
inline constexpr HRESULT error_already_initialized{HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED)};
1819
inline constexpr HRESULT error_no_aggregation{CLASS_E_NOAGGREGATION};
1920
inline constexpr HRESULT error_class_not_available{CLASS_E_CLASSNOTAVAILABLE};
21+
inline constexpr HRESULT error_out_of_memory{E_OUTOFMEMORY};
2022
inline constexpr HRESULT error_invalid_argument{E_INVALIDARG};
23+
inline constexpr HRESULT error_access_denied{STG_E_ACCESSDENIED};
24+
inline constexpr HRESULT error_not_valid_state{E_NOT_VALID_STATE};
2125

2226
namespace wincodec {
2327

src/intellisense.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
#include <wincodec.h>
1515
#include <winreg.h>
1616
#include <propkey.h>
17+
#include "macros.hpp"
1718
#endif

src/jpegls-wic-codec.vcxproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@
3535
<ProjectGuid>{E3900AE2-AE06-4E77-9055-BC4D23AE4F36}</ProjectGuid>
3636
<Keyword>Win32Proj</Keyword>
3737
<ConfigurationType>DynamicLibrary</ConfigurationType>
38+
<AllProjectBMIsArePublic>true</AllProjectBMIsArePublic>
3839
</PropertyGroup>
3940
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
4041
<PropertyGroup>
4142
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
4243
</PropertyGroup>
4344
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
44-
<ImportGroup Label="PropertySheets">
45-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
46-
</ImportGroup>
4745
<ItemDefinitionGroup>
4846
<ClCompile>
4947
<AdditionalIncludeDirectories>../std-header-units;%(AdditionalIncludeDirectories);$(GeneratedFilesDir)</AdditionalIncludeDirectories>
@@ -91,6 +89,9 @@
9189
<ClCompile Include="jpegls_bitmap_frame_decode.ixx" />
9290
<ClCompile Include="jpegls_bitmap_frame_encode.cpp" />
9391
<ClCompile Include="jpegls_bitmap_frame_encode.ixx" />
92+
<ClCompile Include="property_store.cpp" />
93+
<ClCompile Include="property_store.ixx" />
94+
<ClCompile Include="property_variant.ixx" />
9495
<ClCompile Include="storage_buffer.ixx" />
9596
<ClCompile Include="util.ixx" />
9697
<ClCompile Include="winrt.ixx" />

src/jpegls-wic-codec.vcxproj.filters

+9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@
7171
<ClCompile Include="..\charls\include\charls\charls.ixx">
7272
<Filter>Source Files</Filter>
7373
</ClCompile>
74+
<ClCompile Include="property_store.cpp">
75+
<Filter>Source Files</Filter>
76+
</ClCompile>
77+
<ClCompile Include="property_store.ixx">
78+
<Filter>Source Files</Filter>
79+
</ClCompile>
80+
<ClCompile Include="property_variant.ixx">
81+
<Filter>Source Files</Filter>
82+
</ClCompile>
7483
</ItemGroup>
7584
<ItemGroup>
7685
<None Include="jpegls-wic-codec.def">

src/jpegls_bitmap_decoder.cpp

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
// Copyright (c) Team CharLS.
1+
// SPDX-FileCopyrightText: © 2018 Team CharLS
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
module;
55

6-
#include "macros.hpp"
76
#include "intellisense.hpp"
87

98
module jpegls_bitmap_decoder;
109

1110
import std;
12-
import <win.hpp>;
1311
import winrt;
1412
import charls;
13+
import <win.hpp>;
1514

1615
import class_factory;
1716
import guids;
1817
import util;
1918
import hresults;
2019
import jpegls_bitmap_frame_decode;
20+
import "macros.hpp";
2121

2222
using charls::jpegls_category;
2323
using charls::jpegls_decoder;
2424
using charls::jpegls_error;
25-
using std::int64_t;
2625
using std::array;
2726
using std::error_code;
27+
using std::int64_t;
2828
using std::scoped_lock;
29+
using std::uint32_t;
2930
using winrt::check_hresult;
3031
using winrt::com_ptr;
3132
using winrt::make;
32-
using winrt::to_hresult;
33+
3334

3435
namespace {
3536

@@ -84,8 +85,8 @@ struct jpegls_bitmap_decoder : winrt::implements<jpegls_bitmap_decoder, IWICBitm
8485
return to_hresult();
8586
}
8687

87-
HRESULT __stdcall Initialize(_In_ IStream* stream,
88-
[[maybe_unused]] const WICDecodeOptions cache_options) noexcept override
88+
HRESULT __stdcall Initialize(_In_ IStream* stream, [[maybe_unused]]
89+
const WICDecodeOptions cache_options) noexcept override
8990
try
9091
{
9192
TRACE("{} jpegls_bitmap_decoder::Initialize, stream={}, cache_options={}\n", fmt::ptr(this), fmt::ptr(stream),
@@ -133,16 +134,17 @@ struct jpegls_bitmap_decoder : winrt::implements<jpegls_bitmap_decoder, IWICBitm
133134
return to_hresult();
134135
}
135136

136-
HRESULT __stdcall CopyPalette([[maybe_unused]] _In_ IWICPalette* palette) noexcept override
137+
HRESULT __stdcall CopyPalette([[maybe_unused]]
138+
_In_ IWICPalette* palette) noexcept override
137139
{
138140
TRACE("{} jpegls_bitmap_decoder::CopyPalette, palette={}\n", fmt::ptr(this), fmt::ptr(palette));
139141

140142
// Palettes are for JPEG-LS on frame level.
141143
return wincodec::error_palette_unavailable;
142144
}
143145

144-
HRESULT __stdcall GetMetadataQueryReader(
145-
[[maybe_unused]] _Outptr_ IWICMetadataQueryReader** metadata_query_reader) noexcept override
146+
HRESULT __stdcall GetMetadataQueryReader([[maybe_unused]]
147+
_Outptr_ IWICMetadataQueryReader** metadata_query_reader) noexcept override
146148
{
147149
TRACE("{} jpegls_bitmap_decoder::GetMetadataQueryReader, metadata_query_reader=%p\n", fmt::ptr(this),
148150
fmt::ptr(metadata_query_reader));
@@ -151,7 +153,8 @@ struct jpegls_bitmap_decoder : winrt::implements<jpegls_bitmap_decoder, IWICBitm
151153
return wincodec::error_unsupported_operation;
152154
}
153155

154-
HRESULT __stdcall GetPreview([[maybe_unused]] _Outptr_ IWICBitmapSource** bitmap_source) noexcept override
156+
HRESULT __stdcall GetPreview([[maybe_unused]]
157+
_Outptr_ IWICBitmapSource** bitmap_source) noexcept override
155158
{
156159
TRACE("{} jpegls_bitmap_decoder::GetPreview, bitmap_source={}\n", fmt::ptr(this), fmt::ptr(bitmap_source));
157160

@@ -161,7 +164,8 @@ struct jpegls_bitmap_decoder : winrt::implements<jpegls_bitmap_decoder, IWICBitm
161164

162165
HRESULT __stdcall GetColorContexts([[maybe_unused]] const uint32_t count,
163166
[[maybe_unused]] IWICColorContext** color_contexts,
164-
[[maybe_unused]] uint32_t* actual_count) noexcept override
167+
[[maybe_unused]]
168+
uint32_t* actual_count) noexcept override
165169
{
166170
TRACE("{} jpegls_bitmap_decoder::GetColorContexts, count={}, color_contexts={}, actual_count={}\n", fmt::ptr(this),
167171
count, fmt::ptr(color_contexts), fmt::ptr(actual_count));
@@ -170,7 +174,8 @@ struct jpegls_bitmap_decoder : winrt::implements<jpegls_bitmap_decoder, IWICBitm
170174
return wincodec::error_unsupported_operation;
171175
}
172176

173-
HRESULT __stdcall GetThumbnail([[maybe_unused]] _Outptr_ IWICBitmapSource** thumbnail) noexcept override
177+
HRESULT __stdcall GetThumbnail([[maybe_unused]]
178+
_Outptr_ IWICBitmapSource** thumbnail) noexcept override
174179
{
175180
TRACE("{} jpegls_bitmap_decoder::GetThumbnail, thumbnail={}\n", fmt::ptr(this), fmt::ptr(thumbnail));
176181

src/jpegls_bitmap_encoder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Copyright (c) Team CharLS.
1+
// SPDX-FileCopyrightText: © 2019 Team CharLS
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
module;
55

6-
#include "macros.hpp"
6+
#include "intellisense.hpp"
77

88
module jpegls_bitmap_encoder;
99

@@ -17,6 +17,7 @@ import guids;
1717
import hresults;
1818
import jpegls_bitmap_frame_encode;
1919
import util;
20+
import "macros.hpp";
2021

2122
using charls::interleave_mode;
2223
using charls::jpegls_encoder;
@@ -27,7 +28,6 @@ using winrt::check_hresult;
2728
using winrt::com_ptr;
2829
using winrt::implements;
2930
using winrt::make;
30-
using winrt::to_hresult;
3131

3232
namespace {
3333

0 commit comments

Comments
 (0)