Minor update.
[pysvrt.git] / svrt_generator.cc
index 82b7c3b..33b98ee 100644 (file)
@@ -18,7 +18,7 @@
  *  General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with selector.  If not, see <http://www.gnu.org/licenses/>.
+ *  along with svrt.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
 
@@ -145,22 +145,46 @@ VignetteGenerator *new_generator(int nb) {
 
 extern "C" {
 
-  struct VignetteSet {
-    int n_problem;
-    int nb_vignettes;
-    int width;
-    int height;
-    unsigned char *data;
-  };
-
-  void svrt_generate_vignettes(int n_problem, int nb_vignettes, VignetteSet *result) {
-    VignetteGenerator *vg = new_generator(n_problem);
-    result->n_problem = n_problem;
-    result->nb_vignettes = nb_vignettes;
-    result->width = Vignette::width;
-    result->height = Vignette::height;
-    result->data = (unsigned char *) malloc(sizeof(unsigned char) * result->nb_vignettes * result->width * result->height);
-    delete vg;
+struct VignetteSet {
+  int n_problem;
+  int nb_vignettes;
+  int width;
+  int height;
+  unsigned char *data;
+};
+
+void svrt_generate_vignettes(int n_problem, int nb_vignettes, long *labels,
+                             VignetteSet *result) {
+  Vignette tmp;
+
+  if(n_problem < 1 || n_problem > NB_PROBLEMS) {
+    printf("Problem number should be between 1 and %d. Provided value is %d.\n", NB_PROBLEMS, n_problem);
+    exit(1);
+  }
+
+  VignetteGenerator *vg = new_generator(n_problem);
+  result->n_problem = n_problem;
+  result->nb_vignettes = nb_vignettes;
+  result->width = Vignette::width;
+  result->height = Vignette::height;
+  result->data = (unsigned char *) malloc(sizeof(unsigned char) * result->nb_vignettes * result->width * result->height);
+
+  unsigned char *s = result->data;
+  for(int i = 0; i < nb_vignettes; i++) {
+    if(labels[i] == 0 || labels[i] == 1) {
+      vg->generate(labels[i], &tmp);
+    } else {
+      printf("Vignette class label has to be 0 or 1. Provided value is %ld.\n", labels[i]);
+      exit(1);
+    }
+
+    int *r = tmp.content;
+    for(int k = 0; k < Vignette::width * Vignette::height; k++) {
+      *s++ = *r++;
+    }
   }
 
+  delete vg;
+}
+
 }