Commit 07fcaa5c4ee747bfc9599c193dad210a2f526e0a
1 parent
efc85b2a
better handling of bad URLs in DownloadTransform and utGallery, for #207
Showing
2 changed files
with
22 additions
and
25 deletions
openbr/plugins/gallery.cpp
| ... | ... | @@ -238,20 +238,18 @@ class utGallery : public BinaryGallery |
| 238 | 238 | |
| 239 | 239 | void writeTemplate(const Template &t) |
| 240 | 240 | { |
| 241 | - if (t.empty()) | |
| 242 | - return; | |
| 243 | - | |
| 244 | - const QByteArray imageID = QByteArray::fromHex(t.file.get<QByteArray>("ImageID")); | |
| 241 | + const QByteArray imageID = QByteArray::fromHex(t.file.get<QByteArray>("ImageID", QByteArray(32, '0'))); | |
| 245 | 242 | if (imageID.size() != 16) |
| 246 | 243 | qFatal("Expected 16-byte ImageID, got: %d bytes.", imageID.size()); |
| 247 | 244 | |
| 248 | - const int32_t algorithmID = t.file.get<int32_t>("AlgorithmID"); | |
| 245 | + const int32_t algorithmID = t.isEmpty() ? 0 : t.file.get<int32_t>("AlgorithmID"); | |
| 249 | 246 | QByteArray data; |
| 250 | 247 | if (algorithmID == 5) { |
| 251 | 248 | QDataStream stream(&data, QIODevice::WriteOnly); |
| 252 | 249 | stream << t; |
| 253 | 250 | } else { |
| 254 | - data = QByteArray((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize()); | |
| 251 | + if (!t.empty()) | |
| 252 | + data = QByteArray((const char*) t.m().data, t.m().rows * t.m().cols * t.m().elemSize()); | |
| 255 | 253 | |
| 256 | 254 | if (algorithmID == -1) { |
| 257 | 255 | const QRectF frontalFace = t.file.get<QRectF>("FrontalFace"); | ... | ... |
openbr/plugins/misc.cpp
| ... | ... | @@ -106,9 +106,6 @@ private: |
| 106 | 106 | { |
| 107 | 107 | dst.file = src.file; |
| 108 | 108 | QString url = src.file.get<QString>("URL", src.file.name).simplified(); |
| 109 | - if (url.isEmpty()) | |
| 110 | - return; | |
| 111 | - | |
| 112 | 109 | if (url.startsWith("file://")) |
| 113 | 110 | url = url.mid(7); |
| 114 | 111 | |
| ... | ... | @@ -136,25 +133,27 @@ private: |
| 136 | 133 | } |
| 137 | 134 | } |
| 138 | 135 | |
| 139 | - if (!device) | |
| 140 | - return; | |
| 136 | + QByteArray data; | |
| 137 | + if (device) { | |
| 138 | + data = device->readAll(); | |
| 139 | + delete device; | |
| 140 | + device = NULL; | |
| 141 | + } | |
| 141 | 142 | |
| 142 | - const QByteArray data = device->readAll(); | |
| 143 | - delete device; | |
| 144 | - device = NULL; | |
| 143 | + if (!data.isEmpty()) { | |
| 144 | + Mat encoded(1, data.size(), CV_8UC1, (void*)data.data()); | |
| 145 | + encoded = encoded.clone(); | |
| 146 | + if (mode == Permissive) { | |
| 147 | + dst += encoded; | |
| 148 | + } else { | |
| 149 | + Mat decoded = imdecode(encoded, IMREAD_UNCHANGED); | |
| 150 | + if (!decoded.empty()) | |
| 151 | + dst += (mode == Encoded) ? encoded : decoded; | |
| 152 | + } | |
| 145 | 153 | |
| 146 | - Mat encoded(1, data.size(), CV_8UC1, (void*)data.data()); | |
| 147 | - encoded = encoded.clone(); | |
| 148 | - if (mode == Permissive) { | |
| 149 | - dst += encoded; | |
| 150 | - } else { | |
| 151 | - Mat decoded = imdecode(encoded, IMREAD_UNCHANGED); | |
| 152 | - if (!decoded.empty()) | |
| 153 | - dst += (mode == Encoded) ? encoded : decoded; | |
| 154 | + dst.file.set("ImageID", QVariant(QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex())); | |
| 155 | + dst.file.set("AlgorithmID", data.isEmpty() ? 0 : (mode == Decoded ? 5 : 3)); | |
| 154 | 156 | } |
| 155 | - | |
| 156 | - dst.file.set("ImageID", QVariant(QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex())); | |
| 157 | - dst.file.set("AlgorithmID", mode == Decoded ? 5 : 3); | |
| 158 | 157 | } |
| 159 | 158 | }; |
| 160 | 159 | ... | ... |