Exemple #1
0
void IoDev::sendValueScaled(QString tag,double v)
{
    if(tags.contains(tag))
    {
        //qDebug() << "sendValueScaled: tag -" <<  tag << "type:" << tags[tag][2] << " ; value :" << v ;
        QVector<qint16> t(2);
        data_scale[tag][0]=v;
        v=((v-data_scale[tag][1])/(data_scale[tag][2] - data_scale[tag][1]) *4000.0 );

        switch(tags[tag][2]) // тип даних
            {
                default:
                case 0: // Integer
                    sendValue(tag,qint16(v));
                    break;
                case 1: // Bool
                    break;
                case 2: // Real
                    sendValue(tag,v);
                    break;
                case 3: // Timer
                case 4: // Long
                    sendValue(tag,qint32(v));
                    break;
            }


    }
    else
        qDebug() << "Tag not found " << tag;

}
bool Vocabulary::save( const QString& filename ) const {
    QByteArray data;

    QDataStream out( &data, QIODevice::WriteOnly );
    out.setVersion( QDataStream::Qt_2_1 );

    // 0x0010 means 0.10.x version.  
    out << qint32( Vocabulary::magicNumber ) << qint16( 0x0010 ) << *this;

    QByteArray compressedData( qCompress( data ) ); 

    QFile dataFile( filename );
    QFileInfo dataFileInfo( dataFile );
    QDir dataFileDir( dataFileInfo.absoluteDir() );

    if( !dataFileDir.mkpath( dataFileDir.path() ) )
        return( false );

    if( !dataFile.open( QIODevice::WriteOnly ) )
        return( false );

    int ret = dataFile.write( compressedData );
    dataFile.close();

    if( ret == -1 || dataFile.error() != QFile::NoError ) {
        dataFile.unsetError();
        return( false );
    }

    return( true );
}
void weapon::reload()
{
    if (cooldown == 0)
        if (ammoLoad < ammoLoadMax && ammoCarr > 0)
        {
            qint16 amount = qMin(qint16(ammoLoadMax - ammoLoad), ammoCarr);
            ammoCarr -= amount;
            ammoLoad += amount;
            cooldown = reloadTime;
        }
}
Exemple #4
0
void Annotation::toDatastream(QDataStream &out) const
{
	// Write ID
	out << qint16(_id);

	// Write position and size
	out << _rect;

	// Write content
	out << _bgcolor;
	out << _text;
}
 void TcpThread::sendMsg(const QString message)

 {


     QByteArray outBlock;
    QDataStream out(&outBlock,QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_6);

    out<<qint16(0);                          //发送文件头信息大小
    out<<message.toUtf8();//按照UTF-8编码发送

    out.device()->seek(0);
    out<<qint16(outBlock.size()-sizeof(qint16));//实际文件的大小

    tcpSocket->write(outBlock);

     outBlock.resize(0);




 }
Exemple #6
0
void decompress(QString name, QString local){

    QFile file(name);
    Q_ASSERT_X(file.open(QIODevice::ReadOnly), Q_FUNC_INFO, "file not found.");
    QByteArray head =file.read(3);
    int Ttrash = (((uchar(head[0]))&0xe0)>>5);
    int Tsize =  (((qint16(head[0]))&0x1f)<<8)| ((quint16(head[1]))&0xff);
    int Tname = head.at(2);

    //caso tenha que mudar o local
    QString OriginalName= file.read(Tname);
    if(!local.isEmpty()){
       OriginalName = changesLocal(OriginalName,local);
    }

    //qDebug()<<OriginalName;
    QByteArray TreeRep= file.read(Tsize);
    //qDebug()<<TreeRep;
    HuffTree* tree = new HuffTree();
    tree->Rebuild(TreeRep);
    tree->showHuffTree();
    QByteArray data;

    //Lendo o arquivo e passando para bits.
    while (!file.atEnd()) {
         QByteArray line = file.read(1024);
         data.append(line);
    }
    file.close();
    QFile Original (OriginalName);
    Q_ASSERT_X(Original.open(QIODevice::WriteOnly), Q_FUNC_INFO, "file not found.");


    //Bits-Bytes
    QBitArray bit= ToBitArray(data);
    bit.resize(bit.size()-Ttrash);
    int bitsize=bit.size();
    QByteArray RetrieveData;
    //Lendo a arvore e copiando o nó para o arquivo
    for(int i=0;i<bitsize;++i){
        if(tree->transverse(bit.at(i))){
            RetrieveData.append( tree->current()->m_content);
            tree->setCurrent();
        }
    }
    Original.write(RetrieveData);
    Original.close();
    qDebug()<< "Arquivo Descomprimido! :)";
}
TcpServer::TcpServer(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TcpServer)
{
    ui->setupUi(this);
    srv = new QTcpServer(this);
    if (!srv->listen(QHostAddress::Any, qint16(1337)))
    {
        qDebug() << "Error - Not listening\n";
    }
    else
    {
        qDebug() << "Tcp Server started successfully\n";
    }
    connect(srv, SIGNAL(newConnection()), this, SLOT(someNewConnection()));
}
Exemple #8
0
    void OnUpdate(quint64 diff)
    {
        if (m_spawned && m_char)
        {
            m_randomMove -= diff;
            if (m_randomMove <= 0)
            {
                WorldPacket data(SMSG_UPDATE_POSITION);
                data << qint64(-1706442045669898);
                //data << qint32(Utils::irand(-2, 2));
                //data << qint32(Utils::irand(-19, -15));
                data << qint16(0);
                //data << quint8(Utils::randList(QList<qint32>() << 1 << 3 << 5 << 7));
                m_char->GetSession()->SendPacket(data);

                m_randomMove = 6000;
            }
        }
    }
Exemple #9
0
void QAmqpChannel::qos(qint16 prefetchCount, qint32 prefetchSize)
{
    Q_D(QAmqpChannel);
    QAmqpMethodFrame frame(QAmqpFrame::Basic, QAmqpChannelPrivate::bmQos);
    frame.setChannel(d->channelNumber);

    QByteArray arguments;
    QDataStream stream(&arguments, QIODevice::WriteOnly);

    d->requestedPrefetchSize = prefetchSize;
    d->requestedPrefetchCount = prefetchCount;

    stream << qint32(prefetchSize);
    stream << qint16(prefetchCount);
    stream << qint8(0x0);   // global

    frame.setArguments(arguments);
    d->sendFrame(frame);
}
static QString formatRegister(quint64 v, int size, RegisterFormat format, bool forEdit)
{
    QString result;
    if (format == HexadecimalFormat) {
        result = QString::number(v, 16);
        result.prepend(QString(2*size - result.size(), '0'));
    } else if (format == DecimalFormat) {
        result = QString::number(v, 10);
        result.prepend(QString(2*size - result.size(), ' '));
    } else if (format == SignedDecimalFormat) {
        qint64 sv;
        if (size >= 8)
            sv = qint64(v);
        else if (size >= 4)
            sv = qint32(v);
        else if (size >= 2)
            sv = qint16(v);
        else
            sv = qint8(v);
        result = QString::number(sv, 10);
        result.prepend(QString(2*size - result.size(), ' '));
    } else if (format == CharacterFormat) {
        bool spacesOnly = true;
        if (v >= 32 && v < 127) {
            spacesOnly = false;
            if (!forEdit)
                result += '\'';
            result += char(v);
            if (!forEdit)
                result += '\'';
        } else {
            result += "   ";
        }
        if (spacesOnly && forEdit)
            result.clear();
        else
            result.prepend(QString(2*size - result.size(), ' '));
    }
    return result;
}
Exemple #11
0
qint8 U2Bits::readInt16(const uchar* bits, int pos) {
    int res = (readInt8(bits, pos) << 8) + readInt8(bits, pos + 8);
    return qint16(res);
}
Exemple #12
0
void PictureGraphic::writeOutYourSelf(QDataStream &outStream) const
{
    outStream << qint16(Table::ImageType)
              << image;
}
Exemple #13
0
void WorldSession::SendUpdateObject()
{
    Character* character = GetCharacter();
    if (!character)
        return;

    WorldPacket data(SMSG_UPDATE_OBJECT);
    data << quint8(0);
    data << quint8(1);

    data << quint8(0);
    data << character->GetGuid();

    data.StartBlock<quint16>();
    {
        data << quint8(7);
        data << character->GetGuid();
        data << quint8(0);
        data << GetAccountInfos().id;
        data.WriteString(character->GetName(), true);

        data << character->GetBreed();
        data << character->GetPositionX();
        data << character->GetPositionY();
        data << character->GetPositionZ();
        data << character->GetInstanceId();
        data << character->GetDirection();

        // *** Skin
        data << character->GetGender();
        data << character->GetSkinColor();
        data << character->GetHairColor();
        data << character->GetPupilColor();
        data << character->GetSkinColorFactor();
        data << character->GetHairColorFactor();
        data << character->GetClothIndex();
        data << character->GetFaceIndex();
        data << qint16(-1); // Titles

        // PUBLIC_CHARACTERISTICS
        data << quint16(0); // size

        // FIGHT_PROPERTIES
        data << quint8(0); // hasProperties

        // FIGHT
        data << qint32(-1); // currentFightId
        data << quint8(0); // isKo
        data << quint8(0); // isDead
        data << quint8(0); // isSummonned
        data << quint8(0); // isFleeing
        data << qint8(-1); // obstacleId

        data << quint8(0); // hasSummon

        // EQUIPMENT_APPEARANCE
        data << quint16(0); // Views size

        // RUNNING_EFFECTS
        data << quint8(0); // hasInFightData
        data << quint8(0); // hasOutFightData

        // CURRENT_MOVEMENT_PATH
        data << quint8(0); // hasCurrentPath

        // WORLD_PROPERTIES
        data << quint8(0); // hasProperties

        // GROUP
        data << quint64(0); // partyId

        // TEMPLATE
        data << quint16(0); // sightRadius
        data << quint16(0); // aggroRadius

        // COLLECT
        data << quint16(0); // unavailableActions size

        // OCCUPATION
        data << quint8(0); // hasOccupation

        // XP
        data << character->GetXP();

        // XP_CHARACTERISTICS
        data << character->GetXPFreePoints();
        data << quint16(0); // xpBonusPoints size
        data << quint16(0); // characteristicBonusPoints size

        data << character->GetXPGauge(); // Should be named WakfuGauge...

        // CITIZEN_POINT
        data << quint16(0); // nationCitizenScores
        data << quint16(0); // offendedNations

        // GUILD_REMOTE_INFO
        data << character->GetGuildId();
        data << quint64(0); // Blazon
        data << quint16(0); // Level
        data << quint16(0); // GuildName

        // NATION_ID
        data << quint32(0); // NationId

        // NATION_SYNCHRO
        data << quint64(0); // rank
        data << quint64(0); // jobs
        data << quint64(0); // vote
        data << quint8(0); // governmentOpinion
        data << quint8(0); // isCandidate

        // SOCIAL_STATES
        data << quint8(0); // afkState
        data << quint8(0); // dndState

        // PET
        data << quint8(0); // hasPet

        // ACCOUNT_INFORMATION_REMOTE
        data << quint32(0); // subscriptionLevel
        data << quint16(0); // additionalRights size

        // COMPANION_CONTROLLER_ID
        data << quint64(0); // controllerId
        data << quint64(0); // companionId
    }
    data.EndBlock<quint16>();

    SendPacket(data);
}
Exemple #14
0
    void OnActive(Character* character, InteractiveElementType /*type*/)
    {
        // Seuelement une instance du script ou bien ? Du coup va poser des problèmes
        // si plusieurs joueurs en même temps ? Du coup gérer la création de nouvelles instances de scripts ?
        m_char = character;

        // Envoie comme quoi l'élémentId n'est plus "usable" (différence avec le paquet de spawn 200)
        WorldPacket data(SMSG_INTERACTIVE_ELEMENT_UPDATE);

        data << quint64(20114); // Instance ElementId

        data.StartBlock<quint16>();
        {
            data << quint8(1); // BlockCount

            data << quint8(2); // blockId
            data << quint32(6); // offset

            data << quint8(2); // BlockId

            data << quint16(1); // ?
            data << quint8(1); // isVisible
            data << quint8(0); // isUsable
            data << quint8(0); // ?
            data << quint8(0); // ?
            data << quint8(0); // ?
            data << quint32(0); // ?
        }
        data.EndBlock<quint16>();

        character->GetSession()->SendPacket(data);

        // Spawn Wapin
        WorldPacket data2(SMSG_UPDATE_OBJECT);
        data2 << quint8(0);
        data2 << quint8(1);

        data2 << quint8(1);
        data2 << qint64(-1706442045669898);

        data2.StartBlock<quint16>();
        {
            data2 << quint8(7);

            // GUID
            data2 << qint64(-1706442045669898);

            // IDENTITY
            data2 << quint8(1);
            data2 << qint64(-1);

            // NAME
            data2 << quint16(0);

            // BREED
            data2 << quint16(2644);

            // POSITION
            data2 << qint32(0); // X
            data2 << qint32(-17); // Y
            data2 << qint16(0); // Z
            data2 << quint16(-1); // InstanceId
            data2 << quint8(3); // Direction

            // APPEARANCE
            data2 << quint8(1); // Show

            // PUBLIC_CHARACTERISTICS
            data2 << quint16(1); // Level
            data2 << quint16(0); // States size

            // FIGHT_PROPERTIES
            data2 << quint8(0); // hasProperties

            // FIGHT
            data2 << qint32(-1); // currentFightId
            data2 << quint8(0); // isKo
            data2 << quint8(0); // isDead
            data2 << quint8(0); // isSummoned
            data2 << quint8(0); // isFleeing
            data2 << qint8(-1); // obstacleId
            data2 << quint8(0); // hasSummon

            // EQUIPMENT_APPEARANCE
            data2 << quint8(0); // size

            // RUNNING_EFFECTS
            data2 << quint8(1); // hasInFightData
            data2 << quint16(1); // data size
            data2 << quint8(13); // data

            data2 << quint8(1); // hasOutFightData
            data2 << quint16(0); // size

            // CURRENT_MOVEMENT_PATH
            data2 << quint8(0); // hasCurrentPath

            // WORLD_PROPERTIES
            data2 << quint8(0); // hasProperties

            // GROUP
            data2 << quint64(79645873605204); // PartyId
            data2 << quint16(1); // Members size
            data2 << qint16(-1); // breedId
            data2 << qint16(-1); // Level

            // TEMPLATE
            data2 << quint16(0); // sightRadius
            data2 << quint16(0); // aggroRadius

            // COLLECT
            data2 << quint16(0);

            // OCCUPATION
            data2 << quint8(0);

            // XP
            data2 << quint64(0);

            // XP_CHARACTERISTICS
            data2 << quint16(0);
            data2 << quint16(0);
            //data2 << quint16(0);
            //data2 << quint32(0);

            // Pourquoi sniff size 110 et la on est déjà à 117 ??
        }
        data2.EndBlock<quint16>();

        character->GetSession()->SendPacket(data2);

        // Activation du script (mouvement de la fenêtre entre autre)
        // Root aussi le joueur ?
        WorldPacket data3(SMSG_SCENARIO_SCRIPT);
        data3 << quint8(0); // Event
        data3 << quint32(12603); // Function
        data3 << quint32(1611); // ScenarioId
        data3 << quint8(1); // Long size?
        data3 << qint64(-1706442045669898); // Param
        character->GetSession()->SendPacket(data3);

        // Spawn Kano
        WorldPacket data4(SMSG_UPDATE_OBJECT);
        data4 << quint8(0);
        data4 << quint8(1);

        data4 << quint8(1);
        data4 << qint64(-1706442045669878);

        data4.StartBlock<quint16>();
        {
            data4 << quint8(7);

            // GUID
            data4 << qint64(-1706442045669878);

            // IDENTITY
            data4 << quint8(1);
            data4 << qint64(-1);

            // NAME
            data4 << quint16(0);

            // BREED
            data4 << quint16(2694);

            // POSITION
            data4 << qint32(0); // X
            data4 << qint32(-21); // Y
            data4 << qint16(3); // Z
            data4 << quint16(-1); // InstanceId
            data4 << quint8(3); // Direction

            // APPEARANCE
            data4 << quint8(1); // Show

            // PUBLIC_CHARACTERISTICS
            data4 << quint16(100); // Level
            data4 << quint16(0); // States size

            // FIGHT_PROPERTIES
            data4 << quint8(0); // hasProperties

            // FIGHT
            data4 << qint32(-1); // currentFightId
            data4 << quint8(0); // isKo
            data4 << quint8(0); // isDead
            data4 << quint8(0); // isSummoned
            data4 << quint8(0); // isFleeing
            data4 << qint8(-1); // obstacleId
            data4 << quint8(0); // hasSummon

            // EQUIPMENT_APPEARANCE
            data4 << quint8(0); // size

            // RUNNING_EFFECTS should be wrong
            data4 << quint8(1); // hasInFightData
            data4 << quint16(1); // data size
            data4 << quint8(13); // data

            data4 << quint8(1); // hasOutFightData
            data4 << quint16(0); // size

            // CURRENT_MOVEMENT_PATH
            data4 << quint8(0); // hasCurrentPath

            // WORLD_PROPERTIES
            data4 << quint8(0); // hasProperties

            // GROUP
            data4 << quint64(79645873605204); // PartyId
            data4 << quint16(1); // Members size
            data4 << qint16(-1); // breedId
            data4 << qint16(-1); // Level

            // TEMPLATE
            data4 << quint16(0); // sightRadius
            data4 << quint16(0); // aggroRadius

            // COLLECT
            data4 << quint16(0);

            // OCCUPATION
            data4 << quint8(0);

            // XP
            data4 << quint64(0);

            // XP_CHARACTERISTICS
            data4 << quint16(0);
            data4 << quint16(0);
            //data4 << quint16(0);
            //data4 << quint32(0);

            // Pourquoi sniff size 110 et la on est déjà à 117 ??
        }
        data4.EndBlock<quint16>();

        character->GetSession()->SendPacket(data4);

        // Texte : "Hé toi le nouveau" etc.
        WorldPacket data5(SMSG_SCENARIO_SCRIPT);
        data5 << quint8(0); // Event
        data5 << quint32(12687); // Function
        data5 << quint32(1611); // ScenarioId
        data5 << quint8(1); // Params size?
        data5 << qint64(-1706442045669878); // Param
        character->GetSession()->SendPacket(data5);

        // Flèche sur le wapin
        WorldPacket data6(SMSG_SCENARIO_SCRIPT);
        data6 << quint8(0); // Event
        data6 << quint32(12691); // Function
        data6 << quint32(1611); // ScenarioId
        data6 << quint8(1); // Long size?
        data6 << qint64(-1706442045669898); // Param
        character->GetSession()->SendPacket(data6);

        m_spawned = true;
    }
