Coverage Report

Created: 2026-11-12 07:35

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
101k
               pixel_type* out2, size_t w) {
33
101k
  static_assert(transform_type >= 0 && transform_type < 7,
34
101k
                "Invalid transform type");
35
101k
  int second = transform_type >> 1;
36
101k
  int third = transform_type & 1;
37
38
101k
  size_t x = 0;
39
101k
  const HWY_FULL(pixel_type) d;
40
101k
  const size_t N = Lanes(d);
41
1.13M
  for (; x + N - 1 < w; x += N) {
42
1.02M
    if (transform_type == 6) {
43
612k
      auto Y = Load(d, in0 + x);
44
612k
      auto Co = Load(d, in1 + x);
45
612k
      auto Cg = Load(d, in2 + x);
46
612k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
612k
      auto G = Add(Cg, Y);
48
612k
      Y = Sub(Y, ShiftRight<1>(Co));
49
612k
      auto R = Add(Y, Co);
50
612k
      Store(R, d, out0 + x);
51
612k
      Store(G, d, out1 + x);
52
612k
      Store(Y, d, out2 + x);
53
612k
    } else {
54
417k
      auto First = Load(d, in0 + x);
55
417k
      auto Second = Load(d, in1 + x);
56
417k
      auto Third = Load(d, in2 + x);
57
417k
      if (third) Third = Add(Third, First);
58
417k
      if (second == 1) {
59
342k
        Second = Add(Second, First);
60
342k
      } else if (second == 2) {
61
37.0k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
37.0k
      }
63
417k
      Store(First, d, out0 + x);
64
417k
      Store(Second, d, out1 + x);
65
417k
      Store(Third, d, out2 + x);
66
417k
    }
67
1.02M
  }
68
213k
  for (; x < w; x++) {
69
112k
    if (transform_type == 6) {
70
54.7k
      pixel_type Y = in0[x];
71
54.7k
      pixel_type Co = in1[x];
72
54.7k
      pixel_type Cg = in2[x];
73
54.7k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
54.7k
      pixel_type G = PixelAdd(Cg, tmp);
75
54.7k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
54.7k
      pixel_type R = PixelAdd(B, Co);
77
54.7k
      out0[x] = R;
78
54.7k
      out1[x] = G;
79
54.7k
      out2[x] = B;
80
57.6k
    } else {
81
57.6k
      pixel_type First = in0[x];
82
57.6k
      pixel_type Second = in1[x];
83
57.6k
      pixel_type Third = in2[x];
84
57.6k
      if (third) Third = PixelAdd(Third, First);
85
57.6k
      if (second == 1) {
86
37.3k
        Second = PixelAdd(Second, First);
87
37.3k
      } else if (second == 2) {
88
11.5k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
11.5k
      }
90
57.6k
      out0[x] = First;
91
57.6k
      out1[x] = Second;
92
57.6k
      out2[x] = Third;
93
57.6k
    }
94
112k
  }
95
101k
}
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.12k
               pixel_type* out2, size_t w) {
33
4.12k
  static_assert(transform_type >= 0 && transform_type < 7,
34
4.12k
                "Invalid transform type");
35
4.12k
  int second = transform_type >> 1;
36
4.12k
  int third = transform_type & 1;
37
38
4.12k
  size_t x = 0;
39
4.12k
  const HWY_FULL(pixel_type) d;
40
4.12k
  const size_t N = Lanes(d);
41
42.0k
  for (; x + N - 1 < w; x += N) {
42
37.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
37.9k
    } else {
54
37.9k
      auto First = Load(d, in0 + x);
55
37.9k
      auto Second = Load(d, in1 + x);
56
37.9k
      auto Third = Load(d, in2 + x);
57
37.9k
      if (third) Third = Add(Third, First);
58
37.9k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
37.9k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
37.9k
      Store(First, d, out0 + x);
64
37.9k
      Store(Second, d, out1 + x);
65
37.9k
      Store(Third, d, out2 + x);
66
37.9k
    }
67
37.9k
  }
68
12.9k
  for (; x < w; x++) {
69
8.82k
    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
8.82k
    } else {
81
8.82k
      pixel_type First = in0[x];
82
8.82k
      pixel_type Second = in1[x];
83
8.82k
      pixel_type Third = in2[x];
84
8.82k
      if (third) Third = PixelAdd(Third, First);
85
8.82k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
8.82k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
8.82k
      out0[x] = First;
91
8.82k
      out1[x] = Second;
92
8.82k
      out2[x] = Third;
93
8.82k
    }
