+ int i_bytes, i_index, i_width_aligned, i_height_aligned;
+
+ /* Make sure the real dimensions are a multiple of 16 */
+ i_width_aligned = (i_width + 15) >> 4 << 4;
+ i_height_aligned = (i_height + 15) >> 4 << 4;
+
+ if( vout_InitPicture( p_this, p_pic, i_chroma,
+ i_width, i_height, i_aspect ) != VLC_SUCCESS )
+ {
+ p_pic->i_planes = 0;
+ return VLC_EGENERIC;
+ }
+
+ /* Calculate how big the new image should be */
+ i_bytes = p_pic->format.i_bits_per_pixel *
+ i_width_aligned * i_height_aligned / 8;
+
+ p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
+
+ if( p_pic->p_data == NULL )
+ {
+ p_pic->i_planes = 0;
+ return VLC_EGENERIC;
+ }
+
+ /* Fill the p_pixels field for each plane */
+ p_pic->p[ 0 ].p_pixels = p_pic->p_data;
+
+ for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
+ {
+ p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
+ p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
+ }
+
+ return VLC_SUCCESS;
+}
+
+/**
+ * Initialise the video format fields given chroma/size.
+ *
+ * This function initializes all the video_frame_format_t fields given the
+ * static properties of a picture (chroma and size).
+ * \param p_format Pointer to the format structure to initialize
+ * \param i_chroma Chroma to set
+ * \param i_width Width to set
+ * \param i_height Height to set
+ * \param i_aspect Aspect ratio
+ */
+void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
+ int i_width, int i_height, int i_aspect )
+{
+ p_format->i_chroma = i_chroma;
+ p_format->i_width = p_format->i_visible_width = i_width;
+ p_format->i_height = p_format->i_visible_height = i_height;
+ p_format->i_x_offset = p_format->i_y_offset = 0;
+ p_format->i_aspect = i_aspect;
+
+#if 0
+ /* Assume we have square pixels */
+ if( i_width && i_height )
+ p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
+ else
+ p_format->i_aspect = 0;
+#endif
+
+ switch( i_chroma )
+ {
+ case FOURCC_YUVA:
+ p_format->i_bits_per_pixel = 32;
+ break;
+ case FOURCC_I444:
+ case FOURCC_J444:
+ p_format->i_bits_per_pixel = 24;
+ break;
+ case FOURCC_I422:
+ case FOURCC_YUY2:
+ case FOURCC_UYVY:
+ case FOURCC_J422:
+ p_format->i_bits_per_pixel = 16;
+ break;
+ case FOURCC_I411:
+ case FOURCC_YV12:
+ case FOURCC_I420:
+ case FOURCC_J420:
+ case FOURCC_IYUV:
+ p_format->i_bits_per_pixel = 12;
+ break;
+ case FOURCC_I410:
+ case FOURCC_YVU9:
+ p_format->i_bits_per_pixel = 9;
+ break;
+ case FOURCC_Y211:
+ p_format->i_bits_per_pixel = 8;
+ break;
+ case FOURCC_YUVP:
+ p_format->i_bits_per_pixel = 8;
+ break;
+
+ case FOURCC_RV32:
+ case FOURCC_RGBA:
+ p_format->i_bits_per_pixel = 32;
+ break;
+ case FOURCC_RV24:
+ p_format->i_bits_per_pixel = 24;
+ break;
+ case FOURCC_RV15:
+ case FOURCC_RV16:
+ p_format->i_bits_per_pixel = 16;
+ break;
+ case FOURCC_RGB2:
+ p_format->i_bits_per_pixel = 8;
+ break;
+
+ case FOURCC_GREY:
+ case FOURCC_Y800:
+ case FOURCC_Y8:
+ p_format->i_bits_per_pixel = 8;
+ break;
+
+ default:
+ p_format->i_bits_per_pixel = 0;
+ break;
+ }
+}
+
+/**
+ * Initialise the picture_t fields given chroma/size.
+ *
+ * This function initializes most of the picture_t fields given a chroma and
+ * size. It makes the assumption that stride == width.
+ * \param p_this The calling object
+ * \param p_pic Pointer to the picture to initialize
+ * \param i_chroma The chroma fourcc to set
+ * \param i_width The width of the picture
+ * \param i_height The height of the picture
+ * \param i_aspect The aspect ratio of the picture
+ */
+int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
+ vlc_fourcc_t i_chroma,
+ int i_width, int i_height, int i_aspect )
+{
+ int i_index, i_width_aligned, i_height_aligned;