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

📄 ewm.c

📁 EGui是一个开源的图形系统软件,类似于QT/Embedded、GTK-FB、MicroWindow。目标是嵌入式平台整合解 决方案。基于Linux Framebuffer 设备驱动上实现。有完
💻 C
字号:
#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <string.h>#include <Egui.h>#include "bmp.h"EGui_FBinfo Efbinfo;char *read_file (const char* filename, size_t* length){  int fd;  struct stat file_info;  char* buffer;  /* Open the file.  */  fd = open (filename, O_RDONLY);  if (fd<0)    {      printf ("Open file %s error\n",filename);      exit ;    }  /* Get information about the file.  */  fstat (fd, &file_info);  *length = file_info.st_size;  /* Make sure the file is an ordinary file.  */  if (!S_ISREG (file_info.st_mode)) {    /* It's not, so give up.  */    close (fd);    return NULL;  }  /* Allocate a buffer large enough to hold the file's contents.  */  buffer = (char*) malloc (*length);  if (buffer ==NULL)    {      printf ("malloc file buffer error\n");      return NULL;    }  /* Read the file into the buffer.  */  read (fd, buffer, *length);  /* Finish up.  */  close (fd);  return buffer;}intmain(int argc, char **argv){  unsigned char * rgbbuf;  int width,height;  Ecolor *bgcolor;  EGui_Window * ewindow;    if (argc <2)    {      printf (" A 24 bits BMP capture program for Egui\n");      printf ("usage : %s filename\n",argv[0]);      return;    }  if (Egui_open (&Efbinfo))    return ;  bgcolor = malloc (sizeof ( Ecolor));  if (bgcolor == NULL)    {      printf ("malloc color ERROR\n");      return -1;    }  bgcolor->r = bgcolor->g = bgcolor->b = 0xcc;  ewindow = Egui_CreateWindow (&Efbinfo,0,0,Efbinfo.screen_width - 1,			       Efbinfo.screen_height - 1,bgcolor,EGUI_WINDOW_ROOT);  if (ewindow == NULL)    {      printf ("New windows failed\n");      Egui_close ();      return 1;    }  /*do display windows*/  width  = Efbinfo.screen_width  ;  height = Efbinfo.screen_height ;  rgbbuf = (unsigned char *) malloc ( width * height * 3);  if (rgbbuf == NULL)    {      printf ("Get a buffer for RGB error!\n");      return ;    }  get_bmpbuf(width,height,rgbbuf,argv[1]);  Egui_drawrgb (0,0,width,height,rgbbuf,ewindow);  egui_loop ();  free(rgbbuf);  Egui_CloseWindow (ewindow);  free(bgcolor);  Egui_close ();}int get_bmpbuf(int width,int height,char * rgbbuf, char * filename){  char *buffer;  size_t length;  BITMAPFILE *bm;  int i,j;  char pad_num;  char *aBitmapBits;  int tmpwidth;    buffer = read_file(filename, &length);  bm = (BITMAPFILE *)buffer;    if (bm->bmfh.bfType!=0x4D42 || bm->bmih.biBitCount != 24)    {      printf("Not a 24bit BITMAP.\n");      return -1;    }  if ( bm->bmih.biCompression != 0)    {      printf ("I'm sorry,i don't read compression BMP file\n");      return -1;    }	  pad_num = bm->bmih.biWidth * 3 %4==0? 0 : 4 - bm->bmih.biWidth * 3 %4;  aBitmapBits = (char *)((char *)bm + bm->bmfh.bfOffBits);    if (height > bm->bmih.biHeight)    height = bm->bmih.biHeight;    tmpwidth = width;  if (width > bm->bmih.biWidth)    tmpwidth = bm->bmih.biWidth;      for (j=0,i=height-1; j < height; j ++,i--)    {    //line copy       memcpy((rgbbuf + j * width * 3), (void *)(aBitmapBits + i * (bm->bmih.biWidth * 3 + pad_num)),tmpwidth * 3);	    }  free(buffer);    return 0;}

⌨️ 快捷键说明

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