94
8.82k
  }
95
4.12k
}
void jxl::N_AVX2::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
36.9k
               pixel_type* out2, size_t w) {
33
36.9k
  static_assert(transform_type >= 0 && transform_type < 7,
34
36.9k
                "Invalid transform type");
35
36.9k
  int second = transform_type >> 1;
36
36.9k
  int third = transform_type & 1;
37
38
36.9k
  size_t x = 0;
39
36.9k
  const HWY_FULL(pixel_type) d;
40
36.9k
  const size_t N = Lanes(d);
41
330k
  for (; x + N - 1 < w; x += N) {
42
293k
    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
293k
    } else {
54
293k
      auto First = Load(d, in0 + x);
55
293k
      auto Second = Load(d, in1 + x);
56
293k
      auto Third = Load(d, in2 + x);
57
293k
      if (third) Third = Add(Third, First);
58
293k
      if (second == 1) {
59
293k
        Second = Add(Second, First);
60
293k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
293k
      Store(First, d, out0 + x);
64
293k
      Store(Second, d, out1 + x);
65
293k
      Store(Third, d, out2 + x);
66
293k
    }
67
293k
  }
68
63.2k
  for (; x < w; x++) {
69
26.2k
    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
26.2k
    } else {
81
26.2k
      pixel_type First = in0[x];
82
26.2k
      pixel_type Second = in1[x];
83
26.2k
      pixel_type Third = in2[x];
84
26.2k
      if (third) Third = PixelAdd(Third, First);
85
26.2k
      if (second == 1) {
86
26.2k
        Second = PixelAdd(Second, First);
87
26.2k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
26.2k
      out0[x] = First;
91
26.2k
      out1[x] = Second;
92
26.2k
      out2[x] = Third;
93
26.2k
    }
94
26.2k
  }
95
36.9k
}
void jxl::N_AVX2::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
5.45k
               pixel_type* out2, size_t w) {
33
5.45k
  static_assert(transform_type >= 0 && transform_type < 7,
34
5.45k
                "Invalid transform type");
35
5.45k
  int second = transform_type >> 1;
36
5.45k
  int third = transform_type & 1;
37
38
5.45k
  size_t x = 0;
39
5.45k
  const HWY_FULL(pixel_type) d;
40
5.45k
  const size_t N = Lanes(d);
41
54.4k
  for (; x + N - 1 < w; x += N) {
42
48.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
48.9k
    } else {
54
48.9k
      auto First = Load(d, in0 + x);
55
48.9k
      auto Second = Load(d, in1 + x);
56
48.9k
      auto Third = Load(d, in2 + x);
57
48.9k
      if (third) Third = Add(Third, First);
58
48.9k
      if (second == 1) {
59
48.9k
        Second = Add(Second, First);
60
48.9k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
48.9k
      Store(First, d, out0 + x);
64
48.9k
      Store(Second, d, out1 + x);
65
48.9k
      Store(Third, d, out2 + x);
66
48.9k
    }
67
48.9k
  }
68
16.4k
  for (; x < w; x++) {
69
11.0k
    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.0k
    } else {
81
11.0k
      pixel_type First = in0[x];
82
11.0k
      pixel_type Second = in1[x];
83
11.0k
      pixel_type Third = in2[x];
84
11.0k
      if (third) Third = PixelAdd(Third, First);
85
11.0k
      if (second == 1) {
86
11.0k
        Second = PixelAdd(Second, First);
87
11.0k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
11.0k
      out0[x] = First;
91
11.0k
      out1[x] = Second;
92
11.0k
      out2[x] = Third;
93
11.0k
    }
94
11.0k
  }
95
5.45k
}
void jxl::N_AVX2::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
3.18k
               pixel_type* out2, size_t w) {
33
3.18k
  static_assert(transform_type >= 0 && transform_type < 7,
34
3.18k
                "Invalid transform type");
35
3.18k
  int second = transform_type >> 1;
36
3.18k
  int third = transform_type & 1;
37
38
3.18k
  size_t x = 0;
39
3.18k
  const HWY_FULL(pixel_type) d;
40
3.18k
  const size_t N = Lanes(d);
41
24.5k
  for (; x + N - 1 < w; x += N) {
42
21.3k
    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
21.3k
    } else {
54
21.3k
      auto First = Load(d, in0 + x);
55
21.3k
      auto Second = Load(d, in1 + x);
56
21.3k
      auto Third = Load(d, in2 + x);
57
21.3k
      if (third) Third = Add(Third, First);
58
21.3k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
21.3k
      } else if (second == 2) {
61
21.3k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
21.3k
      }
63
21.3k
      Store(First, d, out0 + x);
64
21.3k
      Store(Second, d, out1 + x);
65
21.3k
      Store(Third, d, out2 + x);
66
21.3k
    }
