aboutsummaryrefslogtreecommitdiffstats
path: root/general_filter/generalFilter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'general_filter/generalFilter.cpp')
-rw-r--r--general_filter/generalFilter.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/general_filter/generalFilter.cpp b/general_filter/generalFilter.cpp
new file mode 100644
index 0000000..2ce18b7
--- /dev/null
+++ b/general_filter/generalFilter.cpp
@@ -0,0 +1,130 @@
+////////////////////////////////////////////////////////////////////////////////
+// _____ _ _ _____ _ _
+// |_ _| (_) | | / ____| | | |
+// | | _ __ ___ _ __ ___ _ __ _ __ _| | | | ___ | | | ___ __ _ ___
+// | | | '_ ` _ \| '_ \ / _ \ '__| |/ _` | | | | / _ \| | |/ _ \/ _` |/ _ \
+// _| |_| | | | | | |_) | __/ | | | (_| | | | |___| (_) | | | __/ (_| | __/
+// |_____|_| |_| |_| .__/ \___|_| |_|\__,_|_| \_____\___/|_|_|\___|\__, |\___|
+// | | __/ |
+// |_| |___/
+// _ _
+// | | | |
+// | | ___ _ __ __| | ___ _ __
+// | | / _ \| '_ \ / _` |/ _ \| '_ \
+// | |___| (_) | | | | (_| | (_) | | | |
+// |______\___/|_| |_|\__,_|\___/|_| |_|
+//
+////////////////////////////////////////////////////////////////////////////////
+// File: sobel.cpp
+// Description: video to vga sobel filter - real-time processing
+// By: rad09
+////////////////////////////////////////////////////////////////////////////////
+// this hardware block receives the VGA stream and then produces a blured output
+// based on the FIR design - page 230 of HLS Blue Book
+////////////////////////////////////////////////////////////////////////////////
+// Catapult Project options
+// Constraint Editor:
+// Frequency: 50 MHz
+// Top design: sobel
+// clk>reset sync: disable; reset async: enable; enable: enable
+// Architecture Constraints:
+// interface>vin: wordlength = 90, streaming = 90
+// interface>vout: wordlength = 30, streaming = 30
+// core>main: pipeline + distributed + merged
+// core>main>frame: merged
+// core>main>frame>shift, mac1, mac2: unroll + merged
+////////////////////////////////////////////////////////////////////////////////
+
+
+#include <ac_fixed.h>
+#include "sobel.h"
+#include <iostream>
+
+// shift_class: page 119 HLS Blue Book
+#include "shift_class.h"
+
+
+
+
+#pragma hls_design top
+void sobel(ac_int<PIXEL_WL*KERNEL_WIDTH,false> vin[NUM_PIXELS], ac_int<PIXEL_WL,false> vout[NUM_PIXELS])
+{
+ ac_int<16, false> red, green, blue, r[KERNEL_WIDTH], g[KERNEL_WIDTH], b[KERNEL_WIDTH];
+
+
+// #if 1: use filter
+// #if 0: copy input to output bypassing filter
+#if 1
+
+ // shifts pixels from KERNEL_WIDTH rows and keeps KERNEL_WIDTH columns (KERNEL_WIDTHxKERNEL_WIDTH pixels stored)
+ static shift_class<ac_int<PIXEL_WL*KERNEL_WIDTH,true>, KERNEL_WIDTH> regs;
+ int i;
+
+ FRAME: for(int p = 0; p < NUM_PIXELS; p++) {
+ // init
+ red = 0;
+ green = 0;
+ blue = 0;
+ RESET: for(i = 0; i < KERNEL_WIDTH; i++) {
+ r[i] = 0;
+ g[i] = 0;
+ b[i] = 0;
+ }
+
+ // shift input data in the filter fifo
+ regs << vin[p]; // advance the pointer address by the pixel number (testbench/simulation only)
+ // accumulate
+ ACC1:
+ for (i = 0; i < KERNEL_WIDTH; ++i)
+ {
+ r[0] += (regs[i].slc<COLOUR_WL>(2*COLOUR_WL))*XMATRIX[0][i]*YMATRIX[0][i];
+ g[0] += (regs[i].slc<COLOUR_WL>(COLOUR_WL))*XMATRIX[0][i]*YMATRIX[0][i];
+ b[0] += (regs[i].slc<COLOUR_WL>(0))*XMATRIX[0][i]*YMATRIX[0][i];
+
+ r[1] += (regs[i].slc<COLOUR_WL>(2*COLOUR_WL + PIXEL_WL))*XMATRIX[1][i]*YMATRIX[1][i];
+ g[1] += (regs[i].slc<COLOUR_WL>(COLOUR_WL + PIXEL_WL))*XMATRIX[1][i]*YMATRIX[1][i];
+ b[1] += (regs[i].slc<COLOUR_WL>(0 + PIXEL_WL))*XMATRIX[1][i]*YMATRIX[1][i];
+
+ r[2] += (regs[i].slc<COLOUR_WL>(2*COLOUR_WL + 2*PIXEL_WL))*XMATRIX[2][i]*XMATRIX[2][i];
+ g[2] += (regs[i].slc<COLOUR_WL>(COLOUR_WL + 2*PIXEL_WL))*XMATRIX[2][i]*XMATRIX[2][i];
+ b[2] += (regs[i].slc<COLOUR_WL>(0 + 2*PIXEL_WL))*XMATRIX[2][i]*XMATRIX[2][i];
+ }
+ // add the accumualted value for all processed lines
+ ACC2:
+ for(i = 0; i < KERNEL_WIDTH; i++)
+ {
+ red += r[i];
+ green += g[i];
+ blue += b[i];
+ }
+
+ // normalize result
+ red /= 2*KERNEL_NUMEL;
+ green /= 2*KERNEL_NUMEL;
+ blue /= 2*KERNEL_NUMEL;
+
+ // group the RGB components into a single signal
+ vout[p] = ((((ac_int<PIXEL_WL, false>)red) << (2*COLOUR_WL)) | (((ac_int<PIXEL_WL, false>)green) << COLOUR_WL) | (ac_int<PIXEL_WL, false>)blue);
+
+ }
+}
+
+
+
+
+#else
+// display input (test only)
+ FRAME: for(p = 0; p < NUM_PIXELS; p++) {
+ // copy the value of each colour component from the input stream
+ red = vin[p].slc<COLOUR_WL>(2*COLOUR_WL);
+ green = vin[p].slc<COLOUR_WL>(COLOUR_WL);
+ blue = vin[p].slc<COLOUR_WL>(0);
+
+ // combine the 3 color components into 1 signal only
+ vout[p] = ((((ac_int<PIXEL_WL, false>)red) << (2*COLOUR_WL)) | (((ac_int<PIXEL_WL, false>)green) << COLOUR_WL) | (ac_int<PIXEL_WL, false>)blue);
+ }
+}
+#endif
+
+
+// end of file \ No newline at end of file