Beispiel #1
0
void VideoSource::resizeBuffer()
{
	listener->updatePixelCount( -( vwidth * vheight ) );
    vwidth = videoSink->getImageWidth();
    vheight = videoSink->getImageHeight();
    listener->updatePixelCount(  vwidth * vheight );

    if ( vheight > 0 )
        aspect = (float)vwidth / (float)vheight;
    else
        aspect = 1.33f;

    tex_width = GLUtil::getInstance()->pow2(vwidth);
    if ( videoSink->getImageFormat() == VIDEO_FORMAT_YUV420 )
        tex_height = GLUtil::getInstance()->pow2( 3*vheight/2 );
    else
        tex_height = GLUtil::getInstance()->pow2( vheight );

    gravUtil::logVerbose( "VideoSource::resizeBuffer: image size is %ix%i\n",
            vwidth, vheight );
    gravUtil::logVerbose( "VideoSource::resizeBuffer: texture size is %ix%i\n",
            tex_width, tex_height );

    // if it's not the first time we're allocating a texture
    // (ie, it's a resize) delete the previous texture
    if ( !init ) glDeleteTextures( 1, &texid );
    glGenTextures(1, &texid);

    glBindTexture(GL_TEXTURE_2D, texid);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    unsigned char *buffer = new unsigned char[tex_width * tex_height * 3];
    memset(buffer, 128, tex_width * tex_height * 3);
    glTexImage2D( GL_TEXTURE_2D,
                  0,
                  GL_RGB,
                  tex_width,
                  tex_height,
                  0,
                  GL_LUMINANCE,
                  GL_UNSIGNED_BYTE,
                  buffer);
    delete [] buffer;

    // update text bounds since the width might be different
    updateTextBounds();
}
Beispiel #2
0
bool VideoSource::updateName()
{
    bool nameChanged = false;
    std::string sdesName = getMetadata( VPMSession::VPMSESSION_SDES_NAME );
    std::string sdesCname = getMetadata( VPMSession::VPMSESSION_SDES_CNAME );

    if ( sdesName != "" && sdesName != name )
    {
        name = sdesName;
        nameChanged = true;
        finalName = true;
        gravUtil::logVerbose( "VideoSource::updateName: got name: %s\n",
                name.c_str() );
    }
    if ( sdesCname != "" && sdesCname != altName )
    {
        altName = sdesCname;
        nameChanged = true;
        gravUtil::logVerbose( "VideoSource::updateName: got cname: %s\n",
                altName.c_str() );
    }

    // if we don't have a proper name yet just use cname
    if ( name == "" && sdesCname != "" )
        name = sdesCname;

    // also update the location info
    std::string loc = getMetadata( VPMSession::VPMSESSION_SDES_LOC );
    size_t pos = loc.find( ',' );
    if ( pos != std::string::npos )
    {
        std::string latS = loc.substr( 0, pos );
        std::string lonS = loc.substr( pos+1 );
        lat = strtod( latS.c_str(), NULL );
        lon = strtod( lonS.c_str(), NULL );
    }

    if ( nameChanged )
        updateTextBounds();
    return nameChanged;
}
Beispiel #3
0
void VideoSource::resizeBuffer()
{
    // get intended size so we can resize, since the width might change here
    RectangleBase intended;
    intended.setScale( intendedWidth, intendedHeight );
    float posX = getDestX();
    float posY = getDestY();
    if ( !lastFillFull )
    {
        posX += getCenterOffsetX();
        posY += getCenterOffsetY();
    }
    intended.setPos( posX, posY );

    listener->updatePixelCount( -( vwidth * vheight ) );
    vwidth = videoSink->getImageWidth();
    vheight = videoSink->getImageHeight();
    listener->updatePixelCount(  vwidth * vheight );

    if ( vheight > 0 )
        destAspect = (float)vwidth / (float)vheight;
    else
        destAspect = 1.33f;

    if ( animated )
        aspectAnimating = true;
    else
        aspect = destAspect;

    tex_width = GLUtil::getInstance()->pow2( vwidth );
    if ( videoSink->getImageFormat() == VIDEO_FORMAT_YUV420 )
        tex_height = GLUtil::getInstance()->pow2( 3*vheight/2 );
    else
        tex_height = GLUtil::getInstance()->pow2( vheight );

    gravUtil::logVerbose( "VideoSource::resizeBuffer: image size is %ix%i\n",
                          vwidth, vheight );
    gravUtil::logVerbose( "VideoSource::resizeBuffer: texture size is %ix%i\n",
                          tex_width, tex_height );

    // if it's not the first time we're allocating a texture
    // (ie, it's a resize) delete the previous texture
    if ( !init )
        glDeleteTextures( 1, &texid );

    glGenTextures( 1, &texid );

    glBindTexture( GL_TEXTURE_2D, texid );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    unsigned char *buffer = new unsigned char[ tex_width * tex_height * 3 ];
    memset( buffer, 128, tex_width * tex_height * 3 );
    glTexImage2D( GL_TEXTURE_2D,
                  0,
                  GL_RGB,
                  tex_width,
                  tex_height,
                  0,
                  GL_LUMINANCE,
                  GL_UNSIGNED_BYTE,
                  buffer );
    delete[] buffer;

    // fill to intended size
    fillToRect( intended, lastFillFull );

    // update text bounds since the width might be different
    updateTextBounds();
}
/*--------------------------------------------------------------------------*/
int sci_stringbox(char * fname, void *pvApiCtx)
{
    SciErr sciErr;
    int* piAddrstackPointer = NULL;
    long long* stackPointer = NULL;
    char** strStackPointer   = NULL;
    double* pdblStackPointer = NULL;

    int type = -1;
    int *piType = &type;

    int iParentAxes = 0;
    int* piParentAxes = &iParentAxes;
    double* textCorners = NULL;
    int two   = 2;
    int four  = 4;
    double corners[4][2]; /* the four edges of the boundingRect */

    /* The function should be called with stringbox(handle) */
    CheckInputArgument(pvApiCtx,  1, 6);
    CheckOutputArgument(pvApiCtx,  0, 1);

    if (nbInputArgument(pvApiCtx) == 1)
    {
        int m;
        int n;
        /* A text handle should be specified */

        int iTextUID = 0;
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1);
            return 0;
        }

        /* get the handle */
        sciErr = getVarAddressFromPosition(pvApiCtx,  1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position  1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &m, &n, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: A ''%s'' handle expected.\n"), fname,  1, "Text");
            return 1;
        }

        if (m * n != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A ''%s'' handle expected.\n"), fname, 1, "Text");
            return 0;
        }

        /* Get the handle and check that this is a text handle */
        iTextUID = getObjectFromHandle((long int) * stackPointer);

        if (iTextUID == 0)
        {
            Scierror(999, _("%s: The handle is not valid.\n"), fname);
            return 0;
        }

        getGraphicObjectProperty(iTextUID, __GO_TYPE__, jni_int, (void **)&piType);

        if (type != __GO_LABEL__ && type != __GO_TEXT__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1);
            return 0;
        }

        getGraphicObjectProperty(iTextUID, __GO_PARENT_AXES__, jni_int, (void **)&piParentAxes);

        updateTextBounds(iTextUID);

        /*
         * To do: performs a projection/unprojection to obtain the bounding box in object coordinates
         * but using a rotation matrix corresponding to the default rotation angles (view == 2d)
         */

        getGraphicObjectProperty(iTextUID, __GO_CORNERS__, jni_double_vector, (void **)&textCorners);

        corners[1][0] = textCorners[0];
        corners[1][1] = textCorners[1];

        corners[0][0] = textCorners[3];
        corners[0][1] = textCorners[4];

        corners[3][0] = textCorners[6];
        corners[3][1] = textCorners[7];

        corners[2][0] = textCorners[9];
        corners[2][1] = textCorners[10];
    }
    else if (nbInputArgument(pvApiCtx) == 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d to %d expected.\n"), fname, 1, 3, 6);
        return 0;
    }
    else
    {
        int iParentSubwinUID = getOrCreateDefaultSubwin();
        char ** text = NULL;
        int textNbRow;
        int textNbCol;
        double xPos;
        double yPos;
        double angle = DEFAULT_ANGLE;
        int fontId;
        int *pfontId = &fontId;
        double fontSize;
        double *pfontSize = &fontSize;

        getGraphicObjectProperty(iParentSubwinUID, __GO_FONT_STYLE__, jni_int, (void**)&pfontId);
        getGraphicObjectProperty(iParentSubwinUID, __GO_FONT_SIZE__, jni_double, (void **)&pfontSize);

        /* Check that first argument is a string */
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: 2D array of strings expected.\n"), fname, 1);
            return 0;
        }
        sciErr = getVarAddressFromPosition(pvApiCtx,  1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position  1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrstackPointer, &textNbRow, &textNbCol, &strStackPointer))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname,  1);
            return 1;
        }

        /* retrieve it */
        text = strStackPointer;

        /* Second and third arguments should be scalars */
        if (getScalarFromStack(2, fname, &xPos, pvApiCtx) < 0)
        {
            freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
            return 0;
        }

        if (getScalarFromStack(3, fname, &yPos, pvApiCtx) < 0)
        {
            freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
            return 0;
        }

        if (nbInputArgument(pvApiCtx) >= 4)
        {
            /* angle is defined */
            if (getScalarFromStack(4, fname, &angle, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
        }

        if (nbInputArgument(pvApiCtx) >= 5)
        {
            double fontIdD;
            /* font style is defined */
            if (getScalarFromStack(5, fname, &fontIdD, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
            fontId = (int) fontIdD;
        }

        if (nbInputArgument(pvApiCtx) >= 6)
        {
            /* font size is defined */
            if (getScalarFromStack(6, fname, &fontSize, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
        }

        /* compute the box */
        getTextBoundingBox(text, textNbRow, textNbCol, xPos, yPos, angle, fontId, fontSize, corners);
        freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
    }


    /* copy everything into the lhs */
    sciErr = allocMatrixOfDouble(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, two, four, &pdblStackPointer);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    pdblStackPointer[0] = corners[1][0];
    pdblStackPointer[1] = corners[1][1];
    pdblStackPointer[2] = corners[0][0];
    pdblStackPointer[3] = corners[0][1];
    pdblStackPointer[4] = corners[3][0];
    pdblStackPointer[5] = corners[3][1];
    pdblStackPointer[6] = corners[2][0];
    pdblStackPointer[7] = corners[2][1];

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}