low_memory_render_pipeline.h (3971B)
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 #ifndef LIB_JXL_RENDER_PIPELINE_LOW_MEMORY_RENDER_PIPELINE_H_ 7 #define LIB_JXL_RENDER_PIPELINE_LOW_MEMORY_RENDER_PIPELINE_H_ 8 9 #include <stdint.h> 10 11 #include "lib/jxl/dec_group_border.h" 12 #include "lib/jxl/render_pipeline/render_pipeline.h" 13 14 namespace jxl { 15 16 // A multithreaded, low-memory rendering pipeline that only allocates a minimal 17 // amount of buffers. 18 class LowMemoryRenderPipeline final : public RenderPipeline { 19 private: 20 std::vector<std::pair<ImageF*, Rect>> PrepareBuffers( 21 size_t group_id, size_t thread_id) override; 22 23 Status PrepareForThreadsInternal(size_t num, bool use_group_ids) override; 24 25 Status ProcessBuffers(size_t group_id, size_t thread_id) override; 26 27 void ClearDone(size_t i) override { group_border_assigner_.ClearDone(i); } 28 29 Status Init() override; 30 31 Status EnsureBordersStorage(); 32 size_t GroupInputXSize(size_t c) const; 33 size_t GroupInputYSize(size_t c) const; 34 Status RenderRect(size_t thread_id, std::vector<ImageF>& input_data, 35 Rect data_max_color_channel_rect, 36 Rect image_max_color_channel_rect); 37 Status RenderPadding(size_t thread_id, Rect rect); 38 39 void SaveBorders(size_t group_id, size_t c, const ImageF& in); 40 void LoadBorders(size_t group_id, size_t c, const Rect& r, ImageF* out); 41 42 std::pair<size_t, size_t> ColorDimensionsToChannelDimensions( 43 std::pair<size_t, size_t> in, size_t c, size_t stage) const; 44 45 std::pair<size_t, size_t> BorderToStore(size_t c) const; 46 47 bool use_group_ids_; 48 49 // Storage for borders between groups. Borders of adjacent groups are stacked 50 // together, e.g. bottom border of current group is followed by top border 51 // of next group. 52 std::vector<ImageF> borders_horizontal_; 53 std::vector<ImageF> borders_vertical_; 54 55 // Manages the status of borders. 56 GroupBorderAssigner group_border_assigner_; 57 58 // Size (in color-channel-pixels) of the border around each group that might 59 // be assigned to that group. 60 std::pair<size_t, size_t> group_border_; 61 // base_color_shift_ defines the size of groups in terms of final image 62 // pixels. 63 size_t base_color_shift_; 64 65 // Buffer for decoded pixel data for a group, indexed by [thread][channel] or 66 // [group][channel] depending on `use_group_ids_`. 67 std::vector<std::vector<ImageF>> group_data_; 68 69 // Borders for storing group data. 70 size_t group_data_x_border_; 71 size_t group_data_y_border_; 72 73 // Buffers for intermediate rows for the various stages, indexed by 74 // [thread][channel][stage]. 75 std::vector<std::vector<std::vector<ImageF>>> stage_data_; 76 77 // Buffers for out-of-frame data, indexed by [thread]; every row is a 78 // different channel. 79 std::vector<ImageF> out_of_frame_data_; 80 81 // For each stage, a non-kIgnored channel. 82 std::vector<int32_t> anyc_; 83 84 // Size of the image at each stage. 85 std::vector<Rect> image_rect_; 86 87 // For each stage, for each channel, keep track of the kInOut stage that 88 // produced the input to that stage (which corresponds to the buffer index 89 // containing the data). -1 if data comes from the original input. 90 std::vector<std::vector<int32_t>> stage_input_for_channel_; 91 92 // Number of (virtual) extra rows that must be processed at each stage 93 // to produce sufficient output for future stages. 94 std::vector<int> virtual_ypadding_for_output_; 95 96 // Same thing for columns, except these are real columns and not virtual ones. 97 std::vector<int> xpadding_for_output_; 98 99 // First stage that doesn't have any kInOut channel. 100 size_t first_trailing_stage_; 101 102 // Origin and size of the frame after switching to image dimensions. 103 FrameOrigin frame_origin_; 104 size_t full_image_xsize_; 105 size_t full_image_ysize_; 106 size_t first_image_dim_stage_; 107 }; 108 109 } // namespace jxl 110 111 #endif // LIB_JXL_RENDER_PIPELINE_LOW_MEMORY_RENDER_PIPELINE_H_