mirror of
https://github.com/Steffo99/unimore-hpc-assignments.git
synced 2024-11-25 09:34:23 +00:00
Use a three-line circular buffer
Co-authored-by: Fabio Zanichelli <274956@studenti.unimore.it> Co-authored-by: Stefano Pigozzi <256895@studenti.unimore.it>
This commit is contained in:
parent
ae5f2d0c52
commit
f0cb1c1bed
1 changed files with 9 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
#include <cstring>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "sobel.h"
|
#include "sobel.h"
|
||||||
|
|
||||||
|
@ -14,6 +15,10 @@ void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width,
|
||||||
{-1, 0, 1}
|
{-1, 0, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Carica le prime tre righe nel buffer
|
||||||
|
uint8_t inBuffer[3*height];
|
||||||
|
memcpy(inBuffer, in, 3*height*sizeof(uint8_t));
|
||||||
|
|
||||||
esternoY:
|
esternoY:
|
||||||
for (int y = 0; y < height - 2; y++)
|
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
|
#pragma HLS UNROLL
|
||||||
|
|
||||||
const int inYOffset = (y + k) * width;
|
const int inYOffset = ((y + k) % 3) * width;
|
||||||
|
|
||||||
internoX:
|
internoX:
|
||||||
for (int z = 0; z < 3; z++)
|
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 inXOffset = x + z;
|
||||||
|
|
||||||
const int inOffset = inYOffset + inXOffset;
|
const int inOffset = inYOffset + inXOffset;
|
||||||
const int inElement = in[inOffset];
|
const int inElement = inBuffer[inOffset];
|
||||||
|
|
||||||
dx += sobelFilter[k][z] * inElement;
|
dx += sobelFilter[k][z] * inElement;
|
||||||
dy += sobelFilter[z][k] * 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)));
|
out[outOffset] = sqrt((float)((dx * dx) + (dy * dy)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(inBuffer, in + (y % 3) * height, height*sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue