Debian Codegraph @

lib/jxl/render_pipeline/stage_patches.cc

raw
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/render_pipeline/stage_patches.h"
7
8 #include <cstddef>
9 #include <memory>
10 #include <vector>
11
12 #include "lib/jxl/dec_patch_dictionary.h"
13 #include "lib/jxl/render_pipeline/render_pipeline_stage.h"
14
15 namespace jxl {
16 namespace {
17 class PatchDictionaryStage : public RenderPipelineStage {
18 public:
19 PatchDictionaryStage(const PatchDictionary* patches,
20 const std::vector<ExtraChannelInfo>* extra_channel_info)
21 : RenderPipelineStage(RenderPipelineStage::Settings()),
22 patches_(*patches),
23 extra_channel_info_(extra_channel_info) {}
24
25 Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows,
26 size_t xextra, size_t xsize, size_t xpos, size_t ypos,
27 size_t thread_id) const final {
28 JXL_ENSURE(xpos == 0 || xpos >= xextra);
29 size_t x0 = xpos ? xpos - xextra : 0;
30 size_t num_channels = 3 + extra_channel_info_->size();
31 std::vector<float*> row_ptrs(num_channels);
32 for (size_t i = 0; i < num_channels; i++) {
33 row_ptrs[i] = GetInputRow(input_rows, i, 0) + x0 - xpos;
34 }
35 return patches_.AddOneRow(row_ptrs.data(), ypos, x0,
36 xsize + xextra + xpos - x0, *extra_channel_info_);
37 }
38
39 RenderPipelineChannelMode GetChannelMode(size_t c) const final {
40 size_t num_channels = 3 + extra_channel_info_->size();
41 return c < num_channels ? RenderPipelineChannelMode::kInPlace
42 : RenderPipelineChannelMode::kIgnored;
43 }
44
45 const char* GetName() const override { return "Patches"; }
46
47 private:
48 const PatchDictionary& patches_;
49 const std::vector<ExtraChannelInfo>* extra_channel_info_;
50 };
51 } // namespace
52
53 std::unique_ptr<RenderPipelineStage> GetPatchesStage(
54 const PatchDictionary* patches,
55 const std::vector<ExtraChannelInfo>* extra_channel_info) {
56 return jxl::make_unique<PatchDictionaryStage>(patches, extra_channel_info);
57 }
58
59 } // namespace jxl