Coverage Report

Created: 2026-06-07 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/modular/transform/rct.cc
Line
Count
Source
1
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
//
3
// Use of this source code is governed by a BSD-style
4
// license that can be found in the LICENSE file.
5
6
#include "lib/jxl/modular/transform/rct.h"
7
8
#include <cstddef>
9
#include <cstdint>
10
#include <utility>
11
12
#include "lib/jxl/base/data_parallel.h"
13
#include "lib/jxl/base/status.h"
14
#include "lib/jxl/modular/modular_image.h"
15
#include "lib/jxl/modular/transform/transform.h"
16
#undef HWY_TARGET_INCLUDE
17
#define HWY_TARGET_INCLUDE "lib/jxl/modular/transform/rct.cc"
18
#include <hwy/foreach_target.h>
19
#include <hwy/highway.h>
20
HWY_BEFORE_NAMESPACE();
21
namespace jxl {
22
namespace HWY_NAMESPACE {
23
24
// These templates are not found via ADL.
25
using hwy::HWY_NAMESPACE::Add;
26
using hwy::HWY_NAMESPACE::ShiftRight;
27
using hwy::HWY_NAMESPACE::Sub;
28
29
template <int transform_type>
30
void InvRCTRow(const pixel_type* in0, const pixel_type* in1,
31
               const pixel_type* in2, pixel_type* out0, pixel_type* out1,
32
92.0k
               pixel_type* out2, size_t w) {
33
92.0k
  static_assert(transform_type >= 0 && transform_type < 7,
34
92.0k
                "Invalid transform type");
35
92.0k
  int second = transform_type >> 1;
36
92.0k
  int third = transform_type & 1;
37
38
92.0k
  size_t x = 0;
39
92.0k
  const HWY_FULL(pixel_type) d;
40
92.0k
  const size_t N = Lanes(d);
41
1.07M
  for (; x + N - 1 < w; x += N) {
42
981k
    if (transform_type == 6) {
43
519k
      auto Y = Load(d, in0 + x);
44
519k
      auto Co = Load(d, in1 + x);
45
519k
      auto Cg = Load(d, in2 + x);
46
519k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
519k
      auto G = Add(Cg, Y);
48
519k
      Y = Sub(Y, ShiftRight<1>(Co));
49
519k
      auto R = Add(Y, Co);
50
519k
      Store(R, d, out0 + x);
51
519k
      Store(G, d, out1 + x);
52
519k
      Store(Y, d, out2 + x);
53
519k
    } else {
54
461k
      auto First = Load(d, in0 + x);
55
461k
      auto Second = Load(d, in1 + x);
56
461k
      auto Third = Load(d, in2 + x);
57
461k
      if (third) Third = Add(Third, First);
58
461k
      if (second == 1) {
59
341k
        Second = Add(Second, First);
60
341k
      } else if (second == 2) {
61
46.7k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
46.7k
      }
63
461k
      Store(First, d, out0 + x);
64
461k
      Store(Second, d, out1 + x);
65
461k
      Store(Third, d, out2 + x);
66
461k
    }
67
981k
  }
68
177k
  for (; x < w; x++) {
69
85.5k
    if (transform_type == 6) {
70
36.2k
      pixel_type Y = in0[x];
71
36.2k
      pixel_type Co = in1[x];
72
36.2k
      pixel_type Cg = in2[x];
73
36.2k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
36.2k
      pixel_type G = PixelAdd(Cg, tmp);
75
36.2k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
36.2k
      pixel_type R = PixelAdd(B, Co);
77
36.2k
      out0[x] = R;
78
36.2k
      out1[x] = G;
79
36.2k
      out2[x] = B;
80
49.2k
    } else {
81
49.2k
      pixel_type First = in0[x];
82
49.2k
      pixel_type Second = in1[x];
83
49.2k
      pixel_type Third = in2[x];
84
49.2k
      if (third) Third = PixelAdd(Third, First);
85
49.2k
      if (second == 1) {
86
28.5k
        Second = PixelAdd(Second, First);
87
28.5k
      } else if (second == 2) {
88
13.3k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
13.3k
      }
90
49.2k
      out0[x] = First;
91
49.2k
      out1[x] = Second;
92
49.2k
      out2[x] = Third;
93
49.2k
    }
94
85.5k
  }
95
92.0k
}
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<0>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<1>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE4::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_AVX2::InvRCTRow<0>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
void jxl::N_AVX2::InvRCTRow<1>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
4.35k
               pixel_type* out2, size_t w) {
33
4.35k
  static_assert(transform_type >= 0 && transform_type < 7,
34
4.35k
                "Invalid transform type");
35
4.35k
  int second = transform_type >> 1;
36
4.35k
  int third = transform_type & 1;
37
38
4.35k
  size_t x = 0;
39
4.35k
  const HWY_FULL(pixel_type) d;
40
4.35k
  const size_t N = Lanes(d);
41
76.9k
  for (; x + N - 1 < w; x += N) {
42
72.5k
    if (transform_type == 6) {
43
0
      auto Y = Load(d, in0 + x);
44
0
      auto Co = Load(d, in1 + x);
45
0
      auto Cg = Load(d, in2 + x);
46
0
      Y = Sub(Y, ShiftRight<1>(Cg));
47
0
      auto G = Add(Cg, Y);
48
0
      Y = Sub(Y, ShiftRight<1>(Co));
49
0
      auto R = Add(Y, Co);
50
0
      Store(R, d, out0 + x);
51
0
      Store(G, d, out1 + x);
52
0
      Store(Y, d, out2 + x);
53
72.5k
    } else {
54
72.5k
      auto First = Load(d, in0 + x);
55
72.5k
      auto Second = Load(d, in1 + x);
56
72.5k
      auto Third = Load(d, in2 + x);
57
72.5k
      if (third) Third = Add(Third, First);
58
72.5k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
72.5k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
72.5k
      Store(First, d, out0 + x);
64
72.5k
      Store(Second, d, out1 + x);
65
72.5k
      Store(Third, d, out2 + x);
66
72.5k
    }
67
72.5k
  }
68
11.6k
  for (; x < w; x++) {
69
7.34k
    if (transform_type == 6) {
70
0
      pixel_type Y = in0[x];
71
0
      pixel_type Co = in1[x];
72
0
      pixel_type Cg = in2[x];
73
0
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
0
      pixel_type G = PixelAdd(Cg, tmp);
75
0
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
0
      pixel_type R = PixelAdd(B, Co);
77
0
      out0[x] = R;
78
0
      out1[x] = G;
79
0
      out2[x] = B;
80
7.34k
    } else {
81
7.34k
      pixel_type First = in0[x];
82
7.34k
      pixel_type Second = in1[x];
83
7.34k
      pixel_type Third = in2[x];
84
7.34k
      if (third) Third = PixelAdd(Third, First);
85
7.34k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
7.34k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
7.34k
      out0[x] = First;
91
7.34k
      out1[x] = Second;
92
7.34k
      out2[x] = Third;
93
7.34k
    }
94
7.34k
  }
95
4.35k
}
void jxl::N_AVX2::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
33.3k
               pixel_type* out2, size_t w) {
33
33.3k
  static_assert(transform_type >= 0 && transform_type < 7,
34
33.3k
                "Invalid transform type");
35
33.3k
  int second = transform_type >> 1;
36
33.3k
  int third = transform_type & 1;
37
38
33.3k
  size_t x = 0;
39
33.3k
  const HWY_FULL(pixel_type) d;
40
33.3k
  const size_t N = Lanes(d);
41
284k
  for (; x + N - 1 < w; x += N) {
42
250k
    if (transform_type == 6) {
43
0
      auto Y = Load(d, in0 + x);
44
0
      auto Co = Load(d, in1 + x);
45
0
      auto Cg = Load(d, in2 + x);
46
0
      Y = Sub(Y, ShiftRight<1>(Cg));
47
0
      auto G = Add(Cg, Y);
48
0
      Y = Sub(Y, ShiftRight<1>(Co));
49
0
      auto R = Add(Y, Co);
50
0
      Store(R, d, out0 + x);
51
0
      Store(G, d, out1 + x);
52
0
      Store(Y, d, out2 + x);
53
250k
    } else {
54
250k
      auto First = Load(d, in0 + x);
55
250k
      auto Second = Load(d, in1 + x);
56
250k
      auto Third = Load(d, in2 + x);
57
250k
      if (third) Third = Add(Third, First);
58
250k
      if (second == 1) {
59
250k
        Second = Add(Second, First);
60
250k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
250k
      Store(First, d, out0 + x);
64
250k
      Store(Second, d, out1 + x);
65
250k
      Store(Third, d, out2 + x);
66
250k
    }
67
250k
  }
68
52.4k
  for (; x < w; x++) {
69
19.1k
    if (transform_type == 6) {
70
0
      pixel_type Y = in0[x];
71
0
      pixel_type Co = in1[x];
72
0
      pixel_type Cg = in2[x];
73
0
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
0
      pixel_type G = PixelAdd(Cg, tmp);
75
0
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
0
      pixel_type R = PixelAdd(B, Co);
77
0
      out0[x] = R;
78
0
      out1[x] = G;
79
0
      out2[x] = B;
80
19.1k
    } else {
81
19.1k
      pixel_type First = in0[x];
82
19.1k
      pixel_type Second = in1[x];
83
19.1k
      pixel_type Third = in2[x];
84
19.1k
      if (third) Third = PixelAdd(Third, First);
85
19.1k
      if (second == 1) {
86
19.1k
        Second = PixelAdd(Second, First);
87
19.1k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
19.1k
      out0[x] = First;
91
19.1k
      out1[x] = Second;
92
19.1k
      out2[x] = Third;
93
19.1k
    }
94
19.1k
  }
95
33.3k
}
void jxl::N_AVX2::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
6.61k
               pixel_type* out2, size_t w) {
33
6.61k
  static_assert(transform_type >= 0 && transform_type < 7,
34
6.61k
                "Invalid transform type");
35
6.61k
  int second = transform_type >> 1;
36
6.61k
  int third = transform_type & 1;
37
38
6.61k
  size_t x = 0;
39
6.61k
  const HWY_FULL(pixel_type) d;
40
6.61k
  const size_t N = Lanes(d);
41
97.7k
  for (; x + N - 1 < w; x += N) {
42
91.1k
    if (transform_type == 6) {
43
0
      auto Y = Load(d, in0 + x);
44
0
      auto Co = Load(d, in1 + x);
45
0
      auto Cg = Load(d, in2 + x);
46
0
      Y = Sub(Y, ShiftRight<1>(Cg));
47
0
      auto G = Add(Cg, Y);
48
0
      Y = Sub(Y, ShiftRight<1>(Co));
49
0
      auto R = Add(Y, Co);
50
0
      Store(R, d, out0 + x);
51
0
      Store(G, d, out1 + x);
52
0
      Store(Y, d, out2 + x);
53
91.1k
    } else {
54
91.1k
      auto First = Load(d, in0 + x);
55
91.1k
      auto Second = Load(d, in1 + x);
56
91.1k
      auto Third = Load(d, in2 + x);
57
91.1k
      if (third) Third = Add(Third, First);
58
91.1k
      if (second == 1) {
59
91.1k
        Second = Add(Second, First);
60
91.1k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
91.1k
      Store(First, d, out0 + x);
64
91.1k
      Store(Second, d, out1 + x);
65
91.1k
      Store(Third, d, out2 + x);
66
91.1k
    }
67
91.1k
  }
68
16.0k
  for (; x < w; x++) {
69
9.40k
    if (transform_type == 6) {
70
0
      pixel_type Y = in0[x];
71
0
      pixel_type Co = in1[x];
72
0
      pixel_type Cg = in2[x];
73
0
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
0
      pixel_type G = PixelAdd(Cg, tmp);
75
0
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
0
      pixel_type R = PixelAdd(B, Co);
77
0
      out0[x] = R;
78
0
      out1[x] = G;
79
0
      out2[x] = B;
80
9.40k
    } else {
81
9.40k
      pixel_type First = in0[x];
82
9.40k
      pixel_type Second = in1[x];
83
9.40k
      pixel_type Third = in2[x];
84
9.40k
      if (third) Third = PixelAdd(Third, First);
85
9.40k
      if (second == 1) {
86
9.40k
        Second = PixelAdd(Second, First);
87
9.40k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
9.40k
      out0[x] = First;
91
9.40k
      out1[x] = Second;
92
9.40k
      out2[x] = Third;
93
9.40k
    }
94
9.40k
  }
95
6.61k
}
void jxl::N_AVX2::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
7.57k
               pixel_type* out2, size_t w) {
33
7.57k
  static_assert(transform_type >= 0 && transform_type < 7,
34
7.57k
                "Invalid transform type");
35
7.57k
  int second = transform_type >> 1;
36
7.57k
  int third = transform_type & 1;
37
38
7.57k
  size_t x = 0;
39
7.57k
  const HWY_FULL(pixel_type) d;
40
7.57k
  const size_t N = Lanes(d);
41
43.4k
  for (; x + N - 1 < w; x += N) {
42
35.8k
    if (transform_type == 6) {
43
0
      auto Y = Load(d, in0 + x);
44
0
      auto Co = Load(d, in1 + x);
45
0
      auto Cg = Load(d, in2 + x);
46
0
      Y = Sub(Y, ShiftRight<1>(Cg));
47
0
      auto G = Add(Cg, Y);
48
0
      Y = Sub(Y, ShiftRight<1>(Co));
49
0
      auto R = Add(Y, Co);
50
0
      Store(R, d, out0 + x);
51
0
      Store(G, d, out1 + x);
52
0
      Store(Y, d, out2 + x);
53
35.8k
    } else {
54
35.8k
      auto First = Load(d, in0 + x);
55
35.8k
      auto Second = Load(d, in1 + x);
56
35.8k
      auto Third = Load(d, in2 + x);
57
35.8k
      if (third) Third = Add(Third, First);
58
35.8k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
35.8k
      } else if (second == 2) {
61
35.8k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
35.8k
      }
63
35.8k
      Store(First, d, out0 + x);
64
35.8k
      Store(Second, d, out1 + x);
65
35.8k
      Store(Third, d, out2 + x);
66
35.8k
    }
67
35.8k
  }
68
18.7k
  for (; x < w; x++) {
69
11.1k
    if (transform_type == 6) {
70
0
      pixel_type Y = in0[x];
71
0
      pixel_type Co = in1[x];
72
0
      pixel_type Cg = in2[x];
73
0
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
0
      pixel_type G = PixelAdd(Cg, tmp);
75
0
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
0
      pixel_type R = PixelAdd(B, Co);
77
0
      out0[x] = R;
78
0
      out1[x] = G;
79
0
      out2[x] = B;
80
11.1k
    } else {
81
11.1k
      pixel_type First = in0[x];
82
11.1k
      pixel_type Second = in1[x];
83
11.1k
      pixel_type Third = in2[x];
84
11.1k
      if (third) Third = PixelAdd(Third, First);
85
11.1k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
11.1k
      } else if (second == 2) {
88
11.1k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
11.1k
      }
90
11.1k
      out0[x] = First;
91
11.1k
      out1[x] = Second;
92
11.1k
      out2[x] = Third;
93
11.1k
    }
94
11.1k
  }
95
7.57k
}
void jxl::N_AVX2::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
1.27k
               pixel_type* out2, size_t w) {
33
1.27k
  static_assert(transform_type >= 0 && transform_type < 7,
34
1.27k
                "Invalid transform type");
35
1.27k
  int second = transform_type >> 1;
36
1.27k
  int third = transform_type & 1;
37
38
1.27k
  size_t x = 0;
39
1.27k
  const HWY_FULL(pixel_type) d;
40
1.27k
  const size_t N = Lanes(d);
41
12.2k
  for (; x + N - 1 < w; x += N) {
42
10.9k
    if (transform_type == 6) {
43
0
      auto Y = Load(d, in0 + x);
44
0
      auto Co = Load(d, in1 + x);
45
0
      auto Cg = Load(d, in2 + x);
46
0
      Y = Sub(Y, ShiftRight<1>(Cg));
47
0
      auto G = Add(Cg, Y);
48
0
      Y = Sub(Y, ShiftRight<1>(Co));
49
0
      auto R = Add(Y, Co);
50
0
      Store(R, d, out0 + x);
51
0
      Store(G, d, out1 + x);
52
0
      Store(Y, d, out2 + x);
53
10.9k
    } else {
54
10.9k
      auto First = Load(d, in0 + x);
55
10.9k
      auto Second = Load(d, in1 + x);
56
10.9k
      auto Third = Load(d, in2 + x);
57
10.9k
      if (third) Third = Add(Third, First);
58
10.9k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
10.9k
      } else if (second == 2) {
61
10.9k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
10.9k
      }
63
10.9k
      Store(First, d, out0 + x);
64
10.9k
      Store(Second, d, out1 + x);
65
10.9k
      Store(Third, d, out2 + x);
66
10.9k
    }
67
10.9k
  }
