domingo, 5 de maio de 2019

PIC32 Graphics Primitive Layer - Funções Básicas


 PIC32 e GOL - Graphics Primitive Layer - Funções Básicas para desenhar em um Display Gráfico colorido TFT

 Aprenda a utilizar elementos gráficos em display colorido (QVGA - 240x320 - TFT), como texto, linha, retângulo, círculo, gradiente e imagem. 

Exemplos de aplicação das Funções Básicas da Biblioteca Gráfica da Microchip no MPLAB C32.



Graphic Primitive Layer

Esta é a configuração que utilizei para este projeto:

Hardware:
PIC32 Ethernet Starter Kit
    PIC32MX795F512L
    MIPS32 M4K Core @80 MHz 32-bit
    512 kB de Flash
   128 kB de RAM

Multimedia Expansion Board
     Solomon Systech Graphics Controller (SSD1926)
     Truly LCD ModuleTFT-G240320LTSW-118W-E
     3.2 inch (8.1 cm) QVGA TFT Touchscreen, 240x320, 65000 cores.

Software:
MPLAB IDE v8.83
MPLAB C32 Compiler v2.02
Graphics Library 3.06.04, MLA v2013-06-15



Funções e Macros da Graphics Primitive Layer:

Text Functions
    FONT_HEADER Structure
    FONT_FLASH Structure
    FONT_EXTERNAL Type
    SetFont Function
    GetFontOrientation Macro
    SetFontOrientation Macro
    OutChar Function
    OutText Function
    OutTextXY Function
    GetTextHeight Function
    GetTextWidth Function
    XCHAR Macro
Gradient
    BarGradient Function
    BevelGradient Function
    GFX_GRADIENT_TYPE Enumeration
    GFX_GRADIENT_STYLE Structure
Line Functions
    Line Function
    LineRel Macro
    LineTo Macro
    Thickness Macro
    SetLineType Macro
    Line Types
        SOLID_LINE Macro
        DASHED_LINE Macro
        DOTTED_LINE Macro
    Line Size
        NORMAL_LINE Macro
        THICK_LINE Macro
Rectangle Functions
    Bar Function
    Rectangle Macro
    DrawPoly Function
Circle Functions
    Circle Macro
    FillCircle Macro
    Arc Function
    Bevel Function
    FillBevel Function
    SetBevelDrawType Macro
Graphic Cursor
    GetX Macro
    GetY Macro
    MoveRel Macro
    MoveTo Macro
Bitmap Functions
    PutImage Function
    GetImageHeight Function
    GetImageWidth Function
    BITMAP_HEADER Structure
    Bitmap Settings
        IMAGE_NORMAL Macro
        IMAGE_X2 Macro
    Bitmap Source 


Aprenda a seguir como iniciar o seu programa para utilizar as funçoes da Graphics Primitive Layer da Microchip.

Parte do código foi retirado do programa de exemplo da Microchip: 
Microchip Graphics Library Application. 
MainDemo.c
MLA - Microchip_Solutions_v2013-06-15.
Graphics Primitives Layer Demo.


1 - Primeiramente vamos incluir no nosso projeto os arquivos .H das bibliotecas:


////////////////////////////// INCLUDES //////////////////////////////
    #include "Compiler.h"
    #include "GenericTypeDefs.h"
    #include "HardwareProfile.h"
    #include "Graphics/Graphics.h"
    #include "TimeDelay.h"
    #include "cpld.h"


2 - Depois adicionamos as declarações:


/////////////////////////////////////////////////////////////////////////////
//                            LOCAL PROTOTYPES
/////////////////////////////////////////////////////////////////////////////
void         InitializeBoard(void);          

/////////////////////////////////////////////////////////////////////////////
//                            FONTS
/////////////////////////////////////////////////////////////////////////////
extern const FONT_FLASH     Font25;
extern const FONT_FLASH     Font35;
extern const FONT_FLASH     Font35_Antialiased;
extern const XCHAR          AntialisedText[];

/////////////////////////////////////////////////////////////////////////////
//                            PICTURES
/////////////////////////////////////////////////////////////////////////////

