From 258c9f03a8fe9c435313c501a051d5fc0f474944 Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Tue, 19 May 2015 19:11:10 -0400 Subject: [PATCH] Implemented vecGallery read --- openbr/plugins/gallery/vec.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+), 0 deletions(-) create mode 100644 openbr/plugins/gallery/vec.cpp diff --git a/openbr/plugins/gallery/vec.cpp b/openbr/plugins/gallery/vec.cpp new file mode 100644 index 0000000..11f401e --- /dev/null +++ b/openbr/plugins/gallery/vec.cpp @@ -0,0 +1,77 @@ +#include + +namespace br +{ + +class vecGallery : public Gallery +{ + Q_OBJECT + + // Property for image width/height + Q_PROPERTY(int width READ get_width WRITE set_width RESET reset_width STORED false) + Q_PROPERTY(int height READ get_height WRITE set_height RESET reset_height STORED false) + BR_PROPERTY(int, width, 24) + BR_PROPERTY(int, height, 24) + + TemplateList readBlock(bool *done) + { + *done = true; + + QFile gallery; + gallery.setFileName(file); + if (!gallery.exists()) + qFatal("File %s does not exist", qPrintable(gallery.fileName())); + + QFile::OpenMode mode = QFile::ReadOnly; + if (!gallery.open(mode)) + qFatal("Can't open gallery: %s for reading", qPrintable(gallery.fileName())); + + // Read header + int count, size; + short temp; + + const size_t read1 = gallery.read((char*)&count,sizeof(count)); + const size_t read2 = gallery.read((char*)&size,sizeof(size)); + const size_t read3 = gallery.read((char*)&temp,sizeof(temp)); + const size_t read4 = gallery.read((char*)&temp,sizeof(temp)); + + if (read1 != sizeof(count) || read2 != sizeof(size) || read3 != sizeof(temp) || read4 != sizeof(temp)) + qFatal("Failed to read header."); + + if (size != width*height) + qFatal("Width*height != vector size."); + + // Read content + short *vec = new short[size]; + + TemplateList templates; + for (int i=0; i