Commit aa6daea4da0781c413f3876ab391e4b079667db7

Authored by Charles Otto
1 parent 8a80e124

Remove memGallery::align and associated infrastructure, no noticeable improvemen…

…t in performance and allocating the flat data is not feasible for large enough galleries
openbr/openbr_plugin.h
... ... @@ -447,12 +447,9 @@ BR_EXPORT QDataStream &operator>>(QDataStream &stream, Template &t);
447 447 */
448 448 struct TemplateList : public QList<Template>
449 449 {
450   - bool uniform; /*!< \brief Reserved for internal use. True if all templates are aligned and of the same size and type. */
451   - QVector<uchar> alignedData; /*!< \brief Reserved for internal use. */
452   -
453   - TemplateList() : uniform(false) {}
454   - TemplateList(const QList<Template> &templates) : uniform(false) { append(templates); } /*!< \brief Initialize the template list from another template list. */
455   - TemplateList(const QList<File> &files) : uniform(false) { foreach (const File &file, files) append(file); } /*!< \brief Initialize the template list from a file list. */
  450 + TemplateList() {}
  451 + TemplateList(const QList<Template> &templates) { append(templates); } /*!< \brief Initialize the template list from another template list. */
  452 + TemplateList(const QList<File> &files) { foreach (const File &file, files) append(file); } /*!< \brief Initialize the template list from a file list. */
456 453 BR_EXPORT static TemplateList fromGallery(const File &gallery); /*!< \brief Create a template list from a br::Gallery. */
457 454  
458 455 /*!< \brief Create a template list from a memory buffer of individual templates. Compatible with '.gal' galleries. */
... ...
openbr/plugins/gallery.cpp
... ... @@ -707,11 +707,9 @@ class MemoryGalleries : public Initializer
707 707  
708 708 public:
709 709 static QHash<File, TemplateList> galleries; /*!< TODO */
710   - static QHash<File, bool> aligned; /*!< TODO */
711 710 };
712 711  
713 712 QHash<File, TemplateList> MemoryGalleries::galleries;
714   -QHash<File, bool> MemoryGalleries::aligned;
715 713  
716 714 BR_REGISTER(Initializer, MemoryGalleries)
717 715  
... ... @@ -733,19 +731,12 @@ class memGallery : public Gallery
733 731 if ((galleryFile.suffix() == "gal") && galleryFile.exists() && !MemoryGalleries::galleries.contains(file)) {
734 732 QSharedPointer<Gallery> gallery(Factory<Gallery>::make(galleryFile));
735 733 MemoryGalleries::galleries[file] = gallery->read();
736   - align(MemoryGalleries::galleries[file]);
737   - MemoryGalleries::aligned[file] = true;
738 734 gallerySize = MemoryGalleries::galleries[file].size();
739 735 }
740 736 }
741 737  
742 738 TemplateList readBlock(bool *done)
743 739 {
744   - if (!MemoryGalleries::aligned[file]) {
745   - align(MemoryGalleries::galleries[file]);
746   - MemoryGalleries::aligned[file] = true;
747   - }
748   -
749 740 TemplateList templates = MemoryGalleries::galleries[file].mid(block*readBlockSize, readBlockSize);
750 741 for (qint64 i = 0; i < templates.size();i++) {
751 742 templates[i].file.set("progress", i + block * readBlockSize);
... ... @@ -759,36 +750,6 @@ class memGallery : public Gallery
759 750 void write(const Template &t)
760 751 {
761 752 MemoryGalleries::galleries[file].append(t);
762   - MemoryGalleries::aligned[file] = false;
763   - }
764   -
765   - static void align(TemplateList &templates)
766   - {
767   - if (!templates.empty() && templates[0].size() > 1) return;
768   -
769   - bool uniform = true;
770   - QVector<uchar> alignedData(templates.bytes<size_t>());
771   - size_t offset = 0;
772   - for (int i=0; i<templates.size(); i++) {
773   - Template &t = templates[i];
774   - if (t.size() > 1) qFatal("Can't handle multi-matrix template %s.", qPrintable(t.file.flat()));
775   -
776   - cv::Mat &m = t;
777   - if (m.data) {
778   - const size_t size = m.total() * m.elemSize();
779   - if (!m.isContinuous()) qFatal("Requires continuous matrix data of size %d for %s.", (int)size, qPrintable(t.file.flat()));
780   - memcpy(&(alignedData.data()[offset]), m.ptr(), size);
781   - m = cv::Mat(m.rows, m.cols, m.type(), &(alignedData.data()[offset]));
782   - offset += size;
783   - }
784   - uniform = uniform &&
785   - (m.rows == templates.first().m().rows) &&
786   - (m.cols == templates.first().m().cols) &&
787   - (m.type() == templates.first().m().type());
788   - }
789   -
790   - templates.uniform = uniform;
791   - templates.alignedData = alignedData;
792 753 }
793 754  
794 755 qint64 totalSize()
... ...