Coverage Report

Created: 2025-11-14 07:32

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.17M
  for (; x + N - 1 < w; x += N) {
42
1.06M
    if (transform_type == 6) {
43
671k
      auto Y = Load(d, in0 + x);
44
671k
      auto Co = Load(d, in1 + x);
45
671k
      auto Cg = Load(d, in2 + x);
46
671k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
671k
      auto G = Add(Cg, Y);
48
671k
      Y = Sub(Y, ShiftRight<1>(Co));
49
671k
      auto R = Add(Y, Co);
50
671k
      Store(R, d, out0 + x);
51
671k
      Store(G, d, out1 + x);
52
671k
      Store(Y, d, out2 + x);
53
671k
    } else {
54
398k
      auto First = Load(d, in0 + x);
55
398k
      auto Second = Load(d, in1 + x);
56
398k
      auto Third = Load(d, in2 + x);
57
398k
      if (third) Third = Add(Third, First);
58
398k
      if (second == 1) {
59
322k
        Second = Add(Second, First);
60
322k
      } else if (second == 2) {
61
32.9k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
32.9k
      }
63
398k
      Store(First, d, out0 + x);
64
398k
      Store(Second, d, out1 + x);
65
398k
      Store(Third, d, out2 + x);
66
398k
    }
67
1.06M
  }
68
189k
  for (; x < w; x++) {
69
87.8k
    if (transform_type == 6) {
70
51.2k
      pixel_type Y = in0[x];
71
51.2k
      pixel_type Co = in1[x];
72
51.2k
      pixel_type Cg = in2[x];
73
51.2k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
51.2k
      pixel_type G = PixelAdd(Cg, tmp);
75
51.2k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
51.2k
      pixel_type R = PixelAdd(B, Co);
77
51.2k
      out0[x] = R;
78
51.2k
      out1[x] = G;
79
51.2k
      out2[x] = B;
80
51.2k
    } else {
81
36.5k
      pixel_type First = in0[x];
82
36.5k
      pixel_type Second = in1[x];
83
36.5k
      pixel_type Third = in2[x];
84
36.5k
      if (third) Third = PixelAdd(Third, First);
85
36.5k
      if (second == 1) {
86
25.1k
        Second = PixelAdd(Second, First);
87
25.1k
      } else if (second == 2) {
88
8.16k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
8.16k
      }
90
36.5k
      out0[x] = First;
91
36.5k
      out1[x] = Second;
92
36.5k
      out2[x] = Third;
93
36.5k
    }
94
87.8k
  }
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
3.84k
               pixel_type* out2, size_t w) {
33
3.84k
  static_assert(transform_type >= 0 && transform_type < 7,
34
3.84k
                "Invalid transform type");
35
3.84k
  int second = transform_type >> 1;
36
3.84k
  int third = transform_type & 1;
37
38
3.84k
  size_t x = 0;
39
3.84k
  const HWY_FULL(pixel_type) d;
40
3.84k
  const size_t N = Lanes(d);
41
47.1k
  for (; x + N - 1 < w; x += N) {
42
43.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
43.2k
    } else {
54
43.2k
      auto First = Load(d, in0 + x);
55
43.2k
      auto Second = Load(d, in1 + x);
56
43.2k
      auto Third = Load(d, in2 + x);
57
43.2k
      if (third) Third = Add(Third, First);
58
43.2k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
43.2k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
43.2k
      Store(First, d, out0 + x);
64
43.2k
      Store(Second, d, out1 + x);
65
43.2k
      Store(Third, d, out2 + x);
66
43.2k
    }
67
43.2k
  }
68
7.16k
  for (; x < w; x++) {
69
3.32k
    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.32k
    } else {
81
3.32k
      pixel_type First = in0[x];
82
3.32k
      pixel_type Second = in1[x];
83
3.32k
      pixel_type Third = in2[x];
84
3.32k
      if (third) Third = PixelAdd(Third, First);
85
3.32k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
3.32k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
3.32k
      out0[x] = First;
91
3.32k
      out1[x] = Second;
92
3.32k
      out2[x] = Third;
93
3.32k
    }
94
3.32k
  }
