XilinxProcessorIPLib/drivers/tft/examples/xtft_example.c
static int TftDrawLine(XTft *InstancePtr, u32 ColStartPos, u32 RowStartPos,
			u32 ColEndPos, u32 RowEndPos, u32 PixelVal)
{
	u32 Slope;
	u32 YIntercept;
	u32 Xmin;
	u32 Ymin;
	u32 Xmax;
	u32 Ymax;
	u32 Index1;
	u32 Index2;
	u32 Mx;

	/*
	 * Check whether the given position of X,Y dimensions
	 * are below the limits of the screen.
	 */
	if (ColStartPos >= 0 && ColStartPos <= (XTFT_DISPLAY_WIDTH - 1) &&
		ColEndPos >= 0 && ColEndPos <= (XTFT_DISPLAY_WIDTH - 1) &&
		RowStartPos >= 0 && RowStartPos <= (XTFT_DISPLAY_HEIGHT - 1) &&
		RowEndPos >= 0 && RowEndPos <= (XTFT_DISPLAY_HEIGHT - 1)) {

		/*
		 * Check the exception case where slope can be infinite
		 * that is vertical line.
		 */
		if (ColEndPos-ColStartPos != 0) {
			/*
			 * Calculate slope.
			 */
			Slope = ((RowEndPos - RowStartPos) /
				(ColEndPos - ColStartPos) * 100000);

			/*
			 * Calculate y intercept.
			 */
			YIntercept = RowStartPos -
					((Slope / 100000) * ColStartPos);
		} else {
			/*
			 * Divide by zero.
			 */
			Slope = 0;
			YIntercept = (-1);
		}

		/*
		 * Update the min and max position by conditional checking.
		 */
		if (ColEndPos < ColStartPos) {
			Xmin = ColEndPos;
			Xmax = ColStartPos;
		} else {
			Xmin = ColStartPos;
			Xmax = ColEndPos;
		}
		if (RowEndPos < RowStartPos) {
			Ymin = RowEndPos;
			Ymax = RowStartPos;
		} else {
			Ymin = RowStartPos;
			Ymax = RowEndPos;
		}

		/*
		 * Increment X and Y position values and calculate
		 * slope at the corresponding x position. Check the condition
		 * for general line equation and set the pixel. Otherwise check
		 * for the case of vertical line.
		 */
		for (Index1 = Xmin; Index1 <= Xmax; Index1++) {
			Mx = (Slope * Index1) / 100000;
			for (Index2 = Ymin; Index2 <= Ymax; Index2++) {
				if ((Index2 - Mx) == YIntercept) {

					/*
					 * Calculate visible line.
					 */
					XTft_SetPixel(InstancePtr, Index1,
						 Index2, PixelVal);
				}
				else {
					/*
					 * Divide by zero.
					 */
					if((Slope == 0) &&
							(YIntercept == -1)) {

						/*
						 * Vertical line.
						 */
						XTft_SetPixel(InstancePtr,
							Index1, Index2,
							PixelVal);
					}
				}
			}
		}
		return XST_SUCCESS;
	} else {
		return XST_FAILURE;
	}

}
/*****************************************************************************/
/**
* Draws a line between two points with a specified color.
*
* @param	InstancePtr is a pointer to the XTft instance.
* @param	ColStartPos is the Start point of Column.
*		The valid value is 0 to (XTFT_DISPLAY_WIDTH - 1).
* @param	RowStartPos is the Start point of Row.
*		The valid value is 0 to (XTFT_DISPLAY_HEIGHT - 1).
* @param	ColEndPos is the End point of Column.
*		The valid value is 0 to (XTFT_DISPLAY_WIDTH - 1).
* @param	RowEndPos is the End point of Row.
*		The valid value is 0 to (XTFT_DISPLAY_HEIGHT - 1).
* @param	PixelVal is the Color Value to be put at pixel.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_FAILURE if unsuccessful.
*
* @note		None.
*
******************************************************************************/
Draws a line between two points with a specified color.
Draws a line between two points with a specified color .
static int TftDrawLine(XTft *InstancePtr, u32 ColStartPos, u32 RowStartPos,
			u32 ColEndPos, u32 RowEndPos, u32 PixelVal)
{
	u32 Slope;
	u32 YIntercept;
	u32 Xmin;
	u32 Ymin;
	u32 Xmax;
	u32 Ymax;
	u32 Index1;
	u32 Index2;
	u32 Mx;
	if (ColStartPos >= 0 && ColStartPos <= (XTFT_DISPLAY_WIDTH - 1) &&
		ColEndPos >= 0 && ColEndPos <= (XTFT_DISPLAY_WIDTH - 1) &&
		RowStartPos >= 0 && RowStartPos <= (XTFT_DISPLAY_HEIGHT - 1) &&
		RowEndPos >= 0 && RowEndPos <= (XTFT_DISPLAY_HEIGHT - 1)) {
		if (ColEndPos-ColStartPos != 0) {
			Slope = ((RowEndPos - RowStartPos) /
				(ColEndPos - ColStartPos) * 100000);
			YIntercept = RowStartPos -
					((Slope / 100000) * ColStartPos);
		} else {
			Slope = 0;
			YIntercept = (-1);
		}
		if (ColEndPos < ColStartPos) {
			Xmin = ColEndPos;
			Xmax = ColStartPos;
		} else {
			Xmin = ColStartPos;
			Xmax = ColEndPos;
		}
		if (RowEndPos < RowStartPos) {
			Ymin = RowEndPos;
			Ymax = RowStartPos;
		} else {
			Ymin = RowStartPos;
			Ymax = RowEndPos;
		}
		for (Index1 = Xmin; Index1 <= Xmax; Index1++) {
			Mx = (Slope * Index1) / 100000;
			for (Index2 = Ymin; Index2 <= Ymax; Index2++) {
				if ((Index2 - Mx) == YIntercept) {
					XTft_SetPixel(InstancePtr, Index1,
						 Index2, PixelVal);
				}
				else {
					if((Slope == 0) &&
							(YIntercept == -1)) {
						XTft_SetPixel(InstancePtr,
							Index1, Index2,
							PixelVal);
					}
				}
			}
		}
		return XST_SUCCESS;
	} else {
		return XST_FAILURE;
	}
}
static int TftDrawLine ( XTft * InstancePtr , u32 ColStartPos , u32 RowStartPos , u32 ColEndPos , u32 RowEndPos , u32 PixelVal ) { u32 Slope ; u32 YIntercept ; u32 Xmin ; u32 Ymin ; u32 Xmax ; u32 Ymax ; u32 Index1 ; u32 Index2 ; u32 Mx ; if ( ColStartPos >= 0 && ColStartPos <= ( XTFT_DISPLAY_WIDTH - 1 ) && ColEndPos >= 0 && ColEndPos <= ( XTFT_DISPLAY_WIDTH - 1 ) && RowStartPos >= 0 && RowStartPos <= ( XTFT_DISPLAY_HEIGHT - 1 ) && RowEndPos >= 0 && RowEndPos <= ( XTFT_DISPLAY_HEIGHT - 1 ) ) { if ( ColEndPos - ColStartPos != 0 ) { Slope = ( ( RowEndPos - RowStartPos ) / ( ColEndPos - ColStartPos ) * 100000 ) ; YIntercept = RowStartPos - ( ( Slope / 100000 ) * ColStartPos ) ; } else { Slope = 0 ; YIntercept = ( -1 ) ; } if ( ColEndPos < ColStartPos ) { Xmin = ColEndPos ; Xmax = ColStartPos ; } else { Xmin = ColStartPos ; Xmax = ColEndPos ; } if ( RowEndPos < RowStartPos ) { Ymin = RowEndPos ; Ymax = RowStartPos ; } else { Ymin = RowStartPos ; Ymax = RowEndPos ; } for ( Index1 = Xmin ; Index1 <= Xmax ; Index1 ++ ) { Mx = ( Slope * Index1 ) / 100000 ; for ( Index2 = Ymin ; Index2 <= Ymax ; Index2 ++ ) { if ( ( Index2 - Mx ) == YIntercept ) { XTft_SetPixel ( InstancePtr , Index1 , Index2 , PixelVal ) ; } else { if ( ( Slope == 0 ) && ( YIntercept == -1 ) ) { XTft_SetPixel ( InstancePtr , Index1 , Index2 , PixelVal ) ; } } } } return XST_SUCCESS ; } else { return XST_FAILURE ; } }
Draws a line between two points with a specified color.
Draws a line between two points with a specified color .
/*
	 * Check whether the given position of X,Y dimensions
	 * are below the limits of the screen.
	 */ /*
		 * Check the exception case where slope can be infinite
		 * that is vertical line.
		 */ /*
			 * Calculate slope.
			 */ /*
			 * Calculate y intercept.
			 */ /*
			 * Divide by zero.
			 */ /*
		 * Update the min and max position by conditional checking.
		 */ /*
		 * Increment X and Y position values and calculate
		 * slope at the corresponding x position. Check the condition
		 * for general line equation and set the pixel. Otherwise check
		 * for the case of vertical line.
		 */ /*
					 * Calculate visible line.
					 */ /*
					 * Divide by zero.
					 */ /*
						 * Vertical line.
						 */