68
3.47k
  for (; x < w; x++) {
69
2.19k
    if (transform_type == 6) {
70
0
      pixel_type Y = in0[x];
71
0
      pixel_type Co = in1[x];
72
0
      pixel_type Cg = in2[x];
73
0
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
0
      pixel_type G = PixelAdd(Cg, tmp);
75
0
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
0
      pixel_type R = PixelAdd(B, Co);
77
0
      out0[x] = R;
78
0
      out1[x] = G;
79
0
      out2[x] = B;
80
2.19k
    } else {
81
2.19k
      pixel_type First = in0[x];
82
2.19k
      pixel_type Second = in1[x];
83
2.19k
      pixel_type Third = in2[x];
84
2.19k
      if (third) Third = PixelAdd(Third, First);
85
2.19k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
2.19k
      } else if (second == 2) {
88
2.19k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
2.19k
      }
90
2.19k
      out0[x] = First;
91
2.19k
      out1[x] = Second;
92
2.19k
      out2[x] = Third;
93
2.19k
    }
94
2.19k
  }
95
1.27k
}
void jxl::N_AVX2::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
38.9k
               pixel_type* out2, size_t w) {
33
38.9k
  static_assert(transform_type >= 0 && transform_type < 7,
34
38.9k
                "Invalid transform type");
35
38.9k
  int second = transform_type >> 1;
36
38.9k
  int third = transform_type & 1;
37
38
38.9k
  size_t x = 0;
39
38.9k
  const HWY_FULL(pixel_type) d;
40
38.9k
  const size_t N = Lanes(d);
41
558k
  for (; x + N - 1 < w; x += N) {
42
519k
    if (transform_type == 6) {
43
519k
      auto Y = Load(d, in0 + x);
44
519k
      auto Co = Load(d, in1 + x);
45
519k
      auto Cg = Load(d, in2 + x);
46
519k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
519k
      auto G = Add(Cg, Y);
48
519k
      Y = Sub(Y, ShiftRight<1>(Co));
49
519k
      auto R = Add(Y, Co);
50
519k
      Store(R, d, out0 + x);
51
519k
      Store(G, d, out1 + x);
52
519k
      Store(Y, d, out2 + x);
53
519k
    } else {
54
0
      auto First = Load(d, in0 + x);
55
0
      auto Second = Load(d, in1 + x);
56
0
      auto Third = Load(d, in2 + x);
57
0
      if (third) Third = Add(Third, First);
58
0
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
0
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
0
      Store(First, d, out0 + x);
64
0
      Store(Second, d, out1 + x);
65
0
      Store(Third, d, out2 + x);
66
0
    }
67
519k
  }
68
75.1k
  for (; x < w; x++) {
69
36.2k
    if (transform_type == 6) {
70
36.2k
      pixel_type Y = in0[x];
71
36.2k
      pixel_type Co = in1[x];
72
36.2k
      pixel_type Cg = in2[x];
73
36.2k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
36.2k
      pixel_type G = PixelAdd(Cg, tmp);
75
36.2k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
36.2k
      pixel_type R = PixelAdd(B, Co);
77
36.2k
      out0[x] = R;
78
36.2k
      out1[x] = G;
79
36.2k
      out2[x] = B;
80
36.2k
    } else {
81
0
      pixel_type First = in0[x];
82
0
      pixel_type Second = in1[x];
83
0
      pixel_type Third = in2[x];
84
0
      if (third) Third = PixelAdd(Third, First);
85
0
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
0
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
0
      out0[x] = First;
91
0
      out1[x] = Second;
92
0
      out2[x] = Third;
93
0
    }
94
36.2k
  }
95
38.9k
}
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<0>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<1>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Unexecuted instantiation: void jxl::N_SSE2::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
96
97
4.57k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
4.57k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
4.57k
  size_t m = begin_c;
