void CharsetConversionTool::convertChars() { QApplication::setOverrideCursor( Qt::WaitCursor ); const Okteta::AddressRange convertedSection = mByteArrayView->selection(); QByteArray conversionResult; conversionResult.resize( convertedSection.width() ); Okteta::CharCodec* viewCharCodec = Okteta::CharCodec::createCodec( mByteArrayView->charCodingName() ); Okteta::CharCodec* otherCharCodec = Okteta::CharCodec::createCodec( mOtherCharCodecName ); const bool convertToOther = (mConversionDirection == ConvertTo); Okteta::CharCodec* fromCharCodec = convertToOther ? viewCharCodec : otherCharCodec; Okteta::CharCodec* toCharCodec = convertToOther ? otherCharCodec : viewCharCodec; CharsetConversionJob* charsetConversionJob = new CharsetConversionJob( reinterpret_cast<Okteta::Byte*>(conversionResult.data()), mByteArrayModel, convertedSection, convertToOther ? viewCharCodec : otherCharCodec, convertToOther ? otherCharCodec : viewCharCodec, mSubstitutingMissingChars, mSubstituteByte ); // TODO: report also actually converted bytes const bool success = charsetConversionJob->exec(); if( success ) //TODO: if nothing needed to be converted, just report and don't add change { Okteta::ChangesDescribable *changesDescribable = qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel ); if( changesDescribable ) { const QString description = i18nc("Converted from charset 1 to charset 2", "%1 to %2", fromCharCodec->name(), toCharCodec->name()); changesDescribable->openGroupedChange( description ); } mByteArrayModel->replace( convertedSection, conversionResult ); if( changesDescribable ) changesDescribable->closeGroupedChange(); } delete viewCharCodec; delete otherCharCodec; QApplication::restoreOverrideCursor(); const QMap<Okteta::Byte, int>& failedPerByteCount = charsetConversionJob->failedPerByteCount(); const int convertedBytesCount = charsetConversionJob->convertedBytesCount(); mByteArrayView->setFocus(); emit conversionDone( success, convertedBytesCount, failedPerByteCount ); }
void TableConversionWorker::process(){ Gif* res = NULL; ConversionStatistics* stat = new ConversionStatistics; bool lct = false; for (int i = 0; i < m_gif->getSizeOfFrames(); ++i) { if(m_gif->getFrame(i)->getLctFlag() == 1){ lct = true; break; } } m_mode = lct?Mode::Local_to_Global:Mode::Global_to_Local; std::stringstream oss, lss; oss << "original" << time(NULL) << ".gif"; std::string orgFileName = oss.str(); lss << "./generated/converted" << time(NULL) << ".gif"; std::string lzwFileName = lss.str(); IO orgIOFile(orgFileName); IO lzwIOFile(lzwFileName); #if defined(_WIN32) _mkdir("generated"); #else mkdir("generated", 0777); #endif stat->mode = m_mode; emit modeOut(&m_mode); switch (m_mode) { case Global_to_Local:{ clock_t cBegin = clock(); res = TableConverter::globalToLocal(m_gif); clock_t cEnd = clock(); double cElapsedSecs = double(cEnd - cBegin)*1000 / CLOCKS_PER_SEC; stat->conversionTime = cElapsedSecs; emit conversionDone(res); clock_t lBegin = clock(); lzwIOFile.saveGif(*res); clock_t lEnd = clock(); double lElapsedSecs = double(lEnd - lBegin)*1000 / CLOCKS_PER_SEC; stat->newLZWTime = lElapsedSecs; clock_t oBegin = clock(); orgIOFile.saveGif(*m_gif); clock_t oEnd = clock(); double oElapsedSecs = double(oEnd - oBegin)*1000 / CLOCKS_PER_SEC; stat->orgLZWTime = oElapsedSecs; stat->newSize = getFilesize(lzwFileName); stat->orgSize = getFilesize(orgFileName); remove(orgFileName.c_str()); } break; case Local_to_Global:{ clock_t cBegin = clock(); res = TableConverter::localToGlobal(m_gif); clock_t cEnd = clock(); double cElapsedSecs = double(cEnd - cBegin)*1000 / CLOCKS_PER_SEC; stat->conversionTime = cElapsedSecs; emit conversionDone(res); clock_t lBegin = clock(); lzwIOFile.saveGif(*res); clock_t lEnd = clock(); double lElapsedSecs = double(lEnd - lBegin)*1000 / CLOCKS_PER_SEC; stat->newLZWTime = lElapsedSecs; clock_t oBegin = clock(); orgIOFile.saveGif(*m_gif); clock_t oEnd = clock(); double oElapsedSecs = double(oEnd - oBegin)*1000 / CLOCKS_PER_SEC; stat->orgLZWTime = oElapsedSecs; stat->newSize = getFilesize(lzwFileName); stat->orgSize = getFilesize(orgFileName); remove(orgFileName.c_str()); } break; default: emit error(QString("Invalid mode. (") + m_mode + ")"); break; } if(res == NULL) emit error("Conversion failed."); emit statisticsOut(stat); emit finished(); }