cs_xfm.c
Upload User: shyika
Upload Date: 2017-11-25
Package Size: 1227k
Code Size: 4k
Category:

Video Capture

Development Platform:

Unix_Linux

  1. /* unicap
  2.  *
  3.  * Copyright (C) 2004 Arne Caspari ( arne_caspari@users.sourceforge.net )
  4.  *
  5.   This program is free software; you can redistribute it and/or modify
  6.   it under the terms of the GNU General Public License as published by
  7.   the Free Software Foundation; either version 2 of the License, or
  8.   (at your option) any later version.
  9.   This program is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.   GNU General Public License for more details.
  13.   You should have received a copy of the GNU General Public License
  14.   along with this program; if not, write to the Free Software
  15.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16.  */
  17. #include <gdk/gdk.h>
  18. #include <string.h>
  19. #include <ucil.h>
  20. #include "cs_xfm.h"
  21. size_t cs_xfm_get_image_data_size( unicap_format_t *format )
  22. {
  23.    size_t size = 0;
  24.    switch( format->fourcc )
  25.    {
  26.       case RGB3:
  27.  size = format->size.width * format->size.height * 3;
  28.  break;
  29.       case RGB4:
  30.  size = format->size.width * format->size.height * 4;
  31.  break;
  32.       default:
  33.  size = format->size.width * format->size.height * 3;
  34.    }
  35.    
  36.    return size;
  37. }
  38. void cs_xfm_to_RGB24( unicap_data_buffer_t *data_buffer, guchar *dest )
  39. {
  40.    switch( data_buffer->format.fourcc )
  41.    {
  42.       case RGB3:
  43.  memcpy( dest, data_buffer->data, data_buffer->buffer_size );
  44.  break;
  45.  
  46. /*       case RGB4: */
  47. /*   g_warning( "No conversion method for video format!n" ); */
  48. /*   break; */
  49.  
  50.       default:
  51.       {
  52.  unicap_data_buffer_t target_buffer;  
  53.  target_buffer.buffer_size = target_buffer.format.buffer_size = data_buffer->format.size.width *
  54.     data_buffer->format.size.height * 3;
  55.  target_buffer.format.fourcc = UCIL_FOURCC( 'R', 'G', 'B', 0 );
  56.  target_buffer.format.size.width = data_buffer->format.size.width;
  57.  target_buffer.format.size.height = data_buffer->format.size.height;
  58.  target_buffer.data = dest;
  59.  
  60.  ucil_convert_buffer( &target_buffer, data_buffer );
  61.       }
  62.    }   
  63. }
  64. void cs_xfm_to_RGB32( unicap_data_buffer_t *data_buffer, guchar *dest )
  65. {
  66.    switch( data_buffer->format.fourcc )
  67.    {
  68.       case RGB3:
  69.  memcpy( data_buffer->data, dest, data_buffer->buffer_size );
  70.  break;
  71.  
  72.       case RGB4:
  73.  g_assert( "No conversion" == FALSE );
  74.  break;
  75.  
  76.       default:
  77.       {
  78.  unicap_data_buffer_t target_buffer;  
  79.  target_buffer.buffer_size = target_buffer.format.buffer_size = data_buffer->format.size.width *
  80.     data_buffer->format.size.height * 4;
  81.  target_buffer.format.fourcc = UCIL_FOURCC( 'R', 'G', 'B', 'A' );
  82.  target_buffer.format.size.width = data_buffer->format.size.width;
  83.  target_buffer.format.size.height = data_buffer->format.size.height;
  84.  target_buffer.data = dest;
  85.  
  86.  ucil_convert_buffer( &target_buffer, data_buffer );
  87.       }
  88.    }   
  89. }
  90. GdkPixbuf *cs_xfm_new_pixbuf( unicap_data_buffer_t *image_buffer, guchar *image_data )
  91. {
  92.    GdkPixbuf *pixbuf;
  93.    switch( image_buffer->format.fourcc )
  94.    {
  95.       case RGB3:
  96.  pixbuf = gdk_pixbuf_new_from_data( image_data,
  97.     GDK_COLORSPACE_RGB,
  98.     0, // alpha
  99.     8, // bps
  100.     image_buffer->format.size.width,
  101.     image_buffer->format.size.height,
  102.     image_buffer->format.size.width * 3,
  103.     NULL,
  104.     0 );
  105.  break;
  106.       case RGB4:
  107.  pixbuf = gdk_pixbuf_new_from_data( image_data,
  108.     GDK_COLORSPACE_RGB,
  109.     1, // alpha
  110.     8, // bps
  111.     image_buffer->format.size.width,
  112.     image_buffer->format.size.height,
  113.     image_buffer->format.size.width * 4,
  114.     NULL,
  115.     0 );
  116.  break;
  117.       default:
  118.       {
  119.  unicap_data_buffer_t target_buffer;  
  120.  target_buffer.buffer_size = target_buffer.format.buffer_size = image_buffer->format.size.width *
  121.     image_buffer->format.size.height * 3;
  122.  target_buffer.format.fourcc = UCIL_FOURCC( 'R', 'G', 'B', 0 );
  123.  target_buffer.format.size.width = image_buffer->format.size.width;
  124.  target_buffer.format.size.height = image_buffer->format.size.height;
  125.  target_buffer.data = image_data;
  126.  
  127.  ucil_convert_buffer( &target_buffer, image_buffer );
  128.  pixbuf = gdk_pixbuf_new_from_data( image_data,
  129.     GDK_COLORSPACE_RGB,
  130.     0, // alpha
  131.     8, // bps
  132.     image_buffer->format.size.width,
  133.     image_buffer->format.size.height,
  134.     image_buffer->format.size.width * 3,
  135.     NULL,
  136.     0 );
  137.       }
  138.       break;
  139.    }
  140.    return pixbuf;
  141. }