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_spot.h"
7
8 namespace jxl {
9 class SpotColorStage : public RenderPipelineStage {
10 public:
SpotColorStage(size_t spot_c,const float * spot_color)11 explicit SpotColorStage(size_t spot_c, const float* spot_color)
12 : RenderPipelineStage(RenderPipelineStage::Settings()),
13 spot_c_(spot_c),
14 spot_color_(spot_color) {
15 JXL_ASSERT(spot_c_ >= 3);
16 }
17
ProcessRow(const RowInfo & input_rows,const RowInfo & output_rows,size_t xextra,size_t xsize,size_t xpos,size_t ypos,float * JXL_RESTRICT temp) const18 void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows,
19 size_t xextra, size_t xsize, size_t xpos, size_t ypos,
20 float* JXL_RESTRICT temp) const final {
21 // TODO(veluca): add SIMD.
22 PROFILER_ZONE("RenderSpotColors");
23 float scale = spot_color_[3];
24 for (size_t c = 0; c < 3; c++) {
25 float* JXL_RESTRICT p = GetInputRow(input_rows, c, 0);
26 const float* JXL_RESTRICT s = GetInputRow(input_rows, spot_c_, 0);
27 for (ssize_t x = -xextra; x < ssize_t(xsize + xextra); x++) {
28 float mix = scale * s[x];
29 p[x] = mix * spot_color_[c] + (1.0f - mix) * p[x];
30 }
31 }
32 }
33
GetChannelMode(size_t c) const34 RenderPipelineChannelMode GetChannelMode(size_t c) const final {
35 return c < 3 ? RenderPipelineChannelMode::kInPlace
36 : c == spot_c_ ? RenderPipelineChannelMode::kInput
37 : RenderPipelineChannelMode::kIgnored;
38 }
39
40 private:
41 size_t spot_c_;
42 const float* spot_color_;
43 };
44
GetSpotColorStage(size_t spot_c,const float * spot_color)45 std::unique_ptr<RenderPipelineStage> GetSpotColorStage(
46 size_t spot_c, const float* spot_color) {
47 return jxl::make_unique<SpotColorStage>(spot_c, spot_color);
48 }
49
50 } // namespace jxl
51