Coverage Report

Created: 2026-05-16 07:22

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
85.1k
               pixel_type* out2, size_t w) {
33
85.1k
  static_assert(transform_type >= 0 && transform_type < 7,
34
85.1k
                "Invalid transform type");
35
85.1k
  int second = transform_type >> 1;
36
85.1k
  int third = transform_type & 1;
37
38
85.1k
  size_t x = 0;
39
85.1k
  const HWY_FULL(pixel_type) d;
40
85.1k
  const size_t N = Lanes(d);
41
1.00M
  for (; x + N - 1 < w; x += N) {
42
918k
    if (transform_type == 6) {
43
482k
      auto Y = Load(d, in0 + x);
44
482k
      auto Co = Load(d, in1 + x);
45
482k
      auto Cg = Load(d, in2 + x);
46
482k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
482k
      auto G = Add(Cg, Y);
48
482k
      Y = Sub(Y, ShiftRight<1>(Co));
49
482k
      auto R = Add(Y, Co);
50
482k
      Store(R, d, out0 + x);
51
482k
      Store(G, d, out1 + x);
52
482k
      Store(Y, d, out2 + x);
53
482k
    } else {
54
436k
      auto First = Load(d, in0 + x);
55
436k
      auto Second = Load(d, in1 + x);
56
436k
      auto Third = Load(d, in2 + x);
57
436k
      if (third) Third = Add(Third, First);
58
436k
      if (second == 1) {
59
319k
        Second = Add(Second, First);
60
319k
      } else if (second == 2) {
61
43.7k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
43.7k
      }
63
436k
      Store(First, d, out0 + x);
64
436k
      Store(Second, d, out1 + x);
65
436k
      Store(Third, d, out2 + x);
66
436k
    }
67
918k
  }
68
155k
  for (; x < w; x++) {
69
70.0k
    if (transform_type == 6) {
70
27.8k
      pixel_type Y = in0[x];
71
27.8k
      pixel_type Co = in1[x];
72
27.8k
      pixel_type Cg = in2[x];
73
27.8k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
27.8k
      pixel_type G = PixelAdd(Cg, tmp);
75
27.8k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
27.8k
      pixel_type R = PixelAdd(B, Co);
77
27.8k
      out0[x] = R;
78
27.8k
      out1[x] = G;
79
27.8k
      out2[x] = B;
80
42.1k
    } else {
81
42.1k
      pixel_type First = in0[x];
82
42.1k
      pixel_type Second = in1[x];
83
42.1k
      pixel_type Third = in2[x];
84
42.1k
      if (third) Third = PixelAdd(Third, First);
85
42.1k
      if (second == 1) {
86
24.0k
        Second = PixelAdd(Second, First);
87
24.0k
      } else if (second == 2) {
88
10.8k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
10.8k
      }
90
42.1k
      out0[x] = First;
91
42.1k
      out1[x] = Second;
92
42.1k
      out2[x] = Third;
93
42.1k
    }
94
70.0k
  }
95
85.1k
}
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.8k
  for (; x + N - 1 < w; x += N) {
42
72.4k
    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.4k
    } else {
54
72.4k
      auto First = Load(d, in0 + x);
55
72.4k
      auto Second = Load(d, in1 + x);
56
72.4k
      auto Third = Load(d, in2 + x);
57
72.4k
      if (third) Third = Add(Third, First);
58
72.4k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
72.4k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
72.4k
      Store(First, d, out0 + x);
64
72.4k
      Store(Second, d, out1 + x);
65
72.4k
      Store(Third, d, out2 + x);
66
72.4k
    }
67
72.4k
  }
68
11.6k
  for (; x < w; x++) {
69
7.33k
    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.33k
    } else {
81
7.33k
      pixel_type First = in0[x];
82
7.33k
      pixel_type Second = in1[x];
83
7.33k
      pixel_type Third = in2[x];
84
7.33k
      if (third) Third = PixelAdd(Third, First);
85
7.33k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
7.33k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
7.33k
      out0[x] = First;
91
7.33k
      out1[x] = Second;
92
7.33k
      out2[x] = Third;
93
7.33k
    }