95
3.84k
}
void jxl::N_AVX2::InvRCTRow<2>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
27.2k
               pixel_type* out2, size_t w) {
33
27.2k
  static_assert(transform_type >= 0 && transform_type < 7,
34
27.2k
                "Invalid transform type");
35
27.2k
  int second = transform_type >> 1;
36
27.2k
  int third = transform_type & 1;
37
38
27.2k
  size_t x = 0;
39
27.2k
  const HWY_FULL(pixel_type) d;
40
27.2k
  const size_t N = Lanes(d);
41
292k
  for (; x + N - 1 < w; x += N) {
42
265k
    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
265k
    } else {
54
265k
      auto First = Load(d, in0 + x);
55
265k
      auto Second = Load(d, in1 + x);
56
265k
      auto Third = Load(d, in2 + x);
57
265k
      if (third) Third = Add(Third, First);
58
265k
      if (second == 1) {
59
265k
        Second = Add(Second, First);
60
265k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
265k
      Store(First, d, out0 + x);
64
265k
      Store(Second, d, out1 + x);
65
265k
      Store(Third, d, out2 + x);
66
265k
    }
67
265k
  }
68
46.2k
  for (; x < w; x++) {
69
18.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
18.9k
    } else {
81
18.9k
      pixel_type First = in0[x];
82
18.9k
      pixel_type Second = in1[x];
83
18.9k
      pixel_type Third = in2[x];
84
18.9k
      if (third) Third = PixelAdd(Third, First);
85
18.9k
      if (second == 1) {
86
18.9k
        Second = PixelAdd(Second, First);
87
18.9k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
18.9k
      out0[x] = First;
91
18.9k
      out1[x] = Second;
92
18.9k
      out2[x] = Third;
93
18.9k
    }
94
18.9k
  }
95
27.2k
}
void jxl::N_AVX2::InvRCTRow<3>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
3.91k
               pixel_type* out2, size_t w) {
33
3.91k
  static_assert(transform_type >= 0 && transform_type < 7,
34
3.91k
                "Invalid transform type");
35
3.91k
  int second = transform_type >> 1;
36
3.91k
  int third = transform_type & 1;
37
38
3.91k
  size_t x = 0;
39
3.91k
  const HWY_FULL(pixel_type) d;
40
3.91k
  const size_t N = Lanes(d);
41
61.0k
  for (; x + N - 1 < w; x += N) {
42
57.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
57.1k
    } else {
54
57.1k
      auto First = Load(d, in0 + x);
55
57.1k
      auto Second = Load(d, in1 + x);
56
57.1k
      auto Third = Load(d, in2 + x);
57
57.1k
      if (third) Third = Add(Third, First);
58
57.1k
      if (second == 1) {
59
57.1k
        Second = Add(Second, First);
60
57.1k
      } else if (second == 2) {
61
0
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
0
      }
63
57.1k
      Store(First, d, out0 + x);
64
57.1k
      Store(Second, d, out1 + x);
65
57.1k
      Store(Third, d, out2 + x);
66
57.1k
    }
67
57.1k
  }
68
10.0k
  for (; x < w; x++) {
69
6.13k
    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.13k
    } else {
81
6.13k
      pixel_type First = in0[x];
82
6.13k
      pixel_type Second = in1[x];
83
6.13k
      pixel_type Third = in2[x];
84
6.13k
      if (third) Third = PixelAdd(Third, First);
85
6.13k
      if (second == 1) {
86
6.13k
        Second = PixelAdd(Second, First);
87
6.13k
      } else if (second == 2) {
88
0
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
0
      }
90
6.13k
      out0[x] = First;
91
6.13k
      out1[x] = Second;
92
6.13k
      out2[x] = Third;
93
6.13k
    }
94
6.13k
  }
95
3.91k
}
void jxl::N_AVX2::InvRCTRow<4>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
2.20k
               pixel_type* out2, size_t w) {
33
2.20k
  static_assert(transform_type >= 0 && transform_type < 7,
34
2.20k
                "Invalid transform type");
35
2.20k
  int second = transform_type >> 1;
36
2.20k
  int third = transform_type & 1;
37
38
2.20k
  size_t x = 0;
39
2.20k
  const HWY_FULL(pixel_type) d;
40
2.20k
  const size_t N = Lanes(d);
41
16.2k
  for (; x + N - 1 < w; x += N) {
42
14.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
14.0k
    } else {
54
14.0k
      auto First = Load(d, in0 + x);
55
14.0k
      auto Second = Load(d, in1 + x);
56
14.0k
      auto Third = Load(d, in2 + x);
57
14.0k
      if (third) Third = Add(Third, First);
58
14.0k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
14.0k
      } else if (second == 2) {
61
14.0k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
14.0k
      }
63
14.0k
      Store(First, d, out0 + x);
64
14.0k
      Store(Second, d, out1 + x);
65
14.0k
      Store(Third, d, out2 + x);
66
14.0k
    }
67
14.0k
  }
