[AssistantTool]_7_添加生成测试图的功能

Posted 暮色1994

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[AssistantTool]_7_添加生成测试图的功能相关的知识,希望对你有一定的参考价值。

[AssistantTool]_7_添加生成测试图的功能

创建时间:20200615 17:30:00

功能

  • 生成测试图,并保存对应原始数据到文件中,用来给嵌入式设备测试输出原色是否正常的问题

支持的格式

  • [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bpJ3aC6T-1629641365376)(image/2020-06-15-17-45-45.png)]
    • RGBA8888
    • RGB888
    • RGB565

支持的图像

  • 渐变色

  • 随机数

  • 单色渐变色

  • 黑白条

  • 棋盘格

  • 彩色条

  • 纯色

绘制图像核心函数


/*

 * 函数名称 : clearFrameBuff
 * 函数介绍 : 使用指定颜色刷新FrameBuffer
 * 参数介绍 : data:FrameBuffer相关信息, x,y,w,h:清空的矩形, r,g,b:使用的颜色,
 *           bps:framebuffer的bps
 * 返回值   : -1:失败,  0:成功
 */
int ColorTestForm::clearFrameBuff(char *indata, int x, int y, int w, int h, int r, int g, int b, int bps)
{
    unsigned int rgb = 0;
    int drawW = 0;
    int drawH = 0;
    int fbw = xres;
    int fbh = yres;


    if ( x + w > fbw )
    {
        drawW = fbw-x;
    }
    else
    {
        drawW = w;
    }

    if ( y + h > fbh )
    {
        drawH = fbh-y;
    }
    else
    {
        drawH = h;
    }

    switch( bps )
    {
        case 32:
            rgb = (b<<24) | (g<<16) | (r<<8);
        break;
        case 16:
            rgb = (((unsigned(r) << 8) & 0xF800) |
                    ((unsigned(g) << 3) & 0x7E0) |
                    ((unsigned(b) >> 3)));
        break;
    }


    for( int i = 0; i < drawH; i++ )
    {
        for( int j = 0; j < drawW; j++ )
        {
            switch( bps )
            {
                case 32:
                    indata[fbw*4*(i+y)+(j+x)*4] = (rgb>>24)&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+1] = (rgb>>16)&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+2] = (rgb>>8)&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+3] = a;
                break;
                case 24:
                    indata[fbw*3*(i+y)+(j+x)*3]   = b&0xFF;
                    indata[fbw*3*(i+y)+(j+x)*3+1] = g&0xFF;
                    indata[fbw*3*(i+y)+(j+x)*3+2] = r&0xFF;
                break;
                case 16:
                    indata[fbw*2*(i+y)+(j+x)*2] = (rgb)&0xFF;
                    indata[fbw*2*(i+y)+(j+x)*2+1] = (rgb>>8)&0xFF;
                break;
            }
        }
    }
    return 0;
}



/*
 * 函数名称 : testColor
 * 函数介绍 : 测试颜色FrameBuffer - 渐变色
 * 参数介绍 : data:FrameBuffer相关信息, x,y,w,h:清空的矩形,  br,bg,bb:使用的颜色,
 *           bps:framebuffer的bps
 * 返回值   : -1:失败,  0:成功
 */
int ColorTestForm::testColor(char * indata, int x, int y, int w, int h, int br, int bg, int bb, int bps)
{
    unsigned int rgb = 0;
    int drawW = 0;
    int drawH = 0;
    int fbw = xres;
    int fbh = yres;
    int r = br, g = bg, b = bb;
    int rgFlag = 0;

    if ( x + w > fbw )
    {
        drawW = fbw-x;
    }
    else
    {
        drawW = w;
    }


    if ( y + h > fbh )
    {
        drawH = fbh-y;
    }
    else
    {
        drawH = h;
    }

    for( int i = 0; i < drawH; i++ )
    {
        for( int j = 0; j < drawW; j++ )
        {
            r = (unsigned int)(br + (float)i/drawH*255)%255;
            g = (unsigned int)(bg + (float)j/drawW*255)%255;
            b = bb % 255;
            switch( bps )
            {
                case 32:
                    indata[fbw*4*(i+y)+(j+x)*4]   = b&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+1] = g&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+2] = r&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+3] = a;
                break;
                case 24:
                    indata[fbw*3*(i+y)+(j+x)*3]   = b&0xFF;
                    indata[fbw*3*(i+y)+(j+x)*3+1] = g&0xFF;
                    indata[fbw*3*(i+y)+(j+x)*3+2] = r&0xFF;
                break;
                case 16:
                    rgb = (((r << 8) & 0xF800) |
                        ((g << 3) & 0x7E0) |
                        ((b >> 3)));
                    indata[fbw*2*(i+y)+(j+x)*2] = (rgb)&0xFF;
                    indata[fbw*2*(i+y)+(j+x)*2+1] = (rgb>>8)&0xFF;
                break;
            }
        }
    }
    return 0;
}


/*
 * 函数名称 : testUrandom
 * 函数介绍 : 测试颜色FrameBuffer - 随机数
 * 参数介绍 : fbInfo:FrameBuffer相关信息, x,y,w,h:清空的矩形
 *           bps:framebuffer的bps
 * 返回值   : -1:失败,  0:成功
 */
int ColorTestForm::testUrandom(char *indata, int x, int y, int w, int h, int bps)
{
    unsigned int rgb = 0;
    int drawW = 0;
    int drawH = 0;
    int fbw = xres;
    int fbh = yres;
    int rgFlag = 0;
    int r = 0;
    int g = 0;
    int b = 0;
    int a = 0;

    if ( x + w > fbw )
    {
        drawW = fbw-x;
    }
    else
    {
        drawW = w;
    }

    if ( y + h > fbh )
    {
        drawH = fbh-y;
    }
    else
    {
        drawH = h;
    }

    for( int i = 0; i < drawH; i++ )
    {
        for( int j = 0; j < drawW; j++ )
        {
            r = rand()/255;
            g = rand()/255;
            b = rand()/255;
            a = rand()/255;
            switch( bps )
            {
                case 32:
                    indata[fbw*4*(i+y)+(j+x)*4]   = b&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+1] = g&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+2] = r&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+3] = a;

                break;
                case 16:
                    rgb = (((r << 8) & 0xF800) |
                        ((g << 3) & 0x7E0) |
                        ((b >> 3)));
                    indata[fbw*2*(i+y)+(j+x)*2] = (rgb)&0xFF;
                    indata[fbw*2*(i+y)+(j+x)*2+1] = (rgb>>8)&0xFF;
                break;
            }
        }
    }
    return 0;
}


/*
 * 函数名称 : testSolidColor
 * 函数介绍 : 测试单颜色FrameBuffer - 单色渐变色
 * 参数介绍 : fbInfo:FrameBuffer相关信息, x,y,w,h:清空的矩形,  br,bg,bb:使用的颜色,
 *           bps:framebuffer的bps
 * 返回值   : -1:失败,  0:成功
 */
int ColorTestForm::testSolidColor(char * indata, int x, int y, int w, int h, int br, int bg, int bb, int bps)
{
    unsigned int rgb = 0;
    int drawW = 0;
    int drawH = 0;
    int fbw = xres;
    int fbh = yres;
    int r = br, g = bg, b = bb;
    int rgFlag = 0;

    if ( x + w > fbw )
    {
        drawW = fbw-x;
    }
    else
    {
        drawW = w;
    }

    if ( y + h > fbh )
    {
        drawH = fbh-y;
    }
    else
    {
        drawH = h;
    }

    for( int i = 0; i < drawH; i++ )
    {
        r = br;
        g = bg;
        b = bb;
        for( int j = 0; j < drawW; j++ )
        {
            if ( i <= drawH/3 )
            {
                r = (unsigned int)(br + j*255/drawW)%255;
            }
            else if ( drawH/3 && i <= drawH*2/3 )
            {
                g = (unsigned int)(bg + j*255/drawW)%255;
            }
            else if ( drawH*2/3 < i )
            {
                b = (unsigned int)(bb + j*255/drawW)%255;
            }

            switch( bps )
            {
                case 32:
                    indata[fbw*4*(i+y)+(j+x)*4]   = b&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+1] = g&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+2] = r&0xFF;
                    indata[fbw*4*(i+y)+(j+x)*4+3] = a;
                break;
                case 16:
                    rgb = (((r << 8) & 0xF800) |
                        ((g << 3) & 0x7E0) |
                        ((b >> 3)));
                    indata[fbw*2*(i+y)+(j+x)*2] = (rgb)&0xFF;
                    indata[fbw*2*(i+y)+(j+x)*2+1] = (rgb>>8)&0xFF;
                break;
            }
        }
    }
    return 0;
[AssistantTool]_7_添加生成测试图的功能

[AssistantTool]_6_添加生成YUV文件的功能

[AssistantTool]_6_添加生成YUV文件的功能

[AssistantTool]_6_添加生成YUV文件的功能

[AssistantTool]_3_添加TAB示例

[AssistantTool]_3_添加TAB示例