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

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * vout.c: QNX RTOS video output display method
  3.  *****************************************************************************
  4.  * Copyright (C) 2001, 2002 the VideoLAN team
  5.  *
  6.  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  7.  *          Pascal Levesque <Pascal.Levesque@mindready.com>
  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 <photon/PtWidget.h>
  28. #include <photon/PtWindow.h>
  29. #include <photon/PtLabel.h>
  30. #include <photon/PdDirect.h>
  31. #ifdef HAVE_CONFIG_H
  32. # include "config.h"
  33. #endif
  34. #include <vlc_common.h>
  35. #include <vlc_interface.h>
  36. #include <vlc_vout.h>
  37. /*****************************************************************************
  38.  * vout_sys_t: video output QNX method descriptor
  39.  *****************************************************************************
  40.  * This structure is part of the video output thread descriptor.
  41.  * It describes the QNX specific properties of an output thread. QNX video
  42.  * output is performed through regular resizable windows. Windows can be
  43.  * dynamically resized to adapt to the size of the streams.
  44.  *****************************************************************************/
  45. #define MAX_DIRECTBUFFERS 2
  46. #define MODE_NORMAL_MEM     0
  47. #define MODE_SHARED_MEM     1
  48. #define MODE_VIDEO_MEM      2
  49. #define MODE_VIDEO_OVERLAY  3
  50. struct vout_sys_t
  51. {
  52.     /* video mode */
  53.     int                     i_mode;
  54.     /* internal stuff */
  55.     PtWidget_t *            p_window;
  56.     /* Color palette for 8bpp */
  57.     PgColor_t p_colors[255];
  58.     /* [shared] memory blit */
  59.     int                     i_img_type;
  60.     /* video memory blit */
  61.     /* video overlay */
  62.     PgVideoChannel_t *      p_channel;
  63.     int                     i_vc_flags;
  64.     int                     i_vc_format;
  65.     int                 i_screen_depth;
  66.     int                 i_bytes_per_pixel;
  67.     int                 i_bytes_per_line;
  68.     /* position & dimensions */
  69.     PhPoint_t               pos;
  70.     PhDim_t                 dim;
  71.     PhPoint_t               old_pos;
  72.     PhDim_t                 old_dim;
  73.     PhDim_t                 screen_dim;
  74.     PhRect_t                frame;
  75. };
  76. /*****************************************************************************
  77.  * picture_sys_t: direct buffer method descriptor
  78.  *****************************************************************************
  79.  * This structure is part of the picture descriptor, it describes the
  80.  * XVideo specific properties of a direct buffer.
  81.  *****************************************************************************/
  82. struct picture_sys_t
  83. {
  84.     /* [shared] memory blit */
  85.     PhImage_t *             p_image;
  86.     /* video memory blit and video overlay */
  87.     PdOffscreenContext_t *  p_ctx[3];   /* 0: y, 1: u, 2: v */
  88.     char *                  p_buf[3];
  89. };
  90. /*****************************************************************************
  91.  * Local prototypes
  92.  *****************************************************************************/
  93. static int  QNXInit      ( vout_thread_t * );
  94. static void QNXEnd       ( vout_thread_t * );
  95. static int  QNXManage    ( vout_thread_t * );
  96. static void QNXDisplay   ( vout_thread_t *, picture_t * );
  97. static int  QNXInitDisplay ( vout_thread_t * );
  98. static int  QNXCreateWnd   ( vout_thread_t * );
  99. static int  QNXDestroyWnd  ( vout_thread_t * );
  100. static int  NewPicture     ( vout_thread_t *, picture_t *, int );
  101. static void FreePicture    ( vout_thread_t *, picture_t * );
  102. static int  ResizeOverlayOutput ( vout_thread_t * );
  103. static void SetPalette     ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
  104. /*****************************************************************************
  105.  * OpenVideo: allocate QNX video thread output method
  106.  *****************************************************************************
  107.  * This function allocate and initialize a QNX vout method. It uses some of the
  108.  * vout properties to choose the window size, and change them according to the
  109.  * actual properties of the display.
  110.  *****************************************************************************/
  111. int OpenVideo ( vlc_object_t *p_this )
  112. {
  113.     vout_thread_t * p_vout = (vout_thread_t *)p_this;
  114.     /* init connection to photon */
  115.     if( PtInit( "/dev/photon" ) != 0 )
  116.     {
  117.         msg_Err( p_vout, "unable to connect to photon" );
  118.         return( 1 );
  119.     }
  120.     /* allocate structure */
  121.     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
  122.     if( p_vout->p_sys == NULL )
  123.         return( 1 );
  124.     memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
  125.     p_vout->b_fullscreen = config_GetInt( p_vout, "fullscreen" );
  126.     p_vout->p_sys->i_mode = config_GetInt( p_vout, "overlay" ) ?
  127.                                 MODE_VIDEO_OVERLAY : MODE_VIDEO_MEM;
  128.     p_vout->p_sys->dim.w = p_vout->i_window_width;
  129.     p_vout->p_sys->dim.h = p_vout->i_window_height;
  130.     /* init display and create window */
  131.     if( QNXInitDisplay( p_vout ) || QNXCreateWnd( p_vout ) )
  132.     {
  133.         free( p_vout->p_sys );
  134.         return( 1 );
  135.     }
  136.     p_vout->pf_init = QNXInit;
  137.     p_vout->pf_end = QNXEnd;
  138.     p_vout->pf_manage = QNXManage;
  139.     p_vout->pf_render = NULL;
  140.     p_vout->pf_display = QNXDisplay;
  141.     return( 0 );
  142. }
  143. /*****************************************************************************
  144.  * QNXInit: initialize QNX video thread output method
  145.  *****************************************************************************
  146.  * This function create the buffers needed by the output thread. It is called
  147.  * at the beginning of the thread, but also each time the window is resized.
  148.  *****************************************************************************/
  149. static int QNXInit( vout_thread_t *p_vout )
  150. {
  151.     int i_index;
  152.     picture_t *p_pic;
  153.     I_OUTPUTPICTURES = 0;
  154.     switch( p_vout->p_sys->i_mode )
  155.     {
  156.     case MODE_NORMAL_MEM:
  157.     case MODE_SHARED_MEM:
  158.         p_vout->output.i_width = p_vout->p_sys->dim.w;
  159.         p_vout->output.i_height = p_vout->p_sys->dim.h;
  160.         /* Assume we have square pixels */
  161.         p_vout->output.i_aspect = p_vout->p_sys->dim.w
  162.                                * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;
  163.         break;
  164.     case MODE_VIDEO_MEM:
  165.         p_vout->output.i_width = p_vout->p_sys->dim.w;
  166.         p_vout->output.i_height = p_vout->p_sys->dim.h;
  167.         /* Assume we have square pixels */
  168.         p_vout->output.i_aspect = p_vout->p_sys->dim.w
  169.                                * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;
  170.         break;
  171.     case MODE_VIDEO_OVERLAY:
  172.         p_vout->output.i_width  = p_vout->render.i_width;
  173.         p_vout->output.i_height = p_vout->render.i_height;
  174.         p_vout->output.i_aspect = p_vout->render.i_aspect;
  175.         if (ResizeOverlayOutput(p_vout))
  176.         {
  177.             return (1);
  178.         }
  179.         break;
  180.     default:
  181.         /* This shouldn't happen ! */
  182.         break;
  183.     }
  184.     /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
  185.     while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
  186.     {
  187.         p_pic = NULL;
  188.         /* Find an empty picture slot */
  189.         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
  190.         {
  191.             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
  192.             {
  193.                 p_pic = p_vout->p_picture + i_index;
  194.                 break;
  195.             }
  196.         }
  197.         /* Allocate the picture */
  198.         if( p_pic == NULL || NewPicture( p_vout, p_pic, I_OUTPUTPICTURES ) )
  199.         {
  200.             break;
  201.         }
  202.         p_pic->i_status = DESTROYED_PICTURE;
  203.         p_pic->i_type   = DIRECT_PICTURE;
  204.         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
  205.         I_OUTPUTPICTURES++;
  206.     }
  207.     return( 0 );
  208. }
  209. /*****************************************************************************
  210.  * QNXEnd: terminate QNX video thread output method
  211.  *****************************************************************************
  212.  * Destroy the buffers created by QNXInit. It is called at the end of
  213.  * the thread, but also each time the window is resized.
  214.  *****************************************************************************/
  215. static void QNXEnd( vout_thread_t *p_vout )
  216. {
  217.     int i_index;
  218.     /* Free the direct buffers we allocated */
  219.     for( i_index = I_OUTPUTPICTURES ; i_index ; )
  220.     {
  221.         i_index--;
  222.         FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
  223.     }
  224. }
  225. /*****************************************************************************
  226.  * CloseVideo: destroy QNX video thread output method
  227.  *****************************************************************************
  228.  * Terminate an output method created by QNXCreate
  229.  *****************************************************************************/
  230. void CloseVideo ( vlc_object_t *p_this )
  231. {
  232.     vout_thread_t * p_vout = (vout_thread_t *)p_this;
  233.     /* destroy the window */
  234.     QNXDestroyWnd( p_vout );
  235.     /* destroy structure */
  236.     free( p_vout->p_sys );
  237. }
  238. /*****************************************************************************
  239.  * QNXManage: handle QNX events
  240.  *****************************************************************************
  241.  * This function should be called regularly by video output thread. It allows
  242.  * window resizing. It returns a non null value on error.
  243.  *****************************************************************************/
  244. static int QNXManage( vout_thread_t *p_vout )
  245. {
  246.     int i_ev,  i_buflen;
  247.     PhEvent_t *p_event;
  248.     bool b_repos = 0;
  249.     if (!vlc_object_alive (p_vout))
  250.     {
  251.         return ( 0 );
  252.     }
  253.     /* allocate buffer for event */
  254.     i_buflen = sizeof( PhEvent_t ) * 4;
  255.     if( ( p_event = malloc( i_buflen ) ) == NULL )
  256.         return( 1 );
  257.     /* event loop */
  258.     do
  259.     {
  260.         memset( p_event, 0, i_buflen );
  261.         i_ev = PhEventPeek( p_event, i_buflen );
  262.         if( i_ev == Ph_RESIZE_MSG )
  263.         {
  264.             PhEvent_t *buf;
  265.             i_buflen = PhGetMsgSize( p_event );
  266.             buf = realloc( p_event, i_buflen );
  267.             if( buf == NULL )
  268.             {
  269.                 free( p_event );
  270.                 return( 1 );
  271.             }
  272.             p_event = buf;
  273.         }
  274.         else if( i_ev == Ph_EVENT_MSG )
  275.         {
  276.             PtEventHandler( p_event );
  277.             if( p_event->type == Ph_EV_WM )
  278.             {
  279.                 PhWindowEvent_t *p_ev = PhGetData( p_event );
  280.                 switch( p_ev->event_f )
  281.                 {
  282.                 case Ph_WM_CLOSE:
  283.                     p_vout->p_libvlc->b_die = true;
  284.                     break;
  285.                 case Ph_WM_MOVE:
  286.                     p_vout->p_sys->pos.x = p_ev->pos.x;
  287.                     p_vout->p_sys->pos.y = p_ev->pos.y;
  288.                     b_repos = 1;
  289.                     break;
  290.                 case Ph_WM_RESIZE:
  291.                     p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;
  292.                     p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;
  293.                     p_vout->p_sys->dim.w = p_ev->size.w;
  294.                     p_vout->p_sys->dim.h = p_ev->size.h;
  295.                     p_vout->i_changes |= VOUT_SIZE_CHANGE;
  296.                     break;
  297.                 }
  298.             }
  299.             else if( p_event->type == Ph_EV_KEY )
  300.             {
  301.                 PhKeyEvent_t *p_ev = PhGetData( p_event );
  302.                 long i_key = p_ev->key_sym;
  303.                 if( ( p_ev->key_flags & Pk_KF_Key_Down ) &&
  304.                     ( p_ev->key_flags & Pk_KF_Sym_Valid ) )
  305.                 {
  306.                     switch( i_key )
  307.                     {
  308.                     case Pk_q:
  309.                     case Pk_Q:
  310.                         p_vout->p_libvlc->b_die = true;
  311.                         break;
  312.                     case Pk_f:
  313.                     case Pk_F:
  314.                         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
  315.                         break;
  316.                     default:
  317.                         break;
  318.                     }
  319.                 }
  320.             }
  321.         }
  322.     } while( i_ev != -1 && i_ev != 0 );
  323.     free( p_event );
  324.     /*
  325.      * fullscreen
  326.      */
  327.     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
  328.     {
  329.         PhDim_t dim;
  330.         p_vout->b_fullscreen = !p_vout->b_fullscreen;
  331.         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
  332.         if( p_vout->b_fullscreen )
  333.         {
  334.             p_vout->p_sys->old_pos.x = p_vout->p_sys->pos.x;
  335.             p_vout->p_sys->old_pos.y = p_vout->p_sys->pos.y;
  336.             p_vout->p_sys->pos.x = p_vout->p_sys->pos.y = 0;
  337.             dim.w = p_vout->p_sys->screen_dim.w + 1;
  338.             dim.h = p_vout->p_sys->screen_dim.h + 1;
  339.         }
  340.         else
  341.         {
  342.             p_vout->p_sys->pos.x = p_vout->p_sys->old_pos.x;
  343.             p_vout->p_sys->pos.y = p_vout->p_sys->old_pos.y;
  344.             dim.w = p_vout->p_sys->old_dim.w + 1;
  345.             dim.h = p_vout->p_sys->old_dim.h + 1;
  346.         }
  347.         /* modify render flags, border */
  348.         PtSetResource( p_vout->p_sys->p_window,
  349.             Pt_ARG_WINDOW_RENDER_FLAGS,
  350.             p_vout->b_fullscreen ? Pt_FALSE : Pt_TRUE,
  351.             Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE );
  352.         /* set position and dimension */
  353.         PtSetResource( p_vout->p_sys->p_window,
  354.                        Pt_ARG_POS, &p_vout->p_sys->pos, 0 );
  355.         PtSetResource( p_vout->p_sys->p_window,
  356.                        Pt_ARG_DIM, &dim, 0 );
  357.         /* mark as damaged to force redraw */
  358.         PtDamageWidget( p_vout->p_sys->p_window );
  359.     }
  360.     /*
  361.      * size change
  362.      */
  363.     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
  364.     {
  365.         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
  366.         if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
  367.         {
  368.             ResizeOverlayOutput(p_vout);
  369.         }
  370. #if 0
  371.         else
  372.         {
  373.             p_vout->output.i_width = p_vout->p_sys->dim.w;
  374.             p_vout->output.i_height = p_vout->p_sys->dim.h;
  375.             p_vout->i_changes |= VOUT_YUV_CHANGE;
  376.             QNXEnd( p_vout );
  377.             if( QNXInit( p_vout ) )
  378.             {
  379.                 msg_Err( p_vout, "cannot resize display" );
  380.                 return( 1 );
  381.             }
  382.         }
  383. #endif
  384.         msg_Dbg( p_vout, "video display resized (%dx%d)",
  385.                          p_vout->p_sys->dim.w, p_vout->p_sys->dim.h );
  386.     }
  387.     /*
  388.      * position change, move video channel
  389.      */
  390.     if( b_repos && p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
  391.     {
  392.         ResizeOverlayOutput(p_vout);
  393.     }
  394.     return( i_ev == -1 );
  395. }
  396. /*****************************************************************************
  397.  * QNXDisplay: displays previously rendered output
  398.  *****************************************************************************
  399.  * This function send the currently rendered image to QNX server, wait until
  400.  * it is displayed and switch the two rendering buffer, preparing next frame.
  401.  *****************************************************************************/
  402. static void QNXDisplay( vout_thread_t *p_vout, picture_t *p_pic )
  403. {
  404.     if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
  405.         p_vout->p_sys->i_mode == MODE_SHARED_MEM )
  406.     {
  407.         PhPoint_t pos = { 0, 0 };
  408.         PgSetRegion( PtWidgetRid( p_vout->p_sys->p_window ) );
  409.         if (p_vout->p_sys->i_screen_depth == 8)
  410.         {
  411.             PgSetPalette( p_vout->p_sys->p_colors, 0, 0, 255, Pg_PALSET_SOFT, 0);
  412.         }
  413.         PgDrawPhImagemx( &pos, p_pic->p_sys->p_image, 0 );
  414.         PgFlush();
  415.     }
  416.     else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM )
  417.     {
  418.         PhRect_t rc = { { 0, 0 }, { p_vout->output.i_width, p_vout->output.i_height } };
  419. //        PgSetRegion( PtWidgetRid ( p_vout->p_sys->p_window ) );
  420.         PgContextBlit( p_pic->p_sys->p_ctx[0], &rc, NULL, &rc );
  421.         PgFlush();
  422.     }
  423. }
  424. /*****************************************************************************
  425.  * QNXInitDisplay: check screen resolution, depth, amount of video ram, etc
  426.  *****************************************************************************/
  427. static int QNXInitDisplay( vout_thread_t * p_vout )
  428. {
  429.     PgHWCaps_t hwcaps;
  430.     PgDisplaySettings_t cfg;
  431.     PgVideoModeInfo_t minfo;
  432.     /* get graphics card hw capabilities */
  433.     if( PgGetGraphicsHWCaps( &hwcaps ) != 0 )
  434.     {
  435.         msg_Err( p_vout, "unable to get gfx card capabilities" );
  436.         return( 1 );
  437.     }
  438.     /* get current video mode */
  439.     if( PgGetVideoMode( &cfg ) != 0 )
  440.     {
  441.         msg_Err( p_vout, "unable to get current video mode" );
  442.         return( 1 );
  443.     }
  444.     /* get video mode info */
  445.     if( PgGetVideoModeInfo( cfg.mode, &minfo ) != 0 )
  446.     {
  447.         msg_Err( p_vout, "unable to get info for video mode" );
  448.         return( 1 );
  449.     }
  450.     if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
  451.     {
  452.         int i = 0;
  453.         PgScalerCaps_t vcaps;
  454.         if( ( p_vout->p_sys->p_channel =
  455.             PgCreateVideoChannel( Pg_VIDEO_CHANNEL_SCALER, 0 ) ) == NULL )
  456.         {
  457.             msg_Err( p_vout, "unable to create video channel" );
  458.             printf("errno = %dn", errno);
  459.             p_vout->p_sys->i_mode = MODE_NORMAL_MEM;
  460.         }
  461.         else
  462.         {
  463.             vcaps.size = sizeof( vcaps );
  464.             while( PgGetScalerCapabilities( p_vout->p_sys->p_channel,
  465.                                             i++, &vcaps ) == 0 )
  466.             {
  467.                 printf("vcaps.format = 0x%xn", vcaps.format);
  468.                 if( vcaps.format == Pg_VIDEO_FORMAT_YV12 ||
  469.                     vcaps.format == Pg_VIDEO_FORMAT_YUV420 ||
  470.                     vcaps.format == Pg_VIDEO_FORMAT_YUY2 ||
  471.                     vcaps.format == Pg_VIDEO_FORMAT_UYVY ||
  472.                     vcaps.format == Pg_VIDEO_FORMAT_RGB555 ||
  473.                     vcaps.format == Pg_VIDEO_FORMAT_RGB565 ||
  474.                     vcaps.format == Pg_VIDEO_FORMAT_RGB8888 )
  475.                 {
  476.                     p_vout->p_sys->i_vc_flags  = vcaps.flags;
  477.                     p_vout->p_sys->i_vc_format = vcaps.format;
  478.                 }
  479.                 vcaps.size = sizeof( vcaps );
  480.             }
  481.             if( p_vout->p_sys->i_vc_format == 0 )
  482.             {
  483.                 msg_Warn( p_vout, "need YV12, YUY2 or RGB8888 overlay" );
  484.                 p_vout->p_sys->i_mode = MODE_NORMAL_MEM;
  485.             }
  486.         }
  487.     }
  488.     /* use video ram if we have enough available */
  489.     if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM &&
  490.         (minfo.bits_per_pixel != 8) &&
  491.         hwcaps.currently_available_video_ram >=
  492.         ( ( minfo.width * minfo.height * minfo.bits_per_pixel * MAX_DIRECTBUFFERS) / 8 ) )
  493.     {
  494.         p_vout->p_sys->i_mode = MODE_VIDEO_MEM;
  495.         printf("Using video memory...n");
  496.     }
  497.     p_vout->p_sys->i_img_type = minfo.type;
  498.     p_vout->p_sys->screen_dim.w = minfo.width;
  499.     p_vout->p_sys->screen_dim.h = minfo.height;
  500.     p_vout->p_sys->i_screen_depth = minfo.bits_per_pixel;
  501.     switch( p_vout->p_sys->i_screen_depth )
  502.     {
  503.         case 8:
  504.             p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
  505.             p_vout->p_sys->i_bytes_per_pixel = 1;
  506.             p_vout->output.pf_setpalette = SetPalette;
  507.             break;
  508.         case 15:
  509.             p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
  510.             p_vout->p_sys->i_bytes_per_pixel = 2;
  511.             p_vout->output.i_rmask = 0x7c00;
  512.             p_vout->output.i_gmask = 0x03e0;
  513.             p_vout->output.i_bmask = 0x001f;
  514.             break;
  515.         case 16:
  516.             p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
  517.             p_vout->p_sys->i_bytes_per_pixel = 2;
  518.             p_vout->output.i_rmask = 0xf800;
  519.             p_vout->output.i_gmask = 0x07e0;
  520.             p_vout->output.i_bmask = 0x001f;
  521.             break;
  522.         case 24:
  523.             p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
  524.             p_vout->p_sys->i_bytes_per_pixel = 3;
  525.             p_vout->output.i_rmask = 0xff0000;
  526.             p_vout->output.i_gmask = 0x00ff00;
  527.             p_vout->output.i_bmask = 0x0000ff;
  528.             break;
  529.         case 32:
  530.         default:
  531.             p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
  532.             p_vout->p_sys->i_bytes_per_pixel = 4;
  533.             p_vout->output.i_rmask = 0xff0000;
  534.             p_vout->output.i_gmask = 0x00ff00;
  535.             p_vout->output.i_bmask = 0x0000ff;
  536.             break;
  537.     }
  538.     return( 0 );
  539. }
  540. /*****************************************************************************
  541.  * QNXCreateWnd: create and realize the main window
  542.  *****************************************************************************/
  543. static int QNXCreateWnd( vout_thread_t * p_vout )
  544. {
  545.     PtArg_t args[8];
  546.     PhPoint_t pos = { 0, 0 };
  547.     PgColor_t color = Pg_BLACK;
  548.     if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
  549.     {
  550.         if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY )
  551.         {
  552.             color = PgGetOverlayChromaColor();
  553.         }
  554.     }
  555.     /* fullscreen, set dimension */
  556.     if( p_vout->b_fullscreen )
  557.     {
  558.         p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;
  559.         p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;
  560.         p_vout->output.i_width = p_vout->p_sys->dim.w = p_vout->p_sys->screen_dim.w;
  561.         p_vout->output.i_height = p_vout->p_sys->dim.h = p_vout->p_sys->screen_dim.h;
  562.     }
  563.     /* set window parameters */
  564.     PtSetArg( &args[0], Pt_ARG_POS, &pos, 0 );
  565.     PtSetArg( &args[1], Pt_ARG_DIM, &p_vout->p_sys->dim, 0 );
  566.     PtSetArg( &args[2], Pt_ARG_FILL_COLOR, color, 0 );
  567.     PtSetArg( &args[3], Pt_ARG_WINDOW_TITLE, "VLC media player", 0 );
  568.     PtSetArg( &args[4], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE );
  569.     PtSetArg( &args[5], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
  570.               Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_CLOSE );
  571.     PtSetArg( &args[6], Pt_ARG_WINDOW_RENDER_FLAGS,
  572.               p_vout->b_fullscreen ? Pt_FALSE : Pt_TRUE,
  573.               Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE );
  574.     /* create window */
  575.     p_vout->p_sys->p_window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 7, args);
  576.     if( p_vout->p_sys->p_window == NULL )
  577.     {
  578.         msg_Err( p_vout, "unable to create window" );
  579.         return( 1 );
  580.     }
  581.     /* realize the window widget */
  582.     if( PtRealizeWidget( p_vout->p_sys->p_window ) != 0 )
  583.     {
  584.         msg_Err( p_vout, "unable to realize window widget" );
  585.         PtDestroyWidget( p_vout->p_sys->p_window );
  586.         return( 1 );
  587.     }
  588.     /* get window frame size */
  589.     if( PtWindowFrameSize( NULL, p_vout->p_sys->p_window,
  590.                            &p_vout->p_sys->frame ) != 0 )
  591.     {
  592.         msg_Err( p_vout, "unable to get window frame size" );
  593.         PtDestroyWidget( p_vout->p_sys->p_window );
  594.         return( 1 );
  595.     }
  596.     return( 0 );
  597. }
  598. /*****************************************************************************
  599.  * QNXDestroyWnd: unrealize and destroy the main window
  600.  *****************************************************************************/
  601. static int QNXDestroyWnd( vout_thread_t * p_vout )
  602. {
  603.     /* destroy the window widget */
  604.     PtUnrealizeWidget( p_vout->p_sys->p_window );
  605. //    PtDestroyWidget( p_vout->p_sys->p_window );
  606.     /* destroy video channel */
  607.     if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
  608.     {
  609.         PgDestroyVideoChannel( p_vout->p_sys->p_channel );
  610.     }
  611.     return( 0 );
  612. }
  613. /*****************************************************************************
  614.  * NewPicture: allocate a picture
  615.  *****************************************************************************
  616.  * Returns 0 on success, -1 otherwise
  617.  *****************************************************************************/
  618. static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic, int index )
  619. {
  620.     /* We know the chroma, allocate a buffer which will be used
  621.      * directly by the decoder */
  622.     p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
  623.     if( p_pic->p_sys == NULL )
  624.     {
  625.         return -1;
  626.     }
  627.     switch( p_vout->p_sys->i_mode )
  628.     {
  629.     case MODE_NORMAL_MEM:
  630.     case MODE_SHARED_MEM:
  631.         /* create images for [shared] memory blit */
  632.         if( !( p_pic->p_sys->p_image = PhCreateImage( NULL,
  633.                     p_vout->p_sys->dim.w, p_vout->p_sys->dim.h,
  634.                     p_vout->p_sys->i_img_type, NULL, 0,
  635.                     p_vout->p_sys->i_mode == MODE_SHARED_MEM ) ) ) {
  636.             msg_Err( p_vout, "cannot create image" );
  637.             free( p_pic->p_sys );
  638.             return( -1 );
  639.         }
  640.         p_pic->p->p_pixels = p_pic->p_sys->p_image->image;
  641.         p_pic->p->i_lines = p_pic->p_sys->p_image->size.h;
  642.         p_pic->p->i_visible_lines = p_pic->p_sys->p_image->size.h;
  643.         p_pic->p->i_pitch = p_pic->p_sys->p_image->bpl;
  644.         p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
  645.         p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel
  646.                                      * p_pic->p_sys->p_image->size.w;
  647.         p_pic->i_planes = 1;
  648.         break;
  649.     case MODE_VIDEO_MEM:
  650.         /* create offscreen contexts for video memory blit */
  651.         if( ( p_pic->p_sys->p_ctx[0] = PdCreateOffscreenContext( 0,
  652.                         p_vout->p_sys->dim.w, p_vout->p_sys->dim.h,
  653.                        Pg_OSC_MEM_PAGE_ALIGN) ) == NULL )
  654.         {
  655.             msg_Err( p_vout, "unable to create offscreen context" );
  656.             free( p_pic->p_sys );
  657.             return( -1 );
  658.         }
  659.         /* get context pointers */
  660.         if( (  p_pic->p_sys->p_buf[0] =
  661.             PdGetOffscreenContextPtr ( p_pic->p_sys->p_ctx[0] ) ) == NULL )
  662.         {
  663.             msg_Err( p_vout, "unable to get offscreen context ptr" );
  664.             PhDCRelease ( p_pic->p_sys->p_ctx[0] );
  665.             p_pic->p_sys->p_ctx[0] = NULL;
  666.             free( p_pic->p_sys );
  667.             return( -1 );
  668.         }
  669.         p_vout->p_sys->i_bytes_per_line = p_pic->p_sys->p_ctx[0]->pitch;
  670.         memset( p_pic->p_sys->p_buf[0], 0,
  671.             p_vout->p_sys->i_bytes_per_line * p_vout->p_sys->dim.h );
  672.         p_pic->p->p_pixels = p_pic->p_sys->p_buf[0];
  673.         p_pic->p->i_lines = p_pic->p_sys->p_ctx[0]->dim.h;
  674.         p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[0]->dim.h;
  675.         p_pic->p->i_pitch = p_pic->p_sys->p_ctx[0]->pitch;
  676.         p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
  677.         p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel
  678.                                      * p_pic->p_sys->p_ctx[0]->dim.w;
  679.         p_pic->i_planes = 1;
  680.         break;
  681.     case MODE_VIDEO_OVERLAY:
  682.         if (index == 0)
  683.         {
  684.             p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane1;
  685.             p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane1;
  686.             p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane1;
  687.         }
  688.         else
  689.         {
  690.             p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane2;
  691.             p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane2;
  692.             p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane2;
  693.         }
  694.         p_pic->p_sys->p_buf[Y_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[Y_PLANE] );
  695.         if( p_pic->p_sys->p_buf[Y_PLANE] == NULL )
  696.         {
  697.             msg_Err( p_vout, "unable to get video channel ctx ptr" );
  698.             return( 1 );
  699.         }
  700.         switch (p_vout->p_sys->i_vc_format)
  701.         {
  702.             case Pg_VIDEO_FORMAT_YUV420:
  703.                 p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
  704.                 p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] );
  705.                 p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] );
  706.                 if( p_pic->p_sys->p_buf[U_PLANE] == NULL ||
  707.                     p_pic->p_sys->p_buf[V_PLANE] == NULL )
  708.                 {
  709.                     msg_Err( p_vout, "unable to get video channel ctx ptr" );
  710.                     return( 1 );
  711.                 }
  712.                 p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE];
  713.                 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  714.                 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  715.                 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
  716.                 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
  717.                 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch;
  718.                 p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE];
  719.                 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
  720.                 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
  721.                 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch;
  722.                 p_pic->p[U_PLANE].i_pixel_pitch = 1;
  723.                 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch;
  724.                 p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE];
  725.                 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
  726.                 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
  727.                 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch;
  728.                 p_pic->p[V_PLANE].i_pixel_pitch = 1;
  729.                 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch;
  730.                 p_pic->i_planes = 3;
  731.                 break;
  732.             case Pg_VIDEO_FORMAT_YV12:
  733.                 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
  734.                 p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] );
  735.                 p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] );
  736.                 if( p_pic->p_sys->p_buf[U_PLANE] == NULL ||
  737.                     p_pic->p_sys->p_buf[V_PLANE] == NULL )
  738.                 {
  739.                     msg_Err( p_vout, "unable to get video channel ctx ptr" );
  740.                     return( 1 );
  741.                 }
  742.                 p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE];
  743.                 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  744.                 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  745.                 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
  746.                 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
  747.                 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch;
  748.                 p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE];
  749.                 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
  750.                 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
  751.                 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch;
  752.                 p_pic->p[U_PLANE].i_pixel_pitch = 1;
  753.                 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch;
  754.                 p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE];
  755.                 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
  756.                 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
  757.                 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch;
  758.                 p_pic->p[V_PLANE].i_pixel_pitch = 1;
  759.                 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch;
  760.                 p_pic->i_planes = 3;
  761.                 break;
  762.             case Pg_VIDEO_FORMAT_UYVY:
  763.             case Pg_VIDEO_FORMAT_YUY2:
  764.                 if (p_vout->p_sys->i_vc_format == Pg_VIDEO_FORMAT_UYVY)
  765.                 {
  766.                     p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
  767.                 }
  768.                 else
  769.                 {
  770.                     p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
  771.                 }
  772.                 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
  773.                 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  774.                 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  775.                 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
  776.                 p_pic->p->i_pixel_pitch = 4;
  777.                 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
  778.                 p_pic->i_planes = 1;
  779.                 break;
  780.             case Pg_VIDEO_FORMAT_RGB555:
  781.                 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
  782.                 p_vout->output.i_rmask = 0x001f;
  783.                 p_vout->output.i_gmask = 0x03e0;
  784.                 p_vout->output.i_bmask = 0x7c00;
  785.                 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
  786.                 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  787.                 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  788.                 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
  789.                 p_pic->p->i_pixel_pitch = 2;
  790.                 p_pic->p->i_visible_pitch = 2 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
  791.                 p_pic->i_planes = 1;
  792.                 break;
  793.             case Pg_VIDEO_FORMAT_RGB565:
  794.                 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
  795.                 p_vout->output.i_rmask = 0x001f;
  796.                 p_vout->output.i_gmask = 0x07e0;
  797.                 p_vout->output.i_bmask = 0xf800;
  798.                 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
  799.                 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  800.                 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  801.                 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
  802.                 p_pic->p->i_pixel_pitch = 4;
  803.                 p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
  804.                 p_pic->i_planes = 1;
  805.                 break;
  806.             case Pg_VIDEO_FORMAT_RGB8888:
  807.                 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
  808.                 p_vout->output.i_rmask = 0x000000ff;
  809.                 p_vout->output.i_gmask = 0x0000ff00;
  810.                 p_vout->output.i_bmask = 0x00ff0000;
  811.                 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
  812.                 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  813.                 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
  814.                 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
  815.                 p_pic->p->i_pixel_pitch = 4;
  816.                 p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
  817.                 p_pic->i_planes = 1;
  818.                 break;
  819.         }
  820. #if 0
  821.     switch( p_vout->output.i_chroma )
  822.     {
  823. #ifdef MODULE_NAME_IS_xvideo
  824.         case VLC_FOURCC('Y','2','1','1'):
  825.             p_pic->p->p_pixels = p_pic->p_sys->p_image->data
  826.                                   + p_pic->p_sys->p_image->offsets[0];
  827.             p_pic->p->i_lines = p_vout->output.i_height;
  828.             p_pic->p->i_visible_lines = p_vout->output.i_height;
  829.             /* XXX: this just looks so plain wrong... check it out ! */
  830.             p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4;
  831.             p_pic->p->i_pixel_pitch = 4;
  832.             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
  833.             p_pic->i_planes = 1;
  834.             break;
  835. #endif
  836. #endif
  837.     default:
  838.         /* This shouldn't happen ! */
  839.         break;
  840.     }
  841.     return 0;
  842. }
  843. /*****************************************************************************
  844.  * FreePicture: destroy a picture allocated with NewPicture
  845.  *****************************************************************************
  846.  * Destroy XImage AND associated data. If using Shm, detach shared memory
  847.  * segment from server and process, then free it. The XDestroyImage manpage
  848.  * says that both the image structure _and_ the data pointed to by the
  849.  * image structure are freed, so no need to free p_image->data.
  850.  *****************************************************************************/
  851. static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
  852. {
  853.     if( ( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
  854.         p_vout->p_sys->i_mode == MODE_SHARED_MEM ) &&
  855.         p_pic->p_sys->p_image )
  856.     {
  857.         PhReleaseImage( p_pic->p_sys->p_image );
  858.         free( p_pic->p_sys->p_image );
  859.     }
  860.     else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM &&
  861.              p_pic->p_sys->p_ctx[0] )
  862.     {
  863.         PhDCRelease( p_pic->p_sys->p_ctx[0] );
  864.     }
  865.     free( p_pic->p_sys );
  866. }
  867. static int ResizeOverlayOutput(vout_thread_t *p_vout)
  868. {
  869.     int i_width, i_height, i_x, i_y;
  870.     int i_ret;
  871.     PgScalerProps_t props;
  872.     props.size   = sizeof( props );
  873.     props.format = p_vout->p_sys->i_vc_format;
  874.     props.flags  = Pg_SCALER_PROP_SCALER_ENABLE |
  875.                           Pg_SCALER_PROP_DOUBLE_BUFFER;
  876.     /* enable chroma keying if available */
  877.     if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY )
  878.     {
  879.         props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
  880.     }
  881.     /* set viewport position */
  882.     props.viewport.ul.x = p_vout->p_sys->pos.x;
  883.     props.viewport.ul.y = p_vout->p_sys->pos.y;
  884.     if( !p_vout->b_fullscreen )
  885.     {
  886.         props.viewport.ul.x += p_vout->p_sys->frame.ul.x;
  887.         props.viewport.ul.y += p_vout->p_sys->frame.ul.y;
  888.     }
  889.     /* set viewport dimension */
  890.     vout_PlacePicture( p_vout, p_vout->p_sys->dim.w,
  891.                            p_vout->p_sys->dim.h,
  892.                            &i_x, &i_y, &i_width, &i_height );
  893.     props.viewport.ul.x += i_x;
  894.     props.viewport.ul.y += i_y;
  895.     props.viewport.lr.x = i_width + props.viewport.ul.x;
  896.     props.viewport.lr.y = i_height + props.viewport.ul.y;
  897.     /* set source dimension */
  898.     props.src_dim.w = p_vout->output.i_width;
  899.     props.src_dim.h = p_vout->output.i_height;
  900.     /* configure scaler channel */
  901.     i_ret = PgConfigScalerChannel( p_vout->p_sys->p_channel, &props );
  902.     if( i_ret == -1 )
  903.     {
  904.         msg_Err( p_vout, "unable to configure video channel" );
  905.         return( 1 );
  906.     }
  907.     return ( 0 );
  908. }
  909. /*****************************************************************************
  910.  * SetPalette: sets an 8 bpp palette
  911.  *****************************************************************************
  912.  * This function sets the palette given as an argument. It does not return
  913.  * anything, but could later send information on which colors it was unable
  914.  * to set.
  915.  *****************************************************************************/
  916. static void SetPalette( vout_thread_t *p_vout,
  917.                         uint16_t *red, uint16_t *green, uint16_t *blue )
  918. {
  919.     int i;
  920.     /* allocate palette */
  921.     for( i = 0; i < 255; i++ )
  922.     {
  923.         /* kludge: colors are indexed reversely because color 255 seems
  924.          * to be reserved for black even if we try to set it to white */
  925.         p_vout->p_sys->p_colors[ i ] = PgRGB( red[ i ] >> 8, green[ i ] >> 8, blue[ i ] >> 8 );
  926.     }
  927. }