Пример #1
0
int make_ppm(uint8_t *yuv_buffer, const char *file_name,
             uint32_t width, uint32_t height) {
	unsigned int i;
	unsigned char *rgb_buffer;
	FILE *fd;

	fd = fopen(file_name, "wb");
	if(fd == NULL) {
		perror("make_ppm");
		return -1;
	}
	
	rgb_buffer = (uint8_t *) malloc(3 * width * height);
	convert_yuv_to_rgb_buffer((unsigned char *) yuv_buffer,
	                           rgb_buffer, width, height);

	fprintf(fd, "P3\n%d %d\n255\n", width, height);
	for (i = 0; i < 3*height*width; ++i) {
		fprintf(fd, "%i\n", rgb_buffer[i]);
	}

	free(rgb_buffer);
	fclose(fd);
	return 0;
}
Пример #2
0
static void process_image(const void* p) {
    yuv_img = (unsigned char*)p;
    convert_yuv_to_rgb_buffer(yuv_img, rgb_img, cam_width, cam_height);
#ifdef POINTIT_SDL
    create_sdl_surf();
#endif
}
Пример #3
0
void MyLable::up_date()
{
        rs = vd->get_frame((void **)&p,&len);
        convert_yuv_to_rgb_buffer(p,pp,640,480/*QWidget::width(),QWidget::height()*/);
        frame->loadFromData((uchar *)pp,/*len*/640 * 480 * 3 * sizeof(char));
        vd->unget_frame();
        qDebug("sss\n");
        update();
}
Пример #4
0
//=============================================================================
//
//	g4vl_process_image(THIS,start)
//
//	Process the image found in start and dump the resulting RGB frame into
//	our local frame buffer (THIS->frame). Width, Height and Image size can
//	all be found in THIS->fmt.fmt
//
//	FIXME:: there are lots of formats, I can *only* test YUYV.
//              I'm *assuming* RGB32 is "raw" mode (no conversion)
//		Do "other" RGB formats work without conversion?
//		What other conversion routines do we need?
//		Will BM be moving any/all of these to Image/Picture objects?
//
void gv4l1_process_image (CWEBCAM * _object, void *start)
{
	int format,w,h;
	long size;

	format = THIS->dev->videopict.palette;
	w = THIS->dev->width;
	h = THIS->dev->height;
	size = THIS->dev->buffer_size;

	switch(format) 
	{
		case VIDEO_PALETTE_YUV411P:	gv4l2_debug("YUV411P"); break;
		case VIDEO_PALETTE_YUV420P:	
			//gv4l2_debug("YUV420P");
		case VIDEO_PALETTE_YUV420:
			//gv4l2_debug("YUV420");
			yuv420p_to_rgb (start,THIS->frame,w,h,3);
			return;
		case VIDEO_PALETTE_YUYV:
			//gv4l2_debug("YUYV");
			convert_yuv_to_rgb_buffer(start,THIS->frame,w,h);
			return;

		case VIDEO_PALETTE_GREY:	gv4l2_debug("GREY");	break;
		case VIDEO_PALETTE_HI240:	gv4l2_debug("HI240");	break;
		case VIDEO_PALETTE_RGB565:	gv4l2_debug("RGB5656");	break;
		case VIDEO_PALETTE_RGB24:	gv4l2_debug("RGB24");	break;
		case VIDEO_PALETTE_RGB32:	/* DEFAULT */		break;
		case VIDEO_PALETTE_RGB555:	gv4l2_debug("RGB555");	break;
		case VIDEO_PALETTE_UYVY:	gv4l2_debug("UYVY");	break;
		case VIDEO_PALETTE_YUV411:	gv4l2_debug("YUV411");	break;
		case VIDEO_PALETTE_RAW:		gv4l2_debug("RAW");	break;
		case VIDEO_PALETTE_YUV422P:	gv4l2_debug("YUV422P");	break;
		case VIDEO_PALETTE_YUV410P:	gv4l2_debug("YUV410P");	break;
		case VIDEO_PALETTE_COMPONENT:	gv4l2_debug("COMPONENT");break;
    
		default:
			gv4l2_debug("Frame in unknown format");
			break;
	}
	memcpy(THIS->frame,start,size);
}
Пример #5
0
void *stream_func(void *ptr)
{
    unsigned char *rgb_buffer;
    int ready_buf;
    char cur_name[64];
    int i;

    if( b_shared_mem )
    {
        rgb_buffer = p_shm;
    }
    else
    {
        rgb_buffer = (unsigned char *)malloc(req_width*req_height*3);
    }

    for(i=0; i<total_buffers; i++)
    {
        queue_buffer(i);
    }

    for(;;)
    {
        /* get the idx of ready buffer */
        for(i=0; i<total_buffers; i++)
        {
            /* Check if the thread should stop. */
            if( stream_finish ) return NULL;

		    ready_buf = dequeue_buffer();

            if( b_verbose )
            {
                printf("Buffer %d ready. Length: %uB\n", ready_buf, image_buffers[ready_buf].length);
            }

            switch( check_pixelformat() )
            {
                case V4L2_PIX_FMT_YUYV:
                    /* convert data to rgb */
                    if( b_shared_mem )
                        sem_down(&shm_sem);
                    if( convert_yuv_to_rgb_buffer(
                                        (unsigned char *)(image_buffers[ready_buf].start), 
                                        rgb_buffer, req_width, req_height) == 0 )
                    {
                        if( b_verbose )
                        {
                            printf("\tConverted to rgb.\n");
                        }
                    }
                    if( b_shared_mem )
                        sem_up(&shm_sem);
                    break;
                default:
                    print_pixelformat(stderr);
                    fprintf(stderr,"\n");
                    return NULL;
            }

            /* make the image */

            /* create the file name */
            if( b_named_pipe )
                sprintf(cur_name, "%s", psz_named_pipe);

            switch( e_outfmt )
            {
                case FORMAT_BMP:
                    if( b_shared_mem )
                    {
                        printf("Unsupported!\n");
                        break;
                    }
                    make_bmp(rgb_buffer, 
                             cur_name, 
                             req_width, 
                             req_height);
                    break;
                case FORMAT_RGB:
                    if( b_shared_mem )
                    {
                        /* The buffer is already rgb :) */
                        break;
                    }
                    make_rgb(rgb_buffer, 
                             cur_name, 
                             req_width, 
                             req_height);
                    break;
                default:
                    fprintf(stderr, "Not supported format requested!\n");
                    break;
            }   
            
            queue_buffer(ready_buf);
        }        
    }

    return NULL;
}
Пример #6
0
void *capture_func(void *ptr)
{
    unsigned char *rgb_buffer;
    int ready_buf;
    char cur_name[64];
    int i;
    struct timeval timestamp;

    if( b_shared_mem )
    {
        rgb_buffer = p_shm;
    }
    else
    {
        rgb_buffer = (unsigned char *)malloc(req_width*req_height*3);
    }

    for(;;)
    {
        /* Wait for the start condition */
        pthread_mutex_lock(&cond_mutex);
        pthread_cond_wait(&condition, &cond_mutex);
        pthread_mutex_unlock(&cond_mutex);

        /* queue one buffer and 'refresh it' */
        /* @todo Change 2 to some #define */
        for(i=0; i<2; i++)
        {
            queue_buffer(i);
        }
        for(i=0; i<2 - 1; i++)
        {
            dequeue_buffer();
        }

        /* get the idx of ready buffer */
		ready_buf = dequeue_buffer();

        if( b_verbose )
        {
            printf("Buffer %d ready. Length: %uB\n", ready_buf, image_buffers[ready_buf].length);
        }

        switch( check_pixelformat() )
        {
            case V4L2_PIX_FMT_YUYV:
                /* convert data to rgb */
                if( convert_yuv_to_rgb_buffer(
                                    (unsigned char *)(image_buffers[ready_buf].start), 
                                    rgb_buffer, req_width, req_height) == 0 )
                {
                    if( b_verbose )
                    {
                        printf("\tConverted to rgb.\n");
                    }
                }
                break;
            default:
                print_pixelformat(stderr);
                fprintf(stderr,"\n");
                return NULL;
        }

        timestamp = query_buffer(0);

        /* make the image */

        /* create the file name */
        if( b_named_filename )
        {
            sprintf(cur_name, "%s%s", psz_output_dir, psz_output_filename);
        }
        else if( !b_named_pipe )
            sprintf(cur_name, "%scamshot_%lu.bmp", psz_output_dir, timestamp.tv_sec);
        else
            sprintf(cur_name, "%s", psz_named_pipe);

        switch( e_outfmt )
        {
            case FORMAT_BMP:
                make_bmp(rgb_buffer, 
                         cur_name, 
                         req_width, 
                         req_height);
                break;
            case FORMAT_RGB:
                make_rgb(rgb_buffer, 
                         cur_name, 
                         req_width, 
                         req_height);
                break;
            default:
                fprintf(stderr, "Not supported format requested!\n");
                break;
        }   
    }

    return NULL;
}