Inheritance: java.lang.Object
Ejemplo n.º 1
0
        public override void Write()
        {
            int o = 16 * 16 * 128;
            byte[] data = new byte[o * 5 / 2];

            int i = 0;

            Chunk.Types.CopyTo(data, i);
            i += Chunk.Types.Length;

            Chunk.Data.Data.CopyTo(data, i);
            i += Chunk.Data.Data.Length;

            Chunk.Light.Data.CopyTo(data, i);
            i += Chunk.Light.Data.Length;

            Chunk.SkyLight.Data.CopyTo(data, i);

            byte[] comp = new byte[o * 5 / 2];
            int len;

            Deflater deflater = new Deflater(-1);
            try
            {
                deflater.setInput(data);
                deflater.finish();
                len = deflater.deflate(comp);
            }
            finally
            {
                deflater.end();
            }

            SetCapacity(18 + len);
            Writer.Write(Coords.WorldX);
            Writer.Write((short)Coords.WorldY);
            Writer.Write(Coords.WorldZ);
            Writer.Write(SizeX);
            Writer.Write(SizeY);
            Writer.Write(SizeZ);

            Writer.Write(len);
            Writer.Write(comp, 0, len);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new input stream with the specified compressor and buffer
        /// size.
        /// </summary>
        /// <param name="in"> input stream to read the uncompressed data to </param>
        /// <param name="defl"> compressor ("deflater") for this stream </param>
        /// <param name="bufLen"> compression buffer size </param>
        /// <exception cref="IllegalArgumentException"> if {@code bufLen <= 0} </exception>
        /// <exception cref="NullPointerException"> if {@code in} or {@code defl} is null </exception>
        public DeflaterInputStream(InputStream @in, Deflater defl, int bufLen) : base(@in)
        {
            // Sanity checks
            if (@in == null)
            {
                throw new NullPointerException("Null input");
            }
            if (defl == null)
            {
                throw new NullPointerException("Null deflater");
            }
            if (bufLen < 1)
            {
                throw new IllegalArgumentException("Buffer size < 1");
            }

            // Initialize
            Def = defl;
            Buf = new sbyte[bufLen];
        }
Ejemplo n.º 3
0
        public override void Write(BigEndianStream stream)
        {
            stream.Write(X);
            stream.Write(Y);
            stream.Write(Z);
            stream.Write(SizeX);
            stream.Write(SizeY);
            stream.Write(SizeZ);

            int o = 16 * 16 * 128;
            byte[] data = new byte[o * 5 / 2];

            int i = 0;
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 0; y < 128; y++)
                    {
                        int s = ((i + 1) & 1) * 4;
                        int ofst = i;
                        data[ofst] = Chunk[x, y, z];
                        ofst = i / 2 + o * 2 / 2;
                        data[ofst] = unchecked((byte)(data[ofst] | (Chunk.GetData(x, y, z) << s)));
                        ofst = i / 2 + o * 3 / 2;
                        data[ofst] = unchecked((byte)(data[ofst] | (Chunk.GetBlockLight(x, y, z) << s)));
                        ofst = i / 2 + o * 4 / 2;
                        data[ofst] = unchecked((byte)(data[ofst] | (Chunk.GetSkyLight(x, y, z) << s)));
                        i++;
                    }
                }
            }

            byte[] comp = new byte[o * 5];
            int len;

            Deflater deflater = new Deflater(0);
            try
            {
                deflater.setInput(data);
                deflater.finish();
                len = deflater.deflate(comp);
            }
            finally
            {
                deflater.end();
            }

            stream.Write(len);
            stream.Write(comp, 0, len);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new input stream with the specified compressor and a
 /// default buffer size.
 /// </summary>
 /// <param name="in"> input stream to read the uncompressed data to </param>
 /// <param name="defl"> compressor ("deflater") for this stream </param>
 /// <exception cref="NullPointerException"> if {@code in} or {@code defl} is null </exception>
 public DeflaterInputStream(InputStream @in, Deflater defl) : this(@in, defl, 512)
 {
 }
