Chinaunix首页 | 论坛 | 博客
  • 博客访问: 334299
  • 博文数量: 89
  • 博客积分: 5152
  • 博客等级: 大校
  • 技术积分: 1155
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-25 15:12
文章分类

全部博文(89)

文章存档

2012年(1)

2011年(5)

2010年(14)

2009年(69)

我的朋友

分类: 嵌入式

2011-02-22 11:49:52

http://code.google.com/p/android-screenshot-library/

代码如下

main.c

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>

  4. #include <errno.h>
  5. #include <signal.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <arpa/inet.h>

  10. #define _GNU_SOURCE
  11. #include <getopt.h>

  12. #include "common.h"

  13. #define PORT 42380
  14. #define BUF_SIZE 256
  15. #define SCREENSHOT_CMD "SCREEN"

  16. #ifdef DEBUG
  17. FILE* logFile;
  18. #endif


  19. inline void Log(const char* msg)
  20. {
  21. #ifdef DEBUG
  22.     if (errno != 0 && logFile == stderr)
  23.     {
  24.         char buf[BUF_SIZE];
  25.         snprintf (buf, BUF_SIZE, "%s (errno=%d)", msg, errno);
  26.         perror (buf);
  27.         exit (1);
  28.     }
  29.     else    fprintf(logFile, "%s\n", msg);
  30.     fflush (logFile);
  31. #endif
  32. }


  33. volatile sig_atomic_t end = 0;
  34. void sig_INT(int sig)    { fprintf(logFile, "------ Caught signal %d -----\n", sig); if (sig == SIGINT || sig == SIGSEGV) end = 1; }


  35. ssize_t Receive(int sfd, char* buf, size_t count, int flags)
  36. {
  37.     int c;
  38.     size_t len = 0;

  39.     do
  40.     {
  41.         c = recv(sfd, buf, count, flags);
  42.         if (c < 0)    return c;
  43.         if (c == 0)    return len;

  44.         buf += c;
  45.         len += c;
  46.         count -= c;
  47.     } while (count > 0);

  48.     return len;
  49. }

  50. ssize_t Send(int sfd, const char* buf, ssize_t count, int flags)
  51. {
  52.     int c;
  53.     size_t len = 0;

  54.     do
  55.     {
  56.         c = send(sfd, buf, count, flags);
  57.         if (c < 0)    return c;

  58.         buf += c;
  59.         len += c;
  60.         count -= c;

  61. //#ifdef DEBUG
  62. //        char msg[BUF_SIZE];
  63. //        snprintf (msg, BUF_SIZE, "-- Sent %d bytes (%d total, %d remaining)", c, len, count);
  64. //        Log (msg);
  65. //#endif
  66.     } while (count > 0);

  67.     return len;
  68. }


  69. int start_server()
  70. {
  71.     Log("Starting server...");
  72.     int sfd = socket(AF_INET, SOCK_STREAM, 0);
  73.     if (sfd < 0)    return -1;
  74.     Log("- Socket creation");
  75.     
  76.     struct sockaddr_in sin;
  77.     sin.sin_family = PF_INET;
  78.     sin.sin_port = htons(PORT);
  79.     sin.sin_addr.s_addr = htonl(INADDR_ANY);
  80.     if (bind (sfd, (struct sockaddr*)&sin, sizeof(struct sockaddr_in)) < 0)
  81.         return -1;
  82.     Log("- Socket binding");

  83.     if (listen (sfd, 5) < 0)    return -1;
  84.     Log ("- Socket in listening mode");
  85.     struct linger l = { 0, 0 };
  86.     if (setsockopt(sfd, SOL_SOCKET, SO_LINGER, (const void*)&l, sizeof(struct linger)) < 0)
  87.         return -1;
  88.     Log("Server started.");

  89.     // get local address and display it
  90.     #if DEBUG
  91.         socklen_t sin_len = sizeof(struct sockaddr_in);
  92.         getsockname (sfd, (struct sockaddr*)&sin, &sin_len);
  93.         char msg[BUF_SIZE];
  94.         snprintf (msg, BUF_SIZE, "Listening on %s:%d", inet_ntoa(sin.sin_addr), PORT);
  95.         Log (msg);
  96.     #endif

  97.     return sfd;
  98. }

  99. int setup_signals()
  100. {
  101.     Log("Signal handling setup");

  102.     struct sigaction sa;

  103. //    // handle SIGINT
  104. //    sa.sa_handler = sig_INT;
  105. //    sigemptyset (&sa.sa_mask);
  106. //    sa.sa_flags = 0;
  107. //    if (sigaction(SIGINT, &sa, NULL) < 0)    return -1;
  108. //
  109. //    // ignore SIGHUP
  110. //    sa.sa_handler = SIG_IGN;
  111. //    sigemptyset (&sa.sa_mask);
  112. //    sa.sa_flags = 0;
  113. //    if (sigaction(SIGHUP, &sa, NULL) < 0)    return -1;

  114.     int i;
  115.     for (i = 1; i < 30; ++i) {
  116.         sa.sa_handler = sig_INT;
  117.         sigemptyset (&sa.sa_mask);
  118.         sa.sa_flags = 0;
  119.         sigaction(i, &sa, NULL);
  120.     }
  121.     errno = 0;

  122.     return 0;
  123. }

  124. int accept_client(int servfd, int** client_fd, int* client_count)
  125. {
  126.     Log ("Incoming client connection");

  127.     int cfd = accept(servfd, NULL, NULL);
  128.     if (cfd < 0)    return -1;
  129.     Log ("- Connection accepted");

  130.     /* check whether the client comes from local system; detach if not */
  131.     struct sockaddr_in client_addr;
  132.     socklen_t ca_len = sizeof(struct sockaddr_in);
  133.     if (getpeername(cfd, (struct sockaddr*)&client_addr, &ca_len) < 0)    return -1;
  134.     if (strcmp(inet_ntoa(client_addr.sin_addr), "127.0.0.1") != 0) {
  135.         Log ("- Remote client detected -- closing connection.");
  136.         shutdown (cfd, SHUT_RDWR);
  137.         close (cfd);
  138.         return 0;
  139.     }

  140.     *client_fd = (int*)realloc(*client_fd, sizeof(int) * (*client_count + 1));
  141.     (*client_fd)[(*client_count)++] = cfd;    // (*client_fd)[...] != *client_fd[...] -- f'kin precedence ;/

  142.     return cfd;
  143. }

  144. int handle_client_input(int cfd, char* fddev)
  145. {
  146.     Log ("Client socket signaled for input");
  147.     struct picture pict;
  148.     char buf[BUF_SIZE];
  149.     int c;    
  150.     
  151.     /* read input and parse it */
  152.     Log ("- Retreiving data");
  153.     c = Receive(cfd, buf, strlen(SCREENSHOT_CMD), 0);
  154.     if (c == 0 || (c < 0 && errno == EINTR))    return 0;
  155.     if (c < 0)    return -1;
  156.     if (c >= strlen(SCREENSHOT_CMD) && (buf[strlen(SCREENSHOT_CMD)] = '\0', strcmp(buf, SCREENSHOT_CMD) == 0))
  157.     {
  158.         Log ("- Command identified as " SCREENSHOT_CMD);

  159.         /* screenshot command read; take screenshot and post it through socket */
  160.         Log ("- Taking screenshot");
  161.         if (TakeScreenshot(fddev, &pict) < 0)    return -1;
  162.         Log ("- Screenshot taken");
  163.         
  164.         /* header: width height BPP */
  165.         memset (buf, 0, BUF_SIZE * sizeof(char));
  166.         snprintf (buf, BUF_SIZE, "%d %d %d", pict.xres, pict.yres, pict.bps);
  167.         if (Send(cfd, buf, (strlen(buf) + 1) * sizeof(char), 0) < 0)    /* incl. \0 */
  168.             return -1;
  169.         Log (buf);
  170.         Log ("- Response header sent.");

  171.         /* content */
  172.         if (Send(cfd, pict.buffer, pict.xres * pict.yres * pict.bps / 8, 0) < 0)
  173.             return -1;
  174.         Log ("- Screenshot sent");
  175.     }

  176.     return c;
  177. }

  178. int cleanup(int servfd, int* client_fd, int client_count)
  179. {
  180.     Log ("Shutdown");
  181.     int i;
  182.     for (i = 0; i < client_count; ++i)
  183.         if (close(client_fd[i]) < 0)    return -1;
  184.     free (client_fd);

  185.     Log ("- Closing server socket");
  186.     if (close(servfd) < 0)    return -1;

  187.     Log ("Shutdown complete");

  188. #ifdef DEBUG
  189.     if (logFile != stderr)    fclose (logFile);
  190. #endif
  191.     return 0;
  192. }

  193. int do_work(int servfd, char* fbDevice)
  194. {
  195.     int* client_fd = NULL;
  196.     int client_count = 0;
  197.     int max_fd;
  198.     fd_set readfs;
  199.     int i, c;

  200.     Log ("Starting main loop.");
  201.     while (!end)
  202.     {
  203.         /* fill fd_set to check sockets for reading (client and server ones) */
  204.         Log ("<< select() on sockets... >>");
  205.         FD_ZERO(&readfs); max_fd = 0;
  206.         FD_SET(servfd, &readfs);
  207.         if (servfd > max_fd)    max_fd = servfd;
  208.         for (i = 0; i < client_count; ++i)
  209.         {
  210.             if (client_fd[i] < 0)    continue;

  211.             FD_SET (client_fd[i], &readfs);
  212.             if (client_fd[i] > max_fd)    max_fd = client_fd[i];
  213.         }

  214.         if (select(max_fd + 1, &readfs, NULL, NULL, NULL) == -1)
  215.         {
  216.             if (errno == EINTR)    { errno = 0; continue; }
  217.             return -1;
  218.         }

  219.         /* check for input on client socket and handle it */
  220.         for (i = 0; i < client_count; ++i)
  221.         {
  222.             if (client_fd[i] < 0)    continue;
  223.             if (FD_ISSET(client_fd[i], &readfs))
  224.             {
  225.                 c = handle_client_input (client_fd[i], fbDevice);
  226.                 if (c < 0 && errno != EPIPE && ECONNRESET)    return -1;
  227.                 
  228.                 /* connection finished */
  229.                 close (client_fd[i]);
  230.                 client_fd[i] = -1;    // no socket
  231.             }
  232.         }

  233.         /* check whether we have incoming connection */
  234.         if (FD_ISSET(servfd, &readfs))
  235.             if (accept_client (servfd, &client_fd, &client_count) < 0)
  236.                 return -1;
  237.     }
  238.     Log ("- Caught SIGINT");

  239.     return cleanup(servfd, client_fd, client_count);
  240. }


  241. int main(int argc, char* argv [])
  242. {
  243. #ifdef DEBUG
  244.     // optional logging to file
  245.     if (argc >= 2) {
  246.         logFile = fopen(argv[1], "a+");
  247.     }
  248.     else
  249.         logFile = stderr;
  250. #endif
  251.     Log ("Program initialized");

  252.     char* device;
  253.     device = "/dev/graphics/fb0";

  254.     int server_socket = start_server();
  255.     if (server_socket < 0)
  256.         Log ("Error while starting server");
  257.     if (setup_signals() < 0)
  258.         Log ("Error while setting up signals");

  259. //    Log ("Going into background -- have nice day.");
  260. //    if (setsid () < 0)    Log("Error while going into background");
  261.     if (do_work (server_socket, device) < 0)
  262.         Log ("Error in main loop");
  263. }

fbshot.c

  1. /*
  2.  * fbshot.c -- FrameBuffer Screen Capture Utility
  3.  * (C)opyright 2002 sfires@sfires.net
  4.  *
  5.  * Originally Written by: Stephan Beyer
  6.  * Further changes by: Paul Mundt
  7.  * Rewriten and maintained by: Dariusz Swiderski
  8.  * Modular version by: Karol Kuczmarski
  9.  *
  10.  *     This is a simple program that generates a
  11.  * screenshot of the specified framebuffer device and
  12.  * terminal and writes it to a specified file using
  13.  * the PNG format.
  14.  *
  15.  * See ChangeLog for modifications, CREDITS for credits.
  16.  *
  17.  * fbshot is free software; you can redistribute it and/or
  18.  * modify it under the terms of the GNU General Public License
  19.  * as published by the Free Software Foundation; either Version 2
  20.  * of the License, or (at your option) any later version.
  21.  *
  22.  * fbshot is distributed in the hope that it will be useful, but
  23.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25.  * GNU General Public License for more details.
  26.  *
  27.  * You should have received a copy of the GNU General Public
  28.  * License with fbshot; if not, please write to the Free Software
  29.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  30.  * 02111-1307 USA
  31.  */
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <stdarg.h>
  35. #include <string.h>
  36. #include <unistd.h>
  37. #include <getopt.h>
  38. #include <fcntl.h>
  39. #include <byteswap.h>
  40. #include <sys/types.h>
  41. #include <asm/types.h>
  42. #include <sys/stat.h>
  43. #include <sys/ioctl.h>
  44. #include <mntent.h>
  45. #include <errno.h>
  46. #include <sys/utsname.h>

  47. #include <sys/vt.h>
  48. #include <linux/fb.h>

  49. #include "common.h"

  50. #define DEFAULT_FB "/dev/fb0"
  51. #define PACKAGE     "fbshot"
  52. #define VERSION     "0.3.1"
  53. #define MAINTAINER_NAME "Dariusz Swiderski"
  54. #define MAINTAINER_ADDR "sfires@sfires.net"

  55. static int waitbfg=0; /* wait before grabbing (for -C )... */


  56. /* some conversion macros */
  57. #define RED565(x) ((((x) >> (11 )) & 0x1f) << 3)
  58. #define GREEN565(x) ((((x) >> (5 )) & 0x3f) << 2)
  59. #define BLUE565(x) ((((x) >> (0)) & 0x1f) << 3)

  60. #define ALPHA1555(x) ((((x) >> (15)) & 0x1 ) << 0)
  61. #define RED1555(x) ((((x) >> (10)) & 0x1f) << 3)
  62. #define GREEN1555(x) ((((x) >> (5 )) & 0x1f) << 3)
  63. #define BLUE1555(x) ((((x) >> (0 )) & 0x1f) << 3)

  64. void FatalError(char* err){
  65.   fprintf(stderr,"An error occured: %s %s\nExiting now...\n",err,strerror(errno));
  66.   fflush(stderr);
  67.   exit (1);
  68. }

  69. void Usage(char *binary){
  70.   printf("Usage: %s [-ghi] [-{C|c} vt] [-d dev] [-s n] filename.png\n", binary);
  71. }

  72. void Help(char *binary){
  73.     printf("FBShot - makes screenshots from framebuffer, v%s\n", VERSION);
  74.     printf("\t\tby Dariusz Swiderski \n\n");

  75.     Usage(binary);

  76.     printf("\nPossible options:\n");
  77.     printf("\t-C n \tgrab from console n, for slower framebuffers\n");
  78.     printf("\t-c n \tgrab from console n\n");
  79.     printf("\t-d dev\tuse framebuffer device dev instead of default\n");
  80. /* not supported as for now
  81.     printf("\t-g \tsave a grayscaled PNG\n");
  82.  */
  83.     printf("\t-h \tprint this usage information\n");
  84.     printf("\t-i \tturns OFF interlacing\n");
  85.     printf("\t-s n \tsleep n seconds before making screenshot\n");

  86.     printf("\nSend feedback !!!\n");
  87. }

  88. void chvt(int num){
  89.   int fd;
  90.   if(!(fd = open("/dev/console", O_RDWR)))
  91.     FatalError("cannot open /dev/console");
  92.   if (ioctl(fd, VT_ACTIVATE, num))
  93.     FatalError("ioctl VT_ACTIVATE ");
  94.   if (ioctl(fd, VT_WAITACTIVE, num))
  95.     FatalError("ioctl VT_WAITACTIVE");
  96.   close(fd);
  97.   if (waitbfg)
  98.     sleep (3);
  99. }

  100. unsigned int create_bitmask(struct fb_bitfield* bf) {

  101.     return ~(~0u << bf->length) << bf->offset;
  102. }

  103. // Unifies the picture's pixel format to be 32-bit ARGB
  104. void unify(struct picture *pict, struct fb_var_screeninfo *fb_varinfo) {

  105.     __u32 red_mask, green_mask, blue_mask;
  106.     __u32 c;
  107.     __u32 r, g, b;
  108.     __u32* out;
  109.     int i, j = 0, bytes_pp;

  110.     // build masks for extracting colour bits
  111.     red_mask = create_bitmask(&fb_varinfo->red);
  112.     green_mask = create_bitmask(&fb_varinfo->green);
  113.     blue_mask = create_bitmask(&fb_varinfo->blue);

  114.     // go through the image and put the bits in place
  115.     out = (__u32*)malloc(pict->xres * pict->yres * sizeof(__u32));
  116.     bytes_pp = pict->bps >> 3;
  117.     for (i = 0; i < pict->xres * pict->yres * bytes_pp; i += bytes_pp) {

  118.         memcpy (((char*)&c) + (sizeof(__u32) - bytes_pp), pict->buffer + i, bytes_pp);

  119.         // get the colors
  120.         r = ((c & red_mask) >> fb_varinfo->red.offset) & ~(~0u << fb_varinfo->red.length);
  121.         g = ((c & green_mask) >> fb_varinfo->green.offset) & ~(~0u << fb_varinfo->green.length);
  122.         b = ((c & blue_mask) >> fb_varinfo->blue.offset) & ~(~0u << fb_varinfo->blue.length);

  123.         // format the new pixel
  124.         out[j++] = (0xFF << 24) | (b << 16) | (g << 8) | r;
  125.     }

  126.     pict->buffer = (char*)out;
  127.     pict->bps = 32;
  128. }


  129. int read_fb(char *device, int vt_num, struct picture *pict){
  130.   int fd, vt_old, i,j;
  131.   struct fb_fix_screeninfo fb_fixinfo;
  132.   struct fb_var_screeninfo fb_varinfo;
  133.   struct vt_stat vt_info;

  134.   if (vt_num!=-1){
  135.     if ((fd = open("/dev/console", O_RDONLY)) == -1)
  136.       FatalError("could not open /dev/console");
  137.     if (ioctl(fd, VT_GETSTATE, &vt_info))
  138.       FatalError("ioctl VT_GETSTATE");
  139.     close (fd);
  140.     vt_old=vt_info.v_active;
  141.   }

  142.   if(!(fd=open(device, O_RDONLY)))
  143.     FatalError("Couldn't open framebuffer device");

  144.   if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_fixinfo))
  145.     FatalError("ioctl FBIOGET_FSCREENINFO");

  146.   if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_varinfo))
  147.     FatalError("ioctl FBIOGET_VSCREENINFO");

  148.   pict->xres=fb_varinfo.xres;
  149.   pict->yres=fb_varinfo.yres;
  150.   pict->bps=fb_varinfo.bits_per_pixel;
  151.   pict->gray=fb_varinfo.grayscale;

  152.   if(fb_fixinfo.visual==FB_VISUAL_PSEUDOCOLOR){
  153.     pict->colormap=(struct fb_cmap*)malloc(sizeof(struct fb_cmap));
  154.     pict->colormap->red=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  155.     pict->colormap->green=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  156.     pict->colormap->blue=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  157.     pict->colormap->transp=(__u16*)malloc(sizeof(__u16)*(1<<pict->bps));
  158.     pict->colormap->start=0;
  159.     pict->colormap->len=1<<pict->bps;
  160.     if (ioctl(fd, FBIOGETCMAP, pict->colormap))
  161.       FatalError("ioctl FBIOGETCMAP");
  162.   }
  163.   if (vt_num!=-1)
  164.     chvt(vt_old);

  165.   switch(pict->bps){
  166.   case 15:
  167.     i=2;
  168.     break;
  169.   default:
  170.     i=pict->bps>>3;
  171.   }

  172.   if(!(pict->buffer=malloc(pict->xres*pict->yres*i)))
  173.     FatalError("couldnt malloc");

  174. // fprintf(stdout, "Framebuffer %s is %i bytes.\n", device,
  175. // (fb_varinfo.xres * fb_varinfo.yres * i));
  176. // fprintf(stdout, "Grabbing %ix%i ... \n", fb_varinfo.xres, fb_varinfo.yres);
  177. //
  178. //#ifdef DEBUG
  179. ///* Output some more information bout actual graphics mode
  180. // */
  181. // fprintf(stdout, "%ix%i [%i,%i] %ibps %igr\n",
  182. //     fb_varinfo.xres_virtual, fb_varinfo.yres_virtual,
  183. //     fb_varinfo.xoffset, fb_varinfo.yoffset,
  184. //     fb_varinfo.bits_per_pixel, fb_varinfo.grayscale);
  185. // fprintf(stdout, "FIX: card:%s mem:0x%.8X mem_len:%d visual:%i type:%i type_aux:%i line_len:%i accel:%i\n",
  186. // fb_fixinfo.id,fb_fixinfo.smem_start,fb_fixinfo.smem_len,fb_fixinfo.visual,
  187. // fb_fixinfo.type,fb_fixinfo.type_aux,fb_fixinfo.line_length,fb_fixinfo.accel);
  188. //#endif

  189.   fflush(stdout);
  190.   if (vt_num!=-1)
  191.     chvt(vt_num);

  192.   j= (read(fd, pict->buffer, ((pict->xres * pict->yres) * i) )!=
  193.       (pict->xres * pict->yres *i ));
  194. //#ifdef DEBUG
  195. // printf("to read:%i read:%i\n",(pict->xres* pict->yres * i), j);
  196. //#endif
  197.   if (vt_num!=-1)
  198.     chvt(vt_old);

  199. // if(j)
  200. // FatalError("couldn't read the framebuffer");
  201. // else
  202. // fprintf(stdout,"done.\n");
  203.   close (fd);

  204.   unify(pict, &fb_varinfo);
  205.   return 0;
  206. }


  207. void convert8to32(struct picture *pict){
  208.   int i;
  209.   int j=0;
  210.   __u8 c;
  211.   char *out=(char*)malloc(pict->xres*pict->yres*4);
  212.   for (i=0; i<pict->xres*pict->yres; i++)
  213.   {
  214.     c = ((__u8*)(pict->buffer))[i];
  215.     out[j++]=(char)(pict->colormap->red[c]);
  216.     out[j++]=(char)(pict->colormap->green[c]);
  217.     out[j++]=(char)(pict->colormap->blue[c]);
  218.     out[j++]=(char)(pict->colormap->transp[c]);
  219.   }
  220.   free(pict->buffer);
  221.   pict->buffer=out;
  222. }

  223. void convert1555to32(struct picture *pict){
  224.   int i;
  225.   int j=0;
  226.   __u16 t,c;
  227.   char *out=(char*)malloc(pict->xres*pict->yres*4);
  228.   for (i=0; i<pict->xres*pict->yres; i++)
  229.   {
  230.     c = ( (__u16*)(pict->buffer))[i];
  231.     out[j++]=(char)RED1555(c);
  232.     out[j++]=(char)GREEN1555(c);
  233.     out[j++]=(char)BLUE1555(c);
  234.     out[j++]=(char)ALPHA1555(c);
  235.   }
  236.   free(pict->buffer);
  237.   pict->buffer=out;
  238. }

  239. void convert565to32(struct picture *pict){ // ARGB_8888
  240.   int i;
  241.   int j=0;
  242.   __u16 t,c;
  243.   char *out=(char*)malloc(pict->xres*pict->yres*4);
  244.   for (i=0; i<pict->xres*pict->yres; i++)
  245.   {
  246.     c = ( (__u16*)(pict->buffer))[i];
  247.     out[j++]=(char)0xff;
  248.     out[j++]=(char)RED565(c);
  249.     out[j++]=(char)GREEN565(c);
  250.     out[j++]=(char)BLUE565(c);

  251.   }
  252.   free(pict->buffer);
  253.   pict->buffer=out;
  254. }


  255. static int Write(int fd, char* buf, int c)
  256. {
  257.     int i = 0, r;
  258.     while (i < c)
  259.     {
  260.         r = write(fd, (const void*)(buf + i), c - i);
  261.         i += r;
  262.     }
  263.     return i;
  264. }


  265. #if 0
  266. static int Write_RAW(struct picture* pict, char* filename)
  267. {
  268.   int fd = open(filename, O_CREAT | O_WRONLY | O_SYNC, 0777);
  269.   if (fd < 0)    return -1;

  270.   // convert picture to 32-bit format
  271.   printf ("BPS: %d\n", pict->bps);
  272.   switch (pict->bps)
  273.   {
  274.       case 8:
  275.         convert8to32 (pict);
  276.         break;
  277.     case 15:
  278.         convert1555to32 (pict);
  279.         break;
  280.     case 16:
  281.         convert565to32 (pict);
  282.         break;
  283.     case 32:
  284.         break;
  285.     default:
  286.         return -1;
  287.   }

  288.   Write (fd, pict->buffer, pict->xres*pict->yres*4);
  289.   close (fd);

  290.   return 0;
  291. }
  292. #endif


  293. static char optstring[] = "hiC:c:d:s:";
  294. static struct option long_options[] = {
  295.         {"slowcon", 1, 0, 'C'},
  296.         {"console", 1, 0, 'c'},
  297.         {"device", 1, 0, 'd'},
  298.         {"help", 0, 0, 'h'},
  299.         {"noint", 0, 0, 'i'},
  300.         {"sleep", 1, 0, 's'},
  301.         {0, 0, 0, 0}
  302.         };


  303. int TakeScreenshot (char* device, struct picture* pict)
  304. {
  305.     int vt_num = -1;
  306.     return read_fb(device, vt_num, pict);
  307. }


common.h

  1. #ifndef COMMON_H
  2. #define COMMON_H

  3. struct picture{
  4.   int xres,yres;
  5.   char *buffer;
  6.   struct fb_cmap *colormap;
  7.   char bps,gray;
  8. };

  9. int TakeScreenshot (char* device, struct picture* pict);

  10. #endif

阅读(3379) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~