Coverage Report

Created: 2025-10-12 07:48

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
95.2k
               pixel_type* out2, size_t w) {
33
95.2k
  static_assert(transform_type >= 0 && transform_type < 7,
34
95.2k
                "Invalid transform type");
35
95.2k
  int second = transform_type >> 1;
36
95.2k
  int third = transform_type & 1;
37
38
95.2k
  size_t x = 0;
39
95.2k
  const HWY_FULL(pixel_type) d;
40
95.2k
  const size_t N = Lanes(d);
41
1.05M
  for (; x + N - 1 < w; x += N) {
42
964k
    if (transform_type == 6) {
43
562k
      auto Y = Load(d, in0 + x);
44
562k
      auto Co = Load(d, in1 + x);
45
562k
      auto Cg = Load(d, in2 + x);
46
562k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
562k
      auto G = Add(Cg, Y);
48
562k
      Y = Sub(Y, ShiftRight<1>(Co));
49
562k
      auto R = Add(Y, Co);
50
562k
      Store(R, d, out0 + x);
51
562k
      Store(G, d, out1 + x);
52
562k
      Store(Y, d, out2 + x);
53
562k
    } else {
54
401k
      auto First = Load(d, in0 + x);
55
401k
      auto Second = Load(d, in1 + x);
56
401k
      auto Third = Load(d, in2 + x);
57
401k
      if (third) Third = Add(Third, First);
58
401k
      if (second == 1) {
59
333k
        Second = Add(Second, First);
60
333k
      } else if (second == 2) {
61
29.4k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
29.4k
      }
63
401k
      Store(First, d, out0 + x);
64
401k
      Store(Second, d, out1 + x);
65
401k
      Store(Third, d, out2 + x);
66
401k
    }
67
964k
  }
68
194k
  for (; x < w; x++) {
69
99.5k
    if (transform_type == 6) {
70
65.7k
      pixel_type Y = in0[x];
71
65.7k
      pixel_type Co = in1[x];
72
65.7k
      pixel_type Cg = in2[x];
73
65.7k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
65.7k
      pixel_type G = PixelAdd(Cg, tmp);
75
65.7k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
65.7k
      pixel_type R = PixelAdd(B, Co);
77
65.7k
      out0[x] = R;
78
65.7k
      out1[x] = G;
79
65.7k
      out2[x] = B;
80
65.7k
    } else {
81
33.8k
      pixel_type First = in0[x];
82
33.8k
      pixel_type Second = in1[x];
83
33.8k
      pixel_type Third = in2[x];
84
33.8k
      if (third) Third = PixelAdd(Third, First);
85
33.8k
      if (second == 1) {
86
23.8k
        Second = PixelAdd(Second, First);
87
23.8k
      } else if (second == 2) {
88
6.93k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
6.93k
      }
90
33.8k
      out0[x] = First;
91
33.8k
      out1[x] = Second;
92
33.8k
      out2[x] = Third;
93
33.8k
    }
94
99.5k
  }
95
95.2k
}
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
3.50k
               pixel_type* out2, size_t w) {
33
3.50k
  static_assert(transform_type >= 0 && transform_type < 7,
34
3.50k
                "Invalid transform type");
35
3.50k
  int second = transform_type >> 1;
36
3.50k
  int third = transform_type & 1;
37
38
3.50k
  size_t x = 0;
39
3.50k
  const HWY_FULL(pixel_type) d;
40
3.50k
  const size_t N = Lanes(d);
41
42.5k
  for (; x + N - 1 < w; x += N) {
42
39.0k
    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
39.0k
    } else {
54
39.0k
      auto First = Load(d, in0 + x);
55
39.0k
      auto Second = Load(d, in1 + x);
56
39.0k
      auto Third = Load(d, in2 + x);
57
39.0k
      if (third) Third = Add(Third, First);
58
39.0k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
39.0k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
39.0k
      Store(First, d, out0 + x);
64
39.0k
      Store(Second, d, out1 + x);
65
39.0k
      Store(Third, d, out2 + x);
66
39.0k
    }
67
39.0k
  }
68
6.53k
  for (; x < w; x++) {
69
3.02k
    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
3.02k
    } else {
81
3.02k
      pixel_type First = in0[x];
82
3.02k
      pixel_type Second = in1[x];
83
3.02k
      pixel_type Third = in2[x];
84
3.02k
      if (third) Third = PixelAdd(Third, First);
85
3.02k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
3.02k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
3.02k
      out0[x] = First;
91
3.02k
      out1[x] = Second;
92
3.02k
      out2[x] = Third;
93
3.02k
    }
94
3.02k
  }
95
3.50k
}
void jxl::N_AVX2::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
24.5k
               pixel_type* out2, size_t w) {
33
24.5k
  static_assert(transform_type >= 0 && transform_type < 7,
34
24.5k
                "Invalid transform type");
35
24.5k
  int second = transform_type >> 1;
36
24.5k
  int third = transform_type & 1;
37
38
24.5k
  size_t x = 0;
39
24.5k
  const HWY_FULL(pixel_type) d;
40
24.5k
  const size_t N = Lanes(d);
41
266k
  for (; x + N - 1 < w; x += N) {
42
242k
    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
242k
    } else {
54
242k
      auto First = Load(d, in0 + x);
55
242k
      auto Second = Load(d, in1 + x);
56
242k
      auto Third = Load(d, in2 + x);
57
242k
      if (third) Third = Add(Third, First);
58
242k
      if (second == 1) {
59
242k
        Second = Add(Second, First);
60
242k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
242k
      Store(First, d, out0 + x);
64
242k
      Store(Second, d, out1 + x);
65
242k
      Store(Third, d, out2 + x);
66
242k
    }
67
242k
  }
68
42.2k
  for (; x < w; x++) {
69
17.7k
    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
17.7k
    } else {
81
17.7k
      pixel_type First = in0[x];
82
17.7k
      pixel_type Second = in1[x];
83
17.7k
      pixel_type Third = in2[x];
84
17.7k
      if (third) Third = PixelAdd(Third, First);
85
17.7k
      if (second == 1) {
86
17.7k
        Second = PixelAdd(Second, First);
87
17.7k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
17.7k
      out0[x] = First;
91
17.7k
      out1[x] = Second;
92
17.7k
      out2[x] = Third;
93
17.7k
    }
94
17.7k
  }
95
24.5k
}
void jxl::N_AVX2::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
5.81k
               pixel_type* out2, size_t w) {
33
5.81k
  static_assert(transform_type >= 0 && transform_type < 7,
34
5.81k
                "Invalid transform type");
35
5.81k
  int second = transform_type >> 1;
36
5.81k
  int third = transform_type & 1;
37
38
5.81k
  size_t x = 0;
39
5.81k
  const HWY_FULL(pixel_type) d;
40
5.81k
  const size_t N = Lanes(d);
41
96.4k
  for (; x + N - 1 < w; x += N) {
42
90.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
90.6k
    } else {
54
90.6k
      auto First = Load(d, in0 + x);
55
90.6k
      auto Second = Load(d, in1 + x);
56
90.6k
      auto Third = Load(d, in2 + x);
57
90.6k
      if (third) Third = Add(Third, First);
58
90.6k
      if (second == 1) {
59
90.6k
        Second = Add(Second, First);
60
90.6k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
90.6k
      Store(First, d, out0 + x);
64
90.6k
      Store(Second, d, out1 + x);
65
90.6k
      Store(Third, d, out2 + x);
66
90.6k
    }
67
90.6k
  }
68
11.9k
  for (; x < w; x++) {
69
6.15k
    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
6.15k
    } else {
81
6.15k
      pixel_type First = in0[x];
82
6.15k
      pixel_type Second = in1[x];
83
6.15k
      pixel_type Third = in2[x];
84
6.15k
      if (third) Third = PixelAdd(Third, First);
85
6.15k
      if (second == 1) {
86
6.15k
        Second = PixelAdd(Second, First);
87
6.15k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
6.15k
      out0[x] = First;
91
6.15k
      out1[x] = Second;
92
6.15k
      out2[x] = Third;
93
6.15k
    }
94
6.15k
  }
95
5.81k
}
void jxl::N_AVX2::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
2.31k
               pixel_type* out2, size_t w) {
33
2.31k
  static_assert(transform_type >= 0 && transform_type < 7,
34
2.31k
                "Invalid transform type");
35
2.31k
  int second = transform_type >> 1;
36
2.31k
  int third = transform_type & 1;
37
38
2.31k
  size_t x = 0;
39
2.31k
  const HWY_FULL(pixel_type) d;
40
2.31k
  const size_t N = Lanes(d);
41
14.5k
  for (; x + N - 1 < w; x += N) {
42
12.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
12.1k
    } else {
54
12.1k
      auto First = Load(d, in0 + x);
55
12.1k
      auto Second = Load(d, in1 + x);
56
12.1k
      auto Third = Load(d, in2 + x);
57
12.1k
      if (third) Third = Add(Third, First);
58
12.1k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
12.1k
      } else if (second == 2) {
61
12.1k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
12.1k
      }
63
12.1k
      Store(First, d, out0 + x);
64
12.1k
      Store(Second, d, out1 + x);
65
12.1k
      Store(Third, d, out2 + x);
66
12.1k
    }
67
12.1k
  }
68
7.58k
  for (; x < w; x++) {
69
5.26k
    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
5.26k
    } else {
81
5.26k
      pixel_type First = in0[x];
82
5.26k
      pixel_type Second = in1[x];
83
5.26k
      pixel_type Third = in2[x];
84
5.26k
      if (third) Third = PixelAdd(Third, First);
85
5.26k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
5.26k
      } else if (second == 2) {
88
5.26k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
5.26k
      }
90
5.26k
      out0[x] = First;
91
5.26k
      out1[x] = Second;
92
5.26k
      out2[x] = Third;
93
5.26k
    }
94
5.26k
  }
95
2.31k
}
void jxl::N_AVX2::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
11.9k
               pixel_type* out2, size_t w) {
33
11.9k
  static_assert(transform_type >= 0 && transform_type < 7,
34
11.9k
                "Invalid transform type");
35
11.9k
  int second = transform_type >> 1;
36
11.9k
  int third = transform_type & 1;
37
38
11.9k
  size_t x = 0;
39
11.9k
  const HWY_FULL(pixel_type) d;
40
11.9k
  const size_t N = Lanes(d);
41
29.2k
  for (; x + N - 1 < w; x += N) {
42
17.2k
    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
17.2k
    } else {
54
17.2k
      auto First = Load(d, in0 + x);
55
17.2k
      auto Second = Load(d, in1 + x);
56
17.2k
      auto Third = Load(d, in2 + x);
57
17.2k
      if (third) Third = Add(Third, First);
58
17.2k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
17.2k
      } else if (second == 2) {
61
17.2k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
17.2k
      }
63
17.2k
      Store(First, d, out0 + x);
64
17.2k
      Store(Second, d, out1 + x);
65
17.2k
      Store(Third, d, out2 + x);
66
17.2k
    }
67
17.2k
  }
68
13.6k
  for (; x < w; x++) {
69
1.66k
    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
1.66k
    } else {
81
1.66k
      pixel_type First = in0[x];
82
1.66k
      pixel_type Second = in1[x];
83
1.66k
      pixel_type Third = in2[x];
84
1.66k
      if (third) Third = PixelAdd(Third, First);
85
1.66k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
1.66k
      } else if (second == 2) {
88
1.66k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
1.66k
      }
90
1.66k
      out0[x] = First;
91
1.66k
      out1[x] = Second;
92
1.66k
      out2[x] = Third;
93
1.66k
    }
94
1.66k
  }
95
11.9k
}
void jxl::N_AVX2::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
47.1k
               pixel_type* out2, size_t w) {
33
47.1k
  static_assert(transform_type >= 0 && transform_type < 7,
34
47.1k
                "Invalid transform type");
35
47.1k
  int second = transform_type >> 1;
36
47.1k
  int third = transform_type & 1;
37
38
47.1k
  size_t x = 0;
39
47.1k
  const HWY_FULL(pixel_type) d;
40
47.1k
  const size_t N = Lanes(d);
41
609k
  for (; x + N - 1 < w; x += N) {
42
562k
    if (transform_type == 6) {
43
562k
      auto Y = Load(d, in0 + x);
44
562k
      auto Co = Load(d, in1 + x);
45
562k
      auto Cg = Load(d, in2 + x);
46
562k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
562k
      auto G = Add(Cg, Y);
48
562k
      Y = Sub(Y, ShiftRight<1>(Co));
49
562k
      auto R = Add(Y, Co);
50
562k
      Store(R, d, out0 + x);
51
562k
      Store(G, d, out1 + x);
52
562k
      Store(Y, d, out2 + x);
53
562k
    } 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
562k
  }
68
112k
  for (; x < w; x++) {
69
65.7k
    if (transform_type == 6) {
70
65.7k
      pixel_type Y = in0[x];
71
65.7k
      pixel_type Co = in1[x];
72
65.7k
      pixel_type Cg = in2[x];
73
65.7k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
65.7k
      pixel_type G = PixelAdd(Cg, tmp);
75
65.7k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
65.7k
      pixel_type R = PixelAdd(B, Co);
77
65.7k
      out0[x] = R;
78
65.7k
      out1[x] = G;
79
65.7k
      out2[x] = B;
80
65.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
65.7k
  }
95
47.1k
}
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
3.44k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
3.44k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
3.44k
  size_t m = begin_c;
100
3.44k
  Channel& c0 = input.channel[m + 0];
101
3.44k
  size_t w = c0.w;
102
3.44k
  size_t h = c0.h;
103
3.44k
  if (rct_type == 0) {  // noop
104
1.27k
    return true;
105
1.27k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
2.16k
  int permutation = rct_type / 7;
108
2.16k
  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
2.16k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
2.16k
  if (custom == 0) {
118
26
    Channel ch0 = std::move(input.channel[m]);
119
26
    Channel ch1 = std::move(input.channel[m + 1]);
120
26
    Channel ch2 = std::move(input.channel[m + 2]);
121
26
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
26
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
26
        std::move(ch1);
124
26
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
26
        std::move(ch2);
126
26
    return true;
127
26
  }
128
2.14k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
2.14k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
2.14k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
2.14k
  const auto process_row = [&](const uint32_t task,
132
95.2k
                               size_t /* thread */) -> Status {
133
95.2k
    const size_t y = task;
134
95.2k
    const pixel_type* in0 = input.channel[m].Row(y);
135
95.2k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
95.2k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
95.2k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
95.2k
    pixel_type* out1 =
139
95.2k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
95.2k
    pixel_type* out2 =
141
95.2k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
95.2k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
95.2k
    return true;
144
95.2k
  };
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
95.2k
                               size_t /* thread */) -> Status {
133
95.2k
    const size_t y = task;
134
95.2k
    const pixel_type* in0 = input.channel[m].Row(y);
135
95.2k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
95.2k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
95.2k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
95.2k
    pixel_type* out1 =
139
95.2k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
95.2k
    pixel_type* out2 =
141
95.2k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
95.2k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
95.2k
    return true;
144
95.2k
  };
Unexecuted instantiation: rct.cc:jxl::N_SSE2::InvRCT(jxl::Image&, unsigned long, unsigned long, jxl::ThreadPool*)::$_0::operator()(unsigned int, unsigned long) const
145
2.14k
  JXL_RETURN_IF_ERROR(
146
2.14k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
2.14k
  return true;
148
2.14k
}
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
3.44k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
3.44k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
3.44k
  size_t m = begin_c;
100
3.44k
  Channel& c0 = input.channel[m + 0];
101
3.44k
  size_t w = c0.w;
102
3.44k
  size_t h = c0.h;
103
3.44k
  if (rct_type == 0) {  // noop
104
1.27k
    return true;
105
1.27k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
2.16k
  int permutation = rct_type / 7;
108
2.16k
  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
2.16k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
2.16k
  if (custom == 0) {
118
26
    Channel ch0 = std::move(input.channel[m]);
119
26
    Channel ch1 = std::move(input.channel[m + 1]);
120
26
    Channel ch2 = std::move(input.channel[m + 2]);
121
26
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
26
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
26
        std::move(ch1);
124
26
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
26
        std::move(ch2);
126
26
    return true;
127
26
  }
128
2.14k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
2.14k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
2.14k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
2.14k
  const auto process_row = [&](const uint32_t task,
132
2.14k
                               size_t /* thread */) -> Status {
133
2.14k
    const size_t y = task;
134
2.14k
    const pixel_type* in0 = input.channel[m].Row(y);
135
2.14k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
2.14k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
2.14k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
2.14k
    pixel_type* out1 =
139
2.14k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
2.14k
    pixel_type* out2 =
141
2.14k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
2.14k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
2.14k
    return true;
144
2.14k
  };
145
2.14k
  JXL_RETURN_IF_ERROR(
146
2.14k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
2.14k
  return true;
148
2.14k
}
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
3.44k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
159
3.44k
  return HWY_DYNAMIC_DISPATCH(InvRCT)(input, begin_c, rct_type, pool);
160
3.44k
}
161
162
}  // namespace jxl
163
#endif