if (Sign == CHAR || Sign == SHORT) adder = pow(2, Bits)/2 ; else adder = 0 ; for(i = 0; i < width ; i++) { /* Convert char data to u8 */ if (i == 0) { if(Sign == UNSIGNEDCHAR || Sign == CHAR) { last_data = (u8)(CharBufferPtr[i] + adder)*data_coe ; curr_data = (u8)(CharBufferPtr[i] + adder)*data_coe ; } else { last_data = (u8)((u16)(ShortBufferPtr[i] + adder)*data_coe) ; curr_data = (u8)((u16)(ShortBufferPtr[i] + adder)*data_coe) ; } } else { if(Sign == UNSIGNEDCHAR || Sign == CHAR) { last_data = (u8)(CharBufferPtr[i-1] + adder)*data_coe ; curr_data = (u8)(CharBufferPtr[i] + adder)*data_coe ; } else { last_data = (u8)((u16)(ShortBufferPtr[i-1] + adder)*data_coe) ; curr_data = (u8)((u16)(ShortBufferPtr[i] + adder)*data_coe) ; } } /* Compare last data value and current data value, draw point between two point */ if (curr_data >= last_data) { for (j = 0 ; j < (curr_data - last_data + 1) ; j++) draw_point(CanvasBufferPtr, i, (height - 1 - curr_data) + j, width, wBlue, wGreen, wRed) ; } else { for (j = 0 ; j < (last_data - curr_data + 1) ; j++) draw_point(CanvasBufferPtr, i, (height - 1 - last_data) + j, width, wBlue, wGreen, wRed) ; } } }
时间: 2024-04-26 14:23:11 浏览: 95
2-bit-full-adder-master.zip_full_full adder
这段代码是一个绘图函数,用于将输入的数据绘制成折线图。函数通过对输入的CharBufferPtr或ShortBufferPtr数组进行处理,将其转化为u8类型的数据,并按照一定的规则绘制到CanvasBufferPtr指向的缓冲区上,从而得到折线图。
函数首先判断输入的数据类型Sign是CHAR还是SHORT,如果是CHAR或SHORT,则在后面的计算中需要对数据进行一定的加减操作。接着,函数对每个数据点进行处理,先将其转化为u8类型的数据,然后与前一个数据点的值进行比较。如果当前数据点的值大于等于前一个数据点的值,则从前一个数据点到当前数据点之间的每个y值上绘制一个点;否则从当前数据点到前一个数据点之间的每个y值上绘制一个点。绘制点的函数是draw_point,其中CanvasBufferPtr是绘图缓冲区指针,i是当前数据点的横坐标,wBlue、wGreen、wRed分别是RGB颜色值,height和width分别是绘图区域的高度和宽度。
阅读全文