UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Reply

How to set hls::Scalar to be saturated in case of overflow

Highlighted
Adventurer
Posts: 78
Registered: ‎02-15-2016

How to set hls::Scalar to be saturated in case of overflow

Hello,

 

I am looking at a HLS example at https://github.com/Xilinx/HLx_Examples/blob/master/Vision/video_edge/image_filter.cpp.

I wondered how I can set saturation in case of overflow to hls::Scalar as the below addition example.

 

Regards,

 

typedef hls::Mat<MAX_PICH, MAX_PICW, HLS_8UC1> GRAY_IMG;

typedef hls::Scalar<1, unsigned char>  gray_pix;

 

GRAY_IMG a,b,c;

 

combine2<GRAY_IMG, gray_pix>(a,b,c, MAX_PICH. MAX_PICW);

 

void combine2(

IMG_T& img_in0,
IMG_T& img_in1,
IMG_T& img_out,
int rows,
int cols) {
 
PIXEL_T pin0, pin1;
PIXEL_T pout;
 
L_row: for(int row = 0; row < rows; row++) {
#pragma HLS LOOP_TRIPCOUNT min=1 max=1080
 
L_col: for(int col = 0; col < cols; col++) {
#pragma HLS LOOP_TRIPCOUNT min=1 max=1920
#pragma HLS pipeline rewind
 
img_in0 >> pin0;
img_in1 >> pin1;
 
pout = pin0 + pin1;
img_out << pout;
 
}
 
}
 
}
Scholar
Posts: 2,100
Registered: ‎04-26-2015

Re: How to set hls::Scalar to be saturated in case of overflow

I don't think you can do that directly. You just have to add them (storing the result in a variable 1 bit larger), check if the result is greater than the maximum (ie 255), and then copy either the result itself or the maximum value into the output.

 

Assuming PIXEL_T is just unsigned char:

 

unsigned short pout_tmp = pin0 + pin1;
if (pout_tmp > 255) {
    pout = 255;
} else {
    pout = pout_tmp;
}
Adventurer
Posts: 78
Registered: ‎02-15-2016

Re: How to set hls::Scalar to be saturated in case of overflow

Thank you for your comments.

 

but I got an error:

cannot convert 'hls::Scalar to short unsigned  int'

 

Regards,