94
7.33k
  }
95
4.35k
}
void jxl::N_AVX2::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
29.1k
               pixel_type* out2, size_t w) {
33
29.1k
  static_assert(transform_type >= 0 && transform_type < 7,
34
29.1k
                "Invalid transform type");
35
29.1k
  int second = transform_type >> 1;
36
29.1k
  int third = transform_type & 1;
37
38
29.1k
  size_t x = 0;
39
29.1k
  const HWY_FULL(pixel_type) d;
40
29.1k
  const size_t N = Lanes(d);
41
266k
  for (; x + N - 1 < w; x += N) {
42
237k
    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
237k
    } else {
54
237k
      auto First = Load(d, in0 + x);
55
237k
      auto Second = Load(d, in1 + x);
56
237k
      auto Third = Load(d, in2 + x);
57
237k
      if (third) Third = Add(Third, First);
58
237k
      if (second == 1) {
59
237k
        Second = Add(Second, First);
60
237k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
237k
      Store(First, d, out0 + x);
64
237k
      Store(Second, d, out1 + x);
65
237k
      Store(Third, d, out2 + x);
66
237k
    }
67
237k
  }
68
45.0k
  for (; x < w; x++) {
69
15.9k
    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
15.9k
    } else {
81
15.9k
      pixel_type First = in0[x];
82
15.9k
      pixel_type Second = in1[x];
83
15.9k
      pixel_type Third = in2[x];
84
15.9k
      if (third) Third = PixelAdd(Third, First);
85
15.9k
      if (second == 1) {
86
15.9k
        Second = PixelAdd(Second, First);
87
15.9k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
15.9k
      out0[x] = First;
91
15.9k
      out1[x] = Second;
92
15.9k
      out2[x] = Third;
93
15.9k
    }
94
15.9k
  }
95
29.1k
}
void jxl::N_AVX2::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
5.83k
               pixel_type* out2, size_t w) {
33
5.83k
  static_assert(transform_type >= 0 && transform_type < 7,
34
5.83k
                "Invalid transform type");
35
5.83k
  int second = transform_type >> 1;
36
5.83k
  int third = transform_type & 1;
37
38
5.83k
  size_t x = 0;
39
5.83k
  const HWY_FULL(pixel_type) d;
40
5.83k
  const size_t N = Lanes(d);
41
87.7k
  for (; x + N - 1 < w; x += N) {
42
81.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
81.9k
    } else {
54
81.9k
      auto First = Load(d, in0 + x);
55
81.9k
      auto Second = Load(d, in1 + x);
56
81.9k
      auto Third = Load(d, in2 + x);
57
81.9k
      if (third) Third = Add(Third, First);
58
81.9k
      if (second == 1) {
59
81.9k
        Second = Add(Second, First);
60
81.9k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
81.9k
      Store(First, d, out0 + x);
64
81.9k
      Store(Second, d, out1 + x);
65
81.9k
      Store(Third, d, out2 + x);
66
81.9k
    }
67
81.9k
  }
68
13.9k
  for (; x < w; x++) {
69
8.07k
    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.07k
    } else {
81
8.07k
      pixel_type First = in0[x];
82
8.07k
      pixel_type Second = in1[x];
83
8.07k
      pixel_type Third = in2[x];
84
8.07k
      if (third) Third = PixelAdd(Third, First);
85
8.07k
      if (second == 1) {
86
8.07k
        Second = PixelAdd(Second, First);
87
8.07k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
8.07k
      out0[x] = First;
91
8.07k
      out1[x] = Second;
92
8.07k
      out2[x] = Third;
93
8.07k
    }
94
8.07k
  }
95
5.83k
}
void jxl::N_AVX2::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
7.08k
               pixel_type* out2, size_t w) {
33
7.08k
  static_assert(transform_type >= 0 && transform_type < 7,
34
7.08k
                "Invalid transform type");
35
7.08k
  int second = transform_type >> 1;
36
7.08k
  int third = transform_type & 1;
37
38
7.08k
  size_t x = 0;
39
7.08k
  const HWY_FULL(pixel_type) d;
40
7.08k
  const size_t N = Lanes(d);
41
41.9k
  for (; x + N - 1 < w; x += N) {
42
34.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
34.8k
    } else {
54
34.8k
      auto First = Load(d, in0 + x);
55
34.8k
      auto Second = Load(d, in1 + x);
56
34.8k
      auto Third = Load(d, in2 + x);
57
34.8k
      if (third) Third = Add(Third, First);
58
34.8k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
34.8k
      } else if (second == 2) {
61
34.8k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
34.8k
      }
63
34.8k
      Store(First, d, out0 + x);
64
34.8k
      Store(Second, d, out1 + x);
65
34.8k
      Store(Third, d, out2 + x);
66
34.8k
    }
