@Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   // little endian
   this.cardinality = 0xFFFF & Short.reverseBytes(in.readShort());
   if (this.content.limit() < this.cardinality)
     this.content = ShortBuffer.allocate(this.cardinality);
   for (int k = 0; k < this.cardinality; ++k) {
     this.content.put(k, Short.reverseBytes(in.readShort()));
   }
 }
Beispiel #2
0
  private void loadDataXM(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[20];

    // WHY THE HELL AM I DOING THIS
    name = Util.readStringNoNul(fp, b, 20);
    System.out.printf("name: \"%s\"\n", name);
    fp.read(); // skip 0x1A byte

    // THIS CAN'T BE HAPPENING
    fp.read(b, 0, 20); // skip tracker name

    // OH HELL NO
    int xmver = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    System.out.printf("XM version: %04X\n", xmver);

    // WHAT IS THIS CRAP
    InhibitedFileBlock ifb = new InhibitedFileBlock(fp, Integer.reverseBytes(fp.readInt()) - 4);

    // HELP ME PLEASE
    int ordnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int respos =
        0xFFFF & (int) Short.reverseBytes(ifb.readShort()); // can't be bothered right now --GM
    int chnnum =
        0xFFFF & (int) Short.reverseBytes(ifb.readShort()); // yeah sure, allow out of range values
    if (chnnum > 64)
      throw new RuntimeException(
          String.format("%d-channel modules not supported (max 64)", chnnum));
    int patnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int insnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmflags = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmspeed = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmtempo = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());

    // OH PLEASE, STOP IT
    if (ordnum > 255) ordnum = 255;
    if (xmtempo > 255) xmtempo = 255;
    if (xmspeed > 255) xmspeed = 255;
    this.bpm = xmtempo;
    this.spd = xmspeed;
    this.flags = FLAG_COMPATGXX | FLAG_OLDEFFECTS | FLAG_INSMODE | FLAG_STEREO | FLAG_VOL0MIX;

    if ((xmflags & 0x01) != 0) this.flags |= FLAG_LINEAR;

    // NONONONONONO
    System.out.printf("chn=%d ordnum=%d tempo=%d speed=%s\n", chnnum, ordnum, xmtempo, xmspeed);
    for (int i = 0; i < 256; i++) orderlist[i] = ifb.read();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    ifb.done();

    // SAVE ME PLEEEEEAAASSSSEEEE
    for (int i = 0; i < patnum; i++)
      map_pat.put((Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_XM, chnnum));
    for (int i = 0; i < insnum; i++)
      map_ins.put((Integer) (i + 1), new SessionInstrument(fp, SessionInstrument.FORMAT_XM, this));
  }
 @Override
 protected void writeArray(DataOutput out) throws IOException {
   // little endian
   if (BufferUtil.isBackedBySimpleArray(content)) {
     short[] a = content.array();
     for (int k = 0; k < this.cardinality; ++k) {
       out.writeShort(Short.reverseBytes(a[k]));
     }
   } else {
     for (int k = 0; k < this.cardinality; ++k) {
       out.writeShort(Short.reverseBytes(content.get(k)));
     }
   }
 }
 @Override
 public void writeExternal(ObjectOutput out) throws IOException {
   out.write(this.cardinality & 0xFF);
   out.write((this.cardinality >>> 8) & 0xFF);
   if (BufferUtil.isBackedBySimpleArray(content)) {
     short[] a = content.array();
     for (int k = 0; k < this.cardinality; ++k) {
       out.writeShort(Short.reverseBytes(a[k]));
     }
   } else {
     for (int k = 0; k < this.cardinality; ++k) {
       out.writeShort(Short.reverseBytes(content.get(k)));
     }
   }
 }
Beispiel #5
0
 @Override
 public short readShort() throws IOException {
   short s = this.stream.readShort();
   if (endianness == ByteOrder.LITTLE_ENDIAN) {
     s = Short.reverseBytes(s);
   }
   return s;
 }
