logo.c

来自「利用framebuffer画小企鹅 Linux的framebuffer接口」· C语言 代码 · 共 65 行

C
65
字号
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "linux_logo.h"
#define  height 80
#define  width  80

static int allwidth=640, allheight=480, bpp=16;
#define FBDEV		"/dev/fb/0"
#define FBSIZE		(allwidth*allheight*bpp/8)



int  main()
{
    int row,col,background,count;
	int fb;
	unsigned char* fb_mem;
//	unsigned short int *p=(unsigned short int*)fb_mem;
	unsigned short int *p;

	fb = open (FBDEV, O_RDWR);
	if(fb<0){
		printf("device %s open failed\n", FBDEV);
		return -1;
	}

	fb_mem = mmap (NULL, FBSIZE, PROT_READ|PROT_WRITE,MAP_SHARED,fb,0);
	
   if(fb_mem==NULL){
		printf("mmap failed\n");
		
		close(fb);
		return -1;
	}

	memset (fb_mem, 0x0, FBSIZE);
   p=(unsigned short int*)fb_mem;

	for(row=1;row<=allheight;row++)
	{
        for(col=1;col<=allwidth;col++)
		{
			if((col<=width) && (row<=height)){

		           count=linux_logo[(row-1)*80+col-1]-0x20;
//				  background = ((background << 8)/8) | ((background << 8)/4) | ((background << 8)/8);
				  background=((linux_logo_red[count]>>3)<<11) | ((linux_logo_green[count]>>2)<<5) | (linux_logo_blue[count]>>3);
	             }
			else background=0x0;
				*p=background;
				p++;
		//		printf("%d",background);

         // getchar();
		}

       }      

}

⌨️ 快捷键说明

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