summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl/modular/transform/enc_transform.cc
blob: bdaaf9f87eb6e9fabe3de331bef9ddd963aa4b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "lib/jxl/modular/transform/enc_transform.h"

#include "lib/jxl/modular/transform/enc_palette.h"
#include "lib/jxl/modular/transform/enc_rct.h"
#include "lib/jxl/modular/transform/enc_squeeze.h"

namespace jxl {

Status TransformForward(Transform &t, Image &input,
                        const weighted::Header &wp_header, ThreadPool *pool) {
  switch (t.id) {
    case TransformId::kRCT:
      return FwdRCT(input, t.begin_c, t.rct_type, pool);
    case TransformId::kSqueeze:
      return FwdSqueeze(input, t.squeezes, pool);
    case TransformId::kPalette:
      return FwdPalette(input, t.begin_c, t.begin_c + t.num_c - 1, t.nb_colors,
                        t.nb_deltas, t.ordered_palette, t.lossy_palette,
                        t.predictor, wp_header);
    default:
      return JXL_FAILURE("Unknown transformation (ID=%u)",
                         static_cast<unsigned int>(t.id));
  }
}

void compute_minmax(const Channel &ch, pixel_type *min, pixel_type *max) {
  pixel_type realmin = std::numeric_limits<pixel_type>::max();
  pixel_type realmax = std::numeric_limits<pixel_type>::min();
  for (size_t y = 0; y < ch.h; y++) {
    const pixel_type *JXL_RESTRICT p = ch.Row(y);
    for (size_t x = 0; x < ch.w; x++) {
      if (p[x] < realmin) realmin = p[x];
      if (p[x] > realmax) realmax = p[x];
    }
  }

  if (min) *min = realmin;
  if (max) *max = realmax;
}

}  // namespace jxl