extern const IMAGE_FLASH 	Sep_1BPP;
extern const IMAGE_FLASH        Sun8bit;
extern const IMAGE_FLASH        Gaming4bit;
extern const GFX_IMAGE_HEADER   Gaming4bit_RLE;
extern const GFX_IMAGE_HEADER   Sun8bit_RLE;
extern const GFX_IMAGE_HEADER 	raio_8bpp;
extern const GFX_IMAGE_HEADER 	SPFC_4BPP;
extern const GFX_IMAGE_HEADER 	bateria;

/////////////////////////////////////////////////////////////////////////////
//                            MACROS
/////////////////////////////////////////////////////////////////////////////
#define WAIT_UNTIL_FINISH(x)    while(!x)
#define MIN(x,y)                ((x > y)? y: x)
#define DEMODELAY		1000


3 - Aqui iniciamos nosso programa pela função MAIN:


/////////////////////////////////////////////////////////////////////////////
//                            MAIN
/////////////////////////////////////////////////////////////////////////////
int main(void)
{
    SHORT       width, height, temp, x1, y1, x2, y2;
    SHORT       counter;
    const SHORT polyPoints[] = {
        (GetMaxX()+1)/2,    (GetMaxY()+1)/4,
        (GetMaxX()+1)*3/4,  (GetMaxY()+1)/2,
        (GetMaxX()+1)/2,    (GetMaxY()+1)*3/4,
        (GetMaxX()+1)/4,    (GetMaxY()+1)/2,
        (GetMaxX()+1)/2,    (GetMaxY()+1)/4,
    };

    const SHORT poligonoPontos[] = {			//poligono 5 lados
        (GetMaxX()+1)/2,    (GetMaxY()+1)*2/7,
        (GetMaxX()+1)*6/8,  (GetMaxY()+1)*3/7,
        (GetMaxX()+1)*5/8,  (GetMaxY()+1)*5/7,
        (GetMaxX()+1)*3/8,  (GetMaxY()+1)*5/7,
        (GetMaxX()+1)*2/8,  (GetMaxY()+1)*3/7,
	(GetMaxX()+1)/2,    (GetMaxY()+1)*2/7,
    };

    
    // inicializa componentes de hardware e periféricos
    InitializeBoard();


4 - Pronto! 
Agora podemos utilizar as funçoes da Graphics Primitive Layer da Microchip.
Essa é parte mais legal do nosso blog.
Mãos a obra!
Veja como ficaram as minhas telas:

+++++++++++ Desenha MENSAGEM inicial na tela ++++++++++++++++++++++++++++


// desenha mensagem inicial na tela
        SetFont((void *) &Font25);
        SetColor(BRIGHTRED);
        width = GetTextWidth("Graphic Primitives Layer ", (void *) &Font25);
        height = GetTextHeight((void *) &Font25);

        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 2, "Graphic Primitives Layer ");

        SetColor(WHITE);
        width = GetTextWidth("Utilizando as Funcoes Basicas", (void *) &Font25);
        height = GetTextHeight((void *) &Font25);

        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 1, "Utilizando as Funcoes Basicas");





+++++++++++ PAUSAR e LIMPAR a TELA ++++++++++++++++++++++++++++

O código abaixo executa uma pausa de 4 segundos para permitir visualizar a imagem na tela, depois limpa o display com a cor preta para o fundo.


    DelayMs(4*DEMODELAY);
    SetColor(BLACK);
    ClearDevice();



+++++++++++ Função para desenhar TEXTO ++++++++++++++++++++++++++++



//funcao para desenhar TEXTO
		//WORD OutTextXY(SHORT x,SHORT y,XCHAR * textString);

        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Funcoes de Texto", (void *) &Font25);
        OutTextXY(
			(GetMaxX() - width) >> 1, 
			(GetMaxY() - height) >> 2, 
			"Funcoes de Texto");

		SetColor(BRIGHTGREEN);
		width = GetTextWidth("Fonte 25 Verde", (void *) &Font25);
		OutTextXY(
			(GetMaxX() - width) >> 1, 
			(GetMaxY() - height) >> 1, 
			"Fonte 25 Verde");

		SetFont((void *) &Font35);
		SetColor(BRIGHTBLUE);
	        height = GetTextHeight((void *) &Font35);
		width = GetTextWidth("Fonte 35 Azul", (void *) &Font35);
        OutTextXY(
			(GetMaxX() - width) >> 1, 
			3*((GetMaxY() - height) >> 2), 
			"Fonte 35 Azul");



