Skip to content

Commit

Permalink
Merge trace macros in macros.h + refactoring (#48)
Browse files Browse the repository at this point in the history
* Merge trace macros in macros.h + refactoring

* Build with toolset 14.38.33130
  • Loading branch information
vbaderks authored Nov 24, 2023
1 parent 7c5dcc8 commit 9d5ce76
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ SpaceBeforeCpp11BracedList: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
BreakAfterAttributes: Leave
BreakAfterAttributes: Always
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Run build-wrapper
run: |
build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild jpegls-wic-codec.sln /t:jpegls-wic-codec:rebuild /p:Configuration="Release" /p:Platform="x64" /nodeReuse:false
build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild jpegls-wic-codec.sln /t:jpegls-wic-codec:rebuild /p:Configuration="Release" /p:Platform="x64" /p:VCToolsVersion=14.38.33130 /nodeReuse:false
- name: Run sonar-scanner
env:
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
C4625 = derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted [Just informational]
C4626 = derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted [Just informational]
C4668 = symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives' [Just informational]
C4686 = 'std::_Decode_utf': possible change in behavior, change in UDT return calling convention [problem in format in Visual Studio 2022 17.8.0]
C4710 = function '' function not inlined [Just informational]
C4711 = function '' selected for automatic inline expansion [Just informational]
C4738 = storing 32-bit float result in memory, possible loss of performance [Just informational]
Expand All @@ -69,9 +70,8 @@
C5045 = Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified [Just informational]
C5204 = '': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
C5246 = the initialization of a subobject should be wrapped in braces [prevents simple usage of std::byte]
C5264 = 'const' variable is not used [Too many warnings from STL headers, Visual Studio 2022 17.5 Preview 2.0]
-->
<DisableSpecificWarnings Condition="'$(JPEGLS_WIC_CODEC_ALL_WARNINGS)'!=''">4005;4061;4265;4365;4464;4514;4571;4623;4625;4626;4668;4710;4711;4738;4774;4820;4946;5026;5027;5039;5045;5204;5246;5264</DisableSpecificWarnings>
<DisableSpecificWarnings Condition="'$(JPEGLS_WIC_CODEC_ALL_WARNINGS)'!=''">4005;4061;4265;4365;4464;4514;4571;4623;4625;4626;4668;4686;4710;4711;4738;4774;4820;4946;5026;5027;5039;5045;5204;5246</DisableSpecificWarnings>
<!--
C4005 = macro redefinition [Caused by the use of header units]
C4744 = '' has different type [caused by using named module]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Note \*\*: BGR images will be converted and saved as RGB. JPEG-LS provides no su
## Build Instructions

1. Clone this repo, use clone --recurse-submodules to ensure the CharLS git submodule is also cloned correctly in your local git repository.
2. Open Visual Studio 2022 or newer and open the jpeg-wic-codec.sln. Batch build all projects.
2. Open Visual Studio 2022 17.8.0 or newer and open the jpeg-wic-codec.sln. Batch build all projects.
3. Or use a Developer Command Prompt and run MSBuild in the root of the cloned repository.

## Installation
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
maximumCpuCount: true
msbuildArgs: -p:JPEGLS_WIC_CODEC_PROFILE=true
msbuildArgs: -p:JPEGLS_WIC_CODEC_PROFILE=true -p:VCToolsVersion=14.38.33130

- task: VSTest@2
inputs:
Expand Down
5 changes: 3 additions & 2 deletions src/cpp.hint
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// For more information see https://go.microsoft.com/fwlink/?linkid=865984

#define SUPPRESS_WARNING_NEXT_LINE(x)
#define SUPPRESS_FALSE_WARNING_C6101_NEXT_LINE
#define SUPPRESS_FALSE_WARNING_C26447_NEXT_LINE
#define _CRT_MEMCPY_S_INLINE inline
#define TRACE __noop
#define ASSERT(expression)
#define VERIFY(expression) static_cast<void>(expression)
7 changes: 3 additions & 4 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) Team CharLS.
// SPDX-License-Identifier: BSD-3-Clause

