ISP/rtl/Common/color.svh

57 lines
1.2 KiB
Systemverilog
Raw Permalink Normal View History

2024-11-03 20:38:29 +08:00
`ifndef __COLOR_SVH__
`define __COLOR_SVH__
`define Typedef_Color(Name, DataDeepth) \
`define Name Color#(Name, DataDeepth) \
`ifdef DEBUG \
typedef struct { \
bit [DataDeepth - 1:0] red; \
bit [DataDeepth - 1:0] green; \
bit [DataDeepth - 1:0] blue; \
} \
`else \
typedef struct packed { \
bit [DataDeepth - 1:0] red; \
bit [DataDeepth - 1:0] green; \
bit [DataDeepth - 1:0] blue; \
} \
`endif
class Color #(
type T,
int DEEPTH = 8
);
static function automatic T f_fromRGB(bit [DEEPTH - 1 : 0] red, bit [DEEPTH - 1 : 0] green,
bit [DEEPTH - 1 : 0] blue);
`ifdef DEBUG
T _color;
_color.red = red;
_color.green = green;
_color.blue = blue;
return _color;
`else
return {red, green, blue};
`endif
endfunction
static function automatic T f_fromBits(bit [DEEPTH * 3 - 1 : 0] data);
`ifdef DEBUG
T _color;
_color.red = data[DEEPTH*3-1-:DEEPTH];
_color.green = data[DEEPTH*2-1-:DEEPTH];
_color.blue = data[DEEPTH*1-1-:DEEPTH];
return _color;
`else
return {data};
`endif
endfunction
static function automatic bit [DEEPTH * 3 - 1 : 0] f_toBits(T color);
return {color.red, color.green, color.blue};
endfunction
endclass
`endif