+++++++++++ Funções para desenhar LINHA ++++++++++++++++++++++++++++



// funcoes para desenhar linha
	// WORD Line(SHORT x1,SHORT y1,SHORT x2,SHORT y2);

		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Linha Normal-1 Pixel", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Linha Normal-1 Pixel");


		// desenha tipos de LINHAS NORMAIS
		SetLineThickness(NORMAL_LINE);  //1 pixel

		SetColor(BRIGHTRED);
		SetLineType(SOLID_LINE);
		WAIT_UNTIL_FINISH(
			Line(
				GetMaxX()>>2, 
				GetMaxY()>> 2, 
				3*(GetMaxX()>>2),
				GetMaxY()>> 2));

		SetColor(BRIGHTYELLOW);
		SetLineType(DOTTED_LINE);
		WAIT_UNTIL_FINISH(
			Line(GetMaxX()>>2, 
				GetMaxY()>> 1, 
				3*(GetMaxX()>>2),
				GetMaxY()>> 1));

		SetColor(BRIGHTGREEN);
		SetLineType(DASHED_LINE);
		WAIT_UNTIL_FINISH(
			Line(GetMaxX()>>2, 
				3*(GetMaxY()>> 2), 
				3*(GetMaxX()>>2),
				3*(GetMaxY()>> 2)));




+++++++++++ LINHA Grossa ++++++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Linha Grossa-3Pixels", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Linha Grossa-3Pixels");


		//desenha tipos de LINHAS GROSSAS
		SetLineThickness(THICK_LINE);  // 3 pixel

		SetColor(BRIGHTRED);
		SetLineType(SOLID_LINE);
		WAIT_UNTIL_FINISH(
			Line(GetMaxX()>>2, 
				GetMaxY()>> 2, 
				3*(GetMaxX()>>2),
				GetMaxY()>> 2));

		SetColor(BRIGHTYELLOW);
		SetLineType(DOTTED_LINE);
		WAIT_UNTIL_FINISH(
			Line(GetMaxX()>>2, 
				GetMaxY()>> 1, 
				3*(GetMaxX()>>2),
				GetMaxY()>> 1));

		SetColor(BRIGHTGREEN);
		SetLineType(DASHED_LINE);
		WAIT_UNTIL_FINISH(
			Line(GetMaxX()>>2, 
				3*(GetMaxY()>> 2), 
				3*(GetMaxX()>>2),
				3*(GetMaxY()>> 2)));



+++++++++++ Funções para desenhar RETÂNGULO ++++++++++++++++++++++++++++



// funcoes para desenhar retangulo
		// WORD Bar(SHORT left,SHORT top,SHORT right,SHORT bottom);
		// WORD DrawPoly(SHORT numPoints,SHORT * polyPoints);
				//SHORT polyPoints[numPoints] = {x0, y0, x1, y1, x2, y2 … xn, yn};
				//onde n = numero de Pontos - 1
		//Rectangle Macro
		// #define Rectangle(left, top, right, bottom) Bevel(left, top, right, bottom, 0)


		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Retangulo", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Retangulo");


		// desenha RETANGULO
		SetLineType(SOLID_LINE);
		SetLineThickness(NORMAL_LINE);  //1 pixel
		SetColor(BRIGHTBLUE);
        WAIT_UNTIL_FINISH		
			(
				Bar(					//retangulo preenchido com funcao BAR
					GetMaxX() /4 - 30, 
					GetMaxY() / 2 - 60, 
					GetMaxX() / 4 + 30, 
					GetMaxY() / 2 + 60
					)
			);

		SetColor(BRIGHTYELLOW);
        WAIT_UNTIL_FINISH		
			(
				Rectangle(				//retangulo com Macro RECTANGLE
					(GetMaxX() / 4) * 3 - 30, 
					GetMaxY() / 2 - 60, 
					(GetMaxX() / 4)* 3  + 30, 
					GetMaxY() / 2 + 60
					)
			);



+++++++++++ POLIGONO 5 lados ++++++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Poligono", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Poligono");

			
		// desenha POLIGONO de 5 lados
		SetColor(BRIGHTRED);
		WAIT_UNTIL_FINISH(
			DrawPoly	(6, (SHORT *)poligonoPontos));



