a?adido c?lculo de secciones para optimizar la extracci?n de c?mics

This commit is contained in:
Luis Ángel San Martín 2013-07-15 10:20:48 +02:00
parent ff17d8ef1f
commit b10b27864a
4 changed files with 125 additions and 8 deletions

View File

@ -240,7 +240,12 @@ QList<QString> FileComic::filter(const QList<QString> & src)
} }
void FileComic::fileExtracted(int index, const QByteArray & rawData) void FileComic::fileExtracted(int index, const QByteArray & rawData)
{ {
QFile f("c:/temp/out2.txt");
f.open(QIODevice::Append);
QTextStream out(&f);
int sortedIndex = _fileNames.indexOf(_order.at(index)); int sortedIndex = _fileNames.indexOf(_order.at(index));
out << sortedIndex << " , ";
f.close();
if(sortedIndex == -1) if(sortedIndex == -1)
return; return;
_pages[sortedIndex] = rawData; _pages[sortedIndex] = rawData;
@ -248,6 +253,104 @@ void FileComic::fileExtracted(int index, const QByteArray & rawData)
emit imageLoaded(sortedIndex,_pages[sortedIndex]); emit imageLoaded(sortedIndex,_pages[sortedIndex]);
} }
QList<QVector<quint32> > FileComic::getSections(int & sectionIndex)
{
QVector<quint32> sortedIndexes;
foreach(QString name, _fileNames)
{
sortedIndexes.append(_order.indexOf(name));
}
QList<QVector <quint32> > sections;
quint32 previous = 0;
sectionIndex = -1;
int sectionCount = 0;
QVector <quint32> section;
int idx = 0;
int realIdx;
foreach(quint32 i, sortedIndexes)
{
if(_firstPage == idx)
{
sectionIndex = sectionCount;
realIdx = i;
}
if(previous <= i)
{
//out << "idx : " << i << endl;
section.append(i);
previous = i;
}
else
{
if(sectionIndex == sectionCount) //found
{
if(section.indexOf(realIdx)!=0)
{
QVector <quint32> section1;
QVector <quint32> section2;
foreach(quint32 si,section)
{
if(si<realIdx)
section1.append(si);
else
section2.append(si);
}
sectionIndex++;
sections.append(section1);
sections.append(section2);
//out << "SPLIT" << endl;
}
else
{
sections.append(section);
}
}
else
sections.append(section);
section = QVector <quint32> ();
//out << "---------------" << endl;
section.append(i);
//out << "idx : " << i << endl;
previous = i;
sectionCount++;
}
idx++;
}
if(sectionIndex == sectionCount) //found
{
if(section.indexOf(realIdx)!=0)
{
QVector <quint32> section1;
QVector <quint32> section2;
foreach(quint32 si,section)
{
if(si<realIdx)
section1.append(si);
else
section2.append(si);
}
sectionIndex++;
sections.append(section1);
sections.append(section2);
//out << "SPLIT" << endl;
}
else
{
sections.append(section);
}
}
else
sections.append(section);
//out << "se han encontrado : " << sections.count() << " sectionIndex : " << sectionIndex << endl;
return sections;
}
void FileComic::process() void FileComic::process()
{ {
QFile f("c:/temp/out.txt"); QFile f("c:/temp/out.txt");
@ -290,8 +393,17 @@ void FileComic::process()
out << "tiempo en ordenar : " << myTimer.elapsed() << endl; out << "tiempo en ordenar : " << myTimer.elapsed() << endl;
QList<QByteArray> allData = archive.getAllData(this); _firstPage = 0;
_index = 0;
int sectionIndex;
QList<QVector <quint32> > sections = getSections(sectionIndex);
for(int i = sectionIndex; i<sections.count() ; i++)
archive.getAllData(sections.at(i),this);
for(int i = 0; i<sectionIndex; i++)
archive.getAllData(sections.at(i),this);
//archive.getAllData(QVector<quint32>(),this);
out << "tiempo en obtener datos : " << myTimer.elapsed() << endl; out << "tiempo en obtener datos : " << myTimer.elapsed() << endl;
/* /*
foreach(QString name,_fileNames) foreach(QString name,_fileNames)
@ -303,7 +415,7 @@ void FileComic::process()
emit imageLoaded(sortedIndex,_pages[sortedIndex]); emit imageLoaded(sortedIndex,_pages[sortedIndex]);
}*/ }*/
out << "tiempo en copiar datos : " << myTimer.elapsed() << endl; out << "--tiempo en copiar datos : " << myTimer.elapsed() << endl;
f.close(); f.close();
emit imagesLoaded(); emit imagesLoaded();
} }

View File

@ -29,8 +29,8 @@
int _cfi; int _cfi;
//open the comic at this point
int _firstPage;
bool _isPDF; bool _isPDF;
public: public:
@ -86,6 +86,7 @@
Q_OBJECT Q_OBJECT
private: private:
QList<QString> filter(const QList<QString> & src); QList<QString> filter(const QList<QString> & src);
QList<QVector<quint32> > getSections(int & sectionIndex);
public: public:
FileComic(); FileComic();
FileComic(const QString & path); FileComic(const QString & path);

View File

@ -166,14 +166,18 @@ int CompressedArchive::getNumFiles()
szInterface->archive->GetNumberOfItems(&numItems); szInterface->archive->GetNumberOfItems(&numItems);
return numItems; return numItems;
} }
QList<QByteArray> CompressedArchive::getAllData(ExtractDelegate * delegate) QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
{ {
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(true,delegate); CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(true,delegate);
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec); CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
extractCallbackSpec->PasswordIsDefined = false; extractCallbackSpec->PasswordIsDefined = false;
HRESULT result = szInterface->archive->Extract(NULL, -1, false, extractCallback); HRESULT result;
if(indexes.isEmpty())
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
else
result = szInterface->archive->Extract(indexes.data(), indexes.count(), false, extractCallback);
if (result != S_OK) if (result != S_OK)
{ {
qDebug() << "Extract Error" << endl; qDebug() << "Extract Error" << endl;

View File

@ -36,7 +36,7 @@ signals:
public slots: public slots:
int getNumFiles(); int getNumFiles();
QList<QByteArray> getAllData(ExtractDelegate * delegate = 0); QList<QByteArray> getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate = 0);
QByteArray getRawDataAtIndex(int index); QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames(); QList<QString> getFileNames();
private: private: