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

📄 fbtest.c

📁 IBM source for pallas/vulcan/vesta
💻 C
📖 第 1 页 / 共 4 页
字号:
    }    if (cr > 255)    {        cr = 255;    }    /*-------------------------------------------------------------------------+    | Scale to accepted values.    +-------------------------------------------------------------------------*/    if ((y % 4) > 2)    {        *r_y = (y / 4) + 1;    }    else    {        *r_y = y / 4;    }    if ((*r_y) > 0x3F)    {        *r_y = 0x3F;    }    if ((cb % 16) > 8)    {        *r_cb = (cb / 16) + 1;    }    else    {        *r_cb = cb / 16;    }    if ((*r_cb) > 0xF)    {        *r_cb = 0x0F;    }    if ((cr % 16) > 8)    {        *r_cr = (cr / 16) + 1;    }    else    {        *r_cr = cr / 16;    }    if ((*r_cr) > 0xF)    {        *r_cr = 0x0F;    }#endif    *r_y = y;    *r_cb = cb;    *r_cr = cr;    return;}void write_the_palette(){    int i;    static __u16 red[256];    static __u16 green[256];    static __u16 blue[256];    struct fb_cmap map;         /* fb.h */    /* Load Tux's colors. The Frame buffer expects the color values to be justified to the MSB of a        16-bit word for 8 BPP */    for (i = 0; i < 214; i++)    {        red[i + 32] = linux_logo_red[i] << 8;        green[i + 32] = linux_logo_green[i] << 8;        blue[i + 32] = linux_logo_blue[i] << 8;    }    /* Create the color map. */    map.start = 0;    map.len = 256;    map.red = (__u16 *) & red;    map.green = (__u16 *) & green;    map.blue = (__u16 *) & blue;    map.transp = (__u16 *) NULL;    /* Send it to the hardware via the Frame Buffer. *///    printf("setting the palette\n");    if (i = ioctl(fbfd, FBIOPUTCMAP, &map))    {        switch (i)        {            case EBADF:                printf("fbfd is not a valid descriptor\n");                break;            case EFAULT:                printf("argp references an inaccessible memory area.\n");                break;            case ENOTTY:                printf("The specified request does not apply to the\n"                       "kind of object that the descriptor d references\n");            case EINVAL:                printf("Request or argp is not valid.\n");                break;            default:                printf("ioctl fails\n");        }    }}/****************************************************************************//* This function draws Tux and moves it across the screen. * Tux is an 80x80 pixel image. * */void display_logo2(){    int i, j, h, k, pos, ssize;    int y, cb, cr;    h = 0;    pos = 0;    ssize = finfo.line_length * vinfo.yres;    /* clear the screen */    memset(fbp, 0, ssize);    for (i = 0; i < 80; i++)    {        for (j = 0; j < 80; j++)        {            k = linux_logo[h++];            if (k >= 32)                k -= 32;            rgb_to_ycbcr(linux_logo_red[k], linux_logo_green[k],                         linux_logo_blue[k], &y, &cb, &cr);            *(fbp + pos + j) = (char) y;            if ((j % 2) == 0)            {                *(fbp + pos + j + ssize) = (char) cb;                *(fbp + pos + j + 1 + ssize) = (char) cr;            }        }        pos += finfo.line_length;    }}void display_logo(){    int c, h, i, j, k, l, m, x, y;    int tux = 0;    int x_off = 0;    int y_off = 0;    write_the_palette();    for (c = 0; c < 1; c++)    {                           /* Repeat the demo */        for (i = 0; i < finfo.line_length * vinfo.yres; i++)   /* Clear screen */            *(fbp + i) = FILL;        /* Animate logo */        printf("Display a 80x80 image across the screen\n");        for (y_off = 0; y_off < vinfo.yres - 80; y_off += 80)            for (x_off = 0; x_off < vinfo.xres - 80; x_off += 80)            {                for (i = 0; i < 250; i++)                {                    for (h = y = 0; y < 80; y++)                    {                        k = ((y_off + y) * finfo.line_length) + x_off;                        for (x = 0; x < 80; x++)                        {                            *(fbp + k++) = linux_logo[h++];                        }                    }                }                /* Erase the logo drawn above */                for (h = x = y = 0; y < 80; y++)                {                    k = ((y_off + y) * finfo.line_length) + x_off;                    for (x = 0; x < 80; x++)                        *(fbp + k++) = FILL;                }            }        for (i = 0; i < finfo.line_length * vinfo.yres; i++)   /* Clear screen */            *(fbp + i) = FILL;        printf("fill with screen with 80x80 images\n");        for (m = 0; m < 125; m++)        {                       /* 8 x 6 penguins */            for (h = j = k = 0; j < vinfo.yres; j++)            {                for (l = 0; l < vinfo.xres / 80; l++)                {                    for (i = 0; i < 80; i++)                        *(fbp + k+i + l*80) = linux_logo[i + h];                }                k += finfo.line_length;                h = (h == 6400) ? 0 : (h + 80);            }        }    }}/*****************************************************************************/main(int argc, char *argv[]){    int rc;    int i;    int original_xres,original_yres;     sleep(1);      if (argc < 2)        fbfd = open("/dev/fb0", O_RDWR);    else        fbfd = open(argv[1], O_RDWR);    if (!fbfd)    {        printf("Error: cannot open framebuffer device /dev/fb0.\n");        exit(1);    }    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))    {        printf("Error: reading fixed information.\n");        exit(2);    }    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))    {        printf("Error: reading variable information.\n");        exit(3);    }        original_yres = vinfo.yres;    original_xres = vinfo.xres;    screensize = (finfo.line_length * vinfo.yres * vinfo.bits_per_pixel) >> 3;    printf("xres=%d yres=%d bpp=%d screensize=%d\n", vinfo.xres, vinfo.yres,           vinfo.bits_per_pixel, screensize);    /* display the logo */    fbp = (char *) mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);    if ((int) fbp == -1)    {        printf("Error: failed to map framebuffer device to memory.\n");        exit(4);    }    printf("dislay the logo in default mode \n");    display_logo();    sleep(5);    //clear the display    for (i = 0; i < finfo.line_length * vinfo.yres; i++)   /* Clear screen */       *(fbp + i) = FILL;    /* make the resolution half and display the logo */    printf("switching dislay to 1/2 size window \n");    munmap(fbp, SIZE);    vinfo.xres /= 2;    vinfo.yres /= 2;    vinfo.activate |= FB_ACTIVATE_NOW;    vinfo.activate &= ~FB_ACTIVATE_ALL;    if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &vinfo))    {        printf("Error 5: writing variable information.\n");        exit(5);    }    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))    {        printf("Error: reading fixed information.\n");        exit(2);    }    if (rc = ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))    {        printf("Error: reading variable information.\n");        exit(3);    }    screensize = (finfo.line_length * vinfo.yres * vinfo.bits_per_pixel) >> 3;    printf("xres=%d yres=%d bpp=%d screensize=%d\n", vinfo.xres, vinfo.yres,           vinfo.bits_per_pixel, screensize);                        fbp = (char *) mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);    display_logo();    sleep(5);         //clear the display    for (i = 0; i < finfo.line_length * vinfo.yres; i++)   /* Clear screen */       *(fbp + i) = FILL;    munmap(fbp, SIZE);    vinfo.yres = original_yres;    vinfo.xres = original_xres;    vinfo.activate |= FB_ACTIVATE_NOW;    vinfo.activate &= ~FB_ACTIVATE_ALL;    if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &vinfo))    {        printf("Error 5: writing variable information.\n");        exit(5);    }    close(fbfd);}

⌨️ 快捷键说明

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