time 
设为首页】【收藏本站
当前位置: 主页 > Unix/Linux > Linux管理 > Linux维护 > 嵌入式linux通用截图工具

嵌入式linux通用截图工具

时间:2009-11-27 00:00 点击:5193次 字体:[ ]




程序非原创,是在李先静的工具基础上增加了保存为png格式的支持,在基于framebuffer的x86上和android模拟器上测试成功。下载地址如下:http://blogimg.chinaunix.net/blog/upfile2/090828170135.bz2
源代码如下
/*
* File:    gsnap.c
* Author:  Li XianJing
* Brief:   snap the linux mobile device screen.
*
* Copyright (c) 2009  Li XianJing
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/*
* History:
* ================================================================
* 2009-08-20 Li XianJing  created
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "jpeglib.h"
#include
struct FB
{
    int fd;
    unsigned size;
    unsigned short *bits;
    struct fb_fix_screeninfo fi;
    struct fb_var_screeninfo vi;
};
#define fb_width(fb) ((fb)->vi.xres)
#define fb_height(fb) ((fb)->vi.yres)
#define fb_size(fb) ((fb)->vi.xres * (fb)->vi.yres * 2)
static int fb_open(struct FB *fb, const char* fbfilename)
{
    fb->fd = open(fbfilename, O_RDWR);
    if (fb->fd fd, FBIOGET_FSCREENINFO, &fb->fi) fd, FBIOGET_VSCREENINFO, &fb->vi) bits = mmap(0, fb_size(fb), PROT_READ | PROT_WRITE,
                    MAP_SHARED, fb->fd, 0);
    if (fb->bits == MAP_FAILED)
        goto fail;
    return 0;
fail:
    printf("%s is not a framebuffer.\n", fbfilename);
    close(fb->fd);
    return -1;
}
static void fb_close(struct FB *fb)
{
    munmap(fb->bits, fb_size(fb));
    close(fb->fd);
}
static int snap2jpg(const char * filename, int quality, struct FB* fb)
{
    int row_stride = 0;
    FILE * outfile = NULL;
    JSAMPROW row_pointer[1] = {0};
    struct jpeg_error_mgr jerr = {0};
    struct jpeg_compress_struct cinfo = {0};
    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_compress(&cinfo);
    if ((outfile = fopen(filename, "wb+")) == NULL)
    {
        fprintf(stderr, "can't open %s\n", filename);
        return -1;
    }
    jpeg_stdio_dest(&cinfo, outfile);
    cinfo.image_width = fb_width(fb);
    cinfo.image_height = fb_height(fb);
    cinfo.input_components = 3;
    cinfo.in_color_space = JCS_RGB;
    jpeg_set_defaults(&cinfo);
    jpeg_set_quality(&cinfo, quality, TRUE);
    jpeg_start_compress(&cinfo, TRUE);
    row_stride = fb_width(fb) * 2;
    JSAMPLE* image_buffer = malloc(3 * fb_width(fb));
    while (cinfo.next_scanline bits + cinfo.next_scanline * fb_width(fb);
        for(i = 0; i > 11) & 0xff) > 5) & 0xff)  bits + i * width;
        for(j = 0; j > 11) & 0xff) > 5) & 0xff)  << 2;
            image_buffer[offset + 2] = (line[j] & 0xff )<< 3;
        }
        row_pointers = image_buffer;
        png_write_rows(png_ptr, &row_pointers, 1);
    }
   
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(outfile);
    return 0;
}
int main(int argc, char* argv[])
{
    struct FB fb = {0};
    const char* filename   = NULL;
    const char* fbfilename = NULL;
    if(argc != 3)
    {
        printf("\nusage: %s [jpeg/png] [framebuffer]\n", argv[0]);
        printf("-----------------------------------------\n");
        printf("Powered by broncho(www.broncho.cn)\n");
        return 0;
    }
    filename   = argv[1];
    fbfilename = argv[2];
    if (fb_open(&fb, fbfilename) == 0)
    {
        char *extname = strrchr(argv[1],'.');
        if(!strcasecmp( extname+1, "jpg" ) || !strcasecmp( extname+1, "jpeg" ) )
            snap2jpg(filename, 100, &fb);
        else if (!strcasecmp( extname+1, "png" ))
            snap2png(filename,100,&fb);
        else
                printf("Unsupported file format!\n");
        fb_close(&fb);
    }
    return 0;
}




本文地址 : http://www.fengfly.com/plus/view-163880-1.html
标签: 嵌入式 截图 工具 通用 fb #include The
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码: