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

📄 rgb_4p.c

📁 it s a source code for how to integrate your tvp5150 decoder with driver and how to capture an image
💻 C
字号:
/*  * Copyright (C) 2003 Samsung Electronics          SW.LEE <hitchcar@samsung.com>    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.*/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <ctype.h>#include <errno.h>#include <sys/mman.h>#include <sys/time.h>#include <sys/ioctl.h>#include "userapp.h"static camif_param_t camif_cfg;//#define CAM_WIDTH 240//#define CAM_HEIGHT 180#define CAM_WIDTH 320#define CAM_HEIGHT 240#if 0#define FB_WIDTH 320#define FB_HEIGHT 240#else#define FB_WIDTH 800#define FB_HEIGHT 480#endif#define CODEC_NAME  "/dev/misc/preview"#define FB_NAME    "/dev/fb0" static int cam_fp = -1;static int fb_fp = -1;static char *fb = NULL;static inline int cam_init(void){    int dev_fp = -1;    printf("cam_init() start\n");	dev_fp = open(CODEC_NAME, O_RDWR);        if (dev_fp < 0) {        perror(CODEC_NAME);        return -1;    }    printf("cam_init() end\n");    return dev_fp;}static inline int fb_init(void){    int dev_fp = -1;    printf("fb_init() start\n");    dev_fp = open(FB_NAME, O_RDWR);    if (dev_fp < 0) {        perror(FB_NAME);        return -1;    }    if ((fb = (char*)mmap(0, FB_WIDTH*FB_HEIGHT*2,             PROT_READ | PROT_WRITE, MAP_SHARED, dev_fp, 0)) < 0) {        perror("mmap()");        return -1;    }    printf("fb_init() end\n");    return dev_fp;}static inline int read_data(int fp, char *buf, int width, int height, int bpp){    int ret;    usleep(20000);     if ( bpp == 16)  {        if ((ret = read(fp, buf, width*height*2)) != width*height*2)            return 0;     }    else {        if ((ret = read(fp, buf, width*height*4)) != width*height*4)            return 0;     }    return ret;}static inline void clear(char *dest){    memset(dest, 0xff, FB_WIDTH*FB_HEIGHT*2);}#define MAX(x,y) ((x)>(y)?(x):(y))#define MIN(x,y) ((x)>(y)?(y):(x))static inline void draw(char *dest, char *src, int width, int height, int bpp){    int x,y;    unsigned short *rgb16;     unsigned long *rgb32;    int end_y = MIN(FB_HEIGHT, height);    int end_x = MIN(FB_WIDTH, width);    //printf("end_y = %d, end_x = %d, bpp = %d\n", end_y, end_x, bpp);    //printf("FB_WIDTH = %d, width = %d\n", FB_WIDTH, width);    if (bpp==16) {        for (y=0;y<end_y;y++) {            memcpy(dest+y*FB_WIDTH*2, src+y*width*2, end_x*2);        }    } else {        for (y=0; y<end_y;y++) {            rgb32 = (unsigned long*)(src + y * width * 4 );            rgb16 = (unsigned short*)(dest + y * FB_WIDTH * 2);            for (x=0;x<end_x;x++) {                *rgb16 =  (*rgb32>>8)&0xF800 | (*rgb32>>5)&0x07E0 |                      (*rgb32>>3)&0x001F ;                rgb32++;                rgb16++;            }        }    }}static inline void print_fps(struct timeval *s, struct timeval *e){    unsigned long time;    unsigned long sec;    unsigned long usec;    int fps = 0;    sec = e->tv_sec - s->tv_sec;    if (e->tv_usec > s->tv_usec)        usec = e->tv_usec - s->tv_usec;    else {        usec = e->tv_usec + 1000000 - s->tv_usec;           sec--;    }    time = sec * 1000 + (usec+1) / 1000;    fps = 1000 / (time / 30);    printf("%d fps\n", fps);}#define INPUT_NUM 6int main(int argc, char *argv[]){    unsigned char rgb[640*480*4]; // MAX    unsigned int frames = 0;    struct timeval start_tv, end_tv;    struct timezone tz;    int width, height, bpp;    int goal;    int found = 0;    char inp_test;    if (argc != INPUT_NUM) {        printf("%s <width> <height> <bpp> <num> <flip>\n", argv[0]);        printf("          bpp: 16, 24 \n");        printf("          num:\n");        printf("        0 is non-stop capturing\n"               "        X is the capture count\n");        printf("          flip: \n"               "        0 is normal \n"               "        1 is x-axis mirrorX \n"               "        2 is y-axis mirrorX \n"               "        3 is 180 rotation \n");        printf("EX) \n"                        "   T_SHELL>  %s 240 320 16 0 0 \n", argv[0]);        return 0;    }    camif_cfg.dst_x = width = atoi(argv[1]);    camif_cfg.dst_y = height = atoi(argv[2]);    if (  width>640 || height > 480 )  {        printf("  Camera H/W Preview don't support over 640x480 \n");        return 1;    }                bpp = atoi(argv[3]);    if ((bpp!=16) && (bpp!=24)) {        printf("BPP must be 16 or 24\n");        return 0;    }    if (bpp==16) camif_cfg.bpp = 16;    else camif_cfg.bpp = 24;    goal = atoi(argv[4]);    camif_cfg.flip = atoi(argv[5]);    if ((cam_fp = cam_init()) < 0) goto err;    if ((fb_fp = fb_init()) < 0) goto err;    printf("DISPLAY: BPP(%d) width(%d), height(%d)\n",             bpp, MIN(FB_WIDTH, width), MIN(FB_HEIGHT, height));    fflush(stdout);    if (ioctl(cam_fp, CMD_CAMERA_INIT, &camif_cfg)) {        perror("ioctl");        goto err;    }    //clear(fb); // clear termincal screen    gettimeofday(&start_tv, &tz);    /* Start Camera */    write(cam_fp,"O",2);    while (!found) {        //printf("w");        if (!read_data(cam_fp, &rgb[0], width, height, bpp)) {            printf("there is no data\n");            break;        }        draw(fb, &rgb[0], width, height, bpp);        frames ++;        if (frames == goal)  {            found = 1;            break;        }        #if 1        if ((frames % 30) == 0) {            gettimeofday(&end_tv, &tz);            print_fps(&start_tv, &end_tv);            gettimeofday(&start_tv, &tz);        }        #endif    }    /* Stop Camera */    write(cam_fp,"X",2);err:    if (cam_fp) close(cam_fp);    if (fb) munmap(fb, FB_WIDTH*FB_HEIGHT*2);    if (fb_fp) close(fb_fp);    return 0;}

⌨️ 快捷键说明

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