Changeset 61c29c8f4f906a535430844852ab89f019d85531

Show
Ignore:
Timestamp:
06/01/06 11:57:01 (2 years ago)
Author:
Sam Hocevar <sam@videolan.org>
git-committer:
Sam Hocevar <sam@videolan.org> 1149155821 +0000
git-parent:

[8c672e8dfb6827bcdfa307f06adce2dba22f63ae]

git-author:
Sam Hocevar <sam@videolan.org> 1149155821 +0000
Message:
  • modules/video_output/caca.c: many code simplifications.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/video_output/caca.c

    rec4b9fb r61c29c8  
    3131#include <caca.h> 
    3232 
     33#ifndef CACA_API_VERSION_1 
     34    /* Upward compatibility macros */ 
     35    typedef cucul_canvas_t char 
     36    typedef cucul_dither_t struct caca_bitmap 
     37    typedef caca_display_t char 
     38#   define CUCUL_COLOR_DEFAULT CACA_COLOR_LIGHTGRAY 
     39#   define CUCUL_COLOR_BLACK CACA_COLOR_BLACK 
     40#   define cucul_clear_canvas(x) caca_clear() 
     41#   define cucul_create_canvas(x,y) "" /* kinda hacky */ 
     42#   define cucul_create_dither caca_create_bitmap 
     43#   define cucul_dither_bitmap(x,y,z,t,u,v,w) caca_draw_bitmap(y,z,t,u,v,w) 
     44#   define cucul_free_dither caca_free_bitmap 
     45#   define cucul_free_canvas(x) 
     46#   define cucul_get_canvas_width(x) caca_get_width() 
     47#   define cucul_get_canvas_height(x) caca_get_height() 
     48#   define cucul_set_color(x,y,z) caca_set_color(y,z) 
     49#   define caca_create_display(x) (caca_init() ? NULL : "") /* hacky, too */ 
     50#   define caca_free_display(x) caca_end() 
     51#   define caca_get_event(x,y,z,t) *(z) = caca_get_event(y) 
     52#   define caca_refresh_display(x) caca_refresh() 
     53#   define caca_set_display_title(x,y) caca_set_window_title(y) 
     54#endif 
     55 
    3356#include <vlc/vlc.h> 
    3457#include <vlc/vout.h> 
     
    6891struct vout_sys_t 
    6992{ 
    70 #ifdef CACA_API_VERSION_1 
    7193    cucul_canvas_t *p_cv; 
    7294    caca_display_t *p_dp; 
    7395    cucul_dither_t *p_dither; 
    74 #else 
    75     struct caca_bitmap *p_bitmap; 
    76 #endif 
    7796}; 
    7897 
     
    87106 
    88107#if defined( WIN32 ) && !defined( UNDER_CE ) 
    89     if( AllocConsole() ) 
    90     { 
    91         CONSOLE_SCREEN_BUFFER_INFO csbiInfo; 
    92         SMALL_RECT rect; 
    93         COORD coord; 
    94  
    95         HANDLE hstdout = 
    96             CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 
    97                                        FILE_SHARE_READ | FILE_SHARE_WRITE, 
    98                                        NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); 
    99         if( !hstdout || hstdout == INVALID_HANDLE_VALUE ) 
    100         { 
    101             msg_Err( p_vout, "cannot create screen buffer" ); 
    102             FreeConsole(); 
    103             return VLC_EGENERIC; 
    104         } 
    105  
    106         if( !SetConsoleActiveScreenBuffer( hstdout) ) 
    107         { 
    108             msg_Err( p_vout, "cannot set active screen buffer" ); 
    109             FreeConsole(); 
    110             return VLC_EGENERIC; 
    111         } 
    112  
    113         coord = GetLargestConsoleWindowSize( hstdout ); 
    114         msg_Dbg( p_vout, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y ); 
    115  
    116         /* Force size for now */ 
    117         coord.X = 100; 
    118         coord.Y = 40; 
    119  
    120         if( !SetConsoleScreenBufferSize( hstdout, coord ) ) 
    121             msg_Warn( p_vout, "SetConsoleScreenBufferSize %i %i", 
    122                       coord.X, coord.Y ); 
    123  
    124         /* Get the current screen buffer size and window position. */ 
    125         if( GetConsoleScreenBufferInfo( hstdout, &csbiInfo ) ) 
    126         { 
    127             rect.Top = 0; rect.Left = 0; 
    128             rect.Right = csbiInfo.dwMaximumWindowSize.X - 1; 
    129             rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1; 
    130             if( !SetConsoleWindowInfo( hstdout, TRUE, &rect ) ) 
    131                 msg_Dbg( p_vout, "SetConsoleWindowInfo failed: %ix%i", 
    132                          rect.Right, rect.Bottom ); 
    133         } 
    134     } 
    135     else 
     108    CONSOLE_SCREEN_BUFFER_INFO csbiInfo; 
     109    SMALL_RECT rect; 
     110    COORD coord; 
     111    HANDLE hstdout; 
     112 
     113    if( !AllocConsole() ) 
    136114    { 
    137115        msg_Err( p_vout, "cannot create console" ); 
     
    139117    } 
    140118 
     119    HANDLE hstdout = 
     120        CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, 
     121                                   FILE_SHARE_READ | FILE_SHARE_WRITE, 
     122                                   NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); 
     123    if( !hstdout || hstdout == INVALID_HANDLE_VALUE ) 
     124    { 
     125        msg_Err( p_vout, "cannot create screen buffer" ); 
     126        FreeConsole(); 
     127        return VLC_EGENERIC; 
     128    } 
     129 
     130    if( !SetConsoleActiveScreenBuffer( hstdout) ) 
     131    { 
     132        msg_Err( p_vout, "cannot set active screen buffer" ); 
     133        FreeConsole(); 
     134        return VLC_EGENERIC; 
     135    } 
     136 
     137    coord = GetLargestConsoleWindowSize( hstdout ); 
     138    msg_Dbg( p_vout, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y ); 
     139 
     140    /* Force size for now */ 
     141    coord.X = 100; 
     142    coord.Y = 40; 
     143 
     144    if( !SetConsoleScreenBufferSize( hstdout, coord ) ) 
     145        msg_Warn( p_vout, "SetConsoleScreenBufferSize %i %i", 
     146                  coord.X, coord.Y ); 
     147 
     148    /* Get the current screen buffer size and window position. */ 
     149    if( GetConsoleScreenBufferInfo( hstdout, &csbiInfo ) ) 
     150    { 
     151        rect.Top = 0; rect.Left = 0; 
     152        rect.Right = csbiInfo.dwMaximumWindowSize.X - 1; 
     153        rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1; 
     154        if( !SetConsoleWindowInfo( hstdout, TRUE, &rect ) ) 
     155            msg_Dbg( p_vout, "SetConsoleWindowInfo failed: %ix%i", 
     156                     rect.Right, rect.Bottom ); 
     157    } 
    141158#endif 
    142159 
     
    149166    } 
    150167 
    151 #ifdef CACA_API_VERSION_1 
    152168    p_vout->p_sys->p_cv = cucul_create_canvas(0, 0); 
    153169    if( !p_vout->p_sys->p_cv ) 
     
    169185    caca_set_display_title( p_vout->p_sys->p_dp, 
    170186                            VOUT_TITLE " - Colour AsCii Art (caca)" ); 
    171 #else 
    172     if( caca_init() ) 
    173     { 
    174         msg_Err( p_vout, "cannot initialize libcaca" ); 
    175         free( p_vout->p_sys ); 
    176         return VLC_EGENERIC; 
    177     } 
    178  
    179     caca_set_window_title( VOUT_TITLE " - Colour AsCii Art (caca)" ); 
    180 #endif 
    181187 
    182188    p_vout->pf_init = Init; 
     
    208214    p_vout->output.i_bmask = 0x000000ff; 
    209215 
    210     /* Create the libcaca bitmap */ 
    211 #ifdef CACA_API_VERSION_1 
    212     p_vout->p_sys->p_dither = 
    213         cucul_create_dither 
    214 #else 
    215     p_vout->p_sys->p_bitmap = 
    216         caca_create_bitmap 
    217 #endif 
     216    /* Create the libcaca dither object */ 
     217    p_vout->p_sys->p_dither = cucul_create_dither 
    218218                       ( 32, p_vout->output.i_width, p_vout->output.i_height, 
    219219                         4 * ((p_vout->output.i_width + 15) & ~15), 
     
    221221                         p_vout->output.i_bmask, 0x00000000 ); 
    222222 
    223 #ifdef CACA_API_VERSION_1 
    224223    if( !p_vout->p_sys->p_dither ) 
    225 #else 
    226     if( !p_vout->p_sys->p_bitmap ) 
    227 #endif 
    228     { 
    229         msg_Err( p_vout, "could not create libcaca bitmap" ); 
     224    { 
     225        msg_Err( p_vout, "could not create libcaca dither object" ); 
    230226        return VLC_EGENERIC; 
    231227    } 
     
    269265static void End( vout_thread_t *p_vout ) 
    270266{ 
    271 #ifdef CACA_API_VERSION_1 
    272267    cucul_free_dither( p_vout->p_sys->p_dither ); 
    273 #else 
    274     caca_free_bitmap( p_vout->p_sys->p_bitmap ); 
    275 #endif 
    276268} 
    277269 
     
    285277    vout_thread_t *p_vout = (vout_thread_t *)p_this; 
    286278 
    287 #ifdef CACA_API_VERSION_1 
    288279    caca_free_display( p_vout->p_sys->p_dp ); 
    289280    cucul_free_canvas( p_vout->p_sys->p_cv ); 
    290 #else 
    291     caca_end(); 
    292 #endif 
    293281 
    294282#if defined( WIN32 ) && !defined( UNDER_CE ) 
     
    310298    struct caca_event ev; 
    311299#else 
    312     int event
     300    int ev
    313301#endif 
    314302    vlc_value_t val; 
    315303 
    316 #ifdef CACA_API_VERSION_1 
    317     while(( caca_get_event(p_vout->p_sys->p_dp, 
    318                            CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE, &ev, 0) )) 
    319 #else 
    320     while(( event = caca_get_event(CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE) )) 
    321 #endif 
     304    while( caca_get_event(p_vout->p_sys->p_dp, 
     305                          CACA_EVENT_KEY_PRESS | CACA_EVENT_RESIZE, &ev, 0) ) 
    322306    { 
    323307        /* Acknowledge the resize */ 
    324308#ifdef CACA_API_VERSION_1 
    325309        if( ev.type == CACA_EVENT_RESIZE ) 
     310#else 
     311        if( ev == CACA_EVENT_RESIZE ) 
     312#endif 
    326313        { 
    327314            caca_refresh_display( p_vout->p_sys->p_dp ); 
    328315            continue; 
    329316        } 
    330 #else 
    331         if( event == CACA_EVENT_RESIZE ) 
    332         { 
    333             caca_refresh(); 
    334             continue; 
    335         } 
    336 #endif 
    337317 
    338318#ifdef CACA_API_VERSION_1 
    339319        switch( ev.data.key.ch ) 
    340320#else 
    341         switch( event & 0x00ffffff ) 
     321        switch( ev & 0x00ffffff ) 
    342322#endif 
    343323        { 
     
    363343static void Render( vout_thread_t *p_vout, picture_t *p_pic ) 
    364344{ 
    365 #ifdef CACA_API_VERSION_1 
    366345    cucul_set_color( p_vout->p_sys->p_cv, 
    367346                     CUCUL_COLOR_DEFAULT, CUCUL_COLOR_BLACK ); 
     
    371350                         cucul_get_canvas_height( p_vout->p_sys->p_cv ) - 1, 
    372351                         p_vout->p_sys->p_dither, p_pic->p->p_pixels ); 
    373 #else 
    374     caca_clear(); 
    375     caca_draw_bitmap( 0, 0, caca_get_width() - 1, caca_get_height() - 1, 
    376                       p_vout->p_sys->p_bitmap, p_pic->p->p_pixels ); 
    377 #endif 
    378352} 
    379353 
     
    383357static void Display( vout_thread_t *p_vout, picture_t *p_pic ) 
    384358{ 
    385 #ifdef CACA_API_VERSION_1 
    386359    caca_refresh_display( p_vout->p_sys->p_dp ); 
    387 #else 
    388     caca_refresh(); 
    389 #endif 
    390 
    391  
     360
     361