⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 core_vga.c

📁 嵌入式开发 嵌入式开发 嵌入式开发
💻 C
📖 第 1 页 / 共 5 页
字号:
        }
    }
    for(j=0;filltemp[(count_line-2)%3][j]!=0xffff;j+=2)
    {
        x=filltemp[(count_line-2)%3][j];
        for(k=0;filltemp[(count_line-1)%3][k]!=0xffff;k+=2)
        {
            if(filltemp[(count_line-2)%3][j]==filltemp[(count_line-1)%3][k])
            {
                m=filltemp[(count_line-2)%3][j+1];
                n=filltemp[(count_line-1)%3][k+1];
                if( m>n )
                {   y=m; m=n; n=y;}
                for(y=m+1;y<n;y++)
                {   PutPixel(x,y,r,g,b);}
            }
        }
    }
}

/***
Func: Draw Line
Parameters:
    -x1,y1 ; position of start point
    -x2,y2 ; position of end point
    -r,g,b  ; color of line.
***/
void Line(int x1, int y1, int x2, int y2, int r, int g, int b)
{
    int d;
    int dx,dy;
    int Eincr,NEincr;
    int yincr;
    int t;
    dx = FABS(x2 - x1);
    dy = FABS(y2 - y1);
    if( dy<=dx )
    {
        if( x2<x1 )
        {
            t=x2; x2=x1; x1=t;
            t=y2; y2=y1; y1=t;
        }
        if( y2>y1 ) {   yincr=1;}
        else {   yincr=-1;}
        d = 2*dy - dx;
        Eincr = 2*dy;
        NEincr = 2*(dy - dx);
        PutPixel(x1, y1, r, g, b);
        for(x1++; x1<=x2; x1++)
        {
            if( d<0 )
            {   d+=Eincr;}
            else
            {
                d+=NEincr;
                y1+=yincr;
            }
            PutPixel(x1,y1,r,g,b);
        }
    }
    else
    {
        if( y2 < y1 )
        {   // swap two variables.
            t=x2; x2=x1; x1=t;
            t=y2; y2=y1; y1=t;
        }
        if( x2>x1 )
        {   yincr=1;}
        else
        {   yincr=-1;}
        d = 2*dx - dy;
        Eincr = 2*dx;
        NEincr = 2*(dx - dy);
        PutPixel(x1, y1, r, g, b);
        for (y1++; y1 <= y2; y1++)
        {
            if( d<0 )
            {   d+=Eincr;}
            else
            {   d+=NEincr; x1+=yincr;}
            PutPixel(x1, y1, r, g, b);
        }
    }
}

/***
 Func: Rectangle
 Parameters:
    x0,y0 :  left-top corner position.
    x1,y1 :  right-bottom corner position.
    r,g,b  :  color of Rectangle lines.
 Returns:
    NULL
***/
void Rectangle(int x0, int y0, int x1, int y1, int r, int g, int b)
{
    int t;
    if( x1<x0 ) {   t=x0; x0=x1; x1=t;}
    if( y1<y0 ) {   t=y0; y0=y1; y1=t;}
    for(t=x0; t<=x1; t++)
    {   PutPixel(t, y0, r, g, b); PutPixel(t, y1, r, g, b);}
    for(t=y0; t<=y1; t++)
    {   PutPixel(x0, t, r, g, b); PutPixel(x1, t, r, g, b);}
}

/***
 Func: Square Area
 Parameters:
    x0,y0 :  left-top corner position.
    x1,y1 :  right-bottom corner position.
    r,g,b  :  color of filled area.
 Returns:
    NULL
***/
void Bar(int x0, int y0, int x1, int y1, int r, int g, int b)
{
    int t,k;
    disable();
    if( x1<x0 ) {   t=x0; x0=x1; x1=t;}
    if( y1<y0 ) {   t=y0; y0=y1; y1=t;}
    for(t=y0; t<=y1; t++)
    {
        for(k=x0; k<=x1; k++)
        {   PutPixel(k, t, r, g, b);}
    }
    enable();
}

/***
 Func: Move Paint-Pencil Position
 Parameters:
    x,y :  the cordiation that you wanna.
 Returns:
    NULL
***/
void MoveTo(int x, int y)
{   currx=x; curry=y;}

/***
 Func: Line 2
 Parameters:
    x,y : the cordiation of destination.
    r,g,b : color of line.
 Returns:
    NULL
***/
void LineTo(int x, int y, int r, int g, int b)
{
    Line(currx, curry, x, y, r, g, b);
    currx=x; curry=y;
}

