Commit e67fca6c7e2a4cfaded7156f981539ba2c70d910

Authored by Josh Klontz
1 parent 00e96a41

cleaned up TemplateList::fromGallery

Showing 1 changed file with 15 additions and 11 deletions
openbr/openbr_plugin.cpp
... ... @@ -403,6 +403,11 @@ TemplateList TemplateList::fromGallery(const br::File &gallery)
403 403 foreach (const br::File &file, gallery.split()) {
404 404 QScopedPointer<Gallery> i(Gallery::make(file));
405 405 TemplateList newTemplates = i->read();
  406 +
  407 + // If file is a Format not a Gallery
  408 + if (newTemplates.isEmpty())
  409 + newTemplates.append(file);
  410 +
406 411 newTemplates = newTemplates.mid(gallery.get<int>("pos", 0), gallery.get<int>("length", -1));
407 412  
408 413 const int step = gallery.get<int>("step", 1);
... ... @@ -413,35 +418,34 @@ TemplateList TemplateList::fromGallery(const br::File &amp;gallery)
413 418 newTemplates = downsampled;
414 419 }
415 420  
416   - if (gallery.get<bool>("reduce", false)) newTemplates = newTemplates.reduced();
  421 + if (gallery.getBool("reduce"))
  422 + newTemplates = newTemplates.reduced();
  423 +
417 424 const int crossValidate = gallery.get<int>("crossValidate");
418 425 if (crossValidate > 0) srand(0);
419 426  
420   - // If file is a Format not a Gallery
421   - if (newTemplates.isEmpty())
422   - newTemplates.append(file);
423   -
424 427 // Propogate metadata
425 428 for (int i=newTemplates.size()-1; i>=0; i--) {
426 429 newTemplates[i].file.append(gallery.localMetadata());
427 430 newTemplates[i].file.append(file.localMetadata());
428 431 newTemplates[i].file.set("Index", i+templates.size());
429 432 newTemplates[i].file.set("Gallery", gallery.name);
430   - if (newTemplates[i].file.getBool("allPartitions")) {
431   - if (crossValidate > 0) {
  433 +
  434 + if (crossValidate > 0) {
  435 + if (newTemplates[i].file.getBool("allPartitions")) {
432 436 // Set template to the first parition
433 437 newTemplates[i].file.set("Partition", QVariant(0));
  438 +
  439 + // Insert templates for all the other partitions
434 440 for (int j=crossValidate-1; j>=1; j--) {
435 441 Template allPartitionTemplate = newTemplates[i];
436 442 allPartitionTemplate.file.set("Partition", j);
437   - allPartitionTemplate.file.set("Label", i+templates.size());
438   - // Insert templates for all the other partitions
439 443 newTemplates.insert(i+1, allPartitionTemplate);
440 444 }
  445 + } else {
  446 + newTemplates[i].file.set("Partition", rand() % crossValidate);
441 447 }
442   - else newTemplates[i].file.set("Label", i+templates.size());
443 448 }
444   - else if (crossValidate > 0) newTemplates[i].file.set("Partition", rand()%crossValidate);
445 449 }
446 450  
447 451 if (!templates.isEmpty() && gallery.get<bool>("merge", false)) {
... ...