+++++++++++ Funções para desenhar CIRCULOS ++++++++++++++++++++++++++++



// Funcoes para desenhar CIRCULOS
		// WORD Arc(SHORT xL,SHORT yT,SHORT xR,SHORT yB,SHORT r1,SHORT r2,BYTE octant);
			//SHORT xL x location of the upper left center in the x,y coordinate.
			//SHORT yT y location of the upper left center in the x,y coordinate.
			//SHORT xR x location of the lower right center in the x,y coordinate.
			//SHORT yB y location of the lower right center in the x,y coordinate.
			//SHORT r1 The smaller radius of the two concentric cicles that defines the thickness of theobject.
			//SHORT r2 The larger of radius the two concentric circles that defines the thickness of theobject.
		//WORD Bevel(SHORT x1,SHORT y1,SHORT x2,SHORT y2,SHORT rad);
		//WORD FillBevel(SHORT x1,SHORT y1,SHORT x2,SHORT y2,SHORT rad);
				//SHORT rad defines the redius of the circle, that draws the rounded corners.

		//Circle Macro  #define Circle(x, y, radius) Bevel(x, y, x, y, radius)
				//x Center x position.
				//y Center y position.
				//radius the radius of the circle.
		//FillCircle Macro  #define FillCircle(x1, y1, rad) FillBevel(x1, y1, x1, y1, rad)
				//x1 x coordinate position of the center of the circle.
				//y1 y coordinate position of the center of the circle.
				//rad defines the redius of the circle.
		//SetBevelDrawType Macro	#define SetBevelDrawType(type) (_bevelDrawType = type)
				//• DRAWFULLBEVEL to draw the full shape
				//• DRAWTOPBEVEL to draw the upper half portion
				//• DRAWBOTTOMBEVEL to draw the lower half portion
	

		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Circulo", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Circulo");	

		SetColor(BRIGHTRED);
		//Desenha CIRCULO
		WAIT_UNTIL_FINISH(
			Circle(
				GetMaxX() >> 2, 
				GetMaxY() >> 1, 
				50));	

	    SetColor(BRIGHTGREEN);
		//Desenha CIRCULO Preenchido
		WAIT_UNTIL_FINISH(
			FillCircle(
				3*(GetMaxX() >> 2),
 				GetMaxY() >> 1, 
				50));



+++++++++++ RETANGULO com borda grossa e arredondada +++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Funcao Arc", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Funcao Arc");	


		// desenha RETANGULO com borda grossa e arredondada
        SetColor(BRIGHTRED);
        WAIT_UNTIL_FINISH
        (
            Arc
                (
                    (GetMaxX() >> 2) - 25,		//xL
                    (GetMaxY() >> 1) - 25,		//xT
                    (GetMaxX() >> 2) + 25,		//yR
                    (GetMaxY() >> 1) + 25,		//yB
                    5,					//r1
                    10,					//r2
                    0xFF				//octant
                )
        );

		// desenha CIRCULO cheio no centro da tela
        SetColor(BRIGHTGREEN);
        WAIT_UNTIL_FINISH
        (
            Arc
                (
                    (GetMaxX() >> 1),		    //xL
                    (GetMaxY() >> 1),		    //xT
                    (GetMaxX() >> 1),		    //yR
                    (GetMaxY() >> 1),		    //yB
                    0,				    //r1
                    25,				    //r2
                    0xFF			    //octant
                )
        );

		// desenha RETANGULO
        SetColor(BRIGHTBLUE);
        WAIT_UNTIL_FINISH
        (
            Arc
                (
                    3*(GetMaxX() >> 2) - 25,	        //xL
                    (GetMaxY() >> 1) - 25,		//xT
                    3*(GetMaxX() >> 2) + 25,	        //yR
                    (GetMaxY() >> 1) + 25,		//yB
                    0,					//r1
                    0,					//r2
                    0xFF				//octant
                )
        );




