aa.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:9k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * vout_aa.c: Aa video output display method for testing purposes
  3.  *****************************************************************************
  4.  * Copyright (C) 2002-2009 the VideoLAN team
  5.  * $Id: 0e256851465e28b1d0f2f7c3c4fa5016bd95588c $
  6.  *
  7.  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #include <errno.h>                                                 /* ENOMEM */
  27. #include <aalib.h>
  28. #ifdef HAVE_CONFIG_H
  29. # include "config.h"
  30. #endif
  31. #include <vlc_common.h>
  32. #include <vlc_plugin.h>
  33. #include <vlc_vout.h>
  34. #include <vlc_interface.h>
  35. /*****************************************************************************
  36.  * Local prototypes
  37.  *****************************************************************************/
  38. static int  Create    ( vlc_object_t * );
  39. static void Destroy   ( vlc_object_t * );
  40. static int  Init      ( vout_thread_t * );
  41. static void End       ( vout_thread_t * );
  42. static int  Manage    ( vout_thread_t * );
  43. static void Render    ( vout_thread_t *, picture_t * );
  44. static void Display   ( vout_thread_t *, picture_t * );
  45. static void SetPalette     ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
  46. /*****************************************************************************
  47.  * Module descriptor
  48.  *****************************************************************************/
  49. vlc_module_begin ()
  50.     set_shortname( N_("ASCII Art"))
  51.     set_category( CAT_VIDEO )
  52.     set_subcategory( SUBCAT_VIDEO_VOUT )
  53.     set_description( N_("ASCII-art video output") )
  54.     set_capability( "video output", 10 )
  55.     add_shortcut( "aalib" )
  56.     set_callbacks( Create, Destroy )
  57. vlc_module_end ()
  58. /*****************************************************************************
  59.  * vout_sys_t: aa video output method descriptor
  60.  *****************************************************************************
  61.  * This structure is part of the video output thread descriptor.
  62.  * It describes the aa specific properties of an output thread.
  63.  *****************************************************************************/
  64. struct vout_sys_t
  65. {
  66.     struct aa_context*  aa_context;
  67.     aa_palette          palette;
  68.     int                 i_width;                     /* width of main window */
  69.     int                 i_height;                   /* height of main window */
  70. };
  71. /*****************************************************************************
  72.  * Create: allocates aa video thread output method
  73.  *****************************************************************************
  74.  * This function allocates and initializes a aa vout method.
  75.  *****************************************************************************/
  76. static int Create( vlc_object_t *p_this )
  77. {
  78.     vout_thread_t *p_vout = (vout_thread_t *)p_this;
  79.     /* Allocate structure */
  80.     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
  81.     if( p_vout->p_sys == NULL )
  82.         return VLC_ENOMEM;
  83.     /* Don't parse any options, but take $AAOPTS into account */
  84.     aa_parseoptions( NULL, NULL, NULL, NULL );
  85.     if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
  86.     {
  87.         msg_Err( p_vout, "cannot initialize aalib" );
  88.         free( p_vout->p_sys );
  89.         return VLC_EGENERIC;
  90.     }
  91.     p_vout->pf_init = Init;
  92.     p_vout->pf_end = End;
  93.     p_vout->pf_manage = Manage;
  94.     p_vout->pf_render = Render;
  95.     p_vout->pf_display = Display;
  96.     p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
  97.     p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
  98.     aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
  99.     aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
  100.     aa_hidemouse( p_vout->p_sys->aa_context );
  101.     return VLC_SUCCESS;
  102. }
  103. /*****************************************************************************
  104.  * Init: initialize aa video thread output method
  105.  *****************************************************************************/
  106. static int Init( vout_thread_t *p_vout )
  107. {
  108.     int i_index;
  109.     picture_t *p_pic = NULL;
  110.     I_OUTPUTPICTURES = 0;
  111.     p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
  112.     p_vout->output.i_width = p_vout->p_sys->i_width;
  113.     p_vout->output.i_height = p_vout->p_sys->i_height;
  114.     p_vout->output.i_aspect = p_vout->p_sys->i_width
  115.                                * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
  116.     p_vout->output.pf_setpalette = SetPalette;
  117.     /* Find an empty picture slot */
  118.     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
  119.     {
  120.         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
  121.         {
  122.             p_pic = p_vout->p_picture + i_index;
  123.             break;
  124.         }
  125.     }
  126.     if( p_pic == NULL )
  127.         return VLC_EGENERIC;
  128.     /* Allocate the picture */
  129.     p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
  130.     p_pic->p->i_lines = p_vout->p_sys->i_height;
  131.     p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
  132.     p_pic->p->i_pitch = p_vout->p_sys->i_width;
  133.     p_pic->p->i_pixel_pitch = 1;
  134.     p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
  135.     p_pic->i_planes = 1;
  136.     p_pic->i_status = DESTROYED_PICTURE;
  137.     p_pic->i_type   = DIRECT_PICTURE;
  138.     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
  139.     I_OUTPUTPICTURES++;
  140.     return VLC_SUCCESS;
  141. }
  142. /*****************************************************************************
  143.  * End: terminate aa video thread output method
  144.  *****************************************************************************/
  145. static void End( vout_thread_t *p_vout )
  146. {
  147.     ;
  148. }
  149. /*****************************************************************************
  150.  * Destroy: destroy aa video thread output method
  151.  *****************************************************************************
  152.  * Terminate an output method created by AaCreateOutputMethod
  153.  *****************************************************************************/
  154. static void Destroy( vlc_object_t *p_this )
  155. {
  156.     vout_thread_t *p_vout = (vout_thread_t *)p_this;
  157.     aa_close( p_vout->p_sys->aa_context );
  158.     free( p_vout->p_sys );
  159. }
  160. /*****************************************************************************
  161.  * Manage: handle aa events
  162.  *****************************************************************************
  163.  * This function should be called regularly by video output thread. It manages
  164.  * console events. It returns a non null value on error.
  165.  *****************************************************************************/
  166. static int Manage( vout_thread_t *p_vout )
  167. {
  168.     int event, x, y, b;
  169.     event = aa_getevent( p_vout->p_sys->aa_context, 0 );
  170.     switch ( event )
  171.     {
  172.     case AA_MOUSE:
  173.         aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
  174.         if ( b & AA_BUTTON3 )
  175.             var_SetBool( p_vout->p_libvlc, "intf-popupmenu", true );
  176.         break;
  177.     case AA_RESIZE:
  178.         p_vout->i_changes |= VOUT_SIZE_CHANGE;
  179.         aa_resize( p_vout->p_sys->aa_context );
  180.         p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
  181.         p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
  182.         break;
  183.     default:
  184.         break;
  185.     }
  186.     return VLC_SUCCESS;
  187. }
  188. /*****************************************************************************
  189.  * Render: render previously calculated output
  190.  *****************************************************************************/
  191. static void Render( vout_thread_t *p_vout, picture_t *p_pic )
  192. {
  193.   aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
  194.                  aa_imgwidth( p_vout->p_sys->aa_context ),
  195.                  aa_imgheight( p_vout->p_sys->aa_context ) );
  196. }
  197. /*****************************************************************************
  198.  * Display: displays previously rendered output
  199.  *****************************************************************************/
  200. static void Display( vout_thread_t *p_vout, picture_t *p_pic )
  201. {
  202.     /* No need to do anything, the fake direct buffers stay as they are */
  203.     int i_width, i_height, i_x, i_y;
  204.     vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
  205.                        &i_x, &i_y, &i_width, &i_height );
  206.     aa_flush(p_vout->p_sys->aa_context);
  207. }
  208. /*****************************************************************************
  209.  * SetPalette: set the 8bpp palette
  210.  *****************************************************************************/
  211. static void SetPalette( vout_thread_t *p_vout,
  212.                         uint16_t *red, uint16_t *green, uint16_t *blue )
  213. {
  214.     int i;
  215.     /* Fill colors with color information */
  216.     for( i = 0; i < 256; i++ )
  217.     {
  218.         aa_setpalette( p_vout->p_sys->palette, 256 -i,
  219.                        red[ i ], green[ i ], blue[ i ] );
  220.     }
  221. }