#include "trace.h"
#include "version.h"
#include "macros.h"
#include "version.h"

import "std.h";
import "win.h";
Expand Down Expand Up @@ -87,8 +86,8 @@ void register_decoder()
constexpr wchar_t CLSID_PhotoThumbnailProvider[]{L"{c7657c4a-9f68-40fa-a4df-96bc08eb3551}"};

registry::set_value(LR"(SOFTWARE\Classes\.jls\ShellEx\)" + IID_IThumbnailProvider, L"", CLSID_PhotoThumbnailProvider);
registry::set_value(LR"(SOFTWARE\Classes\SystemFileAssociations\.jls\ShellEx\)" + IID_IThumbnailProvider,
L"", CLSID_PhotoThumbnailProvider);
registry::set_value(LR"(SOFTWARE\Classes\SystemFileAssociations\.jls\ShellEx\)" + IID_IThumbnailProvider, L"",
CLSID_PhotoThumbnailProvider);

// Register with the legacy Windows Photo Viewer (still installed on Windows 10), just forward to the TIFF registration.
registry::set_value(LR"(SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations)", L".jls",
Expand Down
1 change: 0 additions & 1 deletion src/jpegls-wic-codec.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<ItemGroup>
<ClInclude Include="macros.h" />
<ClInclude Include="std.h" />
<ClInclude Include="trace.h" />
<ClInclude Include="version.h" />
<ClInclude Include="win.h" />
</ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions src/jpegls-wic-codec.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="trace.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="version.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
3 changes: 0 additions & 3 deletions src/jpegls_bitmap_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module;

#include "trace.h"
#include "macros.h"

module jpegls_bitmap_decoder;
Expand Down Expand Up @@ -89,7 +88,6 @@ class jpegls_bitmap_decoder final : public winrt::implements<jpegls_bitmap_decod
TRACE("{} jpegls_bitmap_decoder::Initialize, stream={}, cache_options={}\n", fmt::ptr(this), fmt::ptr(stream),
fmt::underlying(cache_options));

SUPPRESS_FALSE_WARNING_C26447_NEXT_LINE
scoped_lock lock{mutex_};

source_stream_.copy_from(check_in_pointer(stream));
Expand Down Expand Up @@ -196,7 +194,6 @@ class jpegls_bitmap_decoder final : public winrt::implements<jpegls_bitmap_decod

check_condition(index == 0, wincodec::error_frame_missing);

SUPPRESS_FALSE_WARNING_C26447_NEXT_LINE
scoped_lock lock{mutex_};

check_condition(static_cast<bool>(source_stream_), wincodec::error_not_initialized);
Expand Down
3 changes: 2 additions & 1 deletion src/jpegls_bitmap_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module;

#include "trace.h"
#include "macros.h"

module jpegls_bitmap_encoder;

Expand All @@ -15,6 +15,7 @@ import errors;
import jpegls_bitmap_frame_encode;
import winrt;
import charls;
import util;

using charls::interleave_mode;
using charls::jpegls_encoder;
Expand Down
8 changes: 4 additions & 4 deletions src/jpegls_bitmap_frame_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module;

#include "trace.h"
#include "macros.h"

module jpegls_bitmap_frame_decode;
Expand All @@ -18,6 +17,7 @@ import charls;

using namespace charls;
using std::make_pair;
using std::vector;
using winrt::check_hresult;
using winrt::throw_hresult;

Expand Down Expand Up @@ -259,7 +259,7 @@ jpegls_bitmap_frame_decode::jpegls_bitmap_frame_decode(_In_ IStream* stream, _In

if (frame_info.component_count != 1 && decoder.interleave_mode() == charls::interleave_mode::none)
{
const auto planar{decoder.decode<std::vector<std::byte>>()};
const auto planar{decoder.decode<vector<std::byte>>()};
if (frame_info.bits_per_sample > 8)
{
convert_planar_to_rgb<uint16_t>(frame_info.width, frame_info.height, planar.data(), data_buffer, stride);
Expand All @@ -271,13 +271,13 @@ jpegls_bitmap_frame_decode::jpegls_bitmap_frame_decode(_In_ IStream* stream, _In
}
else if (frame_info.bits_per_sample == 2)
{
std::vector<std::byte> byte_pixels(static_cast<size_t>(frame_info.width) * frame_info.height);
vector<std::byte> byte_pixels(static_cast<size_t>(frame_info.width) * frame_info.height);
decoder.decode(byte_pixels);
pack_to_crumbs(byte_pixels, data_buffer, frame_info.width, frame_info.height, stride);
}
else if (frame_info.bits_per_sample == 4)
{
std::vector<std::byte> byte_pixels(static_cast<size_t>(frame_info.width) * frame_info.height);
vector<std::byte> byte_pixels(static_cast<size_t>(frame_info.width) * frame_info.height);
decoder.decode(byte_pixels);
pack_to_nibbles(byte_pixels, data_buffer, frame_info.width, frame_info.height, stride);
}
Expand Down
2 changes: 1 addition & 1 deletion src/jpegls_bitmap_frame_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
module;

#include "macros.h"
#include "trace.h"

module jpegls_bitmap_frame_encode;

import "win.h";
import "std.h";
import errors;
import winrt;
import util;

HRESULT __stdcall jpegls_bitmap_frame_encode::Initialize([[maybe_unused]] _In_ IPropertyBag2* encoder_options) noexcept
try
Expand Down
17 changes: 10 additions & 7 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
__pragma(warning(suppress \
: x)) // NOLINT(misc-macro-parentheses, bugprone-macro-parentheses, cppcoreguidelines-macro-usage)

// The 2 macros below are used to disable false positives. These warnings are too useful to disable them globally.

// A false warning is generated when a noexcept methods calls a function that is not marked noexcept.
// Reported to Microsoft:
// https://developercommunity.visualstudio.com/content/problem/804372/c26447-false-positive-when-using-stdscoped-lock-ev.html
#define SUPPRESS_FALSE_WARNING_C26447_NEXT_LINE SUPPRESS_WARNING_NEXT_LINE(26447)

#define ASSERT(expression) \
__pragma(warning(push)) __pragma(warning(disable : 26493)) assert(expression) __pragma(warning(pop))

Expand All @@ -22,3 +15,13 @@
#else
#define VERIFY(expression) assert(expression)
#endif

// The TRACE macro can be used in debug builds to watch the behaviour of the implementation
// when used by 3rd party applications.
// To use it, import also std.h and win.h.
#ifdef NDEBUG
#define TRACE __noop
#else
// Use std::format directly to get compile time checking of the string arguments.
#define TRACE(fmt, ...) OutputDebugStringA(std::format(fmt __VA_OPT__(, ) __VA_ARGS__).c_str())
#endif
2 changes: 2 additions & 0 deletions src/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
#include <span>
#include <string>
#include <vector>
#include <bit>
#include <format>
7 changes: 4 additions & 3 deletions src/storage_buffer.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public:
{
}

[[nodiscard]] size_t size() const noexcept
[[nodiscard]]
size_t size() const noexcept
{
return size_;
}

[[nodiscard]] std::byte* data() const noexcept
[[nodiscard]]
std::byte* data() const noexcept
{
return buffer_.get();
}
Expand All @@ -30,4 +32,3 @@ private:
size_t size_;
std::unique_ptr<std::byte[]> buffer_; // NOLINT(cppcoreguidelines-avoid-c-arrays)
};

42 changes: 0 additions & 42 deletions src/trace.h

This file was deleted.

Loading

0 comments on commit 9d5ce76

Please sign in to comment.