67
21.3k
  }
68
11.7k
  for (; x < w; x++) {
69
8.56k
    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
8.56k
    } else {
81
8.56k
      pixel_type First = in0[x];
82
8.56k
      pixel_type Second = in1[x];
83
8.56k
      pixel_type Third = in2[x];
84
8.56k
      if (third) Third = PixelAdd(Third, First);
85
8.56k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
8.56k
      } else if (second == 2) {
88
8.56k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
8.56k
      }
90
8.56k
      out0[x] = First;
91
8.56k
      out1[x] = Second;
92
8.56k
      out2[x] = Third;
93
8.56k
    }
94
8.56k
  }
95
3.18k
}
void jxl::N_AVX2::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
1.81k
               pixel_type* out2, size_t w) {
33
1.81k
  static_assert(transform_type >= 0 && transform_type < 7,
34
1.81k
                "Invalid transform type");
35
1.81k
  int second = transform_type >> 1;
36
1.81k
  int third = transform_type & 1;
37
38
1.81k
  size_t x = 0;
39
1.81k
  const HWY_FULL(pixel_type) d;
40
1.81k
  const size_t N = Lanes(d);
41
17.4k
  for (; x + N - 1 < w; x += N) {
42
15.6k
    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
15.6k
    } else {
54
15.6k
      auto First = Load(d, in0 + x);
55
15.6k
      auto Second = Load(d, in1 + x);
56
15.6k
      auto Third = Load(d, in2 + x);
57
15.6k
      if (third) Third = Add(Third, First);
58
15.6k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
15.6k
      } else if (second == 2) {
61
15.6k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
15.6k
      }
63
15.6k
      Store(First, d, out0 + x);
64
15.6k
      Store(Second, d, out1 + x);
65
15.6k
      Store(Third, d, out2 + x);
66
15.6k
    }
67
15.6k
  }
68
4.77k
  for (; x < w; x++) {
69
2.95k
    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.95k
    } else {
81
2.95k
      pixel_type First = in0[x];
82
2.95k
      pixel_type Second = in1[x];
83
2.95k
      pixel_type Third = in2[x];
84
2.95k
      if (third) Third = PixelAdd(Third, First);
85
2.95k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
2.95k
      } else if (second == 2) {
88
2.95k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
2.95k
      }
90
2.95k
      out0[x] = First;
91
2.95k
      out1[x] = Second;
92
2.95k
      out2[x] = Third;
93
2.95k
    }
94
2.95k
  }
