예제 #1
0
int readLongLine(QString &buffer, IOAdapter* io, QScopedArrayPointer<char> &charbuff, int readBufferSize) {
    int len;
    buffer.clear();
    do {
        len = io->readLine(charbuff.data(), readBufferSize - 1);
        charbuff.data()[len] = '\0';
        buffer.append(QString(charbuff.data()));
    } while (readBufferSize - 1 == len);
    return buffer.length();
}
예제 #2
0
int readFpkmTrLine(QString &buffer, IOAdapter* io, QScopedArrayPointer<char> &charbuff) {
    int len;
    buffer.clear();
    do {
        len = io->readLine(charbuff.data(), DocumentFormat::READ_BUFF_SIZE - 1);
        charbuff.data()[len] = '\0';
        buffer.append(QString(charbuff.data()));
    } while (DocumentFormat::READ_BUFF_SIZE - 1 == len);
    return buffer.length();
}
예제 #3
0
int readLongLine (QString &buffer, IOAdapter* io, QScopedArrayPointer<char> &charbuff, int readBufferSize, U2OpStatus& os) {
    int len;
    buffer.clear();
    do {
        len = io->readLine(charbuff.data(), readBufferSize - 1);
        CHECK_EXT(!io->hasError(), os.setError(io->errorString()), -1);

        charbuff.data()[len] = '\0';
        buffer.append(QString(charbuff.data()));
    } while (readBufferSize - 1 == len);

    return buffer.length();
}
MetaCreatepatternbrushRecord::MetaCreatepatternbrushRecord(quint16 width, quint16 height, quint8 bitsPerPixel, const QScopedArrayPointer<quint8> &patternBits, size_t patternBitsLength) : MetafileRecord(35 + patternBitsLength, META_CREATEPATTERNBRUSH), type(0), width(width), height(height), planes(1), bitsPerPixel(bitsPerPixel), patternBits(), patternBitsLength(patternBitsLength)
{
    quint16 wb = (this->width * static_cast<quint16>(bitsPerPixel) + 15)/16;
    this->widthBytes = wb * 2;
    if(patternBitsLength != (this->widthBytes * this->height))
    {
        throw std::runtime_error("Invalid patternBitsLength value");
    }
    if(patternBitsLength > 0)
    {
        QScopedArrayPointer<quint8>(new quint8[patternBitsLength]).swap(this->patternBits);
        memcpy(reinterpret_cast<void *>(this->patternBits.data()), reinterpret_cast<const void *>(patternBits.data()), patternBitsLength);
    }
}
예제 #5
0
void Weights::calculateWeights()
{
    mCoefficientNumber = (mTwoDim ? ((size_t)mPolynomeOrder + 1) * ((size_t)mPolynomeOrder + 1)
                                  :  (size_t)mPolynomeOrder + 1);
    size_t  ix, iy, i, j;
    int     x, y;

    // Determine coordinates of pixels to be sampled

    if (mTwoDim)
    {

        int iPolynomeOrder = (int) mPolynomeOrder; //lets avoid signed/unsigned comparison warnings
        int iHeight        = (int) height();
        int iWidth         = (int) width();

        for (y = -iPolynomeOrder; y < iHeight + iPolynomeOrder; ++y)
        {
            for (x = -iPolynomeOrder; x < iWidth + iPolynomeOrder; ++x)
            {
                if ((x < 0 && y < 0 && -x - y < iPolynomeOrder + 2)                             ||
                    (x < 0 && y >= iHeight && -x + y - iHeight < iPolynomeOrder + 1)            ||
                    (x >= iWidth && y < 0 && x - y - iWidth < iPolynomeOrder + 1)               ||
                    (x >= iWidth && y >= iHeight && x + y - iWidth - iHeight < iPolynomeOrder)  ||
                    (x < 0 && y >= 0 && y < iHeight) || (x >= iWidth  && y >= 0 && y < iHeight) ||
                    (y < 0 && x >= 0 && x < iWidth ) || (y >= iHeight && x >= 0 && x < iWidth))
                {
                    QPoint position(x,y);
                    mPositions.append(position);
                }
            }
        }
    }
    else
    {
        // In the one-dimensional case, only the y coordinate and y size is used.  */

        for (y = (-1)*mPolynomeOrder; y < 0; ++y)
        {
            QPoint position(0,y);
            mPositions.append(position);
        }

        for (y = (int) height(); y < (int) height() + (int) mPolynomeOrder; ++y)
        {
            QPoint position(0,y);
            mPositions.append(position);
        }
    }

    // Allocate memory.

    QScopedArrayPointer<double> matrix (new double[mCoefficientNumber * mCoefficientNumber]);
    QScopedArrayPointer<double> vector0(new double[mPositions.count() * mCoefficientNumber]);
    QScopedArrayPointer<double> vector1(new double[mPositions.count() * mCoefficientNumber]);

    // Calculate coefficient matrix and vectors

    for (iy = 0; iy < mCoefficientNumber; ++iy)
    {
        for (ix = 0; ix < mCoefficientNumber; ++ix)
        {
            matrix [iy* mCoefficientNumber+ix] = 0.0;
        }

        for (j = 0; j < (size_t)mPositions.count(); ++j)
        {
            vector0 [iy * mPositions.count() + j] = polyTerm (iy, mPositions.at(j).x(),
                                                    mPositions.at(j).y(), mPolynomeOrder);

            for (ix = 0; ix < mCoefficientNumber; ++ix)
            {
                matrix [iy* mCoefficientNumber + ix] += (vector0 [iy * mPositions.count() + j]
                                                        * polyTerm (ix, mPositions.at(j).x(), mPositions.at(j).y(), mPolynomeOrder));
            }
        }
    }

    // Invert matrix.

    matrixInv (matrix.data(), mCoefficientNumber);

    // Multiply inverse matrix with vector.

    for (iy = 0; iy < mCoefficientNumber; ++iy)
    {
        for (j = 0; j < (size_t)mPositions.count(); ++j)
        {
            vector1 [iy * mPositions.count() + j] = 0.0;

            for (ix = 0; ix < mCoefficientNumber; ++ix)
            {
                vector1 [iy * mPositions.count() + j] += matrix [iy * mCoefficientNumber + ix]
                        * vector0 [ix * mPositions.count() + j];
            }
        }
    }

    // Store weights

    // Allocate mPositions.count() matrices.
    mWeightMatrices = new double** [mPositions.count()];

    for (i=0 ; i < (size_t)mPositions.count() ; ++i)
    {
        // Allocate mHeight rows on each position
        mWeightMatrices[i] = new double*[mHeight];

        for (j=0 ; j < mHeight ; ++j)
        {
            // Allocate mWidth columns on each row
            mWeightMatrices[i][j] = new double[mWidth];
        }
    }

    for (y = 0; y < (int) mHeight; ++y)
    {
        for (x = 0; x < (int) mWidth; ++x)
        {
            for (j = 0; j < (size_t)mPositions.count(); ++j)
            {
                mWeightMatrices [j][y][x] = 0.0;

                for (iy = 0; iy < mCoefficientNumber; ++iy)
                {
                    mWeightMatrices [j][y][x] += vector1 [iy * mPositions.count() + j]
                                                 * polyTerm (iy, x, y, mPolynomeOrder);
                }

                mWeightMatrices [j][y][x] *= (double) mPositions.count();
            }
        }
    }
}
예제 #6
0
// runProcess: Run a command line process (replacement for QProcess which
// does not exist in the bootstrap library).
bool runProcess(const QString &binary, const QStringList &args,
                const QString &workingDirectory,
                unsigned long *exitCode, QByteArray *stdOut, QByteArray *stdErr,
                QString *errorMessage)
{
    QScopedArrayPointer<char> stdOutFileName;
    QScopedArrayPointer<char> stdErrFileName;

    int stdOutFile = 0;
    if (stdOut) {
        stdOutFileName.reset(tempFilePattern());
        stdOutFile = mkstemp(stdOutFileName.data());
        if (stdOutFile < 0) {
            *errorMessage = QStringLiteral("mkstemp() failed: ") + QString::fromLocal8Bit(strerror(errno));
            return false;
        }
    }

    int stdErrFile = 0;
    if (stdErr) {
        stdErrFileName.reset(tempFilePattern());
        stdErrFile = mkstemp(stdErrFileName.data());
        if (stdErrFile < 0) {
            *errorMessage = QStringLiteral("mkstemp() failed: ") + QString::fromLocal8Bit(strerror(errno));
            return false;
        }
    }

    const pid_t pID = fork();

    if (pID < 0) {
        *errorMessage = QStringLiteral("Fork failed: ") + QString::fromLocal8Bit(strerror(errno));
        return false;
    }

    if (!pID) { // Child
        if (stdOut) {
            dup2(stdOutFile, STDOUT_FILENO);
            close(stdOutFile);
        }
        if (stdErr) {
            dup2(stdErrFile, STDERR_FILENO);
            close(stdErrFile);
        }

        if (!workingDirectory.isEmpty() && !QDir::setCurrent(workingDirectory)) {
            std::wcerr << "Failed to change working directory to " << workingDirectory << ".\n";
            ::_exit(-1);
        }

        char **argv  = new char *[args.size() + 2]; // Create argv.
        char **ap = argv;
        *ap++ = encodeFileName(binary);
        foreach (const QString &a, args)
            *ap++ = encodeFileName(a);
        *ap = 0;

        execvp(argv[0], argv);
        ::_exit(-1);
    }

    int status;
    pid_t waitResult;

    do {
        waitResult = waitpid(pID, &status, 0);
    } while (waitResult == -1 && errno == EINTR);

    if (stdOut) {
        *stdOut = readOutRedirectFile(stdOutFile);
        unlink(stdOutFileName.data());
    }
    if (stdErr) {
        *stdErr = readOutRedirectFile(stdErrFile);
        unlink(stdErrFileName.data());
    }

    if (waitResult < 0) {
        *errorMessage = QStringLiteral("Wait failed: ") + QString::fromLocal8Bit(strerror(errno));
        return false;
    }
    if (!WIFEXITED(status)) {
        *errorMessage = binary + QStringLiteral(" did not exit cleanly.");
        return false;
    }
    if (exitCode)
        *exitCode = WEXITSTATUS(status);
    return true;
}