/***
 Func: line of FillPoly
 Parameters:
    x1,y1 : the start point cordiation.
    x2,y2 : the end point cordiation.
    r,g,b  : color of line.
 Returns:
    NULL
***/
void _Line4Poly(int x1, int y1, int x2, int y2, int r, int g, int b)
{
    int d,t,filltemp_count=0;
    int dx,dy,Eincr,NEincr,yincr;
    dx = FABS(x2 - x1);
    dy = FABS(y2 - y1);
    count_line+=1;
    if (dy <= dx)
    {
        if (x2 < x1)
        {
            t = x2; x2 = x1; x1 = t;
            t = y2; y2 = y1; y1 = t;
        }
        if( y2>y1 ) {   yincr=1;}
        else {   yincr=-1;}
        d = 2*dy - dx;
        Eincr = 2*dy;
        NEincr = 2*(dy - dx);
        PutPixel(x1,y1,r,g,b);
        filltemp[count_line%3][filltemp_count++]=x1;
        filltemp[count_line%3][filltemp_count++]=y1;
        filltemp[count_line%3][filltemp_count]=0xffff;
        for (x1++; x1 <= x2; x1++)
        {
            if (d < 0)
            {   d += Eincr;}
            else
            {
                d += NEincr;
                y1 += yincr;
            }
            filltemp[count_line%3][filltemp_count++]=x1;
            filltemp[count_line%3][filltemp_count++]=y1;
            filltemp[count_line%3][filltemp_count]=0xffff;
            PutPixel(x1,y1,r,g,b);
        }
    }
    else
    {
        if (y2 < y1)
        {
            t = x2; x2 = x1; x1 = t;
            t = y2; y2 = y1; y1 = t;
        }
        if (x2 > x1)
        {   yincr = 1;}
        else
        {   yincr = -1;}
        d = 2*dx - dy;
        Eincr = 2*dx;
        NEincr = 2*(dx - dy);
        PutPixel(x1,y1,r,g,b);
        filltemp[count_line%3][filltemp_count++]=x1;
        filltemp[count_line%3][filltemp_count++]=y1;
        filltemp[count_line%3][filltemp_count]=0xffff;
        for (y1++; y1 <= y2; y1++)
        {
            if (d < 0)
            {   d += Eincr;}
            else
            {
                d += NEincr;
                x1 += yincr;
            }
            PutPixel(x1,y1,r,g,b);
            filltemp[count_line%3][filltemp_count++]=x1;
            filltemp[count_line%3][filltemp_count++]=y1;
            filltemp[count_line%3][filltemp_count]=0xffff;
        }
    }
}

/***
 Func: Fill Polygon Area
 Paramters:
    numpoint : number of count-corner.
    points : points-cordiation of each corner.
    r,g,b : filled color.
 Returns:
    NULL
***/
void FillPoly(int numpoint, int far *points, int r, int g, int b)
{
    int i,t;
    unsigned long addr=((unsigned long)points[1]<<12)+((unsigned long)points[0]<<2);
    SetBANK((int)(addr>>16)); addr++;
    SetBANK((int)(addr>>16)); addr++;
    SetBANK((int)(addr>>16));
    for(i=0;i<numpoint-1;i++)
    {
        t=(i<<1);
        _Line4Poly(points[t], points[t+1], points[t+2], points[t+3], r, g, b);
        if( i>0 )
        {
            _Line4Poly(points[t+2], points[t+3], points[0], points[1], r, g, b);
            _FillPixel(r, g, b);
        }
    }
}

/***
 Func: memory's data copy
 Paramters:
    *src : source memory data.
    *dest: destination memory data.
    len : data-length
 Returns:
    NULL
***/
void CopyMem(unsigned char far *src, unsigned char far *dest, unsigned len)
{
    unsigned t;
    for(t=0; t<len; t++)
    {   *(dest+t) = *(src+t);}
}

/***
 Func: Get ImgData of One HorzLine.
 Parameters: 
    -x,y:  line's start point position.
    -imgLineBytes: bytes counter of this ImgData Area.
    -*ptr:  destination buffer;
 Returns:
    NULL
***/
void GetHorzLine(int x, int y, int imgLineBytes, unsigned char far * ptr1)
{
    unsigned long addr=((unsigned long)y<<12)+((unsigned long)x<<2);
    unsigned long off=(addr&0xffffL);
    unsigned long left=(0x10000L-off);
    int bank=(int)(addr>>16);
    unsigned char far *ptr2;
    if( left>=(long)imgLineBytes )
    {
        SetBANK(bank);
        ptr2=LocalScrPtr+(unsigned)off;
        CopyMem(ptr2, ptr1, imgLineBytes);
    }
    else
    {
        SetBANK(bank++);
        ptr2=LocalScrPtr+(unsigned)off;
        CopyMem(ptr2, ptr1, left);
        SetBANK(bank);
        CopyMem(LocalScrPtr, ptr1+left, imgLineBytes-left);
    }
}

