2 A driver and monitor to abstract the interface to the JPEG encoder 9 from cocotb.triggers
import RisingEdge, ReadOnly
10 from cocotb.drivers
import Driver
11 from cocotb.monitors
import Monitor
13 _jpeg_header = open(
"header.bin",
"r").read() 15 class JpegMonitor(Monitor):
19 Monitor.__init__(self, **kwargs)
23 """Creates an Image object from the output of the DUT""" 26 clkedge = RisingEdge(self.dut.clk)
31 if self.dut.data_ready.value:
32 data += self.dut.JPEG_bitstream.value.buff
33 if self.dut.eof_data_partial_ready.value:
34 f_obj = io.BytesIO(_jpeg_header + data +
"\xff\xd9")
35 img = Image.open(f_obj)
36 self.log.info(
"Recovered image %s of %dx%d in mode %s" % (
37 img.format, img.size[0], img.size[1], img.mode))
43 class ImageDriver(Driver):
52 Send an image into the DUT. Image should be in RGB format and a 53 multiple of 8 pixels in both width and height 57 image (PIL.Image) image to send into the dut 59 if image.mode !=
"RGB":
60 raise TypeError(
"Require an format RGB image")
62 width, height = image.size
64 clk_edge = RisingEdge(dut.clk)
70 dut.end_of_file_signal <= 0
74 for y
in xrange(0,height,8):
75 for x
in xrange(0,width,8):
78 self.log.debug(
"Sending block X% 4d/% 4d, Y% 4d/% 4d" % (
81 if y >= height-8
and x >= width-8:
82 dut.end_of_file_signal <= 1
84 for y_block
in xrange(8):
85 for x_block
in xrange(8):
88 x_ofs = min(x+x_block, width-1)
89 y_ofs = min(y+y_block, height-1)
91 r,g,b = pixels[x_ofs, y_ofs]
92 dut.data_in <= (b<<16 | g<<8 | r)
94 dut.end_of_file_signal <= 0
def __init__( self, dut, kwargs)
def _driver_send( self, image, kwargs)