Skip to content

Commit 2d1c60b

Browse files
author
Lior Lahav
committed
Changed: codec parameters interface
1 parent fb7e870 commit 2d1c60b

4 files changed

Lines changed: 103 additions & 25 deletions

File tree

Codecs/CodecJPG/Source/CodecJpeg.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ namespace IMCodec
6363
{
6464
static thread_local tjhandle ftjHandle = tjInitDecompress();
6565
ImageResult result = ImageResult::UnknownError;
66-
/*
6766
int canvasWidth = 0;
68-
int canvasHeight = 0;
69-
70-
if (params.contains(L"canvasWidth"))
71-
canvasWidth = std::get<int>(params.at(L"canvasWidth"));
67+
if (const int* width = params.GetCustomAs<int>(LLUTILS_TEXT("canvasWidth")))
68+
canvasWidth = *width;
7269

73-
if (params.contains(L"canvasHeight"))
74-
canvasHeight = std::get<int>(params.at(L"canvasHeight"));
75-
*/
70+
int canvasHeight = 0;
71+
if (const int* height = params.GetCustomAs<int>(LLUTILS_TEXT("canvasHeight")))
72+
canvasHeight = *height;
7673

7774

7875
int width = 0;

ImageCodec/CMakeLists.txt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,44 @@ file(GLOB_RECURSE sourceFiles
99
set(TargetName ImageCodec)
1010
add_library (${TargetName} ${sourceFiles} )
1111

12-
target_include_directories(${TargetName} PRIVATE ./Include)
12+
target_include_directories(${TargetName} PUBLIC ./Include)
13+
target_include_directories(${TargetName} PUBLIC /ImageUtil/Include)
1314
target_include_directories(${TargetName} PRIVATE ../External/TinyExif)
1415

1516
if ( ${IMCODEC_BUILD_CODEC_BMP})
16-
target_link_libraries(${TargetName} CodecBMP)
17+
target_link_libraries(${TargetName} PRIVATE CodecBMP)
1718
endif()
1819

1920
if ( ${IMCODEC_BUILD_CODEC_DDS})
20-
target_link_libraries(${TargetName} CodecDDS)
21+
target_link_libraries(${TargetName} PRIVATE CodecDDS)
2122
endif()
2223
if ( ${IMCODEC_BUILD_CODEC_ICON})
23-
target_link_libraries(${TargetName} CodecIcon)
24+
target_link_libraries(${TargetName} PRIVATE CodecIcon)
2425
endif()
2526
if ( ${IMCODEC_BUILD_CODEC_PSD})
26-
target_link_libraries(${TargetName} CodecPSD)
27+
target_link_libraries(${TargetName} PRIVATE CodecPSD)
2728
endif()
2829
if ( ${IMCODEC_BUILD_CODEC_JPG})
29-
target_link_libraries(${TargetName} CodecJPG)
30+
target_link_libraries(${TargetName} PRIVATE CodecJPG)
3031
endif()
3132
if ( ${IMCODEC_BUILD_CODEC_PNG})
32-
target_link_libraries(${TargetName} CodecPNG)
33+
target_link_libraries(${TargetName} PRIVATE CodecPNG)
3334
endif()
3435
if ( ${IMCODEC_BUILD_CODEC_GIF})
35-
target_link_libraries(${TargetName} CodecGif)
36+
target_link_libraries(${TargetName} PRIVATE CodecGif)
3637
endif()
3738
if ( ${IMCODEC_BUILD_CODEC_TIFF})
38-
target_link_libraries(${TargetName} CodecTiff)
39+
target_link_libraries(${TargetName} PRIVATE CodecTiff)
3940
endif()
4041
if ( ${IMCODEC_BUILD_CODEC_WEBP})
41-
target_link_libraries(${TargetName} CodecWebP)
42+
target_link_libraries(${TargetName} PRIVATE CodecWebP)
4243
endif()
4344

4445
if ( ${IMCODEC_BUILD_CODEC_FREEIMAGE})
45-
target_link_libraries(${TargetName} CodecFreeImage)
46+
target_link_libraries(${TargetName} PRIVATE CodecFreeImage)
4647
endif()
4748

48-
target_link_libraries(${TargetName} TinyEXIFstatic)
49+
target_link_libraries(${TargetName} PRIVATE TinyEXIFstatic)
50+
target_link_libraries(${TargetName} PUBLIC delayimp)
51+
52+

ImageCodec/Include/IImagePlugin.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <LLUtils/Exception.h>
55
#include "ImageCommon.h"
66
#include "ImageItem.h"
7-
#include <variant>
8-
#include <map>
7+
#include "ImagePluginParameters.h"
98

109
namespace IMCodec
1110
{
@@ -54,9 +53,7 @@ namespace IMCodec
5453
};
5554

5655

57-
using Parameter = std::variant<int, double, string_type>;
58-
using Parameters = std::map<string_type, Parameter>;
59-
56+
6057
struct ParameterDescriptor
6158
{
6259
string_type name;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#pragma once
2+
3+
#include "ImageCommon.h"
4+
5+
#include <any>
6+
#include <map>
7+
#include <utility>
8+
#include <variant>
9+
10+
namespace IMCodec
11+
{
12+
using SharedParameterValue = std::variant<int, double, string_type>;
13+
14+
enum class ParametrType
15+
{
16+
None,
17+
DesiredSize
18+
};
19+
20+
class Parameters
21+
{
22+
public:
23+
using SharedParametersMap = std::map<ParametrType, SharedParameterValue>;
24+
using CustomParametersMap = std::map<string_type, std::any>;
25+
26+
void SetShared(ParametrType type, SharedParameterValue value)
27+
{
28+
sharedParameters_.insert_or_assign(type, std::move(value));
29+
}
30+
31+
const SharedParameterValue* GetShared(ParametrType type) const
32+
{
33+
auto it = sharedParameters_.find(type);
34+
return it != sharedParameters_.end() ? &it->second : nullptr;
35+
}
36+
37+
bool HasShared(ParametrType type) const
38+
{
39+
return sharedParameters_.find(type) != sharedParameters_.end();
40+
}
41+
42+
template <class T>
43+
const T* GetSharedAs(ParametrType type) const
44+
{
45+
auto it = sharedParameters_.find(type);
46+
if (it != sharedParameters_.end())
47+
return std::get_if<T>(&it->second);
48+
return nullptr;
49+
}
50+
51+
void SetCustom(string_type key, std::any value)
52+
{
53+
customParameters_.insert_or_assign(std::move(key), std::move(value));
54+
}
55+
56+
const std::any* GetCustom(const string_type& key) const
57+
{
58+
auto it = customParameters_.find(key);
59+
return it != customParameters_.end() ? &it->second : nullptr;
60+
}
61+
62+
bool HasCustom(const string_type& key) const
63+
{
64+
return customParameters_.find(key) != customParameters_.end();
65+
}
66+
67+
template <class T>
68+
const T* GetCustomAs(const string_type& key) const
69+
{
70+
auto it = customParameters_.find(key);
71+
if (it != customParameters_.end())
72+
return std::any_cast<T>(&it->second);
73+
return nullptr;
74+
}
75+
76+
private:
77+
SharedParametersMap sharedParameters_;
78+
CustomParametersMap customParameters_;
79+
};
80+
}

0 commit comments

Comments
 (0)