| 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 |
#include <cstddef> |
| 9 |
#include <memory> |
| 10 |
|
| 11 |
#include "lib/jxl/base/common.h" |
| 12 |
#include "lib/jxl/base/compiler_specific.h" |
| 13 |
#include "lib/jxl/render_pipeline/render_pipeline_stage.h" |
| 14 |
|
| 15 |
namespace jxl { |
| 16 |
class SpotColorStage : public RenderPipelineStage { |
| 17 |
public: |
| 18 |
explicit SpotColorStage(size_t spot_c_offset, const float* spot_color) |
| 19 |
: RenderPipelineStage(RenderPipelineStage::Settings()), |
| 20 |
spot_c_(3 + spot_c_offset), |
| 21 |
spot_color_(spot_color) {} |
| 22 |
|
| 23 |
Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, |
| 24 |
size_t xextra, size_t xsize, size_t xpos, size_t ypos, |
| 25 |
size_t thread_id) const final { |
| 26 |
// TODO(veluca): add SIMD. |
| 27 |
float scale = spot_color_[3]; |
| 28 |
for (size_t c = 0; c < 3; c++) { |
| 29 |
float* JXL_RESTRICT p = GetInputRow(input_rows, c, 0); |
| 30 |
const float* JXL_RESTRICT s = GetInputRow(input_rows, spot_c_, 0); |
| 31 |
for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); x++) { |
| 32 |
float mix = scale * s[x]; |
| 33 |
p[x] = mix * spot_color_[c] + (1.0f - mix) * p[x]; |
| 34 |
} |
| 35 |
} |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
RenderPipelineChannelMode GetChannelMode(size_t c) const final { |
| 40 |
return c < 3 ? RenderPipelineChannelMode::kInPlace |
| 41 |
: c == spot_c_ ? RenderPipelineChannelMode::kInput |
| 42 |
: RenderPipelineChannelMode::kIgnored; |
| 43 |
} |
| 44 |
|
| 45 |
const char* GetName() const override { return "Spot"; } |
| 46 |
|
| 47 |
private: |
| 48 |
size_t spot_c_; |
| 49 |
const float* spot_color_; |
| 50 |
}; |
| 51 |
|
| 52 |
std::unique_ptr<RenderPipelineStage> GetSpotColorStage( |
| 53 |
size_t spot_c_offset, const float* spot_color) { |
| 54 |
return jxl::make_unique<SpotColorStage>(spot_c_offset, spot_color); |
| 55 |
} |
| 56 |
|
| 57 |
} // namespace jxl |