Beispiel #6
0
  private void loadDataIT(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[26];

    this.name = Util.readString(fp, b, 26);
    System.out.printf("name: \"%s\"\n", name);

    this.philigt = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int ordnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int insnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int smpnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int patnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.cwtv = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.cmwt = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.flags = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.special = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    this.gv = fp.read();
    this.mv = fp.read();
    this.spd = fp.read();
    this.bpm = fp.read();
    this.pwd = fp.read();
    this.sep = fp.read();
    int msglgth = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int msgoffs = Integer.reverseBytes(fp.readInt());
    this.timestamp = Integer.reverseBytes(fp.readInt());
    fp.read(chnpan, 0, 64);
    fp.read(chnvol, 0, 64);

    System.out.printf("ver: %04X / compat: %04X\n", cwtv, cmwt);

    // Load orderlist
    for (int i = 0; i < ordnum; i++) orderlist[i] = fp.readUnsignedByte();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    // Load pointers
    int[] insptrs = new int[insnum];
    int[] smpptrs = new int[smpnum];
    int[] patptrs = new int[patnum];

    for (int i = 0; i < insnum; i++) insptrs[i] = Integer.reverseBytes(fp.readInt());
    for (int i = 0; i < smpnum; i++) smpptrs[i] = Integer.reverseBytes(fp.readInt());
    for (int i = 0; i < patnum; i++) patptrs[i] = Integer.reverseBytes(fp.readInt());

    // TODO: read MIDI + timestamp bollocks
    //   TODO: look up and/or reverse engineer said bollocks

    // Load data
    for (int i = 0; i < insnum; i++) {
      if (insptrs[i] != 0) {
        fp.seek(insptrs[i]);
        map_ins.put(
            (Integer) (i + 1),
            new SessionInstrument(
                fp,
                cmwt < 0x200 ? SessionInstrument.FORMAT_IT100 : SessionInstrument.FORMAT_IT200));
      }
    }

    for (int i = 0; i < smpnum; i++) {
      if (smpptrs[i] != 0) {
        fp.seek(smpptrs[i]);
        map_smp.put((Integer) (i + 1), new SessionSample(fp, SessionSample.FORMAT_IT));
      }
    }

    for (int i = 0; i < patnum; i++) {
      if (patptrs[i] != 0) {
        fp.seek(patptrs[i]);
        map_pat.put((Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_IT));
      }
    }
  }
Beispiel #7
0
  private void loadDataS3M(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[28];

    this.name = Util.readString(fp, b, 28);
    System.out.printf("name: \"%s\"\n", name);

    fp.readInt(); // first two bytes we've seen, second two are unused

    int ordnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int smpnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int patnum = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int s3flags = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int s3cwtv = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    int ffi = 0xFFFF & (int) Short.reverseBytes(fp.readShort());

    fp.readInt(); // should have "SCRM" but really doesn't matter

    this.flags = FLAG_OLDEFFECTS | FLAG_VOL0MIX;

    this.gv = fp.read() * 2;
    this.spd = fp.read();
    this.bpm = fp.read();
    this.mv = fp.read();
    fp.read(); // NO WE DON'T HAVE A GUS
    int dfpflag = fp.read();

    // weird S3M crap
    // note: assuming default of 6/125
    // it actually uses the previously-used speed/tempo

    if (this.spd == 0 || this.spd == 255) this.spd = 6;
    if (this.bpm < 33) this.bpm = 125;

    if ((this.mv & 0x80) != 0) {
      this.mv &= ~0x80;
      this.flags |= FLAG_STEREO;
      // XXX: this might need to be done internally in the player
      //      if it turns out that IT does the same damn thing --GM
      this.mv = (this.mv * 11 + 4) >> 3;
    }

    // skip all that bollocks
    fp.seek(0x40);

    // load channel mappings
    // yes, we WILL want these!
    // though i don't think anyone's done anything completely bonkers
    // except Storlek and myself --GM
    int[] st3chnmap = new int[32];

    for (int i = 32; i < 64; i++) {
      chnvol[i] = (byte) 0xC0;
      chnpan[i] = 0x20;
    }

    for (int i = 0; i < 32; i++) {
      chnpan[i] = 0;

      int v = fp.read();
      st3chnmap[i] = v & 0x7F;

      // don't enable FM channels!
      chnvol[i] = ((v & 0x80) != 0 && (v & 0x7F) < 16) ? 0x40 : (byte) 0xC0;
    }

    // orderlist!
    // DON'T EVEN NEED TO FILTER IT YES :D
    for (int i = 0; i < ordnum; i++) orderlist[i] = fp.read();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    // load pointers
    int[] smpptrs = new int[smpnum];
    int[] patptrs = new int[patnum];

    for (int i = 0; i < smpnum; i++)
      smpptrs[i] = (0xFFFF & (int) Short.reverseBytes(fp.readShort())) * 16;
    for (int i = 0; i < patnum; i++)
      patptrs[i] = (0xFFFF & (int) Short.reverseBytes(fp.readShort())) * 16;

    // load default panning if necessary
    for (int i = 0; i < 32; i++) {
      int v = (dfpflag == 252) ? fp.read() : 0x10;

      int pan =
          (v & 0x10) != 0 ? (flags & FLAG_STEREO) != 0 ? (v & 0x08) != 0 ? 0xC : 0x3 : 0x7 : v & 15;

      // TODO: scale this crap correctly
      chnpan[i] = (byte) ((pan + 2) << 2);
    }

    // load data
    for (int i = 0; i < smpnum; i++)
      if (smpptrs[i] != 0) {
        fp.seek(smpptrs[i]);
        map_smp.put((Integer) (i + 1), new SessionSample(fp, SessionSample.FORMAT_S3M, ffi));
      }
    for (int i = 0; i < patnum; i++)
      if (patptrs[i] != 0) {
        fp.seek(patptrs[i]);
        map_pat.put(
            (Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_S3M, st3chnmap));
      }

    // XXX: any other crap this needs? --GM
  }
 public void func_72668_a(short p_72668_1_) throws IOException {
   field_72673_b.writeShort(Short.reverseBytes(p_72668_1_));
 }
