]> git.imager.perl.org - imager.git/blobdiff - datatypes.c
convert t/t55trans.t to Test::More
[imager.git] / datatypes.c
index e8ecab1614d15e2734292cc06cb4ca82148d5a05..a1efb9952b5027a7f32892f4ca853cbb671539f6 100644 (file)
@@ -132,7 +132,7 @@ llist_push(struct llist *l,void *data) {
   }
   /*   fprintf(stderr,"0x%08X\n",l->t); */
   if (llist_llink_push(l,l->t,data)) { 
-    m_fatal(3, "out of memory\n");
+    i_fatal(3, "out of memory\n");
   }
 }
 
@@ -162,15 +162,15 @@ llist_pop(struct llist *l,void *data) {
 
 void
 llist_dump(struct llist *l) {
-  int k,j;
+  int j;
   int i=0;
   struct llink *lnk; 
   lnk=l->h;
   while(lnk != NULL) {
     for(j=0;j<lnk->fill;j++) {
       /*       memcpy(&k,(char*)(lnk->data)+l->ssize*j,sizeof(void*));*/
-      memcpy(&k,(char*)(lnk->data)+l->ssize*j,sizeof(void*));
-      printf("%d - %X\n",i,k);
+      /*memcpy(&k,(char*)(lnk->data)+l->ssize*j,sizeof(void*));*/
+      printf("%d - %p\n",i,*(void **)((char *)(lnk->data)+l->ssize*j));
       i++;
     }
     lnk=lnk->n;
@@ -216,21 +216,22 @@ int
 octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b) {
   struct octt *c;
   int i,cm;
-  int ci,idx[8];
+  int ci;
   int rc;
   rc=0;
   c=ct;
   /*  printf("[r,g,b]=[%d,%d,%d]\n",r,g,b); */
-  ct->cnt++;
   for(i=7;i>-1;i--) {
     cm=1<<i;
     ci=((!!(r&cm))<<2)+((!!(g&cm))<<1)+!!(b&cm); 
     /* printf("idx[%d]=%d\n",i,ci); */
-    if (c->t[ci] == NULL) { c->t[ci]=octt_new(); rc=1; }
+    if (c->t[ci] == NULL) { 
+      c->t[ci]=octt_new(); 
+      rc=1; 
+    }
     c=c->t[ci];
-    c->cnt++;
-    idx[i]=ci;
   }
+  c->cnt++;  /* New. The only thing really needed (I think) */
   return rc;
 }
 
@@ -247,8 +248,12 @@ void
 octt_dump(struct octt *ct) {
        int i;
        /*      printf("node [0x%08X] -> (%d)\n",ct,ct->cnt); */
-       for(i=0;i<8;i++) if (ct->t[i] != NULL) printf("[ %d ] -> 0x%08X\n",i,(unsigned int)ct->t[i]);   
-       for(i=0;i<8;i++) if (ct->t[i] != NULL) octt_dump(ct->t[i]);
+       for(i=0;i<8;i++)
+         if (ct->t[i] != NULL) 
+           printf("[ %d ] -> %p\n", i, (void *)ct->t[i]);      
+       for(i=0;i<8;i++) 
+         if (ct->t[i] != NULL) 
+           octt_dump(ct->t[i]);
 }
 
 /* note that all calls of octt_count are operating on the same overflow 
@@ -267,3 +272,22 @@ octt_count(struct octt *ct,int *tot,int max,int *overflow) {
   if (!c) (*tot)++;
   if ( (*tot) > (*overflow) ) *overflow=0;
 }
+
+/* This whole function is new */
+/* walk through the tree and for each colour, store its seen count in the
+   space pointed by *col_usage_it_adr */
+void
+octt_histo(struct octt *ct, unsigned int **col_usage_it_adr) {
+    int i,c;
+    c = 0;
+    for(i = 0; i < 8; i++) 
+        if (ct->t[i] != NULL) { 
+            octt_histo(ct->t[i], col_usage_it_adr);
+            c++;
+        }
+    if (!c) {
+        *(*col_usage_it_adr)++ = ct->cnt;
+    }
+}
+
+