68
8.76k
  for (; x < w; x++) {
69
6.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
6.56k
    } else {
81
6.56k
      pixel_type First = in0[x];
82
6.56k
      pixel_type Second = in1[x];
83
6.56k
      pixel_type Third = in2[x];
84
6.56k
      if (third) Third = PixelAdd(Third, First);
85
6.56k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
6.56k
      } else if (second == 2) {
88
6.56k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
6.56k
      }
90
6.56k
      out0[x] = First;
91
6.56k
      out1[x] = Second;
92
6.56k
      out2[x] = Third;
93
6.56k
    }
94
6.56k
  }
95
2.20k
}
void jxl::N_AVX2::InvRCTRow<5>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
11.7k
               pixel_type* out2, size_t w) {
33
11.7k
  static_assert(transform_type >= 0 && transform_type < 7,
34
11.7k
                "Invalid transform type");
35
11.7k
  int second = transform_type >> 1;
36
11.7k
  int third = transform_type & 1;
37
38
11.7k
  size_t x = 0;
39
11.7k
  const HWY_FULL(pixel_type) d;
40
11.7k
  const size_t N = Lanes(d);
41
30.6k
  for (; x + N - 1 < w; x += N) {
42
18.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
18.9k
    } else {
54
18.9k
      auto First = Load(d, in0 + x);
55
18.9k
      auto Second = Load(d, in1 + x);
56
18.9k
      auto Third = Load(d, in2 + x);
57
18.9k
      if (third) Third = Add(Third, First);
58
18.9k
      if (second == 1) {
59
0
        Second = Add(Second, First);
60
18.9k
      } else if (second == 2) {
61
18.9k
        Second = Add(Second, ShiftRight<1>(Add(First, Third)));
62
18.9k
      }
63
18.9k
      Store(First, d, out0 + x);
64
18.9k
      Store(Second, d, out1 + x);
65
18.9k
      Store(Third, d, out2 + x);
66
18.9k
    }
67
18.9k
  }
68
13.3k
  for (; x < w; x++) {
69
1.59k
    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.59k
    } else {
81
1.59k
      pixel_type First = in0[x];
82
1.59k
      pixel_type Second = in1[x];
83
1.59k
      pixel_type Third = in2[x];
84
1.59k
      if (third) Third = PixelAdd(Third, First);
85
1.59k
      if (second == 1) {
86
0
        Second = PixelAdd(Second, First);
87
1.59k
      } else if (second == 2) {
88
1.59k
        Second = PixelAdd(Second, (PixelAdd(First, Third) >> 1));
89
1.59k
      }
90
1.59k
      out0[x] = First;
91
1.59k
      out1[x] = Second;
92
1.59k
      out2[x] = Third;
93
1.59k
    }
94
1.59k
  }
