Ejemplo n.º 1
0
  private static darwin.jopenctm.data.Mesh convertMesh(Mesh mesh, String matName)
      throws IOException {
    // standard checks
    VertexBuffer vbuffer = mesh.getVertices();
    int vc = mesh.getVertexCount();
    if (!vbuffer.layout.hasElement(POSITION)) {
      throw new IOException("The mesh doesn't have a float3 vertex position attribute!");
    }

    if (mesh.getPrimitiv_typ() != GL.GL_TRIANGLES) {
      throw new IOException("The CTM File Format only supports triangle Meshes");
    }

    // create indicie array
    int[] meshIndicies = mesh.getIndicies();
    if (meshIndicies == null) {
      throw new IOException("Only meshes with indices can be exported!");
    }
    int[] indices = new int[mesh.getIndexCount()];
    System.arraycopy(meshIndicies, 0, indices, 0, indices.length);

    AttributeData[] atts = createAttributeData(vbuffer);

    // create position array
    float[] vertices = new float[vc * CTM_POSITION_ELEMENT_COUNT];
    int i = 0;
    for (Vertex v : vbuffer) {
      copyToBuffer(vertices, i, v, POSITION);
      i += CTM_POSITION_ELEMENT_COUNT;
    }

    // create optional normal array
    float[] normals = null;
    if (vbuffer.layout.hasElement(NORMAL)) {
      normals = new float[vc * CTM_NORMAL_ELEMENT_COUNT];
      int k = 0;
      for (Vertex v : vbuffer) {
        copyToBuffer(normals, k, v, NORMAL);
        k += CTM_NORMAL_ELEMENT_COUNT;
      }
    }

    // create uv arrays
    boolean hasUV = vbuffer.layout.hasElement(TEX_COORD);
    AttributeData[] texcoords = new AttributeData[hasUV ? 1 : 0];
    if (hasUV) {
      float[] values = new float[vc * CTM_UV_ELEMENT_COUNT];
      int k = 0;
      for (Vertex v : vbuffer) {
        copyToBuffer(values, k, v, TEX_COORD);
        k += CTM_UV_ELEMENT_COUNT;
      }
      texcoords[0] =
          new AttributeData("TexCoord", matName, AttributeData.STANDARD_UV_PRECISION, values);
    }

    return new darwin.jopenctm.data.Mesh(vertices, normals, indices, texcoords, atts);
  }
  public Packet56MapChunks(List p_i3324_1_) {
    int i = p_i3324_1_.size();
    field_73589_c = new int[i];
    field_73586_d = new int[i];
    field_73590_a = new int[i];
    field_73588_b = new int[i];
    field_73584_f = new byte[i][];
    int j = 0;
    for (int k = 0; k < i; k++) {
      Chunk chunk = (Chunk) p_i3324_1_.get(k);
      Packet51MapChunkData packet51mapchunkdata = Packet51MapChunk.func_73594_a(chunk, true, 65535);
      if (field_73591_h.length < j + packet51mapchunkdata.field_74582_a.length) {
        byte abyte0[] = new byte[j + packet51mapchunkdata.field_74582_a.length];
        System.arraycopy(field_73591_h, 0, abyte0, 0, field_73591_h.length);
        field_73591_h = abyte0;
      }
      System.arraycopy(
          packet51mapchunkdata.field_74582_a,
          0,
          field_73591_h,
          j,
          packet51mapchunkdata.field_74582_a.length);
      j += packet51mapchunkdata.field_74582_a.length;
      field_73589_c[k] = chunk.field_76635_g;
      field_73586_d[k] = chunk.field_76647_h;
      field_73590_a[k] = packet51mapchunkdata.field_74580_b;
      field_73588_b[k] = packet51mapchunkdata.field_74581_c;
      field_73584_f[k] = packet51mapchunkdata.field_74582_a;
    }

    Deflater deflater = new Deflater(-1);
    try {
      deflater.setInput(field_73591_h, 0, j);
      deflater.finish();
      field_73587_e = new byte[j];
      field_73585_g = deflater.deflate(field_73587_e);
    } finally {
      deflater.end();
    }
  }
Ejemplo n.º 3
0
  /**
   * Concat arrays in one.
   *
   * @param arrays Arrays.
   * @return Summary array.
   */
  public static int[] concat(int[]... arrays) {
    assert arrays != null;
    assert arrays.length > 1;

    int len = 0;

    for (int[] a : arrays) len += a.length;

    int[] r = Arrays.copyOf(arrays[0], len);

    for (int i = 1, shift = 0; i < arrays.length; i++) {
      shift += arrays[i - 1].length;
      System.arraycopy(arrays[i], 0, r, shift, arrays[i].length);
    }

    return r;
  }
  public void func_73267_a(DataInputStream p_73267_1_) throws IOException {
    short word0 = p_73267_1_.readShort();
    field_73585_g = p_73267_1_.readInt();
    field_73589_c = new int[word0];
    field_73586_d = new int[word0];
    field_73590_a = new int[word0];
    field_73588_b = new int[word0];
    field_73584_f = new byte[word0][];
    if (field_73591_h.length < field_73585_g) {
      field_73591_h = new byte[field_73585_g];
    }
    p_73267_1_.readFully(field_73591_h, 0, field_73585_g);
    byte abyte0[] = new byte[0x30100 * word0];
    Inflater inflater = new Inflater();
    inflater.setInput(field_73591_h, 0, field_73585_g);
    try {
      inflater.inflate(abyte0);
    } catch (DataFormatException dataformatexception) {
      throw new IOException("Bad compressed data format");
    } finally {
      inflater.end();
    }
    int i = 0;
    for (int j = 0; j < word0; j++) {
      field_73589_c[j] = p_73267_1_.readInt();
      field_73586_d[j] = p_73267_1_.readInt();
      field_73590_a[j] = p_73267_1_.readShort();
      field_73588_b[j] = p_73267_1_.readShort();
      int k = 0;
      for (int l = 0; l < 16; l++) {
        k += field_73590_a[j] >> l & 1;
      }

      int i1 = 2048 * (5 * k) + 256;
      field_73584_f[j] = new byte[i1];
      System.arraycopy(abyte0, i, field_73584_f[j], 0, i1);
      i += i1;
    }
  }
  // {{{ findClass
  protected Class findClass(String name) throws ClassNotFoundException {
    Class cl = null;
    if (verbose) System.out.println("" + this + ".findClass(" + name + ")");
    if ("RJavaClassLoader".equals(name)) return getClass();

    // {{{ use the usual method of URLClassLoader
    if (useSystem) {
      try {
        cl = super.findClass(name);
        if (cl != null) {
          if (verbose)
            System.out.println("RJavaClassLoader: found class " + name + " using URL loader");
          return cl;
        }
      } catch (Exception fnf) {
        if (verbose) System.out.println(" - URL loader did not find it: " + fnf);
      }
    }
    if (verbose) System.out.println("RJavaClassLoader.findClass(\"" + name + "\")");
    // }}}

    // {{{ iterate through the elements of the class path
    InputStream ins = null;
    Exception defineException = null;
    Enumeration /*<UnixFile>*/ e = classPath.elements();
    while (e.hasMoreElements()) {
      UnixFile cp = (UnixFile) e.nextElement();

      if (verbose) System.out.println(" - trying class path \"" + cp + "\"");
      try {
        ins = null;
        /* a file - assume it is a jar file */
        if (cp instanceof UnixJarFile) {
          ins = ((UnixJarFile) cp).getResourceAsStream(classNameToFile(name) + ".class");
          if (verbose)
            System.out.println(
                "   JAR file, can get '"
                    + classNameToFile(name)
                    + "'? "
                    + ((ins == null) ? "NO" : "YES"));
        } else if (cp instanceof UnixDirectory) {
          UnixFile class_f = new UnixFile(cp.getPath() + "/" + classNameToFile(name) + ".class");
          if (class_f.isFile()) {
            ins = new FileInputStream(class_f);
          }
          if (verbose)
            System.out.println(
                "   Directory, can get '" + class_f + "'? " + ((ins == null) ? "NO" : "YES"));
        }

        /* some comments on the following :

           we could call ZipEntry.getSize in case of a jar file to
           find out the size of the byte[] directly

           also ByteBuffer seems more efficient, but the ByteBuffer class
           is java >= 1.4 and the defineClass method that uses the class
           is java >= 1.5
        */

        if (ins != null) {
          int al = 128 * 1024;
          byte fc[] = new byte[al];
          int n = ins.read(fc);
          int rp = n;
          if (verbose) System.out.println("  loading class file, initial n = " + n);
          while (n > 0) {
            if (rp == al) {
              int nexa = al * 2;
              if (nexa < 512 * 1024) nexa = 512 * 1024;
              byte la[] = new byte[nexa];
              System.arraycopy(fc, 0, la, 0, al);
              fc = la;
              al = nexa;
            }
            n = ins.read(fc, rp, fc.length - rp);
            if (verbose) System.out.println("  next n = " + n + " (rp=" + rp + ", al=" + al + ")");
            if (n > 0) rp += n;
          }
          ins.close();
          n = rp;
          if (verbose)
            System.out.println("RJavaClassLoader: loaded class " + name + ", " + n + " bytes");
          try {
            cl = defineClass(name, fc, 0, n);
          } catch (Exception dce) {
            // we want to save this one so we can pass it on
            defineException = dce;
            break;
          }
          if (verbose) System.out.println("  defineClass('" + name + "') returned " + cl);
          // System.out.println(" - class = "+cl);
          return cl;
        }
      } catch (Exception ex) {
        // System.out.println(" * won't work: "+ex.getMessage());
      }
    }
    // }}}

    if (defineException != null) // we bailed out on class interpretation, re-throw it
    throw (new ClassNotFoundException(
          "Class not found - candidate class binary found but could not be loaded",
          defineException));

    // giving up
    if (verbose) System.out.println("    >> ClassNotFoundException ");
    if (cl == null) {
      throw (new ClassNotFoundException());
    }
    return cl;
  }