67
34.8k
  }
68
15.7k
  for (; x < w; x++) {
69
8.65k
    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.65k
    } else {
81
8.65k
      pixel_type First = in0[x];
82
8.65k
      pixel_type Second = in1[x];
83
8.65k
      pixel_type Third = in2[x];
84
8.65k
      if (third) Third = PixelAdd(Third, First);
85
8.65k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
8.65k
      } else if (second == 2) {
88
8.65k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
8.65k
      }
90
8.65k
      out0[x] = First;
91
8.65k
      out1[x] = Second;
92
8.65k
      out2[x] = Third;
93
8.65k
    }
94
8.65k
  }
95
7.08k
}
void jxl::N_AVX2::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
1.14k
               pixel_type* out2, size_t w) {
33
1.14k
  static_assert(transform_type >= 0 && transform_type < 7,
34
1.14k
                "Invalid transform type");
35
1.14k
  int second = transform_type >> 1;
36
1.14k
  int third = transform_type & 1;
37
38
1.14k
  size_t x = 0;
39
1.14k
  const HWY_FULL(pixel_type) d;
40
1.14k
  const size_t N = Lanes(d);
41
9.99k
  for (; x + N - 1 < w; x += N) {
42
8.85k
    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
8.85k
    } else {
54
8.85k
      auto First = Load(d, in0 + x);
55
8.85k
      auto Second = Load(d, in1 + x);
56
8.85k
      auto Third = Load(d, in2 + x);
57
8.85k
      if (third) Third = Add(Third, First);
58
8.85k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
8.85k
      } else if (second == 2) {
61
8.85k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
8.85k
      }
63
8.85k
      Store(First, d, out0 + x);
64
8.85k
      Store(Second, d, out1 + x);
65
8.85k
      Store(Third, d, out2 + x);
66
8.85k
    }
67
8.85k
  }
68
3.31k
  for (; x < w; x++) {
69
2.17k
    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.17k
    } else {
81
2.17k
      pixel_type First = in0[x];
82
2.17k
      pixel_type Second = in1[x];
83
2.17k
      pixel_type Third = in2[x];
84
2.17k
      if (third) Third = PixelAdd(Third, First);
85
2.17k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
2.17k
      } else if (second == 2) {
88
2.17k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
2.17k
      }
90
2.17k
      out0[x] = First;
91
2.17k
      out1[x] = Second;
92
2.17k
      out2[x] = Third;
93
2.17k
    }
94
2.17k
  }
