chiark / gitweb /
image used area stuff found branch-imagearea
authorijackson <ijackson>
Wed, 21 Jan 2004 10:58:45 +0000 (10:58 +0000)
committerijackson <ijackson>
Wed, 21 Jan 2004 10:58:45 +0000 (10:58 +0000)
bcp5-registry.pl
image.c [new file with mode: 0644]

index 3e9b2f6f05b08bb3f6c4cf7ec94b8f50e708835f..3bfaa0df551f7ec9fa98339222fb49c95a24f854 100755 (executable)
@@ -185,6 +185,10 @@ if ($invokestyle eq 'maintain') {
     close STDOUT or die $!;
     exit 0;
 
+} elsif (length $in{'imageareai'}) {
+
+    
+
 } elsif (length $in{'register'}) {
     
     lock_database();
diff --git a/image.c b/image.c
new file mode 100644 (file)
index 0000000..34420a0
--- /dev/null
+++ b/image.c
@@ -0,0 +1,119 @@
+/**/
+
+#define MAXVIEWSIZE 16
+
+typedef unsigned char ae;
+typedef unsigned long ad;
+
+static ae mainary[1<<MAXVIEWSIZE];
+static ae (*ptrary)[1<<MAXVIEWSIZE];
+static char lbuf[100];
+static FILE *file;
+
+static ad space, here;
+static int spacelen,spacesize, aggregate, herelen,heresize, allspace;
+
+int convert(int v, int rgb_io[2], int *cpriority_io) {
+  int rgo, n, rgof;
+  
+  if (!v) return;
+
+  for (n=0, rgof=-1, rgo=4; rgo>0; rgo-=2) {
+    int tn= (v >> rgo) & 3;
+    if (!tn) next;
+    n += tn;
+    if (n>2) { rgb_io[0]=rgb_io[1]=rgb_io[2]=255; *cpriority_io=500; }
+    rgof= rgo;
+  }
+
+  assert(rgof>=0);
+  if (n==1) {
+    memset(rgb_io[0],0
+
+int main(int argc, const char *argv) {
+  const char *ep;
+  ae *aep;
+  ad i;
+
+  if (!argv[1]) fail("no space");
+  space= strtoul(argv[1],ep,16);
+  if (!*ep++) fail("no space len");
+  spacelen= atoi(ep);
+
+  if (space>0xffffffffUL || spacelen<8 || spacelen>30) fail("bad space");
+  spacesize= 32-spacelen;
+  viewsize= spacesize;  if (viewsize>MAXVIEWSIZE) viewsize= MAXVIEWSIZE;
+  aggregate= spacesize-viewsize;
+
+  allspace= 0;
+  
+  file= fopen(LISTFILE, "r"); if (!file) fail(strerror(errno));
+  for (;;) {
+    if (!fgets(lbuf,sizeof(lbuf)-1,file)) readfail();
+    if (buf[0]=='\2' && buf[1]=='\0') break;
+    dp= strchr(buf,'\1'); if (!dp) fail("format delim 1");
+    dp++; here= strtoul(dp,&dp,16); if (!*dp) fail("format strtoul");
+    if (*dp++ != '\1') fail("format delim 2");
+    herelen= atoi(dp);
+    if (!strchr(buf,'\n')) {
+      while ((c=getc(file)) != EOF && c != '\n');
+      if (c==EOF) readfail();
+    }
+    if (here>0xffffffffUL || herelen<1 || herelen>32) fail("bad here");
+    heresize= 32-herelen;
+
+    if (heresize >= spacesize) {
+      if ((here^space) & (~0UL << spacesize)) continue;
+      allspace++;
+      continue;
+    }
+
+    if ((here^space) & (~0UL << heresize)) continue;
+
+    for (h=here; h<here+
+
+    if (aggregate) {
+      ae **paep= &ptrary[here>>aggregate];
+      if (!*paep) { *paep= calloc(1<<aggregate); if (!*paep) fail("calloc"); }
+      aep= &(*paep)[here & ((1UL<<aggregate) - 1)];
+    } else {
+      aep= &mainary[here];
+    }
+
+    rgv= herelen<24 ? 0x10 : herelen==24 ? 0x04 : 0x01;
+    if (~*aep & (rgv|(rgv<<1))) *aep += rgv;
+  }
+  fclose(file);
+
+  file= stdout;
+  fprintf(file,"P3 %d %d 255\n", (viewsize+1)>>1, viewsize>>1);
+  
+  for (i=0; i<(1<<viewsize); i++) {
+    int bn, rgb[3], cpriority;
+
+    ad h0=0,h1=0,h=i;
+    for (b=0; bn<(viewsize+1)>>1; bn++) {
+      h0 |= h&1;  h >>= 1;
+      h1 |= h&1;  h >>= 1;
+    }
+    h= h1<<((viewsize+1)>>1) | h0;
+    
+    if (aggregate) {
+      ad g;
+    
+      rgb[0]=rgb[1]=rgb[2]=0; cpriority=0;
+      for (g=0; g<(1<<aggregate); g++) {
+       convert(ptrary[h][g], &rgb, &cpriority);
+      }
+    } else {
+      cpriority=0;
+      convert(mainary[h], &rgb, &cpriority);
+    }
+
+    fprintf(file,"%d %d %d\n", rgb[0],rgb[1],rgb[2]);
+  }
+
+  if (ferror(file) || fclose(file)) fail(strerror(errno));
+
+  return 0;
+}