Ejemplo n.º 5
0
    protected internal virtual bool writeImageData()
    {
      int num1 = this.height;
      int num2 = 0;
      this.bytesPerPixel = !this.encodeAlpha ? 3 : 4;
      Deflater deflater = new Deflater(this.compressionLevel);
      ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(1024);
      DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream((OutputStream) arrayOutputStream, deflater);
      IOException ioException1;
      IOException ioException2;
      while (true)
      {
        int num3;
        int[] numArray1;
        PixelGrabber pixelGrabber;
        try
        {
          if (num1 > 0)
          {
            int num4 = (int) short.MaxValue;
            int num5 = this.width * (this.bytesPerPixel + 1);
            int num6 = -1;
            num3 = Math.max(Math.min(num5 != num6 ? num4 / num5 : -num4, num1), 1);
            numArray1 = new int[this.width * num3];
            pixelGrabber = new PixelGrabber(this.image, 0, num2, this.width, num3, numArray1, 0, this.width);
            try
            {
              pixelGrabber.grabPixels();
            }
            catch (Exception ex)
            {
              int num7 = 2;
              if (ByteCodeHelper.MapException<Exception>(ex, (ByteCodeHelper.MapFlags) num7) == null)
                throw;
              else
                break;
            }
          }
          else
            goto label_33;
        }
        catch (IOException ex)
        {
          int num4 = 1;
          ioException1 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num4);
          goto label_8;
        }
        try
        {
          if ((pixelGrabber.getStatus() & 128) != 0)
          {
            System.get_err().println("image fetch aborted or errored");
            return false;
          }
          else
          {
            byte[] pixels = new byte[this.width * num3 * this.bytesPerPixel + num3];
            if (this.filter == 1)
              this.leftBytes = new byte[16];
            if (this.filter == 2)
              this.priorRow = new byte[this.width * this.bytesPerPixel];
            int num4 = 0;
            int startPos = 1;
            for (int index1 = 0; index1 < this.width * num3; ++index1)
            {
              int num5 = index1;
              int num6 = this.width;
              int num7 = -1;
              if ((num6 != num7 ? num5 % num6 : 0) == 0)
              {
                byte[] numArray2 = pixels;
                int index2 = num4;
                ++num4;
                int num8 = (int) (sbyte) this.filter;
                numArray2[index2] = (byte) num8;
                startPos = num4;
              }
              byte[] numArray3 = pixels;
              int index3 = num4;
              int num9 = num4 + 1;
              int num10 = (int) (sbyte) (numArray1[index1] >> 16 & (int) byte.MaxValue);
              numArray3[index3] = (byte) num10;
              byte[] numArray4 = pixels;
              int index4 = num9;
              int num11 = num9 + 1;
              int num12 = (int) (sbyte) (numArray1[index1] >> 8 & (int) byte.MaxValue);
              numArray4[index4] = (byte) num12;
              byte[] numArray5 = pixels;
              int index5 = num11;
              num4 = num11 + 1;
              int num13 = (int) (sbyte) (numArray1[index1] & (int) byte.MaxValue);
              numArray5[index5] = (byte) num13;
              if (this.encodeAlpha)
              {
                byte[] numArray2 = pixels;
                int index2 = num4;
                ++num4;
                int num8 = (int) (sbyte) (numArray1[index1] >> 24 & (int) byte.MaxValue);
                numArray2[index2] = (byte) num8;
              }
              int num14 = index1;
              int num15 = this.width;
              int num16 = -1;
              if ((num15 != num16 ? num14 % num15 : 0) == this.width - 1 && this.filter != 0)
              {
                if (this.filter == 1)
                  this.filterSub(pixels, startPos, this.width);
                if (this.filter == 2)
                  this.filterUp(pixels, startPos, this.width);
              }
            }
            deflaterOutputStream.write(pixels, 0, num4);
            num2 += num3;
            num1 -= num3;
          }
        }
        catch (IOException ex)
        {
          int num4 = 1;
          ioException2 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num4);
          goto label_32;
        }
      }
      IOException ioException3;
      try
      {
        System.get_err().println("interrupted waiting for pixels!");
        return false;
      }
      catch (IOException ex)
      {
        int num3 = 1;
        ioException3 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num3);
      }
      IOException ioException4 = ioException3;
      goto label_37;
label_8:
      ioException4 = ioException1;
      goto label_37;
label_32:
      ioException4 = ioException2;
      goto label_37;
label_33:
      int num17;
      IOException ioException5;
      try
      {
        deflaterOutputStream.close();
        byte[] data = arrayOutputStream.toByteArray();
        int length = data.Length;
        this.crc.reset();
        this.bytePos = this.writeInt4(length, this.bytePos);
        this.bytePos = this.writeBytes(PngEncoder.__\u003C\u003EIDAT, this.bytePos);
        this.crc.update(PngEncoder.__\u003C\u003EIDAT);
        this.bytePos = this.writeBytes(data, length, this.bytePos);
        this.crc.update(data, 0, length);
        this.crcValue = this.crc.getValue();
        this.bytePos = this.writeInt4((int) this.crcValue, this.bytePos);
        deflater.finish();
        deflater.end();
        num17 = 1;
      }
      catch (IOException ex)
      {
        int num3 = 1;
        ioException5 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num3);
        goto label_36;
      }
      return num17 != 0;
label_36:
      ioException4 = ioException5;
label_37:
      System.get_err().println(Throwable.instancehelper_toString((Exception) ioException4));
      return false;
    }