100
4.57k
  Channel& c0 = input.channel[m + 0];
101
4.57k
  size_t w = c0.w;
102
4.57k
  size_t h = c0.h;
103
4.57k
  if (rct_type == 0) {  // noop
104
1.43k
    return true;
105
1.43k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
3.14k
  int permutation = rct_type / 7;
108
3.14k
  JXL_ENSURE(permutation < 6);
109
  // 0-5 values have the low bit corresponding to Third and the high bits
110
  // corresponding to Second. 6 corresponds to YCoCg.
111
  //
112
  // Second: 0=nop, 1=SubtractFirst, 2=SubtractAvgFirstThird
113
  //
114
  // Third: 0=nop, 1=SubtractFirst
115
3.14k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
3.14k
  if (custom == 0) {
118
22
    Channel ch0 = std::move(input.channel[m]);
119
22
    Channel ch1 = std::move(input.channel[m + 1]);
120
22
    Channel ch2 = std::move(input.channel[m + 2]);
121
22
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
22
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
22
        std::move(ch1);
124
22
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
22
        std::move(ch2);
126
22
    return true;
127
22
  }
128
3.12k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
3.12k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
3.12k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
3.12k
  const auto process_row = [&](const uint32_t task,
132
92.0k
                               size_t /* thread */) -> Status {
133
92.0k
    const size_t y = task;
134
92.0k
    const pixel_type* in0 = input.channel[m].Row(y);
135
92.0k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
92.0k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
92.0k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
92.0k
    pixel_type* out1 =
139
92.0k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
92.0k
    pixel_type* out2 =
141
92.0k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
92.0k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
92.0k
    return true;
144
92.0k
  };
Unexecuted instantiation: rct.cc:jxl::N_SSE4::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
rct.cc:jxl::N_AVX2::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
Line
Count
Source
132
92.0k
                               size_t /* thread */) -> Status {
133
92.0k
    const size_t y = task;
134
92.0k
    const pixel_type* in0 = input.channel[m].Row(y);
135
92.0k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
92.0k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
92.0k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
92.0k
    pixel_type* out1 =
139
92.0k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
92.0k
    pixel_type* out2 =
141
92.0k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
92.0k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
92.0k
    return true;
144
92.0k
  };