95
1.14k
}
void jxl::N_AVX2::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
37.5k
               pixel_type* out2, size_t w) {
33
37.5k
  static_assert(transform_type >= 0 && transform_type < 7,
34
37.5k
                "Invalid transform type");
35
37.5k
  int second = transform_type >> 1;
36
37.5k
  int third = transform_type & 1;
37
38
37.5k
  size_t x = 0;
39
37.5k
  const HWY_FULL(pixel_type) d;
40
37.5k
  const size_t N = Lanes(d);
41
520k
  for (; x + N - 1 < w; x += N) {
42
482k
    if (transform_type == 6) {
43
482k
      auto Y = Load(d, in0 + x);
44
482k
      auto Co = Load(d, in1 + x);
45
482k
      auto Cg = Load(d, in2 + x);
46
482k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
482k
      auto G = Add(Cg, Y);
48
482k
      Y = Sub(Y, ShiftRight<1>(Co));
49
482k
      auto R = Add(Y, Co);
50
482k
      Store(R, d, out0 + x);
51
482k
      Store(G, d, out1 + x);
52
482k
      Store(Y, d, out2 + x);
53
482k
    } 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
482k
  }
68
65.4k
  for (; x < w; x++) {
69
27.8k
    if (transform_type == 6) {
70
27.8k
      pixel_type Y = in0[x];
71
27.8k
      pixel_type Co = in1[x];
72
27.8k
      pixel_type Cg = in2[x];
73
27.8k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
27.8k
      pixel_type G = PixelAdd(Cg, tmp);
75
27.8k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
27.8k
      pixel_type R = PixelAdd(B, Co);
77
27.8k
      out0[x] = R;
78
27.8k
      out1[x] = G;
79
27.8k
      out2[x] = B;
80
27.8k
    } 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
27.8k
  }
95
37.5k
}
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.11k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
4.11k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
4.11k
  size_t m = begin_c;
100
4.11k
  Channel& c0 = input.channel[m + 0];
101
4.11k
  size_t w = c0.w;
102
4.11k
  size_t h = c0.h;
103
4.11k
  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.84k
  int permutation = rct_type / 7;
108
2.84k
  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.84k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
2.84k
  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
2.81k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
2.81k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
2.81k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
2.81k
  const auto process_row = [&](const uint32_t task,
132
85.1k
                               size_t /* thread */) -> Status {
133
85.1k
    const size_t y = task;
134
85.1k
    const pixel_type* in0 = input.channel[m].Row(y);
135
85.1k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
85.1k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
85.1k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
85.1k
    pixel_type* out1 =
139
85.1k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
85.1k
    pixel_type* out2 =
141
85.1k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
85.1k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
85.1k
    return true;
144
85.1k
  };
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
85.1k
                               size_t /* thread */) -> Status {
133
85.1k
    const size_t y = task;
134
85.1k
    const pixel_type* in0 = input.channel[m].Row(y);
135
85.1k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
85.1k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
85.1k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
85.1k
    pixel_type* out1 =
139
85.1k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
85.1k
    pixel_type* out2 =
141
85.1k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
85.1k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
85.1k
    return true;
144
85.1k
  };
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.81k
  JXL_RETURN_IF_ERROR(
146
2.81k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
2.81k
  return true;
148
2.81k
}
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.11k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
4.11k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
4.11k
  size_t m = begin_c;
100
4.11k
  Channel& c0 = input.channel[m + 0];
101
4.11k
  size_t w = c0.w;
102
4.11k
  size_t h = c0.h;
103
4.11k
  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.84k
  int permutation = rct_type / 7;
108
2.84k
  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.84k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
2.84k
  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
2.81k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
2.81k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
2.81k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
2.81k
  const auto process_row = [&](const uint32_t task,
132
2.81k
                               size_t /* thread */) -> Status {
133
2.81k
    const size_t y = task;
134
2.81k
    const pixel_type* in0 = input.channel[m].Row(y);
135
2.81k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
2.81k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
2.81k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
2.81k
    pixel_type* out1 =
139
2.81k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
2.81k
    pixel_type* out2 =
141
2.81k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
2.81k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
2.81k
    return true;
144
2.81k
  };
145
2.81k
  JXL_RETURN_IF_ERROR(
146
2.81k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
2.81k
  return true;
148
2.81k
}
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.11k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
159
4.11k
  return HWY_DYNAMIC_DISPATCH(InvRCT)(input, begin_c, rct_type, pool);
160
4.11k
}
161
162
}  // namespace jxl
163
#endif