diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /third_party/jpeg-xl/lib/jxl/render_pipeline | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/render_pipeline')
25 files changed, 327 insertions, 252 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.cc index 9aefdd007d..27718e6413 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.cc @@ -6,10 +6,9 @@ #include "lib/jxl/render_pipeline/low_memory_render_pipeline.h" #include <algorithm> -#include <queue> -#include <tuple> #include "lib/jxl/base/arch_macros.h" +#include "lib/jxl/base/status.h" #include "lib/jxl/image_ops.h" namespace jxl { @@ -174,7 +173,7 @@ size_t LowMemoryRenderPipeline::GroupInputYSize(size_t c) const { channel_shifts_[0][c].second; } -void LowMemoryRenderPipeline::EnsureBordersStorage() { +Status LowMemoryRenderPipeline::EnsureBordersStorage() { const auto& shifts = channel_shifts_[0]; if (borders_horizontal_.size() < shifts.size()) { borders_horizontal_.resize(shifts.size()); @@ -194,16 +193,20 @@ void LowMemoryRenderPipeline::EnsureBordersStorage() { 1 << shifts[c].second); Rect horizontal = Rect(0, 0, downsampled_xsize, bordery * num_yborders); if (!SameSize(horizontal, borders_horizontal_[c])) { - borders_horizontal_[c] = ImageF(horizontal.xsize(), horizontal.ysize()); + JXL_ASSIGN_OR_RETURN( + borders_horizontal_[c], + ImageF::Create(horizontal.xsize(), horizontal.ysize())); } Rect vertical = Rect(0, 0, borderx * num_xborders, downsampled_ysize); if (!SameSize(vertical, borders_vertical_[c])) { - borders_vertical_[c] = ImageF(vertical.xsize(), vertical.ysize()); + JXL_ASSIGN_OR_RETURN(borders_vertical_[c], + ImageF::Create(vertical.xsize(), vertical.ysize())); } } + return true; } -void LowMemoryRenderPipeline::Init() { +Status LowMemoryRenderPipeline::Init() { group_border_ = {0, 0}; base_color_shift_ = CeilLog2Nonzero(frame_dimensions_.xsize_upsampled_padded / frame_dimensions_.xsize_padded); @@ -255,7 +258,7 @@ void LowMemoryRenderPipeline::Init() { group_data_x_border_ = RoundUpTo(max_border.first, kGroupXAlign); group_data_y_border_ = max_border.second; - EnsureBordersStorage(); + JXL_RETURN_IF_ERROR(EnsureBordersStorage()); group_border_assigner_.Init(frame_dimensions_); for (first_trailing_stage_ = stages_.size(); first_trailing_stage_ > 0; @@ -282,7 +285,7 @@ void LowMemoryRenderPipeline::Init() { DivCeil(frame_dimensions_.ysize_upsampled, 1 << channel_shifts_[i][c].second)); } - stages_[i]->SetInputSizes(input_sizes); + JXL_RETURN_IF_ERROR(stages_[i]->SetInputSizes(input_sizes)); if (stages_[i]->SwitchToImageDimensions()) { // We don't allow kInOut after switching to image dimensions. JXL_ASSERT(i >= first_trailing_stage_); @@ -300,7 +303,7 @@ void LowMemoryRenderPipeline::Init() { for (size_t c = 0; c < shifts.size(); c++) { input_sizes[c] = {full_image_xsize_, full_image_ysize_}; } - stages_[i]->SetInputSizes(input_sizes); + JXL_RETURN_IF_ERROR(stages_[i]->SetInputSizes(input_sizes)); } anyc_.resize(stages_.size()); @@ -355,10 +358,11 @@ void LowMemoryRenderPipeline::Init() { } } } + return true; } -void LowMemoryRenderPipeline::PrepareForThreadsInternal(size_t num, - bool use_group_ids) { +Status LowMemoryRenderPipeline::PrepareForThreadsInternal(size_t num, + bool use_group_ids) { const auto& shifts = channel_shifts_[0]; use_group_ids_ = use_group_ids; size_t num_buffers = use_group_ids_ ? frame_dimensions_.num_groups : num; @@ -366,8 +370,10 @@ void LowMemoryRenderPipeline::PrepareForThreadsInternal(size_t num, group_data_.emplace_back(); group_data_[t].resize(shifts.size()); for (size_t c = 0; c < shifts.size(); c++) { - group_data_[t][c] = ImageF(GroupInputXSize(c) + group_data_x_border_ * 2, - GroupInputYSize(c) + group_data_y_border_ * 2); + JXL_ASSIGN_OR_RETURN( + group_data_[t][c], + ImageF::Create(GroupInputXSize(c) + group_data_x_border_ * 2, + GroupInputYSize(c) + group_data_y_border_ * 2)); } } // TODO(veluca): avoid reallocating buffers if not needed. @@ -390,7 +396,9 @@ void LowMemoryRenderPipeline::PrepareForThreadsInternal(size_t num, 2 * next_y_border + (1 << stages_[i]->settings_.shift_y); stage_buffer_ysize = 1 << CeilLog2Nonzero(stage_buffer_ysize); next_y_border = stages_[i]->settings_.border_y; - stage_data_[t][c][i] = ImageF(stage_buffer_xsize, stage_buffer_ysize); + JXL_ASSIGN_OR_RETURN( + stage_data_[t][c][i], + ImageF::Create(stage_buffer_xsize, stage_buffer_ysize)); } } } @@ -412,9 +420,11 @@ void LowMemoryRenderPipeline::PrepareForThreadsInternal(size_t num, std::max(left_padding, std::max(middle_padding, right_padding)); out_of_frame_data_.resize(num); for (size_t t = 0; t < num; t++) { - out_of_frame_data_[t] = ImageF(out_of_frame_xsize, shifts.size()); + JXL_ASSIGN_OR_RETURN(out_of_frame_data_[t], + ImageF::Create(out_of_frame_xsize, shifts.size())); } } + return true; } std::vector<std::pair<ImageF*, Rect>> LowMemoryRenderPipeline::PrepareBuffers( @@ -520,7 +530,8 @@ class Rows { .Translate(-group_data_x_border, -group_data_y_border) .ShiftLeft(base_color_shift) .CeilShiftRight(group_data_shift[c]) - .Translate(group_data_x_border - ssize_t(kRenderPipelineXOffset), + .Translate(group_data_x_border - + static_cast<ssize_t>(kRenderPipelineXOffset), group_data_y_border); rows_[0][c].base_ptr = channel_group_data_rect.Row(&input_data[c], 0); rows_[0][c].stride = input_data[c].PixelsPerRow(); @@ -533,7 +544,8 @@ class Rows { JXL_INLINE float* GetBuffer(int stage, int y, size_t c) const { JXL_DASSERT(stage >= -1); const RowInfo& info = rows_[stage + 1][c]; - return info.base_ptr + ssize_t(info.stride) * (y & info.ymod_minus_1); + return info.base_ptr + + static_cast<ssize_t>(info.stride) * (y & info.ymod_minus_1); } private: @@ -551,10 +563,10 @@ class Rows { } // namespace -void LowMemoryRenderPipeline::RenderRect(size_t thread_id, - std::vector<ImageF>& input_data, - Rect data_max_color_channel_rect, - Rect image_max_color_channel_rect) { +Status LowMemoryRenderPipeline::RenderRect(size_t thread_id, + std::vector<ImageF>& input_data, + Rect data_max_color_channel_rect, + Rect image_max_color_channel_rect) { // For each stage, the rect corresponding to the image area currently being // processed, in the coordinates of that stage (i.e. with the scaling factor // that that stage has). @@ -599,7 +611,7 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, // is no point in proceeding. Note: this uses the assumption that if there is // a stage with observable effects (i.e. a kInput stage), it only appears // after the stage that switches to image dimensions. - if (full_image_x1 <= full_image_x0) return; + if (full_image_x1 <= full_image_x0) return true; // Data structures to hold information about input/output rows and their // buffers. @@ -643,7 +655,7 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, } // If we already have rows from a previous iteration, we can just shift // the rows by 1 and insert the new one. - if (input_rows[i][c].size() == 2 * size_t(bordery) + 1) { + if (input_rows[i][c].size() == 2 * static_cast<size_t>(bordery) + 1) { for (ssize_t iy = 0; iy < 2 * bordery; iy++) { input_rows[i][c][iy] = input_rows[i][c][iy + 1]; } @@ -674,7 +686,7 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, virtual_ypadding_for_output_.end()); for (int vy = -num_extra_rows; - vy < int(image_area_rect.ysize()) + num_extra_rows; vy++) { + vy < static_cast<int>(image_area_rect.ysize()) + num_extra_rows; vy++) { for (size_t i = 0; i < first_trailing_stage_; i++) { int stage_vy = vy - num_extra_rows + virtual_ypadding_for_output_[i]; @@ -688,9 +700,10 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, int y = stage_vy >> channel_shifts_[i][anyc_[i]].second; - ssize_t image_y = ssize_t(group_rect[i].y0()) + y; + ssize_t image_y = static_cast<ssize_t>(group_rect[i].y0()) + y; // Do not produce rows in out-of-bounds areas. - if (image_y < 0 || image_y >= ssize_t(image_rect_[i].ysize())) { + if (image_y < 0 || + image_y >= static_cast<ssize_t>(image_rect_[i].ysize())) { continue; } @@ -698,9 +711,9 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, prepare_io_rows(y, i); // Produce output rows. - stages_[i]->ProcessRow(input_rows[i], output_rows, - xpadding_for_output_[i], group_rect[i].xsize(), - group_rect[i].x0(), image_y, thread_id); + JXL_RETURN_IF_ERROR(stages_[i]->ProcessRow( + input_rows[i], output_rows, xpadding_for_output_[i], + group_rect[i].xsize(), group_rect[i].x0(), image_y, thread_id)); } // Process trailing stages, i.e. the final set of non-kInOut stages; they @@ -719,7 +732,7 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, // Check that we are not outside of the bounds for the current rendering // rect. Not doing so might result in overwriting some rows that have been // written (or will be written) by other threads. - if (y < 0 || y >= ssize_t(image_area_rect.ysize())) { + if (y < 0 || y >= static_cast<ssize_t>(image_area_rect.ysize())) { continue; } @@ -728,7 +741,8 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, // (and may be necessary for correctness, as some stages assume coordinates // are within bounds). ssize_t full_image_y = frame_y0 + image_area_rect.y0() + y; - if (full_image_y < 0 || full_image_y >= ssize_t(full_image_ysize)) { + if (full_image_y < 0 || + full_image_y >= static_cast<ssize_t>(full_image_ysize)) { continue; } @@ -739,15 +753,16 @@ void LowMemoryRenderPipeline::RenderRect(size_t thread_id, i < first_image_dim_stage_ ? full_image_x0 - frame_x0 : full_image_x0; size_t y = i < first_image_dim_stage_ ? full_image_y - frame_y0 : full_image_y; - stages_[i]->ProcessRow(input_rows[first_trailing_stage_], output_rows, - /*xextra=*/0, full_image_x1 - full_image_x0, x0, y, - thread_id); + JXL_RETURN_IF_ERROR(stages_[i]->ProcessRow( + input_rows[first_trailing_stage_], output_rows, + /*xextra=*/0, full_image_x1 - full_image_x0, x0, y, thread_id)); } } + return true; } -void LowMemoryRenderPipeline::RenderPadding(size_t thread_id, Rect rect) { - if (rect.xsize() == 0) return; +Status LowMemoryRenderPipeline::RenderPadding(size_t thread_id, Rect rect) { + if (rect.xsize() == 0) return true; size_t numc = channel_shifts_[0].size(); RenderPipelineStage::RowInfo input_rows(numc, std::vector<float*>(1)); RenderPipelineStage::RowInfo output_rows; @@ -760,15 +775,16 @@ void LowMemoryRenderPipeline::RenderPadding(size_t thread_id, Rect rect) { stages_[first_image_dim_stage_ - 1]->ProcessPaddingRow( input_rows, rect.xsize(), rect.x0(), rect.y0() + y); for (size_t i = first_image_dim_stage_; i < stages_.size(); i++) { - stages_[i]->ProcessRow(input_rows, output_rows, - /*xextra=*/0, rect.xsize(), rect.x0(), - rect.y0() + y, thread_id); + JXL_RETURN_IF_ERROR(stages_[i]->ProcessRow( + input_rows, output_rows, + /*xextra=*/0, rect.xsize(), rect.x0(), rect.y0() + y, thread_id)); } } + return true; } -void LowMemoryRenderPipeline::ProcessBuffers(size_t group_id, - size_t thread_id) { +Status LowMemoryRenderPipeline::ProcessBuffers(size_t group_id, + size_t thread_id) { std::vector<ImageF>& input_data = group_data_[use_group_ids_ ? group_id : thread_id]; @@ -804,38 +820,43 @@ void LowMemoryRenderPipeline::ProcessBuffers(size_t group_id, if (group_id == 0 && (image_rect.xsize() == 0 || image_rect.ysize() == 0)) { // If this frame does not intersect with the full image, we have to // initialize the whole image area with RenderPadding. - RenderPadding(thread_id, - Rect(0, 0, full_image_xsize_, full_image_ysize_)); + JXL_RETURN_IF_ERROR(RenderPadding( + thread_id, Rect(0, 0, full_image_xsize_, full_image_ysize_))); } // Render padding for groups that intersect with the full image. The case // where no groups intersect was handled above. if (group_rect.xsize() > 0 && group_rect.ysize() > 0) { if (gx == 0 && gy == 0) { - RenderPadding(thread_id, Rect(0, 0, x0, y0)); + JXL_RETURN_IF_ERROR(RenderPadding(thread_id, Rect(0, 0, x0, y0))); } if (gy == 0) { - RenderPadding(thread_id, Rect(x0, 0, x1 - x0, y0)); + JXL_RETURN_IF_ERROR(RenderPadding(thread_id, Rect(x0, 0, x1 - x0, y0))); } if (gx == 0) { - RenderPadding(thread_id, Rect(0, y0, x0, y1 - y0)); + JXL_RETURN_IF_ERROR(RenderPadding(thread_id, Rect(0, y0, x0, y1 - y0))); } if (gx == 0 && gy + 1 == frame_dimensions_.ysize_groups) { - RenderPadding(thread_id, Rect(0, y1, x0, full_image_ysize_ - y1)); + JXL_RETURN_IF_ERROR( + RenderPadding(thread_id, Rect(0, y1, x0, full_image_ysize_ - y1))); } if (gy + 1 == frame_dimensions_.ysize_groups) { - RenderPadding(thread_id, Rect(x0, y1, x1 - x0, full_image_ysize_ - y1)); + JXL_RETURN_IF_ERROR(RenderPadding( + thread_id, Rect(x0, y1, x1 - x0, full_image_ysize_ - y1))); } if (gy == 0 && gx + 1 == frame_dimensions_.xsize_groups) { - RenderPadding(thread_id, Rect(x1, 0, full_image_xsize_ - x1, y0)); + JXL_RETURN_IF_ERROR( + RenderPadding(thread_id, Rect(x1, 0, full_image_xsize_ - x1, y0))); } if (gx + 1 == frame_dimensions_.xsize_groups) { - RenderPadding(thread_id, Rect(x1, y0, full_image_xsize_ - x1, y1 - y0)); + JXL_RETURN_IF_ERROR(RenderPadding( + thread_id, Rect(x1, y0, full_image_xsize_ - x1, y1 - y0))); } if (gy + 1 == frame_dimensions_.ysize_groups && gx + 1 == frame_dimensions_.xsize_groups) { - RenderPadding(thread_id, Rect(x1, y1, full_image_xsize_ - x1, - full_image_ysize_ - y1)); + JXL_RETURN_IF_ERROR(RenderPadding( + thread_id, + Rect(x1, y1, full_image_xsize_ - x1, full_image_ysize_ - y1))); } } } @@ -857,8 +878,10 @@ void LowMemoryRenderPipeline::ProcessBuffers(size_t group_id, gy * frame_dimensions_.group_dim, image_max_color_channel_rect.xsize(), image_max_color_channel_rect.ysize()); - RenderRect(thread_id, input_data, data_max_color_channel_rect, - image_max_color_channel_rect); + JXL_RETURN_IF_ERROR(RenderRect(thread_id, input_data, + data_max_color_channel_rect, + image_max_color_channel_rect)); } + return true; } } // namespace jxl diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.h b/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.h index b386f7c078..f0b21d3dca 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.h +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/low_memory_render_pipeline.h @@ -20,21 +20,21 @@ class LowMemoryRenderPipeline final : public RenderPipeline { std::vector<std::pair<ImageF*, Rect>> PrepareBuffers( size_t group_id, size_t thread_id) override; - void PrepareForThreadsInternal(size_t num, bool use_group_ids) override; + Status PrepareForThreadsInternal(size_t num, bool use_group_ids) override; - void ProcessBuffers(size_t group_id, size_t thread_id) override; + Status ProcessBuffers(size_t group_id, size_t thread_id) override; void ClearDone(size_t i) override { group_border_assigner_.ClearDone(i); } - void Init() override; + Status Init() override; - void EnsureBordersStorage(); + Status EnsureBordersStorage(); size_t GroupInputXSize(size_t c) const; size_t GroupInputYSize(size_t c) const; - void RenderRect(size_t thread_id, std::vector<ImageF>& input_data, - Rect data_max_color_channel_rect, - Rect image_max_color_channel_rect); - void RenderPadding(size_t thread_id, Rect rect); + Status RenderRect(size_t thread_id, std::vector<ImageF>& input_data, + Rect data_max_color_channel_rect, + Rect image_max_color_channel_rect); + Status RenderPadding(size_t thread_id, Rect rect); void SaveBorders(size_t group_id, size_t c, const ImageF& in); void LoadBorders(size_t group_id, size_t c, const Rect& r, ImageF* out); diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.cc index 68b6ef613f..14bd363110 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.cc @@ -5,8 +5,7 @@ #include "lib/jxl/render_pipeline/render_pipeline.h" -#include <algorithm> - +#include "lib/jxl/base/status.h" #include "lib/jxl/render_pipeline/low_memory_render_pipeline.h" #include "lib/jxl/render_pipeline/simple_render_pipeline.h" #include "lib/jxl/sanitizers.h" @@ -18,7 +17,7 @@ void RenderPipeline::Builder::AddStage( stages_.push_back(std::move(stage)); } -std::unique_ptr<RenderPipeline> RenderPipeline::Builder::Finalize( +StatusOr<std::unique_ptr<RenderPipeline>> RenderPipeline::Builder::Finalize( FrameDimensions frame_dimensions) && { #if JXL_ENABLE_ASSERT // Check that the last stage is not an kInOut stage for any channel, and that @@ -88,7 +87,7 @@ std::unique_ptr<RenderPipeline> RenderPipeline::Builder::Finalize( } } res->stages_ = std::move(stages_); - res->Init(); + JXL_RETURN_IF_ERROR(res->Init()); return res; } @@ -103,7 +102,7 @@ RenderPipelineInput RenderPipeline::GetInputBuffers(size_t group_id, return ret; } -void RenderPipeline::InputReady( +Status RenderPipeline::InputReady( size_t group_id, size_t thread_id, const std::vector<std::pair<ImageF*, Rect>>& buffers) { JXL_DASSERT(group_id < group_completed_passes_.size()); @@ -113,20 +112,22 @@ void RenderPipeline::InputReady( JXL_CHECK_PLANE_INITIALIZED(*buffers[i].first, buffers[i].second, i); } - ProcessBuffers(group_id, thread_id); + JXL_RETURN_IF_ERROR(ProcessBuffers(group_id, thread_id)); + return true; } Status RenderPipeline::PrepareForThreads(size_t num, bool use_group_ids) { for (const auto& stage : stages_) { JXL_RETURN_IF_ERROR(stage->PrepareForThreads(num)); } - PrepareForThreadsInternal(num, use_group_ids); + JXL_RETURN_IF_ERROR(PrepareForThreadsInternal(num, use_group_ids)); return true; } -void RenderPipelineInput::Done() { +Status RenderPipelineInput::Done() { JXL_ASSERT(pipeline_); - pipeline_->InputReady(group_id_, thread_id_, buffers_); + JXL_RETURN_IF_ERROR(pipeline_->InputReady(group_id_, thread_id_, buffers_)); + return true; } } // namespace jxl diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.h b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.h index bf3ad4975e..c61420be4b 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.h +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline.h @@ -32,7 +32,7 @@ class RenderPipelineInput { } RenderPipelineInput() = default; - void Done(); + Status Done(); const std::pair<ImageF*, Rect>& GetBuffer(size_t c) const { JXL_ASSERT(c < buffers_.size()); @@ -63,7 +63,7 @@ class RenderPipeline { // Finalizes setup of the pipeline. Shifts for all channels should be 0 at // this point. - std::unique_ptr<RenderPipeline> Finalize( + StatusOr<std::unique_ptr<RenderPipeline>> Finalize( FrameDimensions frame_dimensions) &&; private: @@ -118,20 +118,20 @@ class RenderPipeline { friend class RenderPipelineInput; private: - void InputReady(size_t group_id, size_t thread_id, - const std::vector<std::pair<ImageF*, Rect>>& buffers); + Status InputReady(size_t group_id, size_t thread_id, + const std::vector<std::pair<ImageF*, Rect>>& buffers); virtual std::vector<std::pair<ImageF*, Rect>> PrepareBuffers( size_t group_id, size_t thread_id) = 0; - virtual void ProcessBuffers(size_t group_id, size_t thread_id) = 0; + virtual Status ProcessBuffers(size_t group_id, size_t thread_id) = 0; // Note that this method may be called multiple times with different (or // equal) `num`. - virtual void PrepareForThreadsInternal(size_t num, bool use_group_ids) = 0; + virtual Status PrepareForThreadsInternal(size_t num, bool use_group_ids) = 0; // Called once frame dimensions and stages are known. - virtual void Init() {} + virtual Status Init() { return true; } }; } // namespace jxl diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_stage.h b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_stage.h index d1a0074161..d054027ba7 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_stage.h +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_stage.h @@ -9,6 +9,7 @@ #include <stdint.h> #include "lib/jxl/base/arch_macros.h" +#include "lib/jxl/base/status.h" #include "lib/jxl/frame_header.h" namespace jxl { @@ -99,9 +100,10 @@ class RenderPipelineStage { // `GroupBorderAssigner::kPaddingXRound`. If `settings_.temp_buffer_size` is // nonzero, `temp` will point to an HWY-aligned buffer of at least that number // of floats; concurrent calls will have different buffers. - virtual void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const = 0; + virtual Status ProcessRow(const RowInfo& input_rows, + const RowInfo& output_rows, size_t xextra, + size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const = 0; // How each channel will be processed. Channels are numbered starting from // color channels (always 3) and followed by all other channels. @@ -114,8 +116,10 @@ class RenderPipelineStage { // Informs the stage about the total size of each channel. Few stages will // actually need to use this information. - virtual void SetInputSizes( - const std::vector<std::pair<size_t, size_t>>& input_sizes) {} + virtual Status SetInputSizes( + const std::vector<std::pair<size_t, size_t>>& input_sizes) { + return true; + } virtual Status PrepareForThreads(size_t num_threads) { return true; } diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_test.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_test.cc index 51b9f273f8..e9cb913983 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_test.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/render_pipeline_test.cc @@ -111,7 +111,7 @@ TEST(RenderPipelineTest, Build) { frame_dimensions.Set(/*xsize=*/1024, /*ysize=*/1024, /*group_size_shift=*/0, /*max_hshift=*/0, /*max_vshift=*/0, /*modular_mode=*/false, /*upsampling=*/1); - std::move(builder).Finalize(frame_dimensions); + std::move(builder).Finalize(frame_dimensions).value(); } TEST(RenderPipelineTest, CallAllGroups) { @@ -124,14 +124,14 @@ TEST(RenderPipelineTest, CallAllGroups) { frame_dimensions.Set(/*xsize=*/1024, /*ysize=*/1024, /*group_size_shift=*/0, /*max_hshift=*/0, /*max_vshift=*/0, /*modular_mode=*/false, /*upsampling=*/1); - auto pipeline = std::move(builder).Finalize(frame_dimensions); + auto pipeline = std::move(builder).Finalize(frame_dimensions).value(); ASSERT_TRUE(pipeline->PrepareForThreads(1, /*use_group_ids=*/false)); for (size_t i = 0; i < frame_dimensions.num_groups; i++) { auto input_buffers = pipeline->GetInputBuffers(i, 0); FillPlane(0.0f, input_buffers.GetBuffer(0).first, input_buffers.GetBuffer(0).second); - input_buffers.Done(); + JXL_CHECK(input_buffers.Done()); } EXPECT_EQ(pipeline->PassesWithAllInput(), 1); @@ -146,7 +146,7 @@ TEST(RenderPipelineTest, BuildFast) { frame_dimensions.Set(/*xsize=*/1024, /*ysize=*/1024, /*group_size_shift=*/0, /*max_hshift=*/0, /*max_vshift=*/0, /*modular_mode=*/false, /*upsampling=*/1); - std::move(builder).Finalize(frame_dimensions); + std::move(builder).Finalize(frame_dimensions).value(); } TEST(RenderPipelineTest, CallAllGroupsFast) { @@ -159,14 +159,14 @@ TEST(RenderPipelineTest, CallAllGroupsFast) { frame_dimensions.Set(/*xsize=*/1024, /*ysize=*/1024, /*group_size_shift=*/0, /*max_hshift=*/0, /*max_vshift=*/0, /*modular_mode=*/false, /*upsampling=*/1); - auto pipeline = std::move(builder).Finalize(frame_dimensions); + auto pipeline = std::move(builder).Finalize(frame_dimensions).value(); ASSERT_TRUE(pipeline->PrepareForThreads(1, /*use_group_ids=*/false)); for (size_t i = 0; i < frame_dimensions.num_groups; i++) { auto input_buffers = pipeline->GetInputBuffers(i, 0); FillPlane(0.0f, input_buffers.GetBuffer(0).first, input_buffers.GetBuffer(0).second); - input_buffers.Done(); + JXL_CHECK(input_buffers.Done()); } EXPECT_EQ(pipeline->PassesWithAllInput(), 1); @@ -208,7 +208,7 @@ TEST_P(RenderPipelineTestParam, PipelineTest) { io.ShrinkTo(config.xsize, config.ysize); if (config.add_spot_color) { - jxl::ImageF spot(config.xsize, config.ysize); + JXL_ASSIGN_OR_DIE(ImageF spot, ImageF::Create(config.xsize, config.ysize)); jxl::ZeroFillImage(&spot); for (size_t y = 0; y < config.ysize; y++) { @@ -227,7 +227,7 @@ TEST_P(RenderPipelineTestParam, PipelineTest) { info.spot_color[3] = 0.5f; io.metadata.m.extra_channel_info.push_back(info); - std::vector<jxl::ImageF> ec; + std::vector<ImageF> ec; ec.push_back(std::move(spot)); io.frames[0].SetExtraChannels(std::move(ec)); } @@ -267,11 +267,11 @@ Splines CreateTestSplines() { const ColorCorrelationMap cmap; std::vector<Spline::Point> control_points{{9, 54}, {118, 159}, {97, 3}, {10, 40}, {150, 25}, {120, 300}}; - const Spline spline{ - control_points, - /*color_dct=*/ - {{0.03125f, 0.00625f, 0.003125f}, {1.f, 0.321875f}, {1.f, 0.24375f}}, - /*sigma_dct=*/{0.3125f, 0.f, 0.f, 0.0625f}}; + const Spline spline{control_points, + /*color_dct=*/ + {Dct32{0.03125f, 0.00625f, 0.003125f}, + Dct32{1.f, 0.321875f}, Dct32{1.f, 0.24375f}}, + /*sigma_dct=*/{0.3125f, 0.f, 0.f, 0.0625f}}; std::vector<Spline> spline_data = {spline}; std::vector<QuantizedSpline> quantized_splines; std::vector<Spline::Point> starting_points; @@ -522,7 +522,7 @@ std::ostream& operator<<(std::ostream& os, filename = c.input_path.substr(pos + 1); } std::replace_if( - filename.begin(), filename.end(), [](char c) { return !isalnum(c); }, + filename.begin(), filename.end(), [](char c) { return isalnum(c) == 0; }, '_'); os << filename << "_" << (c.jpeg_transcode ? "JPEG_" : "") << c.xsize << "x" << c.ysize << "_" << c.cparams_descr; diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.cc index 4495288860..7f5a8ef00f 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.cc @@ -7,27 +7,31 @@ #include <hwy/base.h> +#include "lib/jxl/base/status.h" #include "lib/jxl/image_ops.h" #include "lib/jxl/render_pipeline/render_pipeline_stage.h" #include "lib/jxl/sanitizers.h" namespace jxl { -void SimpleRenderPipeline::PrepareForThreadsInternal(size_t num, - bool use_group_ids) { +Status SimpleRenderPipeline::PrepareForThreadsInternal(size_t num, + bool use_group_ids) { if (!channel_data_.empty()) { - return; + return true; } auto ch_size = [](size_t frame_size, size_t shift) { return DivCeil(frame_size, 1 << shift) + kRenderPipelineXOffset * 2; }; for (size_t c = 0; c < channel_shifts_[0].size(); c++) { - channel_data_.push_back(ImageF( - ch_size(frame_dimensions_.xsize_upsampled, channel_shifts_[0][c].first), - ch_size(frame_dimensions_.ysize_upsampled, - channel_shifts_[0][c].second))); + JXL_ASSIGN_OR_RETURN( + ImageF ch, ImageF::Create(ch_size(frame_dimensions_.xsize_upsampled, + channel_shifts_[0][c].first), + ch_size(frame_dimensions_.ysize_upsampled, + channel_shifts_[0][c].second))); + channel_data_.push_back(std::move(ch)); msan::PoisonImage(channel_data_.back()); } + return true; } Rect SimpleRenderPipeline::MakeChannelRect(size_t group_id, size_t channel) { @@ -60,14 +64,14 @@ std::vector<std::pair<ImageF*, Rect>> SimpleRenderPipeline::PrepareBuffers( return ret; } -void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { +Status SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { for (size_t c = 0; c < channel_data_.size(); c++) { Rect r = MakeChannelRect(group_id, c); (void)r; JXL_CHECK_PLANE_INITIALIZED(channel_data_[c], r, c); } - if (PassesWithAllInput() <= processed_passes_) return; + if (PassesWithAllInput() <= processed_passes_) return true; processed_passes_++; for (size_t stage_id = 0; stage_id < stages_.size(); stage_id++) { @@ -89,11 +93,13 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { } // Ensure that the newly allocated channels are large enough to avoid // problems with padding. - new_channels[c] = - ImageF(frame_dimensions_.xsize_upsampled_padded + - kRenderPipelineXOffset * 2 + hwy::kMaxVectorSize * 8, - frame_dimensions_.ysize_upsampled_padded + - kRenderPipelineXOffset * 2); + JXL_ASSIGN_OR_RETURN( + new_channels[c], + ImageF::Create(frame_dimensions_.xsize_upsampled_padded + + kRenderPipelineXOffset * 2 + + hwy::kMaxVectorSize * 8, + frame_dimensions_.ysize_upsampled_padded + + kRenderPipelineXOffset * 2)); new_channels[c].ShrinkTo( (input_sizes[c].first << stage->settings_.shift_x) + kRenderPipelineXOffset * 2, @@ -116,7 +122,8 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { for (size_t y = 0; y < input_sizes[c].second; y++) { float* row = get_row(c, y); for (size_t ix = 0; ix < stage->settings_.border_x; ix++) { - *(row - ix - 1) = row[Mirror(-ssize_t(ix) - 1, input_sizes[c].first)]; + *(row - ix - 1) = + row[Mirror(-static_cast<ssize_t>(ix) - 1, input_sizes[c].first)]; } for (size_t ix = 0; ix < stage->settings_.border_x; ix++) { *(row + ix + input_sizes[c].first) = @@ -126,7 +133,8 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { // Vertical mirroring. for (int y = 0; y < static_cast<int>(stage->settings_.border_y); y++) { memcpy(get_row(c, -y - 1) - stage->settings_.border_x, - get_row(c, Mirror(-ssize_t(y) - 1, input_sizes[c].second)) - + get_row(c, Mirror(-static_cast<ssize_t>(y) - 1, + input_sizes[c].second)) - stage->settings_.border_x, sizeof(float) * (input_sizes[c].first + 2 * stage->settings_.border_x)); @@ -160,7 +168,7 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { // Run the pipeline. { - stage->SetInputSizes(input_sizes); + JXL_RETURN_IF_ERROR(stage->SetInputSizes(input_sizes)); int border_y = stage->settings_.border_y; for (size_t y = 0; y < ysize; y++) { // Prepare input rows. @@ -183,8 +191,9 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { (y << stage->settings_.shift_y) + iy + kRenderPipelineXOffset); } } - stage->ProcessRow(input_rows, output_rows, /*xextra=*/0, xsize, - /*xpos=*/0, y, thread_id); + JXL_RETURN_IF_ERROR(stage->ProcessRow(input_rows, output_rows, + /*xextra=*/0, xsize, + /*xpos=*/0, y, thread_id)); } } @@ -210,7 +219,8 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { } if (stage->SwitchToImageDimensions()) { - size_t image_xsize, image_ysize; + size_t image_xsize; + size_t image_ysize; FrameOrigin frame_origin; stage->GetImageDimensions(&image_xsize, &image_ysize, &frame_origin); frame_dimensions_.Set(image_xsize, image_ysize, 0, 0, 0, false, 1); @@ -218,8 +228,11 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { channel_data_.clear(); channel_data_.reserve(old_channels.size()); for (size_t c = 0; c < old_channels.size(); c++) { - channel_data_.emplace_back(2 * kRenderPipelineXOffset + image_xsize, - 2 * kRenderPipelineXOffset + image_ysize); + JXL_ASSIGN_OR_RETURN( + ImageF ch, + ImageF::Create(2 * kRenderPipelineXOffset + image_xsize, + 2 * kRenderPipelineXOffset + image_ysize)); + channel_data_.emplace_back(std::move(ch)); } for (size_t y = 0; y < image_ysize; ++y) { for (size_t c = 0; c < channel_data_.size(); c++) { @@ -262,5 +275,6 @@ void SimpleRenderPipeline::ProcessBuffers(size_t group_id, size_t thread_id) { } } } + return true; } } // namespace jxl diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.h b/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.h index 10f4505912..1240b9fa46 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.h +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/simple_render_pipeline.h @@ -19,9 +19,9 @@ class SimpleRenderPipeline : public RenderPipeline { std::vector<std::pair<ImageF*, Rect>> PrepareBuffers( size_t group_id, size_t thread_id) override; - void ProcessBuffers(size_t group_id, size_t thread_id) override; + Status ProcessBuffers(size_t group_id, size_t thread_id) override; - void PrepareForThreadsInternal(size_t num, bool use_group_ids) override; + Status PrepareForThreadsInternal(size_t num, bool use_group_ids) override; // Full frame buffers. Both X and Y dimensions are padded by // kRenderPipelineXOffset. diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_blending.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_blending.cc index b68105f4c9..ef3899d1b3 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_blending.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_blending.cc @@ -109,7 +109,7 @@ class BlendingStage : public RenderPipelineStage { } } }; - make_blending(info_, &blending_info_[0]); + make_blending(info_, blending_info_.data()); for (size_t i = 0; i < ec_info.size(); i++) { make_blending(ec_info[i], &blending_info_[1 + i]); } @@ -117,9 +117,9 @@ class BlendingStage : public RenderPipelineStage { Status IsInitialized() const override { return initialized_; } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { JXL_ASSERT(initialized_); const FrameOrigin& frame_origin = frame_header_.frame_origin; ssize_t bg_xpos = frame_origin.x0 + static_cast<ssize_t>(xpos); @@ -128,7 +128,8 @@ class BlendingStage : public RenderPipelineStage { if (bg_xpos + static_cast<ssize_t>(xsize) <= 0 || frame_origin.x0 >= static_cast<ssize_t>(image_xsize_) || bg_ypos < 0 || bg_ypos >= static_cast<ssize_t>(image_ysize_)) { - return; + // TODO(eustas): or fail? + return true; } if (bg_xpos < 0) { offset -= bg_xpos; @@ -160,9 +161,9 @@ class BlendingStage : public RenderPipelineStage { : zeroes_.data(); } } - PerformBlending(bg_row_ptrs_.data(), fg_row_ptrs_.data(), - fg_row_ptrs_.data(), 0, xsize, blending_info_[0], - blending_info_.data() + 1, *extra_channel_info_); + return PerformBlending(bg_row_ptrs_.data(), fg_row_ptrs_.data(), + fg_row_ptrs_.data(), 0, xsize, blending_info_[0], + blending_info_.data() + 1, *extra_channel_info_); } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_chroma_upsampling.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_chroma_upsampling.cc index 936fbd3a44..2bc88ada67 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_chroma_upsampling.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_chroma_upsampling.cc @@ -27,9 +27,9 @@ class HorizontalChromaUpsamplingStage : public RenderPipelineStage { /*shift=*/1, /*border=*/1)), c_(channel) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { HWY_FULL(float) df; xextra = RoundUpTo(xextra, Lanes(df)); auto threefour = Set(df, 0.75f); @@ -45,6 +45,7 @@ class HorizontalChromaUpsamplingStage : public RenderPipelineStage { auto right = MulAdd(onefour, next, current); StoreInterleaved(df, left, right, row_out + x * 2); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -65,9 +66,9 @@ class VerticalChromaUpsamplingStage : public RenderPipelineStage { /*shift=*/1, /*border=*/1)), c_(channel) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { HWY_FULL(float) df; xextra = RoundUpTo(xextra, Lanes(df)); auto threefour = Set(df, 0.75f); @@ -86,6 +87,7 @@ class VerticalChromaUpsamplingStage : public RenderPipelineStage { Store(MulAdd(it, onefour, im_scaled), df, row_out0 + x); Store(MulAdd(ib, onefour, im_scaled), df, row_out1 + x); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_cms.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_cms.cc index 2465146b47..3202a03e44 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_cms.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_cms.cc @@ -7,10 +7,8 @@ #include <memory> -#include "jxl/cms_interface.h" -#include "jxl/color_encoding.h" +#include "lib/jxl/base/status.h" #include "lib/jxl/color_encoding_internal.h" -#include "lib/jxl/common.h" #include "lib/jxl/dec_xyb.h" #undef HWY_TARGET_INCLUDE @@ -19,7 +17,6 @@ #include <hwy/highway.h> #include "lib/jxl/dec_xyb-inl.h" -#include "lib/jxl/sanitizers.h" HWY_BEFORE_NAMESPACE(); namespace jxl { @@ -44,10 +41,10 @@ class CmsStage : public RenderPipelineStage { not_mixing_color_and_grey; } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { - JXL_ASSERT(xsize == xsize_); + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { + JXL_ASSERT(xsize <= xsize_); // TODO(firsching): handle grey case seperately // interleave float* JXL_RESTRICT row0 = GetInputRow(input_rows, 0, 0); @@ -62,16 +59,15 @@ class CmsStage : public RenderPipelineStage { } const float* buf_src = mutable_buf_src; float* JXL_RESTRICT buf_dst = color_space_transform->BufDst(thread_id); - if (!color_space_transform->Run(thread_id, buf_src, buf_dst)) { - // TODO(firsching): somehow mark failing here? - return; - } + JXL_RETURN_IF_ERROR( + color_space_transform->Run(thread_id, buf_src, buf_dst, xsize)); // de-interleave for (size_t x = 0; x < xsize; x++) { row0[x] = buf_dst[3 * x + 0]; row1[x] = buf_dst[3 * x + 1]; row2[x] = buf_dst[3 * x + 2]; } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { return c < 3 ? RenderPipelineChannelMode::kInPlace @@ -86,7 +82,7 @@ class CmsStage : public RenderPipelineStage { std::unique_ptr<jxl::ColorSpaceTransform> color_space_transform; ColorEncoding c_src_; - void SetInputSizes( + Status SetInputSizes( const std::vector<std::pair<size_t, size_t>>& input_sizes) override { #if JXL_ENABLE_ASSERT JXL_ASSERT(input_sizes.size() >= 3); @@ -96,6 +92,7 @@ class CmsStage : public RenderPipelineStage { } #endif xsize_ = input_sizes[0].first; + return true; } Status PrepareForThreads(size_t num_threads) override { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_epf.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_epf.cc index 5d1a379ede..d3030b02cb 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_epf.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_epf.cc @@ -8,7 +8,6 @@ #include "lib/jxl/base/common.h" #include "lib/jxl/common.h" // JXL_HIGH_PRECISION #include "lib/jxl/epf.h" -#include "lib/jxl/sanitizers.h" #undef HWY_TARGET_INCLUDE #define HWY_TARGET_INCLUDE "lib/jxl/render_pipeline/stage_epf.cc" @@ -67,9 +66,9 @@ class EPF0Stage : public RenderPipelineStage { *B = MulAdd(weight, cb, *B); } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { DF df; using V = decltype(Zero(df)); @@ -163,6 +162,7 @@ class EPF0Stage : public RenderPipelineStage { StoreU(Mul(Y, inv_w), df, GetOutputRow(output_rows, 1, 0) + x); StoreU(Mul(B, inv_w), df, GetOutputRow(output_rows, 2, 0) + x); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -207,9 +207,9 @@ class EPF1Stage : public RenderPipelineStage { *B = MulAdd(weight, cb, *B); } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { DF df; xextra = RoundUpTo(xextra, Lanes(df)); const float* JXL_RESTRICT row_sigma = @@ -343,6 +343,7 @@ class EPF1Stage : public RenderPipelineStage { Store(Mul(Y, inv_w), df, GetOutputRow(output_rows, 1, 0) + x); Store(Mul(B, inv_w), df, GetOutputRow(output_rows, 2, 0) + x); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -392,9 +393,9 @@ class EPF2Stage : public RenderPipelineStage { *B = MulAdd(weight, cb, *B); } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { DF df; xextra = RoundUpTo(xextra, Lanes(df)); const float* JXL_RESTRICT row_sigma = @@ -465,6 +466,7 @@ class EPF2Stage : public RenderPipelineStage { Store(Mul(Y, inv_w), df, GetOutputRow(output_rows, 1, 0) + x); Store(Mul(B, inv_w), df, GetOutputRow(output_rows, 2, 0) + x); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_from_linear.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_from_linear.cc index 6b1f646cd5..922c7da366 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_from_linear.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_from_linear.cc @@ -68,7 +68,7 @@ struct OpPq { }; struct OpHlg { - explicit OpHlg(const float luminances[3], const float intensity_target) + explicit OpHlg(const Vector3& luminances, const float intensity_target) : hlg_ootf_(HlgOOTF::ToSceneLight(/*display_luminance=*/intensity_target, luminances)) {} @@ -105,9 +105,9 @@ class FromLinearStage : public RenderPipelineStage { : RenderPipelineStage(RenderPipelineStage::Settings()), op_(std::move(op)) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { const HWY_FULL(float) d; const size_t xsize_v = RoundUpTo(xsize, Lanes(d)); float* JXL_RESTRICT row0 = GetInputRow(input_rows, 0, 0); @@ -119,7 +119,8 @@ class FromLinearStage : public RenderPipelineStage { msan::UnpoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::UnpoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::UnpoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); - for (ssize_t x = -xextra; x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); + x += Lanes(d)) { auto r = LoadU(d, row0 + x); auto g = LoadU(d, row1 + x); auto b = LoadU(d, row2 + x); @@ -131,6 +132,7 @@ class FromLinearStage : public RenderPipelineStage { msan::PoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_gaborish.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_gaborish.cc index 0917db3f9a..6fcd5e14df 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_gaborish.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_gaborish.cc @@ -44,9 +44,9 @@ class GaborishStage : public RenderPipelineStage { } } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { const HWY_FULL(float) d; for (size_t c = 0; c < 3; c++) { float* JXL_RESTRICT row_t = GetInputRow(input_rows, c, -1); @@ -66,7 +66,7 @@ class GaborishStage : public RenderPipelineStage { // Since GetInputRow(input_rows, c, {-1, 0, 1}) is aligned, rounding // xextra up to Lanes(d) doesn't access anything problematic. for (ssize_t x = -RoundUpTo(xextra, Lanes(d)); - x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + x < static_cast<ssize_t>(xsize + xextra); x += Lanes(d)) { const auto t = LoadMaybeU(d, row_t + x); const auto tl = LoadU(d, row_t + x - 1); const auto tr = LoadU(d, row_t + x + 1); @@ -83,6 +83,7 @@ class GaborishStage : public RenderPipelineStage { Store(pixels, d, row_out + x); } } + return true; } #undef LoadMaybeU diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_noise.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_noise.cc index 5cf8a6ed51..eca679b948 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_noise.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_noise.cc @@ -5,6 +5,8 @@ #include "lib/jxl/render_pipeline/stage_noise.h" +#include "lib/jxl/noise.h" + #undef HWY_TARGET_INCLUDE #define HWY_TARGET_INCLUDE "lib/jxl/render_pipeline/stage_noise.cc" #include <hwy/foreach_target.h> @@ -61,9 +63,10 @@ class StrengthEvalLut { #endif { #if HWY_TARGET != HWY_SCALAR - uint32_t lut[8]; - memcpy(lut, noise_params.lut, sizeof(lut)); - for (size_t i = 0; i < 8; i++) { + uint32_t lut[NoiseParams::kNumNoisePoints]; + memcpy(lut, noise_params.lut.data(), + NoiseParams::kNumNoisePoints * sizeof(uint32_t)); + for (size_t i = 0; i < NoiseParams::kNumNoisePoints; i++) { low16_lut[2 * i] = (lut[i] >> 0) & 0xFF; low16_lut[2 * i + 1] = (lut[i] >> 8) & 0xFF; high16_lut[2 * i] = (lut[i] >> 16) & 0xFF; @@ -161,10 +164,10 @@ class AddNoiseStage : public RenderPipelineStage { cmap_(cmap), first_c_(first_c) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { - if (!noise_params_.HasAny()) return; + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { + if (!noise_params_.HasAny()) return true; const StrengthEvalLut noise_model(noise_params_); D d; const auto half = Set(d, 0.5f); @@ -212,6 +215,7 @@ class AddNoiseStage : public RenderPipelineStage { msan::PoisonMemory(row_x + xsize, (xsize_v - xsize) * sizeof(float)); msan::PoisonMemory(row_y + xsize, (xsize_v - xsize) * sizeof(float)); msan::PoisonMemory(row_b + xsize, (xsize_v - xsize) * sizeof(float)); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -241,9 +245,9 @@ class ConvolveNoiseStage : public RenderPipelineStage { /*shift=*/0, /*border=*/2)), first_c_(first_c) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { const HWY_FULL(float) d; for (size_t c = first_c_; c < first_c_ + 3; c++) { float* JXL_RESTRICT rows[5]; @@ -252,7 +256,7 @@ class ConvolveNoiseStage : public RenderPipelineStage { } float* JXL_RESTRICT row_out = GetOutputRow(output_rows, c, 0); for (ssize_t x = -RoundUpTo(xextra, Lanes(d)); - x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + x < static_cast<ssize_t>(xsize + xextra); x += Lanes(d)) { const auto p00 = LoadU(d, rows[2] + x); auto others = Zero(d); // TODO(eustas): sum loaded values to reduce the calculation chain @@ -271,6 +275,7 @@ class ConvolveNoiseStage : public RenderPipelineStage { StoreU(pixels, d, row_out + x); } } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_patches.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_patches.cc index c5a75b09f7..e0a66167d4 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_patches.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_patches.cc @@ -14,16 +14,17 @@ class PatchDictionaryStage : public RenderPipelineStage { patches_(*patches), num_channels_(num_channels) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { JXL_ASSERT(xpos == 0 || xpos >= xextra); size_t x0 = xpos ? xpos - xextra : 0; std::vector<float*> row_ptrs(num_channels_); for (size_t i = 0; i < num_channels_; i++) { row_ptrs[i] = GetInputRow(input_rows, i, 0) + x0 - xpos; } - patches_.AddOneRow(row_ptrs.data(), ypos, x0, xsize + xextra + xpos - x0); + return patches_.AddOneRow(row_ptrs.data(), ypos, x0, + xsize + xextra + xpos - x0); } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_splines.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_splines.cc index 4a0529ce2c..92a13090a7 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_splines.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_splines.cc @@ -20,13 +20,14 @@ class SplineStage : public RenderPipelineStage { : RenderPipelineStage(RenderPipelineStage::Settings()), splines_(*splines) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { float* row_x = GetInputRow(input_rows, 0, 0); float* row_y = GetInputRow(input_rows, 1, 0); float* row_b = GetInputRow(input_rows, 2, 0); splines_.AddToRow(row_x, row_y, row_b, Rect(xpos, ypos, xsize, 1)); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_spot.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_spot.cc index a43cb4e1ab..18588e2012 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_spot.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_spot.cc @@ -15,19 +15,20 @@ class SpotColorStage : public RenderPipelineStage { JXL_ASSERT(spot_c_ >= 3); } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { // TODO(veluca): add SIMD. float scale = spot_color_[3]; for (size_t c = 0; c < 3; c++) { float* JXL_RESTRICT p = GetInputRow(input_rows, c, 0); const float* JXL_RESTRICT s = GetInputRow(input_rows, spot_c_, 0); - for (ssize_t x = -xextra; x < ssize_t(xsize + xextra); x++) { + for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); x++) { float mix = scale * s[x]; p[x] = mix * spot_color_[c] + (1.0f - mix) * p[x]; } } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_to_linear.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_to_linear.cc index 85eca2f039..c2c5ac484b 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_to_linear.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_to_linear.cc @@ -63,7 +63,7 @@ struct OpPq { }; struct OpHlg { - explicit OpHlg(const float luminances[3], const float intensity_target) + explicit OpHlg(const Vector3& luminances, const float intensity_target) : hlg_ootf_(HlgOOTF::FromSceneLight( /*display_luminance=*/intensity_target, luminances)) {} @@ -113,9 +113,9 @@ class ToLinearStage : public RenderPipelineStage { explicit ToLinearStage() : RenderPipelineStage(RenderPipelineStage::Settings()), valid_(false) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { const HWY_FULL(float) d; const size_t xsize_v = RoundUpTo(xsize, Lanes(d)); float* JXL_RESTRICT row0 = GetInputRow(input_rows, 0, 0); @@ -127,7 +127,8 @@ class ToLinearStage : public RenderPipelineStage { msan::UnpoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::UnpoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::UnpoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); - for (ssize_t x = -xextra; x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); + x += Lanes(d)) { auto r = LoadU(d, row0 + x); auto g = LoadU(d, row1 + x); auto b = LoadU(d, row2 + x); @@ -139,6 +140,7 @@ class ToLinearStage : public RenderPipelineStage { msan::PoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_tone_mapping.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_tone_mapping.cc index 2a272e15dc..e8cd90b244 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_tone_mapping.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_tone_mapping.cc @@ -56,10 +56,10 @@ class ToneMappingStage : public RenderPipelineStage { bool IsNeeded() const { return tone_mapper_ || hlg_ootf_; } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { - if (!(tone_mapper_ || hlg_ootf_)) return; + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { + if (!(tone_mapper_ || hlg_ootf_)) return true; const HWY_FULL(float) d; const size_t xsize_v = RoundUpTo(xsize, Lanes(d)); @@ -72,7 +72,8 @@ class ToneMappingStage : public RenderPipelineStage { msan::UnpoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::UnpoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::UnpoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); - for (ssize_t x = -xextra; x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); + x += Lanes(d)) { auto r = LoadU(d, row0 + x); auto g = LoadU(d, row1 + x); auto b = LoadU(d, row2 + x); @@ -100,6 +101,7 @@ class ToneMappingStage : public RenderPipelineStage { msan::PoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_upsampling.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_upsampling.cc index ade37d59a6..897b20c4c6 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_upsampling.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_upsampling.cc @@ -46,9 +46,9 @@ class UpsamplingStage : public RenderPipelineStage { } } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { static HWY_FULL(float) df; size_t shift = settings_.shift_x; size_t N = 1 << shift; @@ -74,6 +74,7 @@ class UpsamplingStage : public RenderPipelineStage { msan::PoisonMemory(dst_row + xsize * N, sizeof(float) * (xsize_v - xsize) * N); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_write.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_write.cc index 847972acc8..c5a91e8efd 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_write.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_write.cc @@ -9,7 +9,9 @@ #include "lib/jxl/alpha.h" #include "lib/jxl/base/common.h" +#include "lib/jxl/base/status.h" #include "lib/jxl/dec_cache.h" +#include "lib/jxl/image.h" #include "lib/jxl/image_bundle.h" #include "lib/jxl/sanitizers.h" @@ -150,13 +152,13 @@ class WriteToOutputStage : public RenderPipelineStage { } } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { JXL_DASSERT(xextra == 0); JXL_DASSERT(main_.run_opaque_ || main_.buffer_); - if (ypos >= height_) return; - if (xpos >= width_) return; + if (ypos >= height_) return true; + if (xpos >= width_) return true; if (flip_y_) { ypos = height_ - 1u - ypos; } @@ -184,6 +186,7 @@ class WriteToOutputStage : public RenderPipelineStage { OutputBuffers(extra, thread_id, ypos, xstart, len, line_buffers); } } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -202,7 +205,7 @@ class WriteToOutputStage : public RenderPipelineStage { private: struct Output { - Output(const ImageOutput& image_out) + explicit Output(const ImageOutput& image_out) : pixel_callback_(image_out.callback), buffer_(image_out.buffer), buffer_size_(image_out.buffer_size), @@ -406,8 +409,8 @@ class WriteToOutputStage : public RenderPipelineStage { sizeof(output[0]) * out.num_channels_ * padding); } - void StoreFloat16Row(const Output& out, const float* input[4], size_t len, - uint16_t* output) const { + static void StoreFloat16Row(const Output& out, const float* input[4], + size_t len, uint16_t* output) { const HWY_FULL(float) d; const Rebind<uint16_t, decltype(d)> du; const Rebind<hwy::float16_t, decltype(d)> df16; @@ -452,8 +455,8 @@ class WriteToOutputStage : public RenderPipelineStage { sizeof(output[0]) * out.num_channels_ * padding); } - void StoreFloatRow(const Output& out, const float* input[4], size_t len, - float* output) const { + static void StoreFloatRow(const Output& out, const float* input[4], + size_t len, float* output) { const HWY_FULL(float) d; if (out.num_channels_ == 1) { memcpy(output, input[0], len * sizeof(output[0])); @@ -559,7 +562,7 @@ class WriteToImageBundleStage : public RenderPipelineStage { image_bundle_(image_bundle), color_encoding_(std::move(color_encoding)) {} - void SetInputSizes( + Status SetInputSizes( const std::vector<std::pair<size_t, size_t>>& input_sizes) override { #if JXL_ENABLE_ASSERT JXL_ASSERT(input_sizes.size() >= 3); @@ -569,19 +572,22 @@ class WriteToImageBundleStage : public RenderPipelineStage { } #endif // TODO(eustas): what should we do in the case of "want only ECs"? - image_bundle_->SetFromImage( - Image3F(input_sizes[0].first, input_sizes[0].second), color_encoding_); + JXL_ASSIGN_OR_RETURN(Image3F tmp, Image3F::Create(input_sizes[0].first, + input_sizes[0].second)); + image_bundle_->SetFromImage(std::move(tmp), color_encoding_); // TODO(veluca): consider not reallocating ECs if not needed. image_bundle_->extra_channels().clear(); for (size_t c = 3; c < input_sizes.size(); c++) { - image_bundle_->extra_channels().emplace_back(input_sizes[c].first, - input_sizes[c].second); + JXL_ASSIGN_OR_RETURN(ImageF ch, ImageF::Create(input_sizes[c].first, + input_sizes[c].second)); + image_bundle_->extra_channels().emplace_back(std::move(ch)); } + return true; } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { for (size_t c = 0; c < 3; c++) { memcpy(image_bundle_->color()->PlaneRow(c, ypos) + xpos - xextra, GetInputRow(input_rows, c, 0) - xextra, @@ -594,6 +600,7 @@ class WriteToImageBundleStage : public RenderPipelineStage { GetInputRow(input_rows, 3 + ec, 0) - xextra, sizeof(float) * (xsize + 2 * xextra)); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -612,7 +619,7 @@ class WriteToImage3FStage : public RenderPipelineStage { explicit WriteToImage3FStage(Image3F* image) : RenderPipelineStage(RenderPipelineStage::Settings()), image_(image) {} - void SetInputSizes( + Status SetInputSizes( const std::vector<std::pair<size_t, size_t>>& input_sizes) override { #if JXL_ENABLE_ASSERT JXL_ASSERT(input_sizes.size() >= 3); @@ -621,17 +628,20 @@ class WriteToImage3FStage : public RenderPipelineStage { JXL_ASSERT(input_sizes[c].second == input_sizes[0].second); } #endif - *image_ = Image3F(input_sizes[0].first, input_sizes[0].second); + JXL_ASSIGN_OR_RETURN( + *image_, Image3F::Create(input_sizes[0].first, input_sizes[0].second)); + return true; } - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { for (size_t c = 0; c < 3; c++) { memcpy(image_->PlaneRow(c, ypos) + xpos - xextra, GetInputRow(input_rows, c, 0) - xextra, sizeof(float) * (xsize + 2 * xextra)); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_xyb.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_xyb.cc index 56e86e6095..a20e686de6 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_xyb.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_xyb.cc @@ -28,9 +28,9 @@ class XYBStage : public RenderPipelineStage { output_is_xyb_(output_encoding_info.color_encoding.GetColorSpace() == ColorSpace::kXYB) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { const HWY_FULL(float) d; JXL_ASSERT(xextra == 0); const size_t xsize_v = RoundUpTo(xsize, Lanes(d)); @@ -52,7 +52,8 @@ class XYBStage : public RenderPipelineStage { const auto offset_x = Set(d, jxl::cms::kScaledXYBOffset[0]); const auto offset_y = Set(d, jxl::cms::kScaledXYBOffset[1]); const auto offset_bmy = Set(d, jxl::cms::kScaledXYBOffset[2]); - for (ssize_t x = -xextra; x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); + x += Lanes(d)) { const auto in_x = LoadU(d, row0 + x); const auto in_y = LoadU(d, row1 + x); const auto in_b = LoadU(d, row2 + x); @@ -64,7 +65,8 @@ class XYBStage : public RenderPipelineStage { StoreU(out_b, d, row2 + x); } } else { - for (ssize_t x = -xextra; x < (ssize_t)(xsize + xextra); x += Lanes(d)) { + for (ssize_t x = -xextra; x < static_cast<ssize_t>(xsize + xextra); + x += Lanes(d)) { const auto in_opsin_x = LoadU(d, row0 + x); const auto in_opsin_y = LoadU(d, row1 + x); const auto in_opsin_b = LoadU(d, row2 + x); @@ -81,6 +83,7 @@ class XYBStage : public RenderPipelineStage { msan::PoisonMemory(row0 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row1 + xsize, sizeof(float) * (xsize_v - xsize)); msan::PoisonMemory(row2 + xsize, sizeof(float) * (xsize_v - xsize)); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -130,10 +133,10 @@ class FastXYBStage : public RenderPipelineStage { has_alpha_(has_alpha), alpha_c_(alpha_c) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { - if (ypos >= height_) return; + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { + if (ypos >= height_) return true; JXL_ASSERT(xextra == 0); const float* xyba[4] = { GetInputRow(input_rows, 0, 0), GetInputRow(input_rows, 1, 0), @@ -142,6 +145,7 @@ class FastXYBStage : public RenderPipelineStage { uint8_t* out_buf = rgb_ + stride_ * ypos + (rgba_ ? 4 : 3) * xpos; FastXYBTosRGB8(xyba, out_buf, rgba_, xsize + xpos <= width_ ? xsize : width_ - xpos); + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_ycbcr.cc b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_ycbcr.cc index 30ad327221..f21a00c728 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_ycbcr.cc +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/stage_ycbcr.cc @@ -22,9 +22,9 @@ class kYCbCrStage : public RenderPipelineStage { public: kYCbCrStage() : RenderPipelineStage(RenderPipelineStage::Settings()) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { const HWY_FULL(float) df; // Full-range BT.601 as defined by JFIF Clause 7: @@ -51,6 +51,7 @@ class kYCbCrStage : public RenderPipelineStage { StoreU(g_vec, df, row1 + x); StoreU(b_vec, df, row2 + x); } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { diff --git a/third_party/jpeg-xl/lib/jxl/render_pipeline/test_render_pipeline_stages.h b/third_party/jpeg-xl/lib/jxl/render_pipeline/test_render_pipeline_stages.h index 789a52f8b2..c2c25c46c3 100644 --- a/third_party/jpeg-xl/lib/jxl/render_pipeline/test_render_pipeline_stages.h +++ b/third_party/jpeg-xl/lib/jxl/render_pipeline/test_render_pipeline_stages.h @@ -7,10 +7,7 @@ #include <stdint.h> #include <stdio.h> -#include <algorithm> -#include <utility> -#include <vector> - +#include "lib/jxl/base/status.h" #include "lib/jxl/render_pipeline/render_pipeline_stage.h" namespace jxl { @@ -20,13 +17,13 @@ class UpsampleXSlowStage : public RenderPipelineStage { UpsampleXSlowStage() : RenderPipelineStage(RenderPipelineStage::Settings::ShiftX(1, 1)) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { for (size_t c = 0; c < input_rows.size(); c++) { const float* row = GetInputRow(input_rows, c, 0); float* row_out = GetOutputRow(output_rows, c, 0); - for (int64_t x = -xextra; x < (int64_t)(xsize + xextra); x++) { + for (int64_t x = -xextra; x < static_cast<int64_t>(xsize + xextra); x++) { float xp = *(row + x - 1); float xc = *(row + x); float xn = *(row + x + 1); @@ -36,6 +33,7 @@ class UpsampleXSlowStage : public RenderPipelineStage { *(row_out + 2 * x + 1) = xout1; } } + return true; } const char* GetName() const override { return "TEST::UpsampleXSlowStage"; } @@ -50,16 +48,16 @@ class UpsampleYSlowStage : public RenderPipelineStage { UpsampleYSlowStage() : RenderPipelineStage(RenderPipelineStage::Settings::ShiftY(1, 1)) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { for (size_t c = 0; c < input_rows.size(); c++) { const float* rowp = GetInputRow(input_rows, c, -1); const float* rowc = GetInputRow(input_rows, c, 0); const float* rown = GetInputRow(input_rows, c, 1); float* row_out0 = GetOutputRow(output_rows, c, 0); float* row_out1 = GetOutputRow(output_rows, c, 1); - for (int64_t x = -xextra; x < (int64_t)(xsize + xextra); x++) { + for (int64_t x = -xextra; x < static_cast<int64_t>(xsize + xextra); x++) { float xp = *(rowp + x); float xc = *(rowc + x); float xn = *(rown + x); @@ -69,6 +67,7 @@ class UpsampleYSlowStage : public RenderPipelineStage { *(row_out1 + x) = yout1; } } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { @@ -82,14 +81,15 @@ class Check0FinalStage : public RenderPipelineStage { public: Check0FinalStage() : RenderPipelineStage(RenderPipelineStage::Settings()) {} - void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, - size_t xextra, size_t xsize, size_t xpos, size_t ypos, - size_t thread_id) const final { + Status ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, + size_t xextra, size_t xsize, size_t xpos, size_t ypos, + size_t thread_id) const final { for (size_t c = 0; c < input_rows.size(); c++) { for (size_t x = 0; x < xsize; x++) { JXL_CHECK(fabsf(GetInputRow(input_rows, c, 0)[x]) < 1e-8); } } + return true; } RenderPipelineChannelMode GetChannelMode(size_t c) const final { |