| 1 | #include <stdio.h> |
| 2 | #include <stdint.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #define RS_SUBPEL_BITS 6 |
| 6 | #define RS_SCALE_SUBPEL_BITS 14 |
| 7 | #define RS_SCALE_SUBPEL_MASK ((1 << RS_SCALE_SUBPEL_BITS) - 1) |
| 8 | #define RS_SCALE_EXTRA_BITS (RS_SCALE_SUBPEL_BITS - RS_SUBPEL_BITS) |
| 9 | #define RS_SCALE_EXTRA_OFF (1 << (RS_SCALE_EXTRA_BITS - 1)) |
| 10 | #define UPSCALE_NORMATIVE_TAPS 8 |
| 11 | |
| 12 | extern const int16_t av1_resize_filter_normative[1 << RS_SUBPEL_BITS][UPSCALE_NORMATIVE_TAPS]; |
| 13 | extern int32_t av1_get_upscale_convolve_step(int in_length, int out_length); |
| 14 | extern void av1_convolve_horiz_rs_c(const uint8_t *src, int src_stride, |
| 15 | uint8_t *dst, int dst_stride, int w, |
| 16 | int h, const int16_t *x_filters, |
| 17 | int x0_qn, int x_step_qn); |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | static int32_t get_upscale_convolve_x0(int in_length, int out_length, |
| 25 | int32_t x_step_qn) { |
| 26 | const int err = out_length * x_step_qn - (in_length << RS_SCALE_SUBPEL_BITS); |
| 27 | const int32_t x0 = |
| 28 | (-((out_length - in_length) << (RS_SCALE_SUBPEL_BITS - 1)) + |
| 29 | out_length / 2) / |
| 30 | out_length + |
| 31 | RS_SCALE_EXTRA_OFF - err / 2; |
| 32 | return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK); |
| 33 | } |
| 34 | |
| 35 | static void run_case_margin(const char *label, int in_len, int out_len, |
| 36 | const uint8_t *input, const uint8_t *margin, |
| 37 | int margin_len) { |
| 38 | uint8_t padded[512]; |
| 39 | const int pad = 32; |
| 40 | uint8_t *row = padded + pad; |
| 41 | memset(padded, input[0], pad); |
| 42 | memcpy(row, input, in_len); |
| 43 | memcpy(row + in_len, margin, margin_len); |
| 44 | memset(row + in_len + margin_len, margin[margin_len - 1], pad); |
| 45 | |
| 46 | int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); |
| 47 | int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); |
| 48 | printf("%s: x_step_qn=%d x0_qn=%d\n", label, x_step_qn, x0_qn); |
| 49 | uint8_t out[256]; |
| 50 | av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, |
| 51 | &av1_resize_filter_normative[0][0], x0_qn, |
| 52 | x_step_qn); |
| 53 | printf("%s out:", label); |
| 54 | for (int i = 0; i < out_len; i++) printf(" %d", out[i]); |
| 55 | printf("\n"); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | static void run_case(const char *label, int in_len, int out_len, |
| 66 | const uint8_t *input, int right_pad_val) { |
| 67 | uint8_t padded[512]; |
| 68 | const int pad = 32; |
| 69 | uint8_t *row = padded + pad; |
| 70 | memset(padded, input[0], pad); |
| 71 | memcpy(row, input, in_len); |
| 72 | memset(row + in_len, right_pad_val, pad); |
| 73 | |
| 74 | int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); |
| 75 | int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); |
| 76 | printf("%s: in_len=%d out_len=%d x_step_qn=%d x0_qn=%d right_pad=%d\n", |
| 77 | label, in_len, out_len, x_step_qn, x0_qn, right_pad_val); |
| 78 | |
| 79 | uint8_t out[256]; |
| 80 | av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, |
| 81 | &av1_resize_filter_normative[0][0], x0_qn, |
| 82 | x_step_qn); |
| 83 | printf("%s out:", label); |
| 84 | for (int i = 0; i < out_len; i++) printf(" %d", out[i]); |
| 85 | printf("\n"); |
| 86 | } |
| 87 | |
| 88 | int main(void) { |
| 89 | uint8_t input8[8] = { 10, 20, 30, 40, 50, 60, 70, 80 }; |
| 90 | run_case("in8->out12", 8, 12, input8, input8[7]); |
| 91 | run_case("in8->out16", 8, 16, input8, input8[7]); |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | uint8_t row6[43] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, |
| 101 | 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, |
| 102 | 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, |
| 103 | 130, 130, 131, 131, 133, 134, 136, 137, 138, 139, |
| 104 | 140, 140, 141 }; |
| 105 | run_case("row6-replicate", 43, 64, row6, row6[42]); |
| 106 | run_case("row6-farpad", 43, 64, row6, 255); |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | uint8_t row6_real48[48] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, |
| 114 | 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, |
| 115 | 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, |
| 116 | 130, 130, 131, 131, 133, 134, 136, 137, 138, 139, |
| 117 | 140, 140, 141, 140, 140, 140, 140, 140 }; |
| 118 | run_case("row6-realpad48", 48, 64, row6_real48, row6_real48[47]); |
| 119 | |
| 120 | |
| 121 | |
| 122 | run_case("row6-realedgeval", 43, 64, row6, 140); |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | uint8_t row17[43] = { 109, 109, 109, 110, 111, 112, 112, 113, 114, 115, |
| 129 | 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, |
| 130 | 126, 127, 128, 129, 130, 131, 131, 132, 133, 134, |
| 131 | 135, 136, 137, 139, 139, 140, 140, 141, 142, 142, |
| 132 | 143, 144, 145 }; |
| 133 | uint8_t margin17[5] = { 146, 146, 147, 147, 147 }; |
| 134 | run_case_margin("row17-margin", 43, 64, row17, margin17, 5); |
| 135 | |
| 136 | uint8_t row18[43] = { 109, 110, 110, 110, 111, 112, 113, 114, 115, 116, |
| 137 | 117, 118, 119, 120, 121, 122, 122, 123, 124, 125, |
| 138 | 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, |
| 139 | 134, 136, 138, 140, 139, 140, 140, 141, 142, 142, |
| 140 | 143, 144, 145 }; |
| 141 | uint8_t margin18[5] = { 146, 147, 147, 148, 148 }; |
| 142 | run_case_margin("row18-margin", 43, 64, row18, margin18, 5); |
| 143 | return 0; |
| 144 | } |