/***
 Func: GetImage
 Parameters:
    -x1,y1; start point position
    -x2,y2; end point position
    -*buf; the buffer of image save.
 Returns:
    NULL
***/
void GetImage(int x1, int y1, int x2, int y2, unsigned char far * buf)
{
    int t,imgLineBytes=(((int)FABS(x1-x2))<<2);
    unsigned char far *ptr1;
    ptr1=buf;
    for(t=y1; t<(y1+FABS(y1-y2)); t++)
    {
        GetHorzLine(x1, t, imgLineBytes, ptr1);
        ptr1+=imgLineBytes;
    }
}

/***
 Func: PutHorzLine
 Parameters:
    -x,y; position of start point
    -imgLineBytes; bytes counter of LineImage
    -*buf; buffers.
 Returns:
    NULL
***/
void PutHorzLine(int x, int y, int imgLineBytes, unsigned char far * buf)
{
    unsigned long addr=((unsigned long)y<<12)+((unsigned long)x<<2);
    unsigned long off=(addr&0xffffL);
    unsigned long left=(0x10000L-off);
    int bank=(int)(addr>>16);
    unsigned char far *ptr;
    if( left>=(unsigned long)imgLineBytes )
    {
        SetBANK(bank);
        ptr=LocalScrPtr+(unsigned)off;
        CopyMem(buf,ptr,imgLineBytes);
    }
    else
    {
        SetBANK(bank++);
        ptr=LocalScrPtr+(unsigned)off;
        CopyMem(buf,ptr,left);
        SetBANK(bank);
        CopyMem(buf+ left,LocalScrPtr, imgLineBytes - left);
    }
}

/***
 Func: put image on screen
 Parameters:
    -x1,y1; start point
    -x2,y2; end point
    -*buf; buffers.
 Returns:
    NULL
***/
void PutImage(int x1, int y1, int x2, int y2, unsigned char far * buf)
{
    int i,imgLineBytes=(((int)FABS(x1-x2))<<2);
    unsigned char far *off_1;
    off_1=buf;
    for(i=y1; i<(y1+FABS(y2-y1)); i++)
    {
        PutHorzLine(x1,i,imgLineBytes,off_1);
        off_1+= imgLineBytes;
    }
    SetBANK(0);
}

/***
 Func: Circle
 Parameters:
    -x,y; center point position
    -ri; R of Circle.
    -r,g,b; color of circle.
 Returns:
    NULL
***/
void Circle(int x, int y, int ri, int r, int g, int b)
{
    int xx,yy,x1,x2,x3,x4,x5,x6,x7,x8,y1,y2,y3,y4,y5,y6,y7,y8,pk;
    int a,b1,i,j;
    xx = 0;
    yy = ri;
    x1 = x , y1 = y + ri;
    x2 = x , y2 = y + ri;
    x3 = x , y3 = y - ri;
    x4 = x , y4 = y - ri;
    x5 = x + ri , y5 = y;
    x6 = x - ri , y6 = y;
    x7 = x + ri , y7 = y;
    x8 = x - ri , y8 = y;
    pk = 1 - ri;
    PutPixel(x1,y1,r,g,b);
    PutPixel(x2,y2,r,g,b);
    PutPixel(x3,y3,r,g,b);
    PutPixel(x4,y4,r,g,b);
    PutPixel(x5,y5,r,g,b);
    PutPixel(x6,y6,r,g,b);
    PutPixel(x7,y7,r,g,b);
    PutPixel(x8,y8,r,g,b);
    while(xx < yy)
    {
        xx++;
        x1++,x2--,x3++,x4--;
        y5++,y6++,y7--,y8--;
        if(pk<0)
        {   pk+=(2*xx+1);}
        else
        {
            yy--;
            y1--,y2--,y3++,y4++;
            x5--,x6++,x7--,x8++;
            pk+=(2*(xx - yy)+1);
        }
        PutPixel(x1,y1,r,g,b);
        PutPixel(x2,y2,r,g,b);
        PutPixel(x3,y3,r,g,b);
        PutPixel(x4,y4,r,g,b);
        PutPixel(x5,y5,r,g,b);
        PutPixel(x6,y6,r,g,b);
        PutPixel(x7,y7,r,g,b);
        PutPixel(x8,y8,r,g,b);
    }
    b1=ri*ri;
    for(i=x-ri;i<=x+ri+1;i++)
    {
        for(j=y-ri;j<=y+ri+1;j++)
        {
            a=(i-x)*(i-x)+(j-y)*(j-y);
            if(a<b1)
            {   PutPixel(i,j,r,g,b);}
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -