Skip to content

Commit e88e420

Browse files
authored
Add support to charls.ixx for import std; (#339)
Use the macro __cpp_lib_modules to detect if usage of import std; is possible.
1 parent 66a3605 commit e88e420

13 files changed

+68
-48
lines changed

cpp.hint

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

44
//
@@ -29,6 +29,7 @@
2929
#define CHARLS_ATTRIBUTE(a)
3030
#define CHARLS_ATTRIBUTE_ACCESS(a)
3131
#define CHARLS_C_VOID
32+
#define CHARLS_STD ::std::
3233
#define CHARLS_EXPORT
3334
#define CHARLS_CHECK_RETURN
3435
#define CHARLS_RET_MAY_BE_NULL

include/charls/api_abi.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define CHARLS_FINAL final
5050
#define CHARLS_NOEXCEPT noexcept
5151
#define CHARLS_C_VOID
52+
#define CHARLS_STD ::std::
5253

5354
#ifdef CHARLS_BUILD_AS_CPP_MODULE
5455
#define CHARLS_EXPORT export
@@ -61,5 +62,6 @@
6162
#define CHARLS_FINAL
6263
#define CHARLS_NOEXCEPT
6364
#define CHARLS_C_VOID void
65+
#define CHARLS_STD
6466

6567
#endif

include/charls/charls.h

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

44
#pragma once
55

66
#include "charls_jpegls_decoder.h"
77
#include "charls_jpegls_encoder.h"
8+
#include "validate_spiff_header.h"
89
#include "version.h"
910

1011
#include "undef_macros.h"

include/charls/charls.ixx

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

44
module;
55

66
#define CHARLS_BUILD_AS_CPP_MODULE
77

8+
#include <version>
89
#include <sal.h>
10+
11+
#ifndef __cpp_lib_modules
12+
913
#include <cstddef>
1014
#include <cstdint>
1115
#include <system_error>
1216
#include <functional>
1317
#include <memory>
1418
#include <utility>
1519

20+
#endif
21+
1622
export module charls;
1723

24+
#ifdef __cpp_lib_modules
25+
26+
import std;
27+
28+
#endif
29+
1830
#include "jpegls_decoder.hpp"
1931
#include "jpegls_encoder.hpp"
2032
#include "version.h"

include/charls/charls_jpegls_decoder.h

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

44
#pragma once
55

66
#include "jpegls_error.h"
7-
#include "validate_spiff_header.h"
8-
9-
#ifndef __cplusplus
10-
#include <stddef.h>
11-
#endif
127

138
#ifdef __cplusplus
149
struct charls_jpegls_decoder;
1510
extern "C" {
1611
#else
12+
#include <stddef.h>
1713
typedef struct charls_jpegls_decoder charls_jpegls_decoder;
1814
#endif
1915

@@ -110,7 +106,7 @@ charls_jpegls_decoder_get_near_lossless(CHARLS_IN const charls_jpegls_decoder* d
110106
/// <param name="interleave_mode">Reference that will hold the value of the interleave mode.</param>
111107
/// <returns>The result of the operation: success or a failure code.</returns>
112108
CHARLS_CHECK_RETURN CHARLS_API_IMPORT_EXPORT charls_jpegls_errc CHARLS_API_CALLING_CONVENTION
113-
charls_jpegls_decoder_get_interleave_mode(CHARLS_IN const charls_jpegls_decoder* decoder, int32_t component_index,
109+
charls_jpegls_decoder_get_interleave_mode(CHARLS_IN const charls_jpegls_decoder* decoder, int32_t component_index,
114110
CHARLS_OUT charls_interleave_mode* interleave_mode) CHARLS_NOEXCEPT
115111
CHARLS_ATTRIBUTE((nonnull));
116112

include/charls/charls_jpegls_encoder.h

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

44
#pragma once
55

66
#include "jpegls_error.h"
77

8-
#ifdef __cplusplus
9-
#include <cstring>
10-
#include <memory>
11-
#else
12-
#include <stddef.h>
13-
#endif
14-
158
#ifdef __cplusplus
169
struct charls_jpegls_encoder;
1710
extern "C" {
1811
#else
12+
#include <stddef.h>
1913
typedef struct charls_jpegls_encoder charls_jpegls_encoder;
2014
#endif
2115

include/charls/jpegls_decoder.hpp

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

44
#pragma once
55

66
#include "charls_jpegls_decoder.h"
7+
#include "validate_spiff_header.h"
78
#include "jpegls_error.hpp"
89

910
#ifndef CHARLS_BUILD_AS_CPP_MODULE

include/charls/jpegls_encoder.hpp

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

44
#pragma once
55

66
#include "charls_jpegls_encoder.h"
77

8+
#ifndef CHARLS_BUILD_AS_CPP_MODULE
89
#include <cstring>
910
#include <memory>
11+
#endif
1012

1113
CHARLS_EXPORT
1214
namespace charls {

include/charls/public_types.h

+30-28
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ enum class [[nodiscard]] jpegls_errc
386386
invalid_parameter_jpegls_preset_parameters = impl::CHARLS_JPEGLS_ERRC_INVALID_PARAMETER_JPEGLS_PRESET_PARAMETERS,
387387

388388
/// <summary>
389-
/// This error is returned when the stream contains an invalid color transformation segment or one that doesn't match with frame info.
389+
/// This error is returned when the stream contains an invalid color transformation segment or one that doesn't match
390+
/// with frame info.
390391
/// </summary>
391392
invalid_parameter_color_transformation = impl::CHARLS_JPEGLS_ERRC_INVALID_PARAMETER_COLOR_TRANSFORMATION,
392393

@@ -622,7 +623,7 @@ enum class color_transformation
622623
/// Defines the Application profile identifier options that can be used in a SPIFF header v2, as defined in ISO/IEC 10918-3,
623624
/// F.1.2
624625
/// </summary>
625-
enum class spiff_profile_id : int32_t
626+
enum class spiff_profile_id : std::int32_t
626627
{
627628
/// <summary>
628629
/// No profile identified.
@@ -655,7 +656,7 @@ enum class spiff_profile_id : int32_t
655656
/// <summary>
656657
/// Defines the color space options that can be used in a SPIFF header v2, as defined in ISO/IEC 10918-3, F.2.1.1
657658
/// </summary>
658-
enum class spiff_color_space : int32_t
659+
enum class spiff_color_space : std::int32_t
659660
{
660661
/// <summary>
661662
/// Bi-level image. Each image sample is one bit: 0 = white and 1 = black.
@@ -730,7 +731,7 @@ enum class spiff_color_space : int32_t
730731
/// <summary>
731732
/// Defines the compression options that can be used in a SPIFF header v2, as defined in ISO/IEC 10918-3, F.2.1
732733
/// </summary>
733-
enum class spiff_compression_type : int32_t
734+
enum class spiff_compression_type : std::int32_t
734735
{
735736
/// <summary>
736737
/// Picture data is stored in component interleaved format, encoded at BPS per sample.
@@ -773,7 +774,7 @@ enum class spiff_compression_type : int32_t
773774
/// <summary>
774775
/// Defines the resolution units for the VRES and HRES parameters, as defined in ISO/IEC 10918-3, F.2.1
775776
/// </summary>
776-
enum class spiff_resolution_units : int32_t
777+
enum class spiff_resolution_units : std::int32_t
777778
{
778779
/// <summary>
779780
/// VRES and HRES are to be interpreted as aspect ratio.
@@ -799,7 +800,7 @@ enum class spiff_resolution_units : int32_t
799800
/// <summary>
800801
/// Official defined SPIFF tags defined in Table F.5 (ISO/IEC 10918-3)
801802
/// </summary>
802-
enum class spiff_entry_tag : uint32_t
803+
enum class spiff_entry_tag : std::uint32_t
803804
{
804805
/// <summary>
805806
/// This entry describes the opto-electronic transfer characteristics of the source image.
@@ -931,15 +932,15 @@ typedef int32_t charls_spiff_resolution_units;
931932
struct charls_spiff_header CHARLS_FINAL
932933
{
933934
charls_spiff_profile_id profile_id; // P: Application profile, type I.8
934-
int32_t component_count; // NC: Number of color components, range [1, 255], type I.8
935-
uint32_t height; // HEIGHT: Number of lines in image, range [1, 4294967295], type I.32
936-
uint32_t width; // WIDTH: Number of samples per line, range [1, 4294967295], type I.32
935+
CHARLS_STD int32_t component_count; // NC: Number of color components, range [1, 255], type I.8
936+
CHARLS_STD uint32_t height; // HEIGHT: Number of lines in image, range [1, 4294967295], type I.32
937+
CHARLS_STD uint32_t width; // WIDTH: Number of samples per line, range [1, 4294967295], type I.32
937938
charls_spiff_color_space color_space; // S: Color space used by image data, type is I.8
938-
int32_t bits_per_sample; // BPS: Number of bits per sample, range (1, 2, 4, 8, 12, 16), type is I.8
939+
CHARLS_STD int32_t bits_per_sample; // BPS: Number of bits per sample, range (1, 2, 4, 8, 12, 16), type is I.8
939940
charls_spiff_compression_type compression_type; // C: Type of data compression used, type is I.8
940941
charls_spiff_resolution_units resolution_units; // R: Type of resolution units, type is I.8
941-
uint32_t vertical_resolution; // VRES: Vertical resolution, range [1, 4294967295], type can be F or I.32
942-
uint32_t horizontal_resolution; // HRES: Horizontal resolution, range [1, 4294967295], type can be F or I.32
942+
CHARLS_STD uint32_t vertical_resolution; // VRES: Vertical resolution, range [1, 4294967295], type can be F or I.32
943+
CHARLS_STD uint32_t horizontal_resolution; // HRES: Horizontal resolution, range [1, 4294967295], type can be F or I.32
943944
};
944945

945946

@@ -955,22 +956,22 @@ struct charls_frame_info CHARLS_FINAL
955956
/// <summary>
956957
/// Width of the image, range [1, 4294967295].
957958
/// </summary>
958-
uint32_t width;
959+
CHARLS_STD uint32_t width;
959960

960961
/// <summary>
961962
/// Height of the image, range [1, 4294967295].
962963
/// </summary>
963-
uint32_t height;
964+
CHARLS_STD uint32_t height;
964965

965966
/// <summary>
966967
/// Number of bits per sample, range [2, 16]
967968
/// </summary>
968-
int32_t bits_per_sample;
969+
CHARLS_STD int32_t bits_per_sample;
969970

970971
/// <summary>
971972
/// Number of components contained in the frame, range [1, 255]
972973
/// </summary>
973-
int32_t component_count;
974+
CHARLS_STD int32_t component_count;
974975
};
975976

976977

@@ -985,27 +986,27 @@ struct charls_jpegls_pc_parameters CHARLS_FINAL
985986
/// Maximum possible value for any image sample in a scan.
986987
/// This must be greater than or equal to the actual maximum value for the components in a scan.
987988
/// </summary>
988-
int32_t maximum_sample_value;
989+
CHARLS_STD int32_t maximum_sample_value;
989990

990991
/// <summary>
991992
/// First quantization threshold value for the local gradients.
992993
/// </summary>
993-
int32_t threshold1;
994+
CHARLS_STD int32_t threshold1;
994995

995996
/// <summary>
996997
/// Second quantization threshold value for the local gradients.
997998
/// </summary>
998-
int32_t threshold2;
999+
CHARLS_STD int32_t threshold2;
9991000

10001001
/// <summary>
10011002
/// Third quantization threshold value for the local gradients.
10021003
/// </summary>
1003-
int32_t threshold3;
1004+
CHARLS_STD int32_t threshold3;
10041005

10051006
/// <summary>
10061007
/// Value at which the counters A, B, and N are halved.
10071008
/// </summary>
1008-
int32_t reset_value;
1009+
CHARLS_STD int32_t reset_value;
10091010
};
10101011

10111012

@@ -1017,17 +1018,17 @@ struct charls_mapping_table_info CHARLS_FINAL
10171018
/// <summary>
10181019
/// Identifier of the mapping table, range [1, 255].
10191020
/// </summary>
1020-
int32_t table_id;
1021+
CHARLS_STD int32_t table_id;
10211022

10221023
/// <summary>
10231024
/// Width of a table entry in bytes, range [1, 255].
10241025
/// </summary>
1025-
int32_t entry_size;
1026+
CHARLS_STD int32_t entry_size;
10261027

10271028
/// <summary>
10281029
/// Size of the table in bytes, range [1, 16711680]
10291030
/// </summary>
1030-
uint32_t data_size;
1031+
CHARLS_STD uint32_t data_size;
10311032
};
10321033

10331034

@@ -1042,7 +1043,8 @@ struct charls_mapping_table_info CHARLS_FINAL
10421043
/// <param name="size">Size in bytes of the data of the COM segment.</param>
10431044
/// <param name="user_context">Free to use context information that can be set during the installation of the
10441045
/// handler.</param>
1045-
using charls_at_comment_handler = int32_t(CHARLS_API_CALLING_CONVENTION*)(const void* data, size_t size, void* user_context);
1046+
using charls_at_comment_handler = std::int32_t(CHARLS_API_CALLING_CONVENTION*)(const void* data, std::size_t size,
1047+
void* user_context);
10461048

10471049
/// <summary>
10481050
/// Function definition for a callback handler that will be called when an application data (APPn) segment is found.
@@ -1054,9 +1056,9 @@ using charls_at_comment_handler = int32_t(CHARLS_API_CALLING_CONVENTION*)(const
10541056
/// <param name="size">Size in bytes of the data of the APPn segment.</param>
10551057
/// <param name="user_context">Free to use context information that can be set during the installation of the
10561058
/// handler.</param>
1057-
using charls_at_application_data_handler = int32_t(CHARLS_API_CALLING_CONVENTION*)(int32_t application_data_id,
1058-
const void* data, size_t size,
1059-
void* user_context);
1059+
using charls_at_application_data_handler = std::int32_t(CHARLS_API_CALLING_CONVENTION*)(std::int32_t application_data_id,
1060+
const void* data, std::size_t size,
1061+
void* user_context);
10601062

10611063
CHARLS_EXPORT
10621064
namespace charls {

include/charls/undef_macros.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#undef CHARLS_NOEXCEPT
1111
#undef CHARLS_ATTRIBUTE
1212
#undef CHARLS_C_VOID
13+
#undef CHARLS_STD
1314
#undef CHARLS_NO_INLINE
1415
#undef CHARLS_IN
1516
#undef CHARLS_IN_OPT

include/charls/version.h

+4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
#include "api_abi.h"
88

99
#ifdef __cplusplus
10+
11+
#ifndef CHARLS_BUILD_AS_CPP_MODULE
1012
#include <cstdint>
13+
#endif
14+
1115
extern "C" {
1216
#else
1317
#include <stdint.h>

src/CharLS.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
<None Include="design\JpegStream.cd" />
210210
<None Include="design\Strategy.cd" />
211211
<None Include="packages.config" />
212+
<None Include="..\include\charls\charls.ixx" />
212213
</ItemGroup>
213214
<ItemGroup>
214215
<ClCompile Include="golomb_lut.cpp" />

src/CharLS.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<ClCompile Include="quantization_lut.cpp">
3232
<Filter>Source Files</Filter>
3333
</ClCompile>
34+
<ClCompile Include="..\include\charls\charls.ixx">
35+
<Filter>Header Files</Filter>
36+
</ClCompile>
3437
</ItemGroup>
3538
<ItemGroup>
3639
<ClInclude Include="..\include\charls\charls.h">

0 commit comments

Comments
 (0)