Esempio n. 1
0
void QPxaVideoOutput::doRenderFrame( const QVideoFrame& frame )
{
    //qWarning() << "QPxaVideoOutput::renderFrame" << geometry();
    if ( frame.isNull() ) {
        if ( d->overlay )
            d->overlay->fill( 16,128,128 ); // yuv:black
        return;
    }

    if ( frame.size() != d->videoSize ) {
        d->videoSize = frame.size();
        setModified(true);
    }

    //if something has changed, recalculate position of the image:
    if ( isModified() ) {
        setModified(false);

        QRegion paintRegion = deviceMappedClipRegion();
        QRect geometry = deviceMappedGeometry();

        QSize imageSize = frame.size();
        //respect frame aspect ratio
        if ( frame.hasCustomAspectRatio() ) {
            imageSize.setWidth( int(imageSize.height() * frame.aspectRatio()) );
        }

        switch ( effectiveRotation() ) {
            case QtopiaVideo::Rotate0:
            case QtopiaVideo::Rotate180:
                break;
            case QtopiaVideo::Rotate90:
            case QtopiaVideo::Rotate270:
                imageSize = QSize( imageSize.height(), imageSize.width() );
        };

        if ( scaleMode() == QtopiaVideo::FitWindow ) {
            double scaleFactor = qMin( double(geometry.width())/imageSize.width(),
                                       double(geometry.height())/imageSize.height() );

            //don't scale if the size is close to required
            if ( scaleFactor < 0.95 || scaleFactor > 1.1 ) {
                imageSize *= scaleFactor;
            }
        }

        d->imageRect = QRect( QPoint(0,0), imageSize );
        d->imageRect.moveCenter( QPoint( geometry.width()/2, geometry.height()/2 ) );

        if ( d->overlay )
            d->overlay->fill( 16, 128, 128 );//black color in yuv
    }

    if ( d->overlay )
        d->overlay->drawFrame( frame,
                               QRect( QPoint(0,0), frame.size() ),
                               d->imageRect,
                               effectiveRotation() );
}