Unexecuted instantiation: rct.cc:jxl::N_SSE2::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
145
3.12k
  JXL_RETURN_IF_ERROR(
146
3.12k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
3.12k
  return true;
148
3.12k
}
Unexecuted instantiation: jxl::N_SSE4::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)
jxl::N_AVX2::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)
Line
Count
Source
97
4.57k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
4.57k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
4.57k
  size_t m = begin_c;
100
4.57k
  Channel& c0 = input.channel[m + 0];
101
4.57k
  size_t w = c0.w;
102
4.57k
  size_t h = c0.h;
103
4.57k
  if (rct_type == 0) {  // noop
104
1.43k
    return true;
105
1.43k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
3.14k
  int permutation = rct_type / 7;
108
3.14k
  JXL_ENSURE(permutation < 6);
109
  // 0-5 values have the low bit corresponding to Third and the high bits
110
  // corresponding to Second. 6 corresponds to YCoCg.
111
  //
112
  // Second: 0=nop, 1=SubtractFirst, 2=SubtractAvgFirstThird
113
  //
114
  // Third: 0=nop, 1=SubtractFirst
115
3.14k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
3.14k
  if (custom == 0) {
118
22
    Channel ch0 = std::move(input.channel[m]);
119
22
    Channel ch1 = std::move(input.channel[m + 1]);
120
22
    Channel ch2 = std::move(input.channel[m + 2]);
121
22
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
22
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
22
        std::move(ch1);
124
22
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
22
        std::move(ch2);
126
22
    return true;
127
22
  }
128
3.12k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
3.12k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
3.12k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
3.12k
  const auto process_row = [&](const uint32_t task,
132
3.12k
                               size_t /* thread */) -> Status {
133
3.12k
    const size_t y = task;
134
3.12k
    const pixel_type* in0 = input.channel[m].Row(y);
135
3.12k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
3.12k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
3.12k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
3.12k
    pixel_type* out1 =
139
3.12k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
3.12k
    pixel_type* out2 =
141
3.12k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
3.12k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
3.12k
    return true;
144
3.12k
  };
145
3.12k
  JXL_RETURN_IF_ERROR(
146
3.12k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
3.12k
  return true;
148
3.12k
}
Unexecuted instantiation: jxl::N_SSE2::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)
149
150
}  // namespace HWY_NAMESPACE
151
}  // namespace jxl
152
HWY_AFTER_NAMESPACE();
153
154
#if HWY_ONCE
155
namespace jxl {
156
157
HWY_EXPORT(InvRCT);
158
4.57k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
159
4.57k
  return HWY_DYNAMIC_DISPATCH(InvRCT)(input, begin_c, rct_type, pool);
160
4.57k
}
161
162
}  // namespace jxl
163
#endif