95
1.81k
}
void jxl::N_AVX2::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
49.9k
               pixel_type* out2, size_t w) {
33
49.9k
  static_assert(transform_type >= 0 && transform_type < 7,
34
49.9k
                "Invalid transform type");
35
49.9k
  int second = transform_type >> 1;
36
49.9k
  int third = transform_type & 1;
37
38
49.9k
  size_t x = 0;
39
49.9k
  const HWY_FULL(pixel_type) d;
40
49.9k
  const size_t N = Lanes(d);
41
662k
  for (; x + N - 1 < w; x += N) {
42
612k
    if (transform_type == 6) {
43
612k
      auto Y = Load(d, in0 + x);
44
612k
      auto Co = Load(d, in1 + x);
45
612k
      auto Cg = Load(d, in2 + x);
46
612k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
612k
      auto G = Add(Cg, Y);
48
612k
      Y = Sub(Y, ShiftRight<1>(Co));
49
612k
      auto R = Add(Y, Co);
50
612k
      Store(R, d, out0 + x);
51
612k
      Store(G, d, out1 + x);
52
612k
      Store(Y, d, out2 + x);
53
612k
    } 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
612k
  }
68
104k
  for (; x < w; x++) {
69
54.7k
    if (transform_type == 6) {
70
54.7k
      pixel_type Y = in0[x];
71
54.7k
      pixel_type Co = in1[x];
72
54.7k
      pixel_type Cg = in2[x];
73
54.7k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
54.7k
      pixel_type G = PixelAdd(Cg, tmp);
75
54.7k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
54.7k
      pixel_type R = PixelAdd(B, Co);
77
54.7k
      out0[x] = R;
78
54.7k
      out1[x] = G;
79
54.7k
      out2[x] = B;
80
54.7k
    } 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
54.7k
  }
95
49.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.86k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
4.86k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
4.86k
  size_t m = begin_c;
100
4.86k
  Channel& c0 = input.channel[m + 0];
101
4.86k
  size_t w = c0.w;
102
4.86k
  size_t h = c0.h;
103
4.86k
  if (rct_type == 0) {  // noop
104
1.37k
    return true;
105
1.37k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
3.49k
  int permutation = rct_type / 7;
108
3.49k
  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.49k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
3.49k
  if (custom == 0) {
118
64
    Channel ch0 = std::move(input.channel[m]);
119
64
    Channel ch1 = std::move(input.channel[m + 1]);
120
64
    Channel ch2 = std::move(input.channel[m + 2]);
121
64
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
64
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
64
        std::move(ch1);
124
64
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
64
        std::move(ch2);
126
64
    return true;
127
64
  }
128
3.43k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
3.43k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
3.43k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
3.43k
  const auto process_row = [&](const uint32_t task,
132
101k
                               size_t /* thread */) -> Status {
133
101k
    const size_t y = task;
134
101k
    const pixel_type* in0 = input.channel[m].Row(y);
135
101k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
101k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
101k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
101k
    pixel_type* out1 =
139
101k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
101k
    pixel_type* out2 =
141
101k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
101k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
101k
    return true;
144
101k
  };
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
101k
                               size_t /* thread */) -> Status {
133
101k
    const size_t y = task;
134
101k
    const pixel_type* in0 = input.channel[m].Row(y);
135
101k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
101k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
101k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
101k
    pixel_type* out1 =
139
101k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
101k
    pixel_type* out2 =
141
101k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
101k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
101k
    return true;
144
101k
  };
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.43k
  JXL_RETURN_IF_ERROR(
146
3.43k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
3.43k
  return true;
148
3.43k
}
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.86k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
4.86k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
4.86k
  size_t m = begin_c;
100
4.86k
  Channel& c0 = input.channel[m + 0];
101
4.86k
  size_t w = c0.w;
102
4.86k
  size_t h = c0.h;
103
4.86k
  if (rct_type == 0) {  // noop
104
1.37k
    return true;
105
1.37k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
3.49k
  int permutation = rct_type / 7;
108
3.49k
  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.49k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
3.49k
  if (custom == 0) {
118
64
    Channel ch0 = std::move(input.channel[m]);
119
64
    Channel ch1 = std::move(input.channel[m + 1]);
120
64
    Channel ch2 = std::move(input.channel[m + 2]);
121
64
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
64
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
64
        std::move(ch1);
124
64
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
64
        std::move(ch2);
126
64
    return true;
127
64
  }
128
3.43k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
3.43k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
3.43k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
3.43k
  const auto process_row = [&](const uint32_t task,
132
3.43k
                               size_t /* thread */) -> Status {
133
3.43k
    const size_t y = task;
134
3.43k
    const pixel_type* in0 = input.channel[m].Row(y);
135
3.43k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
3.43k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
3.43k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
3.43k
    pixel_type* out1 =
139
3.43k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
3.43k
    pixel_type* out2 =
141
3.43k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
3.43k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
3.43k
    return true;
144
3.43k
  };
145
3.43k
  JXL_RETURN_IF_ERROR(
146
3.43k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
3.43k
  return true;
148
3.43k
}
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.86k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
159
4.86k
  return HWY_DYNAMIC_DISPATCH(InvRCT)(input, begin_c, rct_type, pool);
160
4.86k
}
161
162
}  // namespace jxl
163
#endif