Paint Brush Application
   Ranjani Chandrasekar / Manu Jain

| Introduction | High Level Design | Hardware | Software | Interface | Results | Conclusion | Appendix | Downloads |
Software

Software Description

The software is developed in the Nios II software development environment called the Nios II integrated development environment (IDE). The Nios II IDE is based on the GNU C/C++ compiler and the Eclipse IDE, and provides a familiar and established environment for software development. It is the primary graphical software development tool for the Nios II family of embedded processors. The Nios II IDE provides a consistent development platform that works for all Nios II processor systems. All the software development tasks can be accomplished within the Nios II IDE, including editing, building, debugging, and profiling programs. The IDE allows creating single-threaded programs as well as complex applications based on a real-time operating system (RTOS) and middleware libraries available from Altera and third-party vendors. By using the Nios II IDE, one can immediately begin developing and simulating Nios II software applications. The Nios II software build tools also provide a command line interface.

The NIOS II software in the Paint Brush Application is used to interface the ISP1362 USB drive for the mouse. It also interacts with the VGA adapter implemented in the hardware. The movement of the mouse cursor is sent to the VGA adapter. The software development module sends the pixel co-ordinates and the value of the color to be displayed at a particular pixel on the VGA screen. The software module runs the various algorithms for drawing the various shapes and sends these values one-by-one to the hardware module which in turn sends those values to the SRAM. The VGA controller reads from the SRAM and displays on the VGA screen. The functionality of each icon on the Tool Bar when clicked is displayed on the LCD available on the DE2 board. The Liquid Crystal display is interfaced using the LCD component of the SOPC builder. The LCD is given the initial control signals for clearing the LCD and writting to the first line. The functionality of a selected tool is then sent to it.

Logical flow of the software module

The user first chooses the function that he/she wants to implement on the drawing area and then choose the color in which that figure should be implemented. The default value for the function is "Pencil" which just draws a point on the drawing area wherever a left button of the mouse is pressed and the default value of color is "0x0000" i.e. black. When the user has made the choice of the figure and the color, he/she has to choose two pixel positions on the drawing area by making left mouse clicks on those points which would define the boundary of the figure to be drawn. Thus, the user has to specify the start point and the end point of any figure that he/she wants to be displayed on the drawing area on the VGA screen. The color choice is displayed on a small area at the bottom of the screen which displays the current color value at all times. The user can continue to choose various functions from the toolbar and keep implementing those on the drawing area as explained above. If he/she intends to clear the screen and start with a fresh screen, then the clear area button "C" should be pressed which cleans the drawing area.

Color Palette

The default color is black (value of color is 0x0000). The color that is chosen at any point is displayed on a small area at the bottom of the screen adjacent to the color palette. The user can continue to choose various functions from the toolbar and keep implementing those on the drawing area as explained above. The drawing area can be cleared using the Clear Screen option on the toolbar.

Implementation details of the functions

The prime task is to read a pixel from the VGA and write a pixel value to the VGA. Based on this any shape or color can be implemented. The functions PutPixel() and GetPixel are written for this functionality.

PutPixel:

This method takes the color value and the x and y coordinates of the pixel location where that particular color value is to be displayed on the VGA screen and checks whether these coordinates lie within the drawing area of the screen. If the coordinates do lie inside the drawing area of the application, then these values are passed on to the hardware module and eventually to the VGA controller for displaying on the screen.

GetPixel:

This method reads the color value from the VGA screen by passing the x and y coordinates of the pixel location from where that particular color value is to be read. It gives a delay after reading the value from the VGA and before passing it to the calling function, so as to avoid any timing issues.

The line drawer and circle drawer are implemented in the software, based on the algorithms described in the High Level Design page.

Most of the toolbar functions of the paint brush application can be implemented by calling these functions by passing the appropriate arguments to achieve the desired operation. The implementation of the various toolbar functions of the paint brush application in the Nios2 software module are described below:

1) Pencil

This function sends the pixel co-ordinates and the color value which is selected by the user to the hardware. In the hardware, these values are stored in the SRAM and are then accessed by the VGA controller for displaying on the VGA monitor.

2) Line

For drawing a straight line on the screen, the user has to click on two positions the starting point and the ending point of the line to be drawn. These points are then sent to the line drawer module that implements the Bresenham algorithm and computes the intermediate pixel coordinates to be illuminated for drawing a line joining the two specified points.

3) Rectangle

When the user clicks on the rectangle button on the toolbar, then two further options are displayed in the empty area below the buttons the normal rectangle and the filled rectangle. The default choice is the normal rectangle. The user has to click on two points on the drawing area after which the module for implementing the square is called. The 2 points selected are taken as the end points of the diagonal of the rectangle. The rectangle is then implemented by drawing four lines using the Bresenham sending the coordinates of the corners of this rectangle in adjoining pairs.

4) Circle

When the user clicks on the circle button on the toolbar, then two further options are displayed in the empty area below the buttons the normal circle and the filled circle. The default choice is the normal circle. For drawing a circle on the drawing area, the user has to specify two point positions the starting point and the ending point which determines the length of the diameter of the circle in the horizontal direction. These points are then sent to the circle drawer module that implements the Bresenham algorithm for circle drawing in the software and computes the intermediate pixel coordinates to be illuminated for drawing a circle based on the points specifying the diameter of the circle.

5) Polygon

For drawing the polygon, the user can click on various points on the drawing area and the consecutive points are joined by straight lines. The Polygon is closed by marking the last position by clicking on the starting point. Any desired polygon can be implemented on the drawing area by the clicks the user makes.

6) Eraser

When the user clicks on the eraser button on the toolbar, then three options of varying sizes of the eraser are displayed. The default choice is the eraser of the smallest size. The shape of the cursor is also changed to represent the area that would be cleared when that particular eraser type is used on the drawing screen. The eraser clears that particular area in which it is called to the initial background color.

7) Spray

This function randomly illuminates some of the pixels around the area clicked by the user with the chosen color value. If the spray function is pressed on any particular location over and over, eventually all the pixels around that point will be illuminated with the chosen color value. This function is implemented by having a fixed area of pixels and then specifying for each of the pixels in that area whether that pixel should be illuminated or not based on a random value generator which generates only zero and one. If the generated value is zero, then that particular pixel is illuminated by the chosen color otherwise the background color is kept only.

8) Fill Color

This function is implemented by using the "Edge Fill" algorithm as defined in detail in the High Level Design. The algorithm is optimized by using the concept of fencing according to which the user defines a fence in which the figure to be filled with the desired color is bounded. The algorithm runs only for this boundary fenced and not for the complete drawing area. This saves the time and resources used for scanning the area. The module for implementing the fill color logic reads the color value at every pixel within the scope of the fence and compares its value with its adjacent pixel in the positive x direction. If the two color values are different, then that point is the starting point of the polygon boundary. This comparison of color values is continued till the end of the fence before which the other boundary of the polygon would be determined as the entire polygon is included in the fence as defined in the initial condition of the algorithm. Then, it runs a loop for changing the color value to the desired color between the two boundary values obtained above.

9) Pick Color

The user can pick any color on the drawing area using this tool. Once the color is picked, it can then be used to draw any shape using that color. This function is implemented reading the value of color stored at that location on the VGA screen and update the value for color and displays the same in the "selected color" area near the color pallet on the bottom of the screen.

10) Clear Area

This button clears the entire drawing area by sending the value of "0xFFFF" i.e. white color for all the pixels inside the drawing area of the application.