95
11.7k
}
void jxl::N_AVX2::InvRCTRow<6>(int const*, int const*, int const*, int*, int*, int*, unsigned long)
Line
Count
Source
32
52.6k
               pixel_type* out2, size_t w) {
33
52.6k
  static_assert(transform_type >= 0 && transform_type < 7,
34
52.6k
                "Invalid transform type");
35
52.6k
  int second = transform_type >> 1;
36
52.6k
  int third = transform_type & 1;
37
38
52.6k
  size_t x = 0;
39
52.6k
  const HWY_FULL(pixel_type) d;
40
52.6k
  const size_t N = Lanes(d);
41
723k
  for (; x + N - 1 < w; x += N) {
42
671k
    if (transform_type == 6) {
43
671k
      auto Y = Load(d, in0 + x);
44
671k
      auto Co = Load(d, in1 + x);
45
671k
      auto Cg = Load(d, in2 + x);
46
671k
      Y = Sub(Y, ShiftRight<1>(Cg));
47
671k
      auto G = Add(Cg, Y);
48
671k
      Y = Sub(Y, ShiftRight<1>(Co));
49
671k
      auto R = Add(Y, Co);
50
671k
      Store(R, d, out0 + x);
51
671k
      Store(G, d, out1 + x);
52
671k
      Store(Y, d, out2 + x);
53
671k
    } 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
671k
  }
68
103k
  for (; x < w; x++) {
69
51.2k
    if (transform_type == 6) {
70
51.2k
      pixel_type Y = in0[x];
71
51.2k
      pixel_type Co = in1[x];
72
51.2k
      pixel_type Cg = in2[x];
73
51.2k
      pixel_type tmp = PixelAdd(Y, -(Cg >> 1));
74
51.2k
      pixel_type G = PixelAdd(Cg, tmp);
75
51.2k
      pixel_type B = PixelAdd(tmp, -(Co >> 1));
76
51.2k
      pixel_type R = PixelAdd(B, Co);
77
51.2k
      out0[x] = R;
78
51.2k
      out1[x] = G;
79
51.2k
      out2[x] = B;
80
51.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
51.2k
  }
95
52.6k
}
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.93k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
3.93k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
3.93k
  size_t m = begin_c;
100
3.93k
  Channel& c0 = input.channel[m + 0];
101
3.93k
  size_t w = c0.w;
102
3.93k
  size_t h = c0.h;
103
3.93k
  if (rct_type == 0) {  // noop
104
1.48k
    return true;
105
1.48k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
2.45k
  int permutation = rct_type / 7;
108
2.45k
  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.45k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
2.45k
  if (custom == 0) {
118
29
    Channel ch0 = std::move(input.channel[m]);
119
29
    Channel ch1 = std::move(input.channel[m + 1]);
120
29
    Channel ch2 = std::move(input.channel[m + 2]);
121
29
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
29
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
29
        std::move(ch1);
124
29
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
29
        std::move(ch2);
126
29
    return true;
127
29
  }
128
2.42k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
2.42k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
2.42k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
2.42k
  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
2.42k
  JXL_RETURN_IF_ERROR(
146
2.42k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
2.42k
  return true;
148
2.42k
}
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.93k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
98
3.93k
  JXL_RETURN_IF_ERROR(CheckEqualChannels(input, begin_c, begin_c + 2));
99
3.93k
  size_t m = begin_c;
100
3.93k
  Channel& c0 = input.channel[m + 0];
101
3.93k
  size_t w = c0.w;
102
3.93k
  size_t h = c0.h;
103
3.93k
  if (rct_type == 0) {  // noop
104
1.48k
    return true;
105
1.48k
  }
106
  // Permutation: 0=RGB, 1=GBR, 2=BRG, 3=RBG, 4=GRB, 5=BGR
107
2.45k
  int permutation = rct_type / 7;
108
2.45k
  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.45k
  int custom = rct_type % 7;
116
  // Special case: permute-only. Swap channels around.
117
2.45k
  if (custom == 0) {
118
29
    Channel ch0 = std::move(input.channel[m]);
119
29
    Channel ch1 = std::move(input.channel[m + 1]);
120
29
    Channel ch2 = std::move(input.channel[m + 2]);
121
29
    input.channel[m + (permutation % 3)] = std::move(ch0);
122
29
    input.channel[m + ((permutation + 1 + permutation / 3) % 3)] =
123
29
        std::move(ch1);
124
29
    input.channel[m + ((permutation + 2 - permutation / 3) % 3)] =
125
29
        std::move(ch2);
126
29
    return true;
127
29
  }
128
2.42k
  constexpr decltype(&InvRCTRow<0>) inv_rct_row[] = {
129
2.42k
      InvRCTRow<0>, InvRCTRow<1>, InvRCTRow<2>, InvRCTRow<3>,
130
2.42k
      InvRCTRow<4>, InvRCTRow<5>, InvRCTRow<6>};
131
2.42k
  const auto process_row = [&](const uint32_t task,
132
2.42k
                               size_t /* thread */) -> Status {
133
2.42k
    const size_t y = task;
134
2.42k
    const pixel_type* in0 = input.channel[m].Row(y);
135
2.42k
    const pixel_type* in1 = input.channel[m + 1].Row(y);
136
2.42k
    const pixel_type* in2 = input.channel[m + 2].Row(y);
137
2.42k
    pixel_type* out0 = input.channel[m + (permutation % 3)].Row(y);
138
2.42k
    pixel_type* out1 =
139
2.42k
        input.channel[m + ((permutation + 1 + permutation / 3) % 3)].Row(y);
140
2.42k
    pixel_type* out2 =
141
2.42k
        input.channel[m + ((permutation + 2 - permutation / 3) % 3)].Row(y);
142
2.42k
    inv_rct_row[custom](in0, in1, in2, out0, out1, out2, w);
143
2.42k
    return true;
144
2.42k
  };
145
2.42k
  JXL_RETURN_IF_ERROR(
146
2.42k
      RunOnPool(pool, 0, h, ThreadPool::NoInit, process_row, "InvRCT"));
147
2.42k
  return true;
148
2.42k
}
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.93k
Status InvRCT(Image& input, size_t begin_c, size_t rct_type, ThreadPool* pool) {
159
3.93k
  return HWY_DYNAMIC_DISPATCH(InvRCT)(input, begin_c, rct_type, pool);
160
3.93k
}
161
162
}  // namespace jxl
163
#endif