예제 #1
0
  public void readRect(int x, int y, int w, int h, CMsgHandler handler) {
    rdr.InStream is = reader.getInStream();
    byte[] buf = reader.getImageBuf(16 * 16 * 4, 0);

    int bg = 0;
    int fg = 0;

    for (int ty = y; ty < y + h; ty += 16) {

      int th = Math.min(y + h - ty, 16);

      for (int tx = x; tx < x + w; tx += 16) {

        int tw = Math.min(x + w - tx, 16);

        int tileType = is.readU8();

        if ((tileType & Hextile.raw) != 0) {
          is.readBytes(buf, 0, tw * th * (BPP / 8));
          handler.imageRect(tx, ty, tw, th, buf, 0);
          continue;
        }

        if ((tileType & Hextile.bgSpecified) != 0) bg = readPixel(is);

        int len = tw * th;
        int ptr = 0;
        while (len-- > 0) buf[ptr++] = (byte) bg;

        if ((tileType & Hextile.fgSpecified) != 0) fg = readPixel(is);

        if ((tileType & Hextile.anySubrects) != 0) {
          int nSubrects = is.readU8();

          for (int i = 0; i < nSubrects; i++) {

            if ((tileType & Hextile.subrectsColoured) != 0) fg = readPixel(is);

            int xy = is.readU8();
            int wh = is.readU8();
            int sx = ((xy >> 4) & 15);
            int sy = (xy & 15);
            int sw = ((wh >> 4) & 15) + 1;
            int sh = (wh & 15) + 1;
            ptr = sy * tw + sx;
            int rowAdd = tw - sw;
            while (sh-- > 0) {
              len = sw;
              while (len-- > 0) buf[ptr++] = (byte) fg;
              ptr += rowAdd;
            }
          }
        }
        handler.imageRect(tx, ty, tw, th, buf, 0);
      }
    }
  }
예제 #2
0
 static final int readPixel(rdr.InStream is) {
   return is.readU8();
 }