diff --git a/hls/assignment/sobel/sobel.cpp b/hls/assignment/sobel/sobel.cpp index 6b1c2a8..00d9720 100644 --- a/hls/assignment/sobel/sobel.cpp +++ b/hls/assignment/sobel/sobel.cpp @@ -1,3 +1,4 @@ +#include #include #include "sobel.h" @@ -14,6 +15,10 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, {-1, 0, 1} }; + // Carica le prime tre righe nel buffer + uint8_t inBuffer[3*height]; + memcpy(inBuffer, in, 3*height*sizeof(uint8_t)); + esternoY: for (int y = 0; y < height - 2; y++) { @@ -30,7 +35,7 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, { #pragma HLS UNROLL - const int inYOffset = (y + k) * width; + const int inYOffset = ((y + k) % 3) * width; internoX: for (int z = 0; z < 3; z++) @@ -40,7 +45,7 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, const int inXOffset = x + z; const int inOffset = inYOffset + inXOffset; - const int inElement = in[inOffset]; + const int inElement = inBuffer[inOffset]; dx += sobelFilter[k][z] * inElement; dy += sobelFilter[z][k] * inElement; @@ -53,5 +58,7 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, out[outOffset] = sqrt((float)((dx * dx) + (dy * dy))); } + + memcpy(inBuffer, in + (y % 3) * height, height*sizeof(uint8_t)); } }