Skip to content

Commit 0b4bd65

Browse files
committed
Prepare python binding 2 take those options
1 parent 683c99b commit 0b4bd65

7 files changed

Lines changed: 80 additions & 18 deletions

File tree

source/lib/api/include/DecoderFacade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <lib/infrastructure/include/ParameterCollector.h>
88
#include <lib/infrastructure/include/ContextFwd.h>
99

10+
#include <lib/dip/include/PreProcessorOptions.h>
11+
1012
#include <lib/input/api/include/InputElement.h>
1113
#include <lib/input/api/include/LoadResult.h>
1214

source/lib/api/source/DecoderFacade.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace api
4343
std::optional<unsigned int> loadOptionDpi;
4444
std::optional<int> imageRotation;
4545
std::optional<unsigned int> imageScale;
46-
std::optional<std::string> imageSplit;
46+
std::optional<std::string> imageSplitting;
4747
std::optional<unsigned int> imageFlipping;
4848
std::optional<detector::api::DetectorType> detectorType;
4949
std::optional<bool> pureBarcode;
@@ -62,7 +62,7 @@ namespace api
6262

6363
unsigned int getImageScale() const { return imageScale.value_or(dip::PreProcessorOptions::DEFAULT.scalePercent); }
6464

65-
std::string getImageSplit() const { return imageSplit.value_or(dip::PreProcessorOptions::DEFAULT.split); }
65+
std::string getImageSplit() const { return imageSplitting.value_or(dip::PreProcessorOptions::DEFAULT.splittingMode); }
6666

6767
unsigned int getImageFlipping() const { return imageFlipping.value_or(dip::PreProcessorOptions::DEFAULT.flippingMode); }
6868

@@ -199,7 +199,7 @@ namespace api
199199

200200
DecoderFacadeBuilder &DecoderFacadeBuilder::withImageSplit(std::string split)
201201
{
202-
options->imageSplit = std::make_optional(split);
202+
options->imageSplitting = std::make_optional(split);
203203
return *this;
204204
}
205205

source/lib/dip/include/PreProcessor.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#pragma once
55

6+
#include "PreProcessorOptions.h"
7+
68
#include "lib/input/api/include/InputElement.h"
79

810
#include "lib/infrastructure/include/ParameterSupplier.h"
@@ -15,16 +17,6 @@
1517

1618
namespace dip
1719
{
18-
struct PreProcessorOptions
19-
{
20-
int rotationDegree = 0;
21-
unsigned int scalePercent = 100u;
22-
std::string split = "11";
23-
unsigned int flippingMode = 0; // 0 nothing, 1 flip around X, 2 flip around Y, 3 flip around X and Y
24-
25-
static PreProcessorOptions const DEFAULT;
26-
};
27-
2820
std::pair<unsigned int, unsigned int> splitStringToPair(std::string input);
2921

3022
std::map<unsigned int, unsigned int> splitPairToMap(std::pair<unsigned int, unsigned int> input);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-FileCopyrightText: (C) 2026 user4223 and (other) contributors to ticket-decoder <https://github.com/user4223/ticket-decoder>
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
#pragma once
5+
6+
#include <string>
7+
8+
namespace dip
9+
{
10+
class OptionsBuilder;
11+
12+
struct PreProcessorOptions
13+
{
14+
int rotationDegree = 0;
15+
unsigned int scalePercent = 100u;
16+
std::string splittingMode = "11"; // 11 first of one part, 2x x of two parts, 4x x of four parts
17+
unsigned int flippingMode = 0; // 0 nothing, 1 flip around X, 2 flip around Y, 3 flip around X and Y
18+
19+
static PreProcessorOptions const DEFAULT;
20+
21+
OptionsBuilder create();
22+
};
23+
24+
class OptionsBuilder
25+
{
26+
PreProcessorOptions options;
27+
28+
OptionsBuilder(PreProcessorOptions o);
29+
30+
public:
31+
friend PreProcessorOptions;
32+
33+
PreProcessorOptions build();
34+
};
35+
}

source/lib/dip/source/PreProcessor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace dip
1313
{
14-
PreProcessorOptions const PreProcessorOptions::DEFAULT = PreProcessorOptions{};
15-
1614
std::pair<unsigned int, unsigned int> splitStringToPair(std::string input)
1715
{
1816
if (input.size() != 2)
@@ -69,7 +67,7 @@ namespace dip
6967
: logger(CREATE_LOGGER(context.getLoggerFactory())),
7068
options(std::move(o)),
7169
isEnabled(true),
72-
partMap(splitPairToMap(splitStringToPair(options.split))),
70+
partMap(splitPairToMap(splitStringToPair(options.splittingMode))),
7371
parts()
7472
{
7573
updatePartMap();
@@ -130,7 +128,7 @@ namespace dip
130128
std::string PreProcessor::reset()
131129
{
132130
auto const defaultOptions = PreProcessorOptions{};
133-
partMap = splitPairToMap(splitStringToPair(defaultOptions.split));
131+
partMap = splitPairToMap(splitStringToPair(defaultOptions.splittingMode));
134132
options.rotationDegree = defaultOptions.rotationDegree;
135133
options.scalePercent = defaultOptions.scalePercent;
136134
options.flippingMode = defaultOptions.flippingMode;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-FileCopyrightText: (C) 2026 user4223 and (other) contributors to ticket-decoder <https://github.com/user4223/ticket-decoder>
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
#include "../include/PreProcessorOptions.h"
5+
6+
namespace dip
7+
{
8+
9+
PreProcessorOptions const PreProcessorOptions::DEFAULT = PreProcessorOptions{};
10+
11+
OptionsBuilder::OptionsBuilder(PreProcessorOptions o)
12+
: options(std::move(o))
13+
{
14+
}
15+
16+
PreProcessorOptions OptionsBuilder::build()
17+
{
18+
return std::move(options);
19+
}
20+
21+
OptionsBuilder PreProcessorOptions::create()
22+
{
23+
return OptionsBuilder(DEFAULT);
24+
}
25+
}

source/python/source/Binding.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ class DecoderFacadeWrapper
7272
return get().decodeRawBase64ToJson(base64, origin);
7373
}
7474

75-
std::vector<std::pair<std::string, std::string>> decodeFiles(std::string const &path)
75+
std::vector<std::pair<std::string, std::string>> decodeFiles(
76+
std::string const &path,
77+
int const rotationDegree,
78+
unsigned int const scalePercent,
79+
std::string const &splittingMode,
80+
unsigned int const flippingMode)
7681
{
82+
auto options = dip::PreProcessorOptions{rotationDegree, scalePercent, splittingMode, flippingMode};
7783
return get().decodeImageFilesToJson(path);
7884
}
7985
};
@@ -115,5 +121,9 @@ NB_MODULE(ticket_decoder, m)
115121
"Decode base64-encoded raw barcode data into structured json")
116122
.def("decode_files", &DecoderFacadeWrapper::decodeFiles,
117123
"path"_a,
124+
"rotationDegree"_a = dip::PreProcessorOptions::DEFAULT.rotationDegree,
125+
"scalePercent"_a = dip::PreProcessorOptions::DEFAULT.scalePercent,
126+
"splittingMode"_a = dip::PreProcessorOptions::DEFAULT.splittingMode,
127+
"flippingMode"_a = dip::PreProcessorOptions::DEFAULT.flippingMode,
118128
"Decode Aztec-Code and containing raw data from image/PDF file or files into structured json");
119129
}

0 commit comments

Comments
 (0)