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,6 +403,11 @@ TemplateList TemplateList::fromGallery(const br::File &gallery)
403 foreach (const br::File &file, gallery.split()) { 403 foreach (const br::File &file, gallery.split()) {
404 QScopedPointer<Gallery> i(Gallery::make(file)); 404 QScopedPointer<Gallery> i(Gallery::make(file));
405 TemplateList newTemplates = i->read(); 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 newTemplates = newTemplates.mid(gallery.get<int>("pos", 0), gallery.get<int>("length", -1)); 411 newTemplates = newTemplates.mid(gallery.get<int>("pos", 0), gallery.get<int>("length", -1));
407 412
408 const int step = gallery.get<int>("step", 1); 413 const int step = gallery.get<int>("step", 1);
@@ -413,35 +418,34 @@ TemplateList TemplateList::fromGallery(const br::File &amp;gallery) @@ -413,35 +418,34 @@ TemplateList TemplateList::fromGallery(const br::File &amp;gallery)
413 newTemplates = downsampled; 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 const int crossValidate = gallery.get<int>("crossValidate"); 424 const int crossValidate = gallery.get<int>("crossValidate");
418 if (crossValidate > 0) srand(0); 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 // Propogate metadata 427 // Propogate metadata
425 for (int i=newTemplates.size()-1; i>=0; i--) { 428 for (int i=newTemplates.size()-1; i>=0; i--) {
426 newTemplates[i].file.append(gallery.localMetadata()); 429 newTemplates[i].file.append(gallery.localMetadata());
427 newTemplates[i].file.append(file.localMetadata()); 430 newTemplates[i].file.append(file.localMetadata());
428 newTemplates[i].file.set("Index", i+templates.size()); 431 newTemplates[i].file.set("Index", i+templates.size());
429 newTemplates[i].file.set("Gallery", gallery.name); 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 // Set template to the first parition 436 // Set template to the first parition
433 newTemplates[i].file.set("Partition", QVariant(0)); 437 newTemplates[i].file.set("Partition", QVariant(0));
  438 +
  439 + // Insert templates for all the other partitions
434 for (int j=crossValidate-1; j>=1; j--) { 440 for (int j=crossValidate-1; j>=1; j--) {
435 Template allPartitionTemplate = newTemplates[i]; 441 Template allPartitionTemplate = newTemplates[i];
436 allPartitionTemplate.file.set("Partition", j); 442 allPartitionTemplate.file.set("Partition", j);
437 - allPartitionTemplate.file.set("Label", i+templates.size());  
438 - // Insert templates for all the other partitions  
439 newTemplates.insert(i+1, allPartitionTemplate); 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 if (!templates.isEmpty() && gallery.get<bool>("merge", false)) { 451 if (!templates.isEmpty() && gallery.get<bool>("merge", false)) {