X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=svrt.c;h=4969d5aac43f22750088c309850e97433217a8cc;hb=198149a1334feddec21a0a01e7f503ab4396e610;hp=307fcf646ef839f69bf4f3f8613a68e21682554d;hpb=dfca7e16051d1752db7daed892ecb200237e3bb6;p=pysvrt.git
diff --git a/svrt.c b/svrt.c
index 307fcf6..4969d5a 100644
--- a/svrt.c
+++ b/svrt.c
@@ -19,7 +19,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 .
+ * along with svrt. If not, see .
*
*/
@@ -27,6 +27,69 @@
#include "svrt_generator.h"
+THByteStorage *compress(THByteStorage *x) {
+ long k, g, n;
+
+ k = 0; n = 0;
+ while(k < x->size) {
+ g = 0;
+ while(k < x->size && x->data[k] == 255 && g < 255) { g++; k++; }
+ n++;
+ if(k < x->size && g < 255) { k++; }
+ }
+
+ if(x->data[k-1] == 0) {
+ n++;
+ }
+
+ THByteStorage *result = THByteStorage_newWithSize(n);
+
+ k = 0; n = 0;
+ while(k < x->size) {
+ g = 0;
+ while(k < x->size && x->data[k] == 255 && g < 255) { g++; k++; }
+ result->data[n++] = g;
+ if(k < x->size && g < 255) { k++; }
+ }
+ if(x->data[k-1] == 0) {
+ result->data[n++] = 0;
+ }
+
+ return result;
+}
+
+THByteStorage *uncompress(THByteStorage *x) {
+ long k, g, n;
+
+ k = 0;
+ for(n = 0; n < x->size - 1; n++) {
+ k = k + x->data[n];
+ if(x->data[n] < 255) { k++; }
+ }
+ k = k + x->data[n];
+
+ THByteStorage *result = THByteStorage_newWithSize(k);
+
+ k = 0;
+ for(n = 0; n < x->size - 1; n++) {
+ for(g = 0; g < x->data[n]; g++) {
+ result->data[k++] = 255;
+ }
+ if(x->data[n] < 255) {
+ result->data[k++] = 0;
+ }
+ }
+ for(g = 0; g < x->data[n]; g++) {
+ result->data[k++] = 255;
+ }
+
+ return result;
+}
+
+void seed(long s) {
+ srand48(s);
+}
+
THByteTensor *generate_vignettes(long n_problem, THLongTensor *labels) {
struct VignetteSet vs;
long nb_vignettes;