测试Gridea的网页编辑能力

🤠🤠🤠🤠

#include "denoise.h"
#include
#include <hls_video_mem.h> // 2025.2 中用于 LineBuffer(行缓存) 和 Window(平滑窗口) 的库

void hls_denoise_3_3(
pixel_stream& input,
pixel_stream& output,
int width,
int height
){
// 静态定义行缓存(存储 3 行)和 3x3 滑动窗口
// static hls::LineBuffer<int ROWS, int COLS, typename T>
// static hls::Window<int ROWS, int COLS, typename T>
static hls::LineBuffer<3, MAX_WIDTH, unsigned char> line_buf;
static hls::Window<3, 3, unsigned char> win;

// 嵌套循环处理图像
for(int r = 0; r < height; r++){
    for(int c = 0; c < width; c++){
        #pragma HLS PIPELINE II=1
        // 1. 从输入流读取当前像素
        unsigned char pixel_in = input.read();
        
        // 2. 更新行缓存:将列 c 的数据向上移动,腾出最底层放新像素
        // line_buf.shift_pixels_up(int col)
        // line_buf.insert_bottom_row(unsigned char value, int col)
        line_buf.shift_pixels_up(c);
        line_buf.insert_bottom_row(pixel_in, c);

        // 3. 更新滑动窗口:窗口向左移动,并从行缓存中取出一列新数据填入窗口最右侧
        // win.insert_pixel(unsigned char value, int row, int col)
        win.shift_pixels_left();
        win.insert_pixel(line_buf.getval(0, c), 0, 2);
        win.insert_pixel(line_buf.getval(1, c), 1, 2);
        win.insert_pixel(line_buf.getval(2, c), 2, 2);

        // 4. 计算 3x3 均值(降噪核心)
        // 当行和列都达到 2 以上时,窗口才填满了有效的 3x3 像素
        if (r >= 2 && c >= 2){
            int sum = 0;
            for(int i = 0; i < 3; i++){
                for(int j = 0; j < 3; j++){
                    #pragma HLS PIPELINE II=1       // 可以测试一下看一看这块有没有影响
                    sum += win.getval(i, j);
                }
            }
            output.write((unsigned char)(sum / 9));
        }else{
            output.write(0);            // 窗口未填满时的边界处理:输出 0
        }
    }
}

}