+++++++++++ RETANGULO chanfrados (arredondados) ++++++++++++++++++++++++++++




		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Funcao Bevel", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Funcao Bevel");


		// desenha RETANGULO chanfrados (arredondados) 
        SetColor(BRIGHTRED);
        WAIT_UNTIL_FINISH
		(
			Bevel
				(
					(GetMaxX() >> 2) - 25, 	//x1
					(GetMaxY() >> 1) - 25, 	//y1
					(GetMaxX() >> 2) + 25, 	//x2
					(GetMaxY() >> 1) + 25, 	//y2
					20			//rad
				)
		);

		// desenha CIRCULO no meio da tela
        SetColor(BRIGHTGREEN);
        WAIT_UNTIL_FINISH
		(
			Bevel
				(
					(GetMaxX() >> 1), 	//x1
					(GetMaxY() >> 1), 	//y1
					(GetMaxX() >> 1), 	//x2
					(GetMaxY() >> 1), 	//y2
					25			//rad
				)
		);   

		// desenha RETANGULO 
        SetColor(BRIGHTBLUE);
        WAIT_UNTIL_FINISH
		(
			Bevel
				(
					(GetMaxX() >> 2)*3 - 25, 	//x1
					(GetMaxY() >> 1) - 25, 		//y1
					(GetMaxX() >> 2)*3 + 25, 	//x2
					(GetMaxY() >> 1) + 25, 		//y2
					0				//rad
				)
		);     



+++++++++++ RETANGULO chanfrados (arredondados) cheio ++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Funcao FillBevel", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Funcao FillBevel");


		// desenha RETANGULO chanfrados (arredondados) cheio
        SetColor(BRIGHTRED);
        WAIT_UNTIL_FINISH
		(
			FillBevel
				(
					(GetMaxX() >> 2) - 25, 	//x1
					(GetMaxY() >> 1) - 25, 	//y1
					(GetMaxX() >> 2) + 25, 	//x2
					(GetMaxY() >> 1) + 25, 	//y2
					20			//rad
				)
		);

		// desenha CIRCULO cheio no meio da tela
        SetColor(BRIGHTGREEN);
        WAIT_UNTIL_FINISH
		(
			FillBevel
				(
					(GetMaxX() >> 1), 	//x1
					(GetMaxY() >> 1), 	//y1
					(GetMaxX() >> 1), 	//x2
					(GetMaxY() >> 1), 	//y2
					25			//rad
				)
		);   

		// desenha RETANGULO cheio
        SetColor(BRIGHTBLUE);
        WAIT_UNTIL_FINISH
		(
			FillBevel
				(
					(GetMaxX() >> 2)*3 - 25, 	//x1
					(GetMaxY() >> 1) - 25, 		//y1
					(GetMaxX() >> 2)*3 + 25, 	//x2
					(GetMaxY() >> 1) + 25, 		//y2
					0							//rad
				)
		);     




+++++++++++ Funções para GRADIENT ++++++++++++++++++++++++++++



// Funcoes para Gradient
		//WORD BarGradient(SHORT left,SHORT top,SHORT right,SHORT bottom,GFX_COLOR color1,GFX_COLOR color2,DWORD length,BYTE direction);
			//From 0-100%. How much of a gradient is wanted

		//WORD BevelGradient(SHORT left,SHORT top,SHORT right,SHORT bottom,SHORT rad,GFX_COLOR color1,GFX_COLOR color2,DWORD length,BYTE direction);
		
		//GFX_GRADIENT_TYPE Enumeration
			//GRAD_NONE = 0 No Gradients ( see page 361) to be drawn
			//GRAD_DOWN gradient changes in the vertical direction
			//GRAD_RIGHT gradient change in the horizontal direction
			//GRAD_UP gradient changes in the vertical direction
			//GRAD_LEFT gradient change in the horizontal direction
			//GRAD_DOUBLE_VER two gradient transitions in the vertical direction
			//GRAD_DOUBLE_HOR two gradient transitions in the horizontal direction

		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Funcao BarGradient", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Funcao BarGradient");


		BarGradient		//11
			(
				(GetMaxX() >> 2) - 20, 		//x1
				(GetMaxY() >> 2)*3/2 - 20, 	//y1
				(GetMaxX() >> 2) + 20, 		//x2
				(GetMaxY() >> 2)*3/2 + 20, 	//y2
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_DOWN			//direction
			);
        while(IsDeviceBusy());

		BarGradient		//12
			(
				(GetMaxX() >> 1) - 20, 		//x1
				(GetMaxY() >> 2)*3/2 - 20, 	//y1
				(GetMaxX() >> 1) + 20, 		//x2
				(GetMaxY() >> 2)*3/2 + 20, 	//y2
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_RIGHT			//direction
			);
        while(IsDeviceBusy());

		BarGradient		//13
			(
				(GetMaxX() >> 2)*3 - 20, 	//x1
				(GetMaxY() >> 2)*3/2 - 20, 	//y1
				(GetMaxX() >> 2)*3 + 20, 	//x2
				(GetMaxY() >> 2)*3/2 + 20, 	//y2
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_UP				//direction
			);
        while(IsDeviceBusy());

		BarGradient		//21
			(
				(GetMaxX() >> 2) - 20, 		//x1
				(GetMaxY() >> 2)*3 - 20, 	//y1
				(GetMaxX() >> 2) + 20, 		//x2
				(GetMaxY() >> 2)*3 + 20, 	//y2
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_LEFT			//direction
			);
        while(IsDeviceBusy());

		BarGradient		//22
			(
				(GetMaxX() >> 1) - 20, 		//x1
				(GetMaxY() >> 2)*3 - 20, 	//y1
				(GetMaxX() >> 1) + 20, 		//x2
				(GetMaxY() >> 2)*3 + 20, 	//y2
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_DOUBLE_VER			//direction
			);
        while(IsDeviceBusy());

		BarGradient		//23
			(
				(GetMaxX() >> 2)*3 - 20, 	//x1
				(GetMaxY() >> 2)*3 - 20, 	//y1
				(GetMaxX() >> 2)*3 + 20, 	//x2
				(GetMaxY() >> 2)*3 + 20, 	//y2
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_DOUBLE_HOR			//direction
			);
        while(IsDeviceBusy());





