GCC Code Coverage Report


Directory: ./
File: tasks/otcheskov_s_contrast_lin_stretch/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 5 5 100.0%
Branches: 8 10 80.0%

Line Branch Exec Source
1 #include "otcheskov_s_contrast_lin_stretch/omp/include/ops_omp.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <cstdint>
6 #include <vector>
7
8 #include "otcheskov_s_contrast_lin_stretch/common/include/common.hpp"
9
10 namespace otcheskov_s_contrast_lin_stretch {
11
12
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
36 OtcheskovSContrastLinStretchOMP::OtcheskovSContrastLinStretchOMP(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
36 GetInput() = in;
15 GetOutput().clear();
16 36 }
17
18 36 bool OtcheskovSContrastLinStretchOMP::ValidationImpl() {
19 36 return !GetInput().empty();
20 }
21
22 36 bool OtcheskovSContrastLinStretchOMP::PreProcessingImpl() {
23 36 GetOutput().resize(GetInput().size());
24 36 return GetOutput().size() == GetInput().size();
25 }
26
27
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
36 bool OtcheskovSContrastLinStretchOMP::RunImpl() {
28
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
36 if (GetInput().empty()) {
29 return false;
30 }
31
32 const InType &input = GetInput();
33 OutType &output = GetOutput();
34 const size_t size = input.size();
35
36 uint8_t min_val = 255;
37 uint8_t max_val = 0;
38
39 32 #pragma omp parallel for default(none) shared(input, size) reduction(min : min_val) reduction(max : max_val)
40 for (size_t i = 0; i < size; ++i) {
41 min_val = std::min(input[i], min_val);
42 max_val = std::max(input[i], max_val);
43 }
44
45 const size_t threshold_size = 1000000;
46
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 20 times.
32 if (min_val == max_val) {
47 12 #pragma omp parallel for if (input.size() > threshold_size) default(none) shared(input, output, size)
48 for (size_t i = 0; i < size; ++i) {
49 output[i] = input[i];
50 }
51
52 12 return true;
53 }
54
55 20 const int min_i = static_cast<int>(min_val);
56 20 const int range = static_cast<int>(max_val) - min_i;
57
58 20 #pragma omp parallel for default(none) shared(input, output, min_i, range, size)
59 for (size_t i = 0; i < size; ++i) {
60 int pixel = static_cast<int>(input[i]);
61 int value = (pixel - min_i) * 255 / range;
62 output[i] = static_cast<uint8_t>(std::clamp(value, 0, 255));
63 }
64
65 20 return true;
66 }
67
68 36 bool OtcheskovSContrastLinStretchOMP::PostProcessingImpl() {
69 36 return true;
70 }
71
72 } // namespace otcheskov_s_contrast_lin_stretch
73