FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Information Visualization
(Moderators: forkinsocket, REAS)
   unpacked bits
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: unpacked bits  (Read 1275 times)
rgovostes

rgovostes
unpacked bits
« on: Oct 24th, 2004, 12:45am »

In my continuing search for some hidden images in the ROM of a Macintosh SE, I've written some code which functions identically to the UnpackBits, which is used in the compression of Macintosh PICT resources. It pulls out a chunk of data from a source file, attempts to decompress it, and then displays the output.
 
If I find them I'll be sure to share You can run this on other Mac files (renamed "input.dat" and dropped in the sketch's data folder) and look for other hidden goodies.
 
I'm not positive it works; I tested the unpacking routine on a string I came up with and it output the expected data. I haven't tried it on images or anything else yet.
 
Code:
int y, z;
byte[] b;
float offset;
boolean auto = false;
 
void setup() {
  size(512, 342 + 8);
  b = loadBytes("input.dat");
  y = width * (height - 8) / 8;
  z = width * (height - 8);
}
 
void loop() {
  renderPICT();
  if(auto) offset ++;
  
  fill(0xffcccccc); stroke(0xffcccccc);
  rect(0, height - 8, width - 1, 7);
  
  fill(0xffffffff); stroke(0xff000000);
  rect((offset / b.length) * (width - 8), (height - 8), 7, 7);
}
 
void renderPICT() {
  int i, j, k, l = 0;
  byte[] p = new byte[y + 1];
  byte[] q = new byte[y];
  
  System.arraycopy(b, (int)offset, p, 0, y + 1);
 
  for(i = 0; i < p.length; i ++) {
    if(p[i] < 0) {
      k = p[i ++] + 0x80;
      for(j = 0; j <= k; j ++) { q[l] = p[i]; l ++; if(l >= q.length) break; }
    } else {
      k = p[i];
      for(j = 0; j <= k; j ++) { q[l] = p[i ++ + 1]; l ++; if(l >= q.length) break; }
    }
    
    if(l >= q.length) break;
  }
  
  for(i = 0; i < z; i ++)
    pixels[i] = (~(q[i / 8] & 0xff) >> (7 - (i % 8)) & 1) * 0xffffffff;
}
 
void keyPressed() {
  if (key == UP || key == RIGHT) {
    offset = constrain(offset - 1, 0, b.length - 1);
  } else if (key == DOWN || key == LEFT) {
    offset = constrain(offset + 1, 0, b.length - 1);
  } else if (key == ' ') {
    auto = !auto;
  }
}
 
void mouseReleased() {
  println("Index: " + ((mouseY * width) + mouseX + (int)offset)/8);
}
« Last Edit: Oct 24th, 2004, 2:04am by rgovostes »  
Pages: 1 

« Previous topic | Next topic »