Example #1
0
void ucil_fill( unicap_data_buffer_t *buffer, ucil_color_t *color )
{
    switch( buffer->format.fourcc )
    {
    case UCIL_FOURCC( 'U', 'Y', 'V', 'Y' ):
    {
        ucil_fill_uyvy( buffer, color );
    }
    break;

    case UCIL_FOURCC( 'R', 'G', 'B', '3' ):
    {
        ucil_fill_rgb24( buffer, color );
    }
    break;

    case UCIL_FOURCC( 'R', 'G', 'B', '4' ):
    {
        ucil_fill_rgb32( buffer, color );
    }
    break;

    default:
    {
        g_warning( "Operation not defined for color format\n" );
    }
    break;
    }
}
static void prepare_yuv_buffer( unicap_data_buffer_t *buffer, unicap_format_t *format )
{
   unicap_copy_format( &buffer->format, format );
   buffer->format.fourcc = UCIL_FOURCC( 'I', '4', '2', '0' );
   buffer->format.bpp = 12;
   buffer->format.buffer_size = format->size.width * format->size.height * 12 / 8;
   
   buffer->buffer_size = buffer->format.buffer_size;
   buffer->data = malloc( buffer->buffer_size );
/*    start_time = get_time(); */  
}
Example #3
0
unicap_status_t ucil_copy_color_plane( unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf, ucil_color_plane_t plane )
{
    unicap_status_t status = STATUS_SUCCESS;

    memcpy( &destbuf->capture_start_time, &srcbuf->capture_start_time, sizeof( struct timeval ) );
    memcpy( &destbuf->duration, &srcbuf->duration, sizeof( struct timeval ) );
    memcpy( &destbuf->fill_time, &srcbuf->fill_time, sizeof( struct timeval ) );

    switch( srcbuf->format.fourcc ) {
    case UCIL_FOURCC( 'B', 'Y', '8', ' '):
    case UCIL_FOURCC( 'B', 'A', '8', '1'):
        ucil_copy_color_plane_by8( destbuf, srcbuf, plane );
        break;
    default:
        status = STATUS_NOT_IMPLEMENTED;
        break;
    }

    return status;
}
Example #4
0
__HIDDEN__ unicap_data_buffer_t *ucil_ppm_read_file( const char *path )
{
   int fd;
   char buffer[16];
   
   fd = open( path, O_RDONLY );
   if (fd < 0)
      return NULL;
   
   if (read (fd, buffer, 2) < 2){
      close(fd);
      return NULL;
   }
   
   int width;
   int height;
   int maxval;
   int size;

   width = nextval( fd );
   height = nextval( fd );
   maxval = nextval( fd );

   if ((width == -1) || (height == -1) || (maxval == -1) ){
      close(fd);
      return NULL;
   }

   size = width * height * 3 * ( maxval < 256 ? 1 : 2 );
   
   unicap_data_buffer_t *destbuf;
   destbuf = ucil_allocate_buffer( width, height, UCIL_FOURCC( 'R', 'G', 'B', '3' ), maxval < 256 ? 24 : 48 );
   
   int bytes_read = 0;
   
   while (bytes_read < size){
      ssize_t rc;
      rc = read( fd, destbuf->data + bytes_read, size - bytes_read );
      if (rc<0){
	 if (errno != EINTR){
	    free(destbuf->data);
	    free(destbuf);
	    close(fd);
	    return NULL;
	 }
      } else {
	 bytes_read += rc;
      }
   }   
   
   return destbuf;
}
Example #5
0
void ucil_composite( unicap_data_buffer_t *dest,
                     unicap_data_buffer_t *img,
                     int xpos,
                     int ypos,
                     double scalex,
                     double scaley,
                     ucil_interpolation_type_t interp )
{
    switch( dest->format.fourcc )
    {
    case UCIL_FOURCC( 'U', 'Y', 'V', 'Y' ):
        ucil_composite_UYVY_YUVA( dest, img, xpos, ypos, scalex, scaley, interp );
        break;
    case UCIL_FOURCC( 'Y', 'U', 'Y', 'V' ):
    case UCIL_FOURCC( 'Y', 'U', 'Y', '2' ):
        ucil_composite_YUYV_YUVA( dest, img, xpos, ypos, scalex, scaley, interp );
        break;
    default:
        g_warning( "Operation not defined for color format\n" );
        break;
    }

}
void backend_gtk_get_image_data( gpointer _data, unicap_data_buffer_t *data_buffer, int b )
{
   struct backend_data *data = _data;
   int tmp;

   unicap_void_format( &data_buffer->format );
   data_buffer->format.fourcc = UCIL_FOURCC( 'R', 'G', 'B', '3' );
   data_buffer->format.bpp = 24;
   data_buffer->format.size.width = data->format.size.width;
   data_buffer->format.size.height = data->format.size.height;
   data_buffer->format.buffer_size = data->format.size.width * data->format.size.height * 3;
   data_buffer->buffer_size = data_buffer->format.buffer_size;
   tmp = ( data->current_buffer + 1 ) % NUM_BUFFERS;
   data_buffer->data = data->image_data[ tmp ];
   memcpy( &data_buffer->fill_time, &data->fill_times[tmp], sizeof( struct timeval ) );   
}
Example #7
0
void ucil_convolution_mask( unicap_data_buffer_t *dest, unicap_data_buffer_t *src, ucil_convolution_mask_t *mask )
{
    switch( src->format.fourcc )
    {
    case UCIL_FOURCC( 'U', 'Y', 'V', 'Y' ):
    {
        ucil_convolution_mask_uyvy( dest, src, mask );
    }
    break;

    default:
    {
        g_warning( "Operation not defined for color format\n" );
    }
    break;
    }
}
void backend_gtk_update_image( gpointer _data, unicap_data_buffer_t *data_buffer, GError **err )
{
   unicap_data_buffer_t tmp_buffer;
   struct backend_data *data = _data;
   int tmp;

   if( !data_buffer )
   {
      g_warning( "update_image: data_buffer == NULL!\n" );
      return;
   }

   if( /* ( data_buffer->format.fourcc != data->format.fourcc ) ||  */
       ( data_buffer->format.size.width != data->format.size.width ) || 
       ( data_buffer->format.size.height != data->format.size.height ) /* || */
/*        ( data_buffer->format.bpp != data->format.bpp  )*/ )
   {
      g_warning( "update_image: data_buffer format missmatch\n" );      
      return;
   }

   unicap_copy_format( &tmp_buffer.format, &data_buffer->format );
   tmp_buffer.format.bpp = 24;
   tmp_buffer.format.fourcc = UCIL_FOURCC( 'R', 'G', 'B', '3' );

   tmp = ( data->current_buffer + 1 ) % NUM_BUFFERS;   
   memcpy( &data->fill_times[tmp], &data_buffer->fill_time, sizeof( struct timeval ) );
   tmp_buffer.data = data->image_data[tmp];
   tmp_buffer.buffer_size = data->format.size.width * data->format.size.height * 3;
   if( !data->color_conversion_cb )
   {
      ucil_convert_buffer( &tmp_buffer, data_buffer );
   }
   else
   {
      if( !data->color_conversion_cb( &tmp_buffer, data_buffer, data->color_conversion_data ) )
      {
	 ucil_convert_buffer( &tmp_buffer, data_buffer );
      } 
   }
}
}

/*
  Initializes object structures. Looks for first matching video format and resizes the drawing area accordingly.

  Input: ugtk
  
  Output: 

  Returns:
*/
static void new( UnicapgtkVideoDisplay *ugtk )
{
   unicap_format_t format_spec, format;
   unicap_void_format( &format_spec );
   format_spec.fourcc = UCIL_FOURCC( 'U', 'Y', 'V', 'Y' );
	
   ugtk->capture_running = FALSE;
   ugtk->pause = TRUE;
   ugtk->display_timeout_tag = TIMEOUT_UNSET;
   ugtk->still_image_pixbuf = NULL;
   ugtk->backend = NULL;   

   if( !SUCCESS( unicap_enumerate_formats( ugtk->unicap_handle, 
					   &format_spec, 
					   &format, 
					   0 ) ) )
   {
      if( !SUCCESS( unicap_enumerate_formats( ugtk->unicap_handle, 
					      NULL, 
					      &format, 
static int read_png(FILE *fp, unsigned int sig_read, unicap_data_buffer_t *buffer )  /* file is already open */
{
   png_structp png_ptr;
   png_infop info_ptr;
   png_uint_32 width, height;
/*    int bit_depth, color_type, interlace_type; */
   int i;
   png_bytepp row_pointers;

   /* Create and initialize the png_struct with the desired error handler
    * functions.  If you want to use the default stderr and longjump method,
    * you can supply NULL for the last three parameters.  We also supply the
    * the compiler header file version, so that we know if the application
    * was compiled with a compatible version of the library.  REQUIRED
    */
   png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,
				     NULL, NULL, NULL );

   if (png_ptr == NULL)
   {
      fclose(fp);
      return( -1 );
   }

   /* Allocate/initialize the memory for image information.  REQUIRED. */
   info_ptr = png_create_info_struct(png_ptr);
   if (info_ptr == NULL)
   {
      fclose(fp);
      png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
      return( -1 );
   }

   /* Set error handling if you are using the setjmp/longjmp method (this is
    * the normal method of doing things with libpng).  REQUIRED unless you
    * set up your own error handlers in the png_create_read_struct() earlier.
    */

   if (setjmp(png_jmpbuf(png_ptr)))
   {
      /* Free all of the memory associated with the png_ptr and info_ptr */
      png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
      fclose(fp);
      /* If we get here, we had a problem reading the file */
      return( -1 );
   }

   /* Set up the input control if you are using standard C streams */
   png_init_io(png_ptr, fp);

   /* If we have already read some of the signature */
   png_set_sig_bytes(png_ptr, sig_read);

   /*
    * If you have enough memory to read in the entire image at once,
    * and you need to specify only transforms that can be controlled
    * with one of the PNG_TRANSFORM_* bits (this presently excludes
    * dithering, filling, setting background, and doing gamma
    * adjustment), then you can read the entire image (including
    * pixels) into the info structure with this call:
    */
   png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, png_voidp_NULL);

   /* At this point you have read the entire image */
   
   row_pointers = png_get_rows( png_ptr, info_ptr );
   width = png_get_image_width( png_ptr, info_ptr );
   height = png_get_image_height( png_ptr, info_ptr );

   buffer->buffer_size = buffer->format.buffer_size = width * height * buffer->format.bpp / 8;
   buffer->format.size.width = width;
   buffer->format.size.height = height;
   buffer->data = malloc( buffer->buffer_size );
   

   for( i = 0; i < height; i++ )
   {
      int j;
      unsigned char *dest;
      int channels = png_get_channels( png_ptr, info_ptr );

      dest = buffer->data + ( i * ( buffer->format.size.width * buffer->format.bpp / 8 ) );

	 
      switch( buffer->format.fourcc )
      {
	 case( UCIL_FOURCC( 'Y', 'U', 'V', 'A' ) ):
	 {
	    for( j = 0; j < width; j++ )
	    {
	       int xoff = j * channels;
	       unsigned char r,g,b,a;
	       int y, u, v;
	       
	       r = row_pointers[i][xoff];
	       g = row_pointers[i][xoff+1];
	       b = row_pointers[i][xoff+2];
	       a = channels == 4 ? row_pointers[i][xoff+3] : 255;
	       
	       y = ( 0.2990 * (float)r + 0.5870 * (float)g + 0.1140 * (float)b );
	       u = (-0.1687 * (float)r - 0.3313 * (float)g + 0.5000 * (float)b + 128.0 );
	       v = ( 0.5000 * (float)r - 0.4187 * (float)g - 0.0813 * (float)b + 128.0);
	       
	       *dest++ = y;
	       *dest++ = u;
	       *dest++ = v;
	       *dest++ = a;
	    }
	 }
	 break;

	 case( UCIL_FOURCC( 'R', 'G', 'B', 'A' ) ):
	 {
	    memcpy( dest, row_pointers[i], width * 4 );
	    dest += width * 4;
	 }
	 break;

	 default:
	 {
	    TRACE( "Operation not defined for color format!\n" );
	 }
      }
   }

   /* clean up after the read, and free any memory allocated - REQUIRED */
   png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);

   /* close the file */
   fclose(fp);

   /* that's it */
   return( 0 );
}
Example #11
0
ucil_colorspace_t ucil_get_colorspace_from_fourcc( unsigned int fourcc )
{
    ucil_colorspace_t cs = UCIL_COLORSPACE_UNKNOWN;

    switch( fourcc )
    {
    case UCIL_FOURCC( 'Y', '8', '0', '0' ):
    case UCIL_FOURCC( 'G', 'R', 'E', 'Y' ):
        cs = UCIL_COLORSPACE_Y8;
        break;

    case UCIL_FOURCC( 'R', 'G', 'B', ' ' ):
    case UCIL_FOURCC( 'R', 'G', 'B', '3' ):
        cs = UCIL_COLORSPACE_RGB24;
        break;

    case UCIL_FOURCC( 'R', 'G', 'B', 'A' ):
    case UCIL_FOURCC( 'R', 'G', 'B', '4' ):
        cs = UCIL_COLORSPACE_RGB32;
        break;

    case UCIL_FOURCC( 'U', 'Y', 'V', 'Y' ):
    case UCIL_FOURCC( 'Y', 'U', 'Y', 'V' ):
    case UCIL_FOURCC( 'Y', 'U', 'Y', '2' ):
    case UCIL_FOURCC( 'Y', '4', '2', '2' ):
    case UCIL_FOURCC( 'Y', '4', '1', '1' ):
    case UCIL_FOURCC( 'Y', '4', '2', '0' ):
        cs = UCIL_COLORSPACE_YUV;
        break;

    default:
        cs = UCIL_COLORSPACE_UNKNOWN;
        break;
    }

    return cs;
}