Exemple #15
0
void dlgVbCtrl::slotSet(int v)
{
    src.sendValue(QString("en_p_%1").arg(nI,2,10,QChar('0')),qint16(-v));
}
void ClientThread::getSignalFromClient()
{
    if (client.bytesAvailable() < 1)
        return;
    QByteArray data = client.read(5);
    qint64 size;
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    char *d = data.data();
    if (d[0] == 'f' || d[0] == 'd'){  //client is asking for all the entry names in image folder
        isCanceled = false;
        QDir imageDir(filePath);
        fileNames = imageDir.entryList(fileFilters, QDir::Files);
        folderNames = imageDir.entryList(folderFilters, QDir::Dirs);
        folderNames.removeAt(folderNames.indexOf("."));
        folderNames.removeAt(folderNames.indexOf(".."));
        for (int i = 0; i < folderNames.length(); i ++){
            block.clear();
            out.device()->seek(0);
            out << qint16(0x0000) << folderNames.at(i).toUtf8();
            size = block.size();
            client.write((char*)&size, sizeof(qint64));
            client.write(block.data(), size);
            if(!client.waitForBytesWritten(-1)){
                emit error(3);
                return;
            }
        }
        for (int i = 0; i < fileNames.length(); i ++){
            block.clear();
            out.device()->seek(0);
            out << qint16(0x0000) << fileNames.at(i).toUtf8();
            size = block.size();
            client.write((char*)&size, sizeof(qint64));
            client.write(block.data(), size);
            if(!client.waitForBytesWritten(-1)){
                emit error(3);
                return;
            }
        }
        //send file name
        block.clear();
        out.device()->seek(0);
        if (d[0] == 'f')
            out << qint16(0x000A);
        else if (d[0] == 'd')
            out << qint16(0x000B);
        size = block.size();
        client.write((char*)&size, sizeof(qint64));
        client.write(block.data(), size);
        if(!client.waitForBytesWritten(-1)){
            emit error(3);
            return;
        }
    }
    else if (d[0] == 't' || d[0] == 'r'){  //client has selected an entry in image folder and asks server to transmit that entry
        numberOfBytesToBeTransmit = 0;
        numberOfFilesSent = 0;
        indexOfEntry = d[1] + (d[2] << 8) + (d[3] << 16) + (d[4] << 24);

        if (d[0] == 't'){
            if (indexOfEntry < folderNames.length()){ //entry selected is a folder
                imageFolderPath = folderNames.at(indexOfEntry);
                imageFolderPath.prepend(filePath);
                imageFolderPath.append("/");
                QDir dir(imageFolderPath);
                QStringList nameFilters;
                nameFilters << "*.tif" << "*.ppf";
                QStringList filesInFolder = dir.entryList(nameFilters, QDir::Files);
                //send file quantity
                block.clear();
                out.device()->seek(0);
                QString fileQuantity;
                fileQuantity.setNum(filesInFolder.length());
                out << qint16(0x0001) << fileQuantity.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
                numberOfFilesToBeTransmit = filesInFolder.length();
                isFileSelected = false;
                isFolderSelected = true;
                for (int i = 0; i < filesInFolder.length(); i ++){
                    QString fp = filesInFolder.at(i);
                    fp.prepend(imageFolderPath);
                    QFile f(fp);
                    numberOfBytesToBeTransmit += f.size();
                }
                emit progressRange(numberOfBytesToBeTransmit);
            }
            else if (indexOfEntry < (folderNames.length() + fileNames.length())){       //entry selected is a single file
                imageFilePath = fileNames.at(indexOfEntry - folderNames.length());
                imageFilePath.prepend(filePath);

                //send file quantity
                block.clear();
                out.device()->seek(0);
                QString fileQuantity;
                fileQuantity.setNum(1);
                out << qint16(0x0001) << fileQuantity.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
                numberOfFilesToBeTransmit = 1;
                isFileSelected = true;
                isFolderSelected = false;

                QString fp = imageFilePath;
                QFile f(fp);
                numberOfBytesToBeTransmit = f.size();
                emit progressRange(numberOfBytesToBeTransmit);
            }
        }
        else if (d[0] == 'r'){
            if (indexOfEntry < folderNames.length() && (indexOfEntry >= 0)){
                QString pathOfTheFolderToDelete = filePath + folderNames.at(indexOfEntry);
                pathOfTheFolderToDelete = pathOfTheFolderToDelete.replace('/', '\\');
                char str[100];
                QByteArray tempString1 = pathOfTheFolderToDelete.toAscii();
                const char *tempString2 = tempString1.data();
                sprintf(str, "rd/s/q %s", tempString2);
                system(str);
            }
            else if (indexOfEntry < (folderNames.length() + fileNames.length()) && (indexOfEntry >= 0)){
                QString pathOfTheFileToDelete = filePath + fileNames.at(indexOfEntry - folderNames.length());
                QFile fileToDelete(pathOfTheFileToDelete);
                fileToDelete.remove();
            }
            else{   //DELETE ALL FILES!!!
                qDebug() << "DELETING ALL FILES!!!" << d[1] << d[2] << d[3] << d[4];
                for (int i = 0; i < (folderNames.length() + fileNames.length()); i ++){
                    if (i < folderNames.length()){          //delete all the folders
                        QString pathOfTheFolderToDelete = filePath + folderNames.at(i);
                        pathOfTheFolderToDelete = pathOfTheFolderToDelete.replace('/', '\\');
                        char str[100];
                        QByteArray tempString1 = pathOfTheFolderToDelete.toAscii();
                        const char *tempString2 = tempString1.data();
                        sprintf(str, "rd/s/q %s", tempString2);
                        system(str);
                    }
                    else{                                   //delete all the files
                        QString pathOfTheFileToDelete = filePath + fileNames.at(i - folderNames.length());
                        QFile fileToDelete(pathOfTheFileToDelete);
                        fileToDelete.remove();
                    }
                }
            }
        }
    }
    else if (d[0] == 'e'){  //errors,could be more than 6 color files or file size too big
        emit bytesSent(0);
        emit progressRange(10000);
        return;
    }
    else if (d[0] == 'n'){  //send file name and size
        if (isFolderSelected){  //sending folder
            QDir dir(imageFolderPath);
            QStringList nameFilters;
            nameFilters << "*.tif" << "*.ppf";
            QStringList filesInFolder = dir.entryList(nameFilters, QDir::Files);
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName, fileSize;

                //send file name
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0002) << filesInFolder.at(numberOfFilesSent).toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }

                //send file size
                block.clear();
                out.device()->seek(0);
                fileName = imageFolderPath;
                fileName.append(filesInFolder.at(numberOfFilesSent));
                QFile imageFile(fileName);
                fileSize = fileSize.setNum(imageFile.size());
                out << qint16(0x0003) << fileSize.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
            }
        }
        else{       //sending single file
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName, fileSize;
                QFile imageFile(imageFilePath);
                fileName = imageFilePath.right(imageFilePath.length() - imageFilePath.lastIndexOf("/") - 1);
                //send file name
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0002) << fileName.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }

                //send file size
                block.clear();
                out.device()->seek(0);
                fileSize = fileSize.setNum(imageFile.size());
                out << qint16(0x0003) << fileSize.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
            }
        }
    }
    else if (d[0] == 'g'){
        if (isFolderSelected){  //sending folder
            QDir dir(imageFolderPath);
            QStringList nameFilters;
            nameFilters << "*.tif" << "*.ppf";
            QStringList filesInFolder = dir.entryList(nameFilters, QDir::Files);
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName = imageFolderPath;
                fileName.append(filesInFolder.at(numberOfFilesSent));
                QFile imageFile(fileName);

                imageFile.open(QIODevice::ReadWrite);
                //send file content
                do{
                    qApp->processEvents();
                    if (!isCanceled){
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0004) << imageFile.read(0xFFF0);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1)){
                            emit error(3);
                        }
                    }
                    else{
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0006);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1)){
                            emit error(3);
                        }
                        emit status(6);
                        return;
                    }
                } while(!imageFile.atEnd() && (!isCanceled));
                //send file EOF
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0005);
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1))
                    emit error(3);
                emit status(3);
                imageFile.close();

                numberOfFilesSent ++;
            }
        }
        else{
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName;
                QFile imageFile(imageFilePath);
                fileName = imageFilePath.right(imageFilePath.length() - imageFilePath.lastIndexOf("/") - 1);

                imageFile.open(QIODevice::ReadWrite);
                //send file content
                do{
                    if (!isCanceled){
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0004) << imageFile.read(0xFFF0);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1)){
                            emit error(3);
                        }
                    }
                    else{
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0006);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1))
                            emit error(3);
                        emit status(6);
                        return;
                    }
                } while(!imageFile.atEnd() && (!isCanceled));
                //send file EOF
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0005);
                size = block.size();

                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1))
                    emit error(3);
                emit status(3);
                imageFile.close();
                numberOfFilesSent ++;
            }
        }
    }
}
Exemple #17
0
qint8 U2Bits::readInt32(const uchar* bits, int pos) {
    int res = (readInt8(bits, pos) << 24) + (readInt8(bits, pos + 8) << 16) + (readInt8(bits, pos + 16) << 8) + readInt8(bits, pos + 24);
    return qint16(res);
}
Exemple #18
0
void KoRgb32fTest::testConversion()
{
    const KoColorSpace* rgb32f = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);
    QVERIFY(rgb32f);
    KoRgbTraits<float>::Pixel p32f;
    quint8* p32fPtr = reinterpret_cast<quint8*>(&p32f);
    KoRgbTraits<float>::Pixel p32f1;
    quint8* p32fPtr1 = reinterpret_cast<quint8*>(&p32f1);
    KoRgbTraits<float>::Pixel p32f2;
    quint8* p32fPtr2 = reinterpret_cast<quint8*>(&p32f2);
    KoRgbTraits<float>::Pixel p32f3;
    quint8* p32fPtr3 = reinterpret_cast<quint8*>(&p32f3);
    KoRgbU16Traits::Pixel p16u;
    quint8* p16uPtr = reinterpret_cast<quint8*>(&p16u);

    // Test alpha function
    p32f.alpha = 1.0;
    QCOMPARE(qint32(rgb32f->opacityU8(p32fPtr)), 255);
    p32f.alpha = 0.5;
    QCOMPARE(qint32(rgb32f->opacityU8(p32fPtr)), qint32(float2int(255 * 0.5)));

    // Test setAlpha
    rgb32f->setOpacity(p32fPtr, quint8(255), 1);
    QCOMPARE(p32f.alpha, 1.0f);
    rgb32f->setOpacity(p32fPtr, quint8(0), 1);
    QCOMPARE(p32f.alpha, 0.0f);
    rgb32f->setOpacity(p32fPtr, quint8(127), 1);
    QCOMPARE(p32f.alpha, float(127 / 255.0));

    // Test conversion of black from 32f to 16u back to 32f
    p32f.red = 0.0;
    p32f.green = 0.0;
    p32f.blue = 0.0;
    p32f.alpha = 1.0;
    randomizator<quint16>(p16u);
    rgb32f->toRgbA16(p32fPtr, p16uPtr, 1);
    QCOMPARE(p16u.red, quint16(0));
    QCOMPARE(p16u.green, quint16(0));
    QCOMPARE(p16u.blue, quint16(0));
    QCOMPARE(p16u.alpha, quint16(65535));
    rgb32f->fromRgbA16(p16uPtr, p32fPtr, 1);
    QCOMPARE(p32f.red, 0.0f);
    QCOMPARE(p32f.green, 0.0f);
    QCOMPARE(p32f.blue, 0.0f);
    QCOMPARE(p32f.alpha, 1.0f);

    // Test conversion to QColor
    QColor color;
    rgb32f->toQColor(p32fPtr, &color, 0);
    QCOMPARE(color.red(), 0);
    QCOMPARE(color.green(), 0);
    QCOMPARE(color.blue(), 0);
    QCOMPARE(color.alpha(), 255);
    rgb32f->fromQColor(color, p32fPtr, 0);
    QCOMPARE(p32f.red, 0.0f);
    QCOMPARE(p32f.green, 0.0f);
    QCOMPARE(p32f.blue, 0.0f);
    QCOMPARE(p32f.alpha, 1.0f);

    // Test conversion of white from 32f to 16u back to 32f
    p32f.red = 1.0;
    p32f.green = 1.0;
    p32f.blue = 1.0;
    p32f.alpha = 1.0;
    randomizator<quint16>(p16u);
    rgb32f->toRgbA16(p32fPtr, p16uPtr, 1);
    QCOMPARE(p16u.red, quint16(47803));
    QCOMPARE(p16u.green, quint16(47803));
    QCOMPARE(p16u.blue, quint16(47803));
    QCOMPARE(p16u.alpha, quint16(65535));
    rgb32f->fromRgbA16(p16uPtr, p32fPtr, 1);
    QCOMPARE(p32f.red, 1.0f);
    QCOMPARE(p32f.green, 1.0f);
    QCOMPARE(p32f.blue, 1.0f);
    QCOMPARE(p32f.alpha, 1.0f);

    // Test mix op
    quint8* colors[3];
    colors[0] = p32fPtr;
    colors[1] = p32fPtr1;
    colors[2] = p32fPtr2;
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
    p32f2.red = 0.7; p32f2.green = 0.6; p32f2.blue = 0.7; p32f2.alpha = 1.0;
    p32f3.red = -1.0; p32f3.green = -1.0; p32f3.blue = -1.0; p32f3.alpha = -1.0;
    qint16 weights[3];
    weights[0] = qint16(255 / 3);
    weights[1] = qint16(255 / 3);
    weights[2] = qint16(255 / 3);
    rgb32f->mixColorsOp()->mixColors(colors, weights, 3, p32fPtr3);
    QCOMPARE(p32f3.red, 0.5f);
    QCOMPARE(p32f3.green, 0.4f);
    QCOMPARE(p32f3.blue, 0.7f);
    QCOMPARE(p32f3.alpha, 1.0f);

    // Test composite op
    const KoCompositeOp* over = rgb32f->compositeOp(COMPOSITE_OVER);
    QVERIFY(over);
    // Test no mask, full opacity
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
    QCOMPARE(p32f1.red, 0.5f);
    QCOMPARE(p32f1.green, 0.1f);
    QCOMPARE(p32f1.blue, 0.6f);
    QCOMPARE(p32f1.alpha, 1.0f);

    // Test no mask, half opacity
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 127);
    QCOMPARE(p32f1.red, 0.399608f);
    QCOMPARE(p32f1.green, 0.300784f);
    QCOMPARE(p32f1.blue, 0.700392f);
    QCOMPARE(p32f1.alpha, 1.0f);

    // Test mask, full opacity
    quint8 mask; mask = 127;
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), &mask, 1, 1, 1, 255);
    QCOMPARE(p32f1.red, 0.399608f);
    QCOMPARE(p32f1.green, 0.300784f);
    QCOMPARE(p32f1.blue, 0.700392f);
    QCOMPARE(p32f1.alpha, 1.0f);

    // Test mask, full opacity
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), &mask, 1, 1, 1, 127);
    QCOMPARE(p32f1.red, 0.349609f);
    QCOMPARE(p32f1.green, 0.400783f);
    QCOMPARE(p32f1.blue, 0.750391f);
    QCOMPARE(p32f1.alpha, 1.0f);

    // Test no mask, full opacity, transparent source
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 0.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 1.0;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
    QCOMPARE(p32f1.red, 0.3f);
    QCOMPARE(p32f1.green, 0.5f);
    QCOMPARE(p32f1.blue, 0.8f);
    QCOMPARE(p32f1.alpha, 1.0f);

    // Test no mask, full opacity, transparent dst
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 0.0;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
    QCOMPARE(p32f1.red, 0.5f);
    QCOMPARE(p32f1.green, 0.1f);
    QCOMPARE(p32f1.blue, 0.6f);
    QCOMPARE(p32f1.alpha, 1.0f);

    // Test no mask, full opacity, half-transparent dst
    p32f.red = 0.5; p32f.green = 0.1; p32f.blue = 0.6; p32f.alpha = 1.0;
    p32f1.red = 0.3; p32f1.green = 0.5; p32f1.blue = 0.8; p32f1.alpha = 0.5;
    over->composite(p32fPtr1, rgb32f->pixelSize(), p32fPtr, rgb32f->pixelSize(), 0, 0, 1, 1, 255);
    QCOMPARE(p32f1.red, 0.5f);
    QCOMPARE(p32f1.green, 0.1f);
    QCOMPARE(p32f1.blue, 0.6f);
    QCOMPARE(p32f1.alpha, 1.0f);
}
void MobiHeaderGenerator::generatePalmDataBase()
{
    m_dbHeader->title = m_title;
    m_dbHeader->type = "BOOK";
    m_dbHeader->creator = "MOBI";

    // set creation date
    // seconds since start of January 1, 1970
    QDateTime date = QDateTime::currentDateTime();

    qint32 pdTime = date.toTime_t();
    m_dbHeader->creationDate = pdTime;
    m_dbHeader->modificationDate = pdTime;

    qint16 recordsCount = qint16(calculateRecordsCount());

    m_dbHeader->uniqueIdSeed = (2 * recordsCount) - 1;
    m_dbHeader->nextRecordIdList = 0;
    m_dbHeader->numberOfRecords = recordsCount;

    m_dbHeader->headerLength = (78 + (calculateRecordsCount() * 8)) + 2; // 2 gap zero to make
                                                                        //a multiple of 4

    // I want to set offset but first i need the sizes.
    int recordId = 0;
    // record 0
    m_dbHeader->recordOffset = m_dbHeader->headerLength;
    m_dbHeader->recordUniqueId = recordId;
    m_dbHeader->recordsInfo.insert(m_dbHeader->recordOffset, m_dbHeader->recordUniqueId);
    recordId++;
    // text record.

    // palmDBHeader length + palmDoc header length (16) + MobiHeader length + EXTH header length
    // + EHTH header padding + book name (title) length + padding
    // *(padding are for to make it multiple of four bytes)
    // + 2052 bytes (I don't know what exactly it is for but i see it in
    // every file that i have made it by mobi packet creator)
    // + 1 ( to point the first character of text)

    m_dbHeader->recordOffset = qint32((m_dbHeader->headerLength + 16
                                       + m_mobiHeader->mobiHeaderLength
                                       + m_exthHeader->headerLength + m_exthHeader->pad
                                       + m_title.size() + (4 - (m_title.size() % 4)) + 2052));


    m_dbHeader->recordsInfo.insert(m_dbHeader->recordOffset, recordId);
    qint32 temp = m_dbHeader->recordOffset;
    recordId++;
    // "i" ?: I have added a zero byte between block texts, so record offset has gone to forward
    // after each insert.
    int i;
    for (i = 1; i < m_textRecordsOffset.size(); i++) {
        m_dbHeader->recordOffset = m_textRecordsOffset.at(i) + temp;
        m_dbHeader->recordOffset += qint32(i);
        m_dbHeader->recordsInfo.insert(m_dbHeader->recordOffset, recordId);
        recordId++;
    }
    m_dbHeader->recordOffset = (qint32(m_rawTextSize)) + temp + qint32(i - 1);
    // Each image is just a record and images records can be more that 4096.
    if (!m_imgListSize.isEmpty()) {
        m_dbHeader->recordOffset += qint32(1);
        m_dbHeader->recordUniqueId = recordId;
        m_dbHeader->recordsInfo.insert(m_dbHeader->recordOffset, m_dbHeader->recordUniqueId);
        m_dbHeader->recordOffset += qint32(1);
        recordId++;
        foreach (int imgSize, m_imgListSize) {
                // Our image has just one record.
                m_dbHeader->recordUniqueId = recordId;
                m_dbHeader->recordsInfo.insert(m_dbHeader->recordOffset, m_dbHeader->recordUniqueId);
                m_dbHeader->recordOffset += qint32(imgSize);
                recordId++;
            }