Beispiel #9
0
  private static ImageData readPPM(File file) throws IOException, BadImageFileException {
    FileInputStream s = new FileInputStream(file);

    ImageData imageData;
    try {
      String S1 = readln(s);

      int width;
      int height;
      int bands;
      int dataType;
      if (S1.equals("P5") || S1.equals("P6")) {
        bands = S1.equals("P5") ? 1 : 3;
        String S2 = readln(s);
        String S3 = readln(s);

        String dimensions[] = S2.split("\\s");
        width = Integer.parseInt(dimensions[0]);
        height = Integer.parseInt(dimensions[1]);

        dataType = S3.equals("255") ? DataBuffer.TYPE_BYTE : DataBuffer.TYPE_USHORT;

        imageData = new ImageData(width, height, bands, dataType);
      } else if (S1.equals("P7")) {
        String WIDTH = "WIDTH ";
        String HEIGHT = "HEIGHT ";
        String DEPTH = "DEPTH ";
        String MAXVAL = "MAXVAL ";
        // String TUPLTYPE = "TUPLTYPE ";
        // String ENDHDR = "ENDHDR";
        String SWIDTH = readln(s);
        width = Integer.parseInt(SWIDTH.substring(WIDTH.length()));
        String SHEIGHT = readln(s);
        height = Integer.parseInt(SHEIGHT.substring(HEIGHT.length()));
        String SDEPTH = readln(s);
        bands = Integer.parseInt(SDEPTH.substring(DEPTH.length()));
        String SMAXVAL = readln(s);
        dataType =
            SMAXVAL.substring(MAXVAL.length()).equals("65535")
                ? DataBuffer.TYPE_USHORT
                : DataBuffer.TYPE_BYTE;
        // String STUPLTYPE = readln(s);
        // String SENDHDR = readln(s);
        imageData = new ImageData(width, height, bands, dataType);
      } else return null;

      int totalData = width * height * bands * (dataType == DataBuffer.TYPE_BYTE ? 1 : 2);

      FileChannel c = s.getChannel();

      if (file.length() != totalData + c.position()) {
        c.close();
        throw new BadImageFileException(file);
      }

      ByteBuffer bb = c.map(FileChannel.MapMode.READ_ONLY, c.position(), totalData);

      if (dataType == DataBuffer.TYPE_USHORT) {
        // bb.order(ByteOrder.BIG_ENDIAN);
        bb.order(ByteOrder.nativeOrder());
        bb.asShortBuffer().get((short[]) imageData.data);

        // Darty hack to prevent crash on Arch Linux (issue #125)
        if (ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
          for (int i = 0; i < ((short[]) imageData.data).length; ++i)
            ((short[]) imageData.data)[i] = Short.reverseBytes(((short[]) imageData.data)[i]);
      } else bb.get((byte[]) imageData.data);

      if (bb instanceof DirectBuffer) ((DirectBuffer) bb).cleaner().clean();

      c.close();
    } catch (Exception e) {
      e.printStackTrace();
      s.close();
      throw new BadImageFileException(file, e);
    } finally {
      s.close();
    }

    return imageData;
  }