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 <math.h> 7 #include <stdint.h> 8 #include <stdio.h> 9 10 #include <algorithm> 11 #include <utility> 12 #include <vector> 13 14 #include "lib/jxl/render_pipeline/render_pipeline_stage.h" 15 16 namespace jxl { 17 18 class UpsampleXSlowStage : public RenderPipelineStage { 19 public: UpsampleXSlowStage()20 UpsampleXSlowStage() 21 : RenderPipelineStage(RenderPipelineStage::Settings::ShiftX(1, 1)) {} 22 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)23 void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, 24 size_t xextra, size_t xsize, size_t xpos, size_t ypos, 25 float* JXL_RESTRICT temp) const final { 26 for (size_t c = 0; c < input_rows.size(); c++) { 27 const float* row = GetInputRow(input_rows, c, 0); 28 float* row_out = GetOutputRow(output_rows, c, 0); 29 for (int64_t x = -xextra; x < (int64_t)(xsize + xextra); x++) { 30 float xp = *(row + x - 1); 31 float xc = *(row + x); 32 float xn = *(row + x + 1); 33 float xout0 = xp * 0.25f + xc * 0.75f; 34 float xout1 = xc * 0.75f + xn * 0.25f; 35 *(row_out + 2 * x + 0) = xout0; 36 *(row_out + 2 * x + 1) = xout1; 37 } 38 } 39 } 40 GetChannelMode(size_t c)41 RenderPipelineChannelMode GetChannelMode(size_t c) const final { 42 return RenderPipelineChannelMode::kInOut; 43 } 44 }; 45 46 class UpsampleYSlowStage : public RenderPipelineStage { 47 public: UpsampleYSlowStage()48 UpsampleYSlowStage() 49 : RenderPipelineStage(RenderPipelineStage::Settings::ShiftY(1, 1)) {} 50 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)51 void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, 52 size_t xextra, size_t xsize, size_t xpos, size_t ypos, 53 float* JXL_RESTRICT temp) const final { 54 for (size_t c = 0; c < input_rows.size(); c++) { 55 const float* rowp = GetInputRow(input_rows, c, -1); 56 const float* rowc = GetInputRow(input_rows, c, 0); 57 const float* rown = GetInputRow(input_rows, c, 1); 58 float* row_out0 = GetOutputRow(output_rows, c, 0); 59 float* row_out1 = GetOutputRow(output_rows, c, 1); 60 for (int64_t x = -xextra; x < (int64_t)(xsize + xextra); x++) { 61 float xp = *(rowp + x); 62 float xc = *(rowc + x); 63 float xn = *(rown + x); 64 float yout0 = xp * 0.25f + xc * 0.75f; 65 float yout1 = xc * 0.75f + xn * 0.25f; 66 *(row_out0 + x) = yout0; 67 *(row_out1 + x) = yout1; 68 } 69 } 70 } 71 GetChannelMode(size_t c)72 RenderPipelineChannelMode GetChannelMode(size_t c) const final { 73 return RenderPipelineChannelMode::kInOut; 74 } 75 }; 76 77 class Check0FinalStage : public RenderPipelineStage { 78 public: Check0FinalStage()79 Check0FinalStage() : RenderPipelineStage(RenderPipelineStage::Settings()) {} 80 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)81 void ProcessRow(const RowInfo& input_rows, const RowInfo& output_rows, 82 size_t xextra, size_t xsize, size_t xpos, size_t ypos, 83 float* JXL_RESTRICT temp) const final { 84 for (size_t c = 0; c < input_rows.size(); c++) { 85 for (size_t x = 0; x < xsize; x++) { 86 JXL_CHECK(fabsf(GetInputRow(input_rows, c, 0)[x]) < 1e-8); 87 } 88 } 89 } 90 GetChannelMode(size_t c)91 RenderPipelineChannelMode GetChannelMode(size_t c) const final { 92 return RenderPipelineChannelMode::kInput; 93 } 94 }; 95 96 } // namespace jxl 97