Ejemplo n.º 6
0
 public void setFileContents(byte[] aByteArray) {
   fileContents = new byte[aByteArray.length];
   System.arraycopy(aByteArray, 0, fileContents, 0, aByteArray.length);
 }
Ejemplo n.º 7
0
  public void build_bricks() {

    ImagePlus imp;
    ImagePlus orgimp;
    ImageStack stack;
    FileInfo finfo;

    if (lvImgTitle.isEmpty()) return;
    orgimp = WindowManager.getImage(lvImgTitle.get(0));
    imp = orgimp;

    finfo = imp.getFileInfo();
    if (finfo == null) return;

    int[] dims = imp.getDimensions();
    int imageW = dims[0];
    int imageH = dims[1];
    int nCh = dims[2];
    int imageD = dims[3];
    int nFrame = dims[4];
    int bdepth = imp.getBitDepth();
    double xspc = finfo.pixelWidth;
    double yspc = finfo.pixelHeight;
    double zspc = finfo.pixelDepth;
    double z_aspect = Math.max(xspc, yspc) / zspc;

    int orgW = imageW;
    int orgH = imageH;
    int orgD = imageD;
    double orgxspc = xspc;
    double orgyspc = yspc;
    double orgzspc = zspc;

    lv = lvImgTitle.size();
    if (filetype == "JPEG") {
      for (int l = 0; l < lv; l++) {
        if (WindowManager.getImage(lvImgTitle.get(l)).getBitDepth() != 8) {
          IJ.error("A SOURCE IMAGE MUST BE 8BIT GLAYSCALE");
          return;
        }
      }
    }

    // calculate levels
    /*		int baseXY = 256;
    		int baseZ = 256;

    		if (z_aspect < 0.5) baseZ = 128;
    		if (z_aspect > 2.0) baseXY = 128;
    		if (z_aspect >= 0.5 && z_aspect < 1.0) baseZ = (int)(baseZ*z_aspect);
    		if (z_aspect > 1.0 && z_aspect <= 2.0) baseXY = (int)(baseXY/z_aspect);

    		IJ.log("Z_aspect: " + z_aspect);
    		IJ.log("BaseXY: " + baseXY);
    		IJ.log("BaseZ: " + baseZ);
    */

    int baseXY = 256;
    int baseZ = 128;
    int dbXY = Math.max(orgW, orgH) / baseXY;
    if (Math.max(orgW, orgH) % baseXY > 0) dbXY *= 2;
    int dbZ = orgD / baseZ;
    if (orgD % baseZ > 0) dbZ *= 2;
    lv = Math.max(log2(dbXY), log2(dbZ)) + 1;

    int ww = orgW;
    int hh = orgH;
    int dd = orgD;
    for (int l = 0; l < lv; l++) {
      int bwnum = ww / baseXY;
      if (ww % baseXY > 0) bwnum++;
      int bhnum = hh / baseXY;
      if (hh % baseXY > 0) bhnum++;
      int bdnum = dd / baseZ;
      if (dd % baseZ > 0) bdnum++;

      if (bwnum % 2 == 0) bwnum++;
      if (bhnum % 2 == 0) bhnum++;
      if (bdnum % 2 == 0) bdnum++;

      int bw = (bwnum <= 1) ? ww : ww / bwnum + 1 + (ww % bwnum > 0 ? 1 : 0);
      int bh = (bhnum <= 1) ? hh : hh / bhnum + 1 + (hh % bhnum > 0 ? 1 : 0);
      int bd = (bdnum <= 1) ? dd : dd / bdnum + 1 + (dd % bdnum > 0 ? 1 : 0);

      bwlist.add(bw);
      bhlist.add(bh);
      bdlist.add(bd);

      IJ.log("LEVEL: " + l);
      IJ.log("  width: " + ww);
      IJ.log("  hight: " + hh);
      IJ.log("  depth: " + dd);
      IJ.log("  bw: " + bw);
      IJ.log("  bh: " + bh);
      IJ.log("  bd: " + bd);

      int xyl2 = Math.max(ww, hh) / baseXY;
      if (Math.max(ww, hh) % baseXY > 0) xyl2 *= 2;
      if (lv - 1 - log2(xyl2) <= l) {
        ww /= 2;
        hh /= 2;
      }
      IJ.log("  xyl2: " + (lv - 1 - log2(xyl2)));

      int zl2 = dd / baseZ;
      if (dd % baseZ > 0) zl2 *= 2;
      if (lv - 1 - log2(zl2) <= l) dd /= 2;
      IJ.log("  zl2: " + (lv - 1 - log2(zl2)));

      if (l < lv - 1) {
        lvImgTitle.add(lvImgTitle.get(0) + "_level" + (l + 1));
        IJ.selectWindow(lvImgTitle.get(0));
        IJ.run(
            "Scale...",
            "x=- y=- z=- width="
                + ww
                + " height="
                + hh
                + " depth="
                + dd
                + " interpolation=Bicubic average process create title="
                + lvImgTitle.get(l + 1));
      }
    }

    for (int l = 0; l < lv; l++) {
      IJ.log(lvImgTitle.get(l));
    }

    Document doc = newXMLDocument();
    Element root = doc.createElement("BRK");
    root.setAttribute("version", "1.0");
    root.setAttribute("nLevel", String.valueOf(lv));
    root.setAttribute("nChannel", String.valueOf(nCh));
    root.setAttribute("nFrame", String.valueOf(nFrame));
    doc.appendChild(root);

    for (int l = 0; l < lv; l++) {
      IJ.showProgress(0.0);

      int[] dims2 = imp.getDimensions();
      IJ.log(
          "W: "
              + String.valueOf(dims2[0])
              + " H: "
              + String.valueOf(dims2[1])
              + " C: "
              + String.valueOf(dims2[2])
              + " D: "
              + String.valueOf(dims2[3])
              + " T: "
              + String.valueOf(dims2[4])
              + " b: "
              + String.valueOf(bdepth));

      bw = bwlist.get(l).intValue();
      bh = bhlist.get(l).intValue();
      bd = bdlist.get(l).intValue();

      boolean force_pow2 = false;
      /*			if(IsPowerOf2(bw) && IsPowerOf2(bh) && IsPowerOf2(bd)) force_pow2 = true;

      			if(force_pow2){
      				//force pow2
      				if(Pow2(bw) > bw) bw = Pow2(bw)/2;
      				if(Pow2(bh) > bh) bh = Pow2(bh)/2;
      				if(Pow2(bd) > bd) bd = Pow2(bd)/2;
      			}

      			if(bw > imageW) bw = (Pow2(imageW) == imageW) ? imageW : Pow2(imageW)/2;
      			if(bh > imageH) bh = (Pow2(imageH) == imageH) ? imageH : Pow2(imageH)/2;
      			if(bd > imageD) bd = (Pow2(imageD) == imageD) ? imageD : Pow2(imageD)/2;

      */
      if (bw > imageW) bw = imageW;
      if (bh > imageH) bh = imageH;
      if (bd > imageD) bd = imageD;

      if (bw <= 1 || bh <= 1 || bd <= 1) break;

      if (filetype == "JPEG" && (bw < 8 || bh < 8)) break;

      Element lvnode = doc.createElement("Level");
      lvnode.setAttribute("lv", String.valueOf(l));
      lvnode.setAttribute("imageW", String.valueOf(imageW));
      lvnode.setAttribute("imageH", String.valueOf(imageH));
      lvnode.setAttribute("imageD", String.valueOf(imageD));
      lvnode.setAttribute("xspc", String.valueOf(xspc));
      lvnode.setAttribute("yspc", String.valueOf(yspc));
      lvnode.setAttribute("zspc", String.valueOf(zspc));
      lvnode.setAttribute("bitDepth", String.valueOf(bdepth));
      root.appendChild(lvnode);

      Element brksnode = doc.createElement("Bricks");
      brksnode.setAttribute("brick_baseW", String.valueOf(bw));
      brksnode.setAttribute("brick_baseH", String.valueOf(bh));
      brksnode.setAttribute("brick_baseD", String.valueOf(bd));
      lvnode.appendChild(brksnode);

      ArrayList<Brick> bricks = new ArrayList<Brick>();
      int mw, mh, md, mw2, mh2, md2;
      double tx0, ty0, tz0, tx1, ty1, tz1;
      double bx0, by0, bz0, bx1, by1, bz1;
      for (int k = 0; k < imageD; k += bd) {
        if (k > 0) k--;
        for (int j = 0; j < imageH; j += bh) {
          if (j > 0) j--;
          for (int i = 0; i < imageW; i += bw) {
            if (i > 0) i--;
            mw = Math.min(bw, imageW - i);
            mh = Math.min(bh, imageH - j);
            md = Math.min(bd, imageD - k);

            if (force_pow2) {
              mw2 = Pow2(mw);
              mh2 = Pow2(mh);
              md2 = Pow2(md);
            } else {
              mw2 = mw;
              mh2 = mh;
              md2 = md;
            }

            if (filetype == "JPEG") {
              if (mw2 < 8) mw2 = 8;
              if (mh2 < 8) mh2 = 8;
            }

            tx0 = i == 0 ? 0.0d : ((mw2 - mw + 0.5d) / mw2);
            ty0 = j == 0 ? 0.0d : ((mh2 - mh + 0.5d) / mh2);
            tz0 = k == 0 ? 0.0d : ((md2 - md + 0.5d) / md2);

            tx1 = 1.0d - 0.5d / mw2;
            if (mw < bw) tx1 = 1.0d;
            if (imageW - i == bw) tx1 = 1.0d;

            ty1 = 1.0d - 0.5d / mh2;
            if (mh < bh) ty1 = 1.0d;
            if (imageH - j == bh) ty1 = 1.0d;

            tz1 = 1.0d - 0.5d / md2;
            if (md < bd) tz1 = 1.0d;
            if (imageD - k == bd) tz1 = 1.0d;

            bx0 = i == 0 ? 0.0d : (i + 0.5d) / (double) imageW;
            by0 = j == 0 ? 0.0d : (j + 0.5d) / (double) imageH;
            bz0 = k == 0 ? 0.0d : (k + 0.5d) / (double) imageD;

            bx1 = Math.min((i + bw - 0.5d) / (double) imageW, 1.0d);
            if (imageW - i == bw) bx1 = 1.0d;

            by1 = Math.min((j + bh - 0.5d) / (double) imageH, 1.0d);
            if (imageH - j == bh) by1 = 1.0d;

            bz1 = Math.min((k + bd - 0.5d) / (double) imageD, 1.0d);
            if (imageD - k == bd) bz1 = 1.0d;

            int x, y, z;
            x = i - (mw2 - mw);
            y = j - (mh2 - mh);
            z = k - (md2 - md);
            bricks.add(
                new Brick(
                    x, y, z, mw2, mh2, md2, 0, 0, tx0, ty0, tz0, tx1, ty1, tz1, bx0, by0, bz0, bx1,
                    by1, bz1));
          }
        }
      }

      Element fsnode = doc.createElement("Files");
      lvnode.appendChild(fsnode);

      stack = imp.getStack();

      int totalbricknum = nFrame * nCh * bricks.size();
      int curbricknum = 0;
      for (int f = 0; f < nFrame; f++) {
        for (int ch = 0; ch < nCh; ch++) {
          int sizelimit = bdsizelimit * 1024 * 1024;
          int bytecount = 0;
          int filecount = 0;
          int pd_bufsize = Math.max(sizelimit, bw * bh * bd * bdepth / 8);
          byte[] packed_data = new byte[pd_bufsize];
          String base_dataname =
              basename
                  + "_Lv"
                  + String.valueOf(l)
                  + "_Ch"
                  + String.valueOf(ch)
                  + "_Fr"
                  + String.valueOf(f);
          String current_dataname = base_dataname + "_data" + filecount;

          Brick b_first = bricks.get(0);
          if (b_first.z_ != 0) IJ.log("warning");
          int st_z = b_first.z_;
          int ed_z = b_first.z_ + b_first.d_;
          LinkedList<ImageProcessor> iplist = new LinkedList<ImageProcessor>();
          for (int s = st_z; s < ed_z; s++)
            iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));

          //					ImagePlus test;
          //					ImageStack tsst;
          //					test = NewImage.createByteImage("test", imageW, imageH, imageD,
          // NewImage.FILL_BLACK);
          //					tsst = test.getStack();
          for (int i = 0; i < bricks.size(); i++) {
            Brick b = bricks.get(i);

            if (ed_z > b.z_ || st_z < b.z_ + b.d_) {
              if (b.z_ > st_z) {
                for (int s = 0; s < b.z_ - st_z; s++) iplist.pollFirst();
                st_z = b.z_;
              } else if (b.z_ < st_z) {
                IJ.log("warning");
                for (int s = st_z - 1; s > b.z_; s--)
                  iplist.addFirst(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                st_z = b.z_;
              }

              if (b.z_ + b.d_ > ed_z) {
                for (int s = ed_z; s < b.z_ + b.d_; s++)
                  iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                ed_z = b.z_ + b.d_;
              } else if (b.z_ + b.d_ < ed_z) {
                IJ.log("warning");
                for (int s = 0; s < ed_z - (b.z_ + b.d_); s++) iplist.pollLast();
                ed_z = b.z_ + b.d_;
              }
            } else {
              IJ.log("warning");
              iplist.clear();
              st_z = b.z_;
              ed_z = b.z_ + b.d_;
              for (int s = st_z; s < ed_z; s++)
                iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
            }

            if (iplist.size() != b.d_) {
              IJ.log("Stack Error");
              return;
            }

            //						int zz = st_z;

            int bsize = 0;
            byte[] bdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
            Iterator<ImageProcessor> ipite = iplist.iterator();
            while (ipite.hasNext()) {

              //							ImageProcessor tsip = tsst.getProcessor(zz+1);

              ImageProcessor ip = ipite.next();
              ip.setRoi(b.x_, b.y_, b.w_, b.h_);
              if (bdepth == 8) {
                byte[] data = (byte[]) ip.crop().getPixels();
                System.arraycopy(data, 0, bdata, bsize, data.length);
                bsize += data.length;
              } else if (bdepth == 16) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                short[] data = (short[]) ip.crop().getPixels();
                for (short e : data) buffer.putShort(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              } else if (bdepth == 32) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                float[] data = (float[]) ip.crop().getPixels();
                for (float e : data) buffer.putFloat(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              }
            }

            String filename =
                basename
                    + "_Lv"
                    + String.valueOf(l)
                    + "_Ch"
                    + String.valueOf(ch)
                    + "_Fr"
                    + String.valueOf(f)
                    + "_ID"
                    + String.valueOf(i);

            int offset = bytecount;
            int datasize = bdata.length;

            if (filetype == "RAW") {
              int dummy = -1;
              // do nothing
            }
            if (filetype == "JPEG" && bdepth == 8) {
              try {
                DataBufferByte db = new DataBufferByte(bdata, datasize);
                Raster raster = Raster.createPackedRaster(db, b.w_, b.h_ * b.d_, 8, null);
                BufferedImage img =
                    new BufferedImage(b.w_, b.h_ * b.d_, BufferedImage.TYPE_BYTE_GRAY);
                img.setData(raster);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
                String format = "jpg";
                Iterator<javax.imageio.ImageWriter> iter =
                    ImageIO.getImageWritersByFormatName("jpeg");
                javax.imageio.ImageWriter writer = iter.next();
                ImageWriteParam iwp = writer.getDefaultWriteParam();
                iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwp.setCompressionQuality((float) jpeg_quality * 0.01f);
                writer.setOutput(ios);
                writer.write(null, new IIOImage(img, null, null), iwp);
                // ImageIO.write(img, format, baos);
                bdata = baos.toByteArray();
                datasize = bdata.length;
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
            if (filetype == "ZLIB") {
              byte[] tmpdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
              Deflater compresser = new Deflater();
              compresser.setInput(bdata);
              compresser.setLevel(Deflater.DEFAULT_COMPRESSION);
              compresser.setStrategy(Deflater.DEFAULT_STRATEGY);
              compresser.finish();
              datasize = compresser.deflate(tmpdata);
              bdata = tmpdata;
              compresser.end();
            }

            if (bytecount + datasize > sizelimit && bytecount > 0) {
              BufferedOutputStream fis = null;
              try {
                File file = new File(directory + current_dataname);
                fis = new BufferedOutputStream(new FileOutputStream(file));
                fis.write(packed_data, 0, bytecount);
              } catch (IOException e) {
                e.printStackTrace();
                return;
              } finally {
                try {
                  if (fis != null) fis.close();
                } catch (IOException e) {
                  e.printStackTrace();
                  return;
                }
              }
              filecount++;
              current_dataname = base_dataname + "_data" + filecount;
              bytecount = 0;
              offset = 0;
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            } else {
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            }

            Element filenode = doc.createElement("File");
            filenode.setAttribute("filename", current_dataname);
            filenode.setAttribute("channel", String.valueOf(ch));
            filenode.setAttribute("frame", String.valueOf(f));
            filenode.setAttribute("brickID", String.valueOf(i));
            filenode.setAttribute("offset", String.valueOf(offset));
            filenode.setAttribute("datasize", String.valueOf(datasize));
            filenode.setAttribute("filetype", String.valueOf(filetype));

            fsnode.appendChild(filenode);

            curbricknum++;
            IJ.showProgress((double) (curbricknum) / (double) (totalbricknum));
          }
          if (bytecount > 0) {
            BufferedOutputStream fis = null;
            try {
              File file = new File(directory + current_dataname);
              fis = new BufferedOutputStream(new FileOutputStream(file));
              fis.write(packed_data, 0, bytecount);
            } catch (IOException e) {
              e.printStackTrace();
              return;
            } finally {
              try {
                if (fis != null) fis.close();
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
          }
        }
      }

      for (int i = 0; i < bricks.size(); i++) {
        Brick b = bricks.get(i);
        Element bricknode = doc.createElement("Brick");
        bricknode.setAttribute("id", String.valueOf(i));
        bricknode.setAttribute("st_x", String.valueOf(b.x_));
        bricknode.setAttribute("st_y", String.valueOf(b.y_));
        bricknode.setAttribute("st_z", String.valueOf(b.z_));
        bricknode.setAttribute("width", String.valueOf(b.w_));
        bricknode.setAttribute("height", String.valueOf(b.h_));
        bricknode.setAttribute("depth", String.valueOf(b.d_));
        brksnode.appendChild(bricknode);

        Element tboxnode = doc.createElement("tbox");
        tboxnode.setAttribute("x0", String.valueOf(b.tx0_));
        tboxnode.setAttribute("y0", String.valueOf(b.ty0_));
        tboxnode.setAttribute("z0", String.valueOf(b.tz0_));
        tboxnode.setAttribute("x1", String.valueOf(b.tx1_));
        tboxnode.setAttribute("y1", String.valueOf(b.ty1_));
        tboxnode.setAttribute("z1", String.valueOf(b.tz1_));
        bricknode.appendChild(tboxnode);

        Element bboxnode = doc.createElement("bbox");
        bboxnode.setAttribute("x0", String.valueOf(b.bx0_));
        bboxnode.setAttribute("y0", String.valueOf(b.by0_));
        bboxnode.setAttribute("z0", String.valueOf(b.bz0_));
        bboxnode.setAttribute("x1", String.valueOf(b.bx1_));
        bboxnode.setAttribute("y1", String.valueOf(b.by1_));
        bboxnode.setAttribute("z1", String.valueOf(b.bz1_));
        bricknode.appendChild(bboxnode);
      }

      if (l < lv - 1) {
        imp = WindowManager.getImage(lvImgTitle.get(l + 1));
        int[] newdims = imp.getDimensions();
        imageW = newdims[0];
        imageH = newdims[1];
        imageD = newdims[3];
        xspc = orgxspc * ((double) orgW / (double) imageW);
        yspc = orgyspc * ((double) orgH / (double) imageH);
        zspc = orgzspc * ((double) orgD / (double) imageD);
        bdepth = imp.getBitDepth();
      }
    }

    File newXMLfile = new File(directory + basename + ".vvd");
    writeXML(newXMLfile, doc);

    for (int l = 1; l < lv; l++) {
      imp = WindowManager.getImage(lvImgTitle.get(l));
      imp.changes = false;
      imp.close();
    }
  }
Ejemplo n.º 8
0
 public static int[] remove(int[] a, int i) {
   int[] tmp = Arrays.copyOf(a,a.length-1);
   System.arraycopy(a,i+1,tmp,i,tmp.length-i);
   return tmp;
 }
Ejemplo n.º 9
0
 public static <T> T[] append(T[] a, T... b) {
   if( a==null ) return b;
   T[] tmp = Arrays.copyOf(a,a.length+b.length);
   System.arraycopy(b,0,tmp,a.length,b.length);
   return tmp;
 }
Ejemplo n.º 10
0
 public static String[] append(String[] a, String[] b) {
   String[] res = new String[a.length + b.length];
   System.arraycopy(a, 0, res, 0, a.length);
   System.arraycopy(b, 0, res, a.length, b.length);
   return res;
 }
Ejemplo n.º 11
0
 public static int[] append(int[] a, int[] b) {
   int[] res = new int[a.length + b.length];
   System.arraycopy(a, 0, res, 0, a.length);
   System.arraycopy(b, 0, res, a.length, b.length);
   return res;
 }
Ejemplo n.º 12
0
 public static double[][] append(double[][] a, double[][] b) {
   double[][] res = new double[a.length + b.length][];
   System.arraycopy(a, 0, res, 0, a.length);
   System.arraycopy(b, 0, res, a.length, b.length);
   return res;
 }
Ejemplo n.º 13
0
  /**
   * headerCheck(String) takes the file path of a module, returns a boolean (true if the module is a
   * valid MOD/S3M/XM file) and updates 'modtype'.
   *
   * @return boolean
   */
  public boolean headerCheck(String tune) {
    boolean valid = false;

    if (p.createInput(tune) == null) {
      System.out.println(
          "PortaMod says: couldn't find the file when performing a header check. Please check the filename and path.");
    } else {
      InputStream file_input_stream = p.createInput(tune);

      String headercheck = "unknown";

      DataInputStream data_input_stream = new DataInputStream(file_input_stream);
      byte[] xm_header = new byte[60];
      try {
        data_input_stream.readFully(xm_header);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      String xm_identifier;
      xm_identifier = FastTracker2.ascii_text(xm_header, 0, 17);
      if (xm_identifier.equals("Extended Module: ")) {
        headercheck = "xm";
        modtype = "XM";
        // println("Is it an XM? " +headercheck);
      }

      // Check if data is in ScreamTracker 3 format.
      byte[] s3m_header = new byte[96];
      System.arraycopy(xm_header, 0, s3m_header, 0, 60);
      try {
        data_input_stream.readFully(s3m_header, 60, 36);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (ScreamTracker3.is_s3m(s3m_header) == true) {
        headercheck = "s3m";
        modtype = "S3M";
      }

      // Check if data is in ProTracker format.
      mod_header = new byte[1084];
      System.arraycopy(s3m_header, 0, mod_header, 0, 96);
      try {
        data_input_stream.readFully(mod_header, 96, 988);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      localmod_header = mod_header;
      if (ProTracker.is_mod(mod_header) == true) {
        headercheck = "mod";
        modtype = "MOD";
      }

      if (headercheck == "xm" || headercheck == "s3m" || headercheck == "mod") {
        valid = true;
      } else {
        valid = false;
      }
    }
    return valid;
  }
Ejemplo n.º 14
0
 /** Parses command line arguments. */
 boolean parseArgs(String args[]) {
   /* Preprocess and expand @file arguments */
   try {
     args = CommandLine.parse(args);
   } catch (FileNotFoundException e) {
     fatalError(formatMsg("error.cant.open", e.getMessage()));
     return false;
   } catch (IOException e) {
     fatalError(e);
     return false;
   }
   /* parse flags */
   int count = 1;
   try {
     String flags = args[0];
     if (flags.startsWith("-")) {
       flags = flags.substring(1);
     }
     for (int i = 0; i < flags.length(); i++) {
       switch (flags.charAt(i)) {
         case 'c':
           if (xflag || tflag || uflag || iflag) {
             usageError();
             return false;
           }
           cflag = true;
           break;
         case 'u':
           if (cflag || xflag || tflag || iflag) {
             usageError();
             return false;
           }
           uflag = true;
           break;
         case 'x':
           if (cflag || uflag || tflag || iflag) {
             usageError();
             return false;
           }
           xflag = true;
           break;
         case 't':
           if (cflag || uflag || xflag || iflag) {
             usageError();
             return false;
           }
           tflag = true;
           break;
         case 'M':
           Mflag = true;
           break;
         case 'v':
           vflag = true;
           break;
         case 'f':
           fname = args[count++];
           break;
         case 'm':
           mname = args[count++];
           break;
         case '0':
           flag0 = true;
           break;
         case 'i':
           if (cflag || uflag || xflag || tflag) {
             usageError();
             return false;
           }
           // do not increase the counter, files will contain rootjar
           rootjar = args[count++];
           iflag = true;
           break;
         case 'e':
           ename = args[count++];
           break;
         case 'p':
           pname = args[count++];
           break;
         default:
           error(formatMsg("error.illegal.option", String.valueOf(flags.charAt(i))));
           usageError();
           return false;
       }
     }
   } catch (ArrayIndexOutOfBoundsException e) {
     usageError();
     return false;
   }
   if (!cflag && !tflag && !xflag && !uflag && !iflag) {
     error(getMsg("error.bad.option"));
     usageError();
     return false;
   }
   /* parse file arguments */
   int n = args.length - count;
   if (n > 0) {
     int k = 0;
     String[] nameBuf = new String[n];
     try {
       for (int i = count; i < args.length; i++) {
         if (args[i].equals("-C")) {
           /* change the directory */
           String dir = args[++i];
           dir = (dir.endsWith(File.separator) ? dir : (dir + File.separator));
           dir = dir.replace(File.separatorChar, '/');
           while (dir.indexOf("//") > -1) {
             dir = dir.replace("//", "/");
           }
           paths.add(dir.replace(File.separatorChar, '/'));
           nameBuf[k++] = dir + args[++i];
         } else {
           nameBuf[k++] = args[i];
         }
       }
     } catch (ArrayIndexOutOfBoundsException e) {
       usageError();
       return false;
     }
     files = new String[k];
     System.arraycopy(nameBuf, 0, files, 0, k);
   } else if (cflag && (mname == null)) {
     error(getMsg("error.bad.cflag"));
     usageError();
     return false;
   } else if (uflag) {
     if ((mname != null) || (ename != null) || (pname != null)) {
       /* just want to update the manifest */
       return true;
     } else {
       error(getMsg("error.bad.uflag"));
       usageError();
       return false;
     }
   }
   return true;
 }