For some labs you may need to display an image from a file such as a jpeg, png, etc. onto the VGA monitor. This tutorial describes the process and provides two scripts to process an RGB color image from a file into a verilog case statement suitable for use in a ROM which stores the image's bitmap.
This script requires opencv-python module (cv2 module). To install cv2 on Linux/OSX, type 'pip install opencv-python' in terminal.
For Windows, please consult this helpful installation procedure for Anaconda, written by Ning Miao.
Download the python script img2v.py
Choose OUT_MODE to select an output format:
For M9K ROMs:
OUT_MODE = True
→
output: mem[0] = 12'brrrr_gggg_bbbb;
For case statement ROM tables:
OUT_MODE = False
→
output: 8'b0000_0000: begin mem = 12'brrrr_gggg_bbbb; end
To view the image in python, uncomment the four indicated lines in the script and press q to exit the imshow window
python img2v.py OUT_MODE SIZE_X SIZE_Y IMAGE_FILENAME > OUT_FILENAME.v OUT_MODE=0 For use in a case statement OUT_MODE=1 For use in an initial block SIZE_X, SIZE_Y Image will be scaled to this size in pixels Example: python img2v.py 0 16 16 mario.jpg > rom.vAcceptable image format types include jpeg, png, tiff. pbm, pgm, and ppm. The code determines the type of an image by the content, not by the file extension. The formats bmp, dib, jpeg2000, jpeg2000, are likely to work; these notes explain details.
Some values such as the image file name must be changed in the script. In addition, the verilog output very likely requires some work to be useful.
smile.16x16.png 16 x 16 pixels
smile.32x32.png 32 x 32 pixels
smile.64x64.png 64 x 64 pixels
2019/06/01 Written 2019/06/04 Added details and reference for acceptable image file types. Written by Bevan Baas and Arthur Hlaing