+++++++++++ GRADIENT  arredondado ++++++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Funcao BevelGradient", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Funcao BevelGradient");


		BevelGradient		//11
			(
				(GetMaxX() >> 2) - 20, 		//x1
				(GetMaxY() >> 2)*3/2 - 20, 	//y1
				(GetMaxX() >> 2) + 20, 		//x2
				(GetMaxY() >> 2)*3/2 + 20, 	//y2
				10,				//rad
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_DOWN			//direction
			);
        while(IsDeviceBusy());

		BevelGradient		//12
			(
				(GetMaxX() >> 1) - 20, 	//x1
				(GetMaxY() >> 2)*3/2 - 20, 	//y1
				(GetMaxX() >> 1) + 20, 	//x2
				(GetMaxY() >> 2)*3/2 + 20, 	//y2
				10,				//rad
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_RIGHT			//direction
			);
        while(IsDeviceBusy());

		BevelGradient		//13
			(
				(GetMaxX() >> 2)*3 - 20, 	//x1
				(GetMaxY() >> 2)*3/2 - 20, 	//y1
				(GetMaxX() >> 2)*3 + 20, 	//x2
				(GetMaxY() >> 2)*3/2 + 20, 	//y2
				10,				//rad
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_UP				//direction
			);
        while(IsDeviceBusy());

		BevelGradient	//21
			(
				(GetMaxX() >> 2) - 20, 	//x1
				(GetMaxY() >> 2)*3 - 20, 	//y1
				(GetMaxX() >> 2) + 20, 	//x2
				(GetMaxY() >> 2)*3 + 20, 	//y2
				10,				//rad
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_LEFT			//direction
			);
        while(IsDeviceBusy());

		BevelGradient		//22
			(
				(GetMaxX() >> 1) - 20, 	//x1
				(GetMaxY() >> 2)*3 - 20, 	//y1
				(GetMaxX() >> 1) + 20, 	//x2
				(GetMaxY() >> 2)*3 + 20, 	//y2
				10,				//rad
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_DOUBLE_VER			//direction
			);
        while(IsDeviceBusy());

		BevelGradient		//23
			(
				(GetMaxX() >> 2)*3 - 20, 	//x1
				(GetMaxY() >> 2)*3 - 20, 	//y1
				(GetMaxX() >> 2)*3 + 20, 	//x2
				(GetMaxY() >> 2)*3 + 20, 	//y2
				10,				//rad
				BRIGHTRED, 			//color1
				BRIGHTBLUE, 			//color2
				100, 				//lenght
				GRAD_DOUBLE_HOR			//direction
			);
        while(IsDeviceBusy());





+++++++++++ Função para desenhar IMAGEM BITMAP 1 BPP - Preto & Branco +++++++++



