Exemplo n.º 1
0
 private static byte[] Compress(byte[] zlib)
 {
     // Create a GZIP stream with decompression mode.
     // ... Then create a buffer and write into while reading from the GZIP stream.
     using (MemoryStream memory = new MemoryStream())
     {
         var def = new Deflater();
         def.setInput(gzip);
         def.finish();
         var decompressStream = new MemoryStream();
         int i      = 0;
         var buffer = new byte[1024 * 1024];
         while ((i = def.deflate(buffer)) > 0)
         {
             decompressStream.Write(buffer, 0, i);
         }
         return(decompressStream.ToArray());
     }
     //using (GZipStream stream = new GZipStream(memory, CompressionMode.Compress))
     //{
     //    stream.Write(gzip, 0, gzip.Length);
     //    stream.Flush();
     //    stream.Close();
     //    return memory.ToArray();
     //}
 }
Exemplo n.º 2
0
        public Packet51MapChunk(int i, int j, int k, int l, int i1, int j1, World world)
        {
            isChunkDataPacket = true;
            xPosition         = i;
            yPosition         = j;
            zPosition         = k;
            xSize             = l;
            ySize             = i1;
            zSize             = j1;
            byte[] abyte0   = world.getChunkData(i, j, k, l, i1, j1);
            var    deflater = new Deflater(1);

            try
            {
                deflater.setInput(abyte0);
                deflater.finish();
                chunk     = new byte[(l * i1 * j1 * 5) / 2];
                chunkSize = deflater.deflate(chunk);
            }
            finally
            {
                deflater.end();
            }
        }
Exemplo n.º 3
0
        private static int compress(int tp, byte[] inBytes, int inSize, byte[] outBytes)
        {
            if (inSize == 0)
            {
                return(0);
            }

            int t1 = 0, t2 = (inSize + 1) / 2;
            int inPtr = 0, ret;

            byte[] tmp = new byte[inSize];

            // zip and rle treat the data first, in the same way so I'm not
            // repeating the code
            if ((tp == ZIP_COMPRESSION) || (tp == RLE_COMPRESSION))
            {
                // reorder the pixel data ~ straight from ImfZipCompressor.cpp :)
                while (true)
                {
                    if (inPtr < inSize)
                    {
                        tmp[t1++] = inBytes[inPtr++];
                    }
                    else
                    {
                        break;
                    }

                    if (inPtr < inSize)
                    {
                        tmp[t2++] = inBytes[inPtr++];
                    }
                    else
                    {
                        break;
                    }
                }

                // Predictor ~ straight from ImfZipCompressor.cpp :)
                t1 = 1;
                int p = tmp[t1 - 1];
                while (t1 < inSize)
                {
                    int d = (int)tmp[t1] - p + (128 + 256);
                    p       = (int)tmp[t1];
                    tmp[t1] = (byte)d;
                    t1++;
                }
            }

            // We'll just jump from here to the wanted compress/decompress stuff if
            // need be
            switch (tp)
            {
            case ZIP_COMPRESSION:
                Deflater def = new Deflater(Deflater.DEFAULT_COMPRESSION, false);
                def.setInput(tmp, 0, inSize);
                def.finish();
                ret = def.deflate(outBytes);
                return(ret);

            case RLE_COMPRESSION:
                return(rleCompress(tmp, inSize, outBytes));

            default:
                return(-1);
            }
        }
Exemplo n.º 4
0
        private static int compress(int tp, byte[] inBytes, int inSize, byte[] outBytes)
        {
            if (inSize == 0)
                return 0;

            int t1 = 0, t2 = (inSize + 1) / 2;
            int inPtr = 0, ret;
            byte[] tmp = new byte[inSize];

            // zip and rle treat the data first, in the same way so I'm not
            // repeating the code
            if ((tp == ZIP_COMPRESSION) || (tp == RLE_COMPRESSION))
            {
                // reorder the pixel data ~ straight from ImfZipCompressor.cpp :)
                while (true)
                {
                    if (inPtr < inSize)
                        tmp[t1++] = inBytes[inPtr++];
                    else
                        break;

                    if (inPtr < inSize)
                        tmp[t2++] = inBytes[inPtr++];
                    else
                        break;
                }

                // Predictor ~ straight from ImfZipCompressor.cpp :)
                t1 = 1;
                int p = tmp[t1 - 1];
                while (t1 < inSize)
                {
                    int d = (int)tmp[t1] - p + (128 + 256);
                    p = (int)tmp[t1];
                    tmp[t1] = (byte)d;
                    t1++;
                }
            }

            // We'll just jump from here to the wanted compress/decompress stuff if
            // need be
            switch (tp)
            {
                case ZIP_COMPRESSION:
                    Deflater def = new Deflater(Deflater.DEFAULT_COMPRESSION, false);
                    def.setInput(tmp, 0, inSize);
                    def.finish();
                    ret = def.deflate(outBytes);
                    return ret;
                case RLE_COMPRESSION:
                    return rleCompress(tmp, inSize, outBytes);
                default:
                    return -1;
            }
        }