// Funcao para desenhar IMAGEM BITMAP
		//WORD PutImage(SHORT left,SHORT top,void * bitmap,BYTE stretch);
				//IMAGE_NORMAL - Normal image stretch code
				//IMAGE_X2 - Stretched image stretch code
		//SHORT GetImageHeight(void * bitmap);
		//SHORT GetImageWidth(void * bitmap);

		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Imagem 1 BPP", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Imagem 1 BPP");

	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("51x56  402 bytes", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, ((GetMaxY() - height) >> 3)*7, "51x56  402 bytes");


		// desenha figura na tela 1 BPP bitmap,  402 bytes, 51x56
		height = GetImageHeight((void *) &Sep_1BPP);
        width = GetImageWidth((void *) &Sep_1BPP);
        WAIT_UNTIL_FINISH
			(
				PutImage
					(
						(GetMaxX() - width*2) >> 1,	//left
						(GetMaxY() - height*2) >> 1, 	//top
						(void *) &Sep_1BPP, 		//* bitmap
						IMAGE_X2						//stretch
					)
			);





+++++++++++ IMAGEM BITMAP 4 BPP ++++++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Imagem 4 BPP Comprimida", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Imagem 4 BPP Comprimida");

	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("108x112 6086 => 2072 bytes", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, ((GetMaxY() - height) >> 3)*7, "108x112 6086 => 2072 bytes");


		// desenha figura na tela 4 BPP bitmap,  2072 bytes, 108x112
	height = GetImageHeight((void *) &SPFC_4BPP);
        width = GetImageWidth((void *) &SPFC_4BPP);
        WAIT_UNTIL_FINISH
			(
				PutImage
					(
						(GetMaxX() - width) >> 1,		//left
						(GetMaxY() - height) >> 1, 		//top
						(void *) &SPFC_4BPP, 			//* bitmap
						IMAGE_NORMAL				//stretch
					)
			);






+++++++++++ IMAGEM BITMAP 8 BPP ++++++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Imagem 8 BPP Comprimida", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 3, "Imagem 8 BPP Comprimida");

	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("99x99 10319 => 5112 bytes", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, ((GetMaxY() - height) >> 3)*7, "99x99 10319 => 5112 bytes");


		// desenha figura na tela 4 BPP bitmap,  99x99 10319 => 5112 bytes
	height = GetImageHeight((void *) &raio_8bpp);
        width = GetImageWidth((void *) &raio_8bpp);
        WAIT_UNTIL_FINISH
			(
				PutImage
					(
						(GetMaxX() - width) >> 1,		//left
						(GetMaxY() - height) >> 1, 		//top
						(void *) &raio_8bpp, 			//* bitmap
						IMAGE_NORMAL				//stretch
					)
			);






+++++++++++ IMAGEM BITMAP 16 BPP ++++++++++++++++++++++++++++



		// texto
        SetFont((void *) &Font25);
        SetColor(WHITE);
	height = GetTextHeight((void *) &Font25);
        width = GetTextWidth("Imagem 16 BPP 110x81 17kB", (void *) &Font25);
        OutTextXY((GetMaxX() - width) >> 1, (GetMaxY() - height) >> 4, "Imagem 16 BPP 110x81 17kB");


		// desenha figura na tela 4 BPP bitmap,  99x99 10319 => 5112 bytes
	height = GetImageHeight((void *) &bateria);
        width = GetImageWidth((void *) &bateria);
        WAIT_UNTIL_FINISH
			(
				PutImage
					(
						(GetMaxX() - width*2) >> 1,		//left
						((GetMaxY() - height*2) >> 1)+10, 	//top
						(void *) &bateria, 			//* bitmap
						IMAGE_X2				//stretch
					)
			);








 
Assista ao vídeo para ver o resultado do meu programa de exemplo para treino das funções da Graphics Primitive Layer da Microchip.

CRIE seu programa também! 
A sua imaginação é o seu limite!


Vídeo 1 - PIC32 + GOL - Graphics Primitive Layer - Funções Básicas

Referencias:

MICROCHIP web site: www.microchip.com

MICROCHIP - Graphics Library Application. MLA - Microchip_Solutions_v2013-06-15.
Graphics Primitives Layer Demo.  

Nenhum comentário:

Postar um comentário