Exemple #1
0
        /// <exception cref="System.IO.IOException"/>
        public static void Write(java.nio.channels.WritableByteChannel outputChannel, Capnproto.MessageBuilder message)
        {
            java.nio.ByteBuffer[] segments = message.GetSegmentsForOutput();
            int tableSize = (segments.Length + 2) & (~1);

            java.nio.ByteBuffer table = java.nio.ByteBuffer.allocate(4 * tableSize);
            table.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            table.putInt(0, segments.Length - 1);
            for (int i = 0; i < segments.Length; ++i)
            {
                table.putInt(4 * (i + 1), segments[i].limit() / 8);
            }
            //Any padding is already zeroed.
            while (table.hasRemaining())
            {
                outputChannel.Write(table);
            }
            foreach (java.nio.ByteBuffer buffer in segments)
            {
                while (buffer.hasRemaining())
                {
                    outputChannel.Write(buffer);
                }
            }
        }
Exemple #2
0
 public override java.nio.IntBuffer put(int c)
 {
     if (_position == _limit)
     {
         throw new java.nio.BufferOverflowException();
     }
     byteBuffer.putInt(_position++ *libcore.io.SizeOf.INT, c);
     return(this);
 }
        public void compressImage(java.awt.image.BufferedImage image, DXTCompressionAttributes attributes,
                                  java.nio.ByteBuffer buffer)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (attributes == null)
            {
                String message = Logging.getMessage("nullValue.AttributesIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.BufferNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // If it is determined that the image and block have no alpha component, then we compress with DXT1 using a
            // four color palette. Otherwise, we use the three color palette (with the fourth color as transparent black).

            ColorBlock4x4       colorBlock          = new ColorBlock4x4();
            ColorBlockExtractor colorBlockExtractor = this.getColorBlockExtractor(image);

            BlockDXT1           dxt1Block      = new BlockDXT1();
            BlockDXT1Compressor dxt1Compressor = new BlockDXT1Compressor();

            int width  = image.getWidth();
            int height = image.getHeight();

            bool imageHasAlpha  = image.getColorModel().hasAlpha();
            bool enableAlpha    = attributes.isEnableDXT1Alpha();
            int  alphaThreshold = attributes.getDXT1AlphaThreshold();

            for (int j = 0; j < height; j += 4)
            {
                for (int i = 0; i < width; i += 4)
                {
                    colorBlockExtractor.extractColorBlock4x4(attributes, i, j, colorBlock);

                    if (enableAlpha && imageHasAlpha && blockHasDXT1Alpha(colorBlock, alphaThreshold))
                    {
                        dxt1Compressor.compressBlockDXT1a(colorBlock, attributes, dxt1Block);
                    }
                    else
                    {
                        dxt1Compressor.compressBlockDXT1(colorBlock, attributes, dxt1Block);
                    }

                    buffer.putShort((short)dxt1Block.color0);
                    buffer.putShort((short)dxt1Block.color1);
                    buffer.putInt((int)dxt1Block.colorIndexMask);
                }
            }
        }
Exemple #4
0
        /// <exception cref="System.IO.IOException"/>
        private void writeChunkHead(Chunk chunk)
        {
            long messageLength = chunk.getMessageLength();
            int  headLength    = messageLength > -1L ? ArangoDBConstants.CHUNK_MAX_HEADER_SIZE
                 : ArangoDBConstants.CHUNK_MIN_HEADER_SIZE;
            int length = chunk.getContentLength() + headLength;

            java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(headLength).order(java.nio.ByteOrder
                                                                                        .LITTLE_ENDIAN);
            buffer.putInt(length);
            buffer.putInt(chunk.getChunkX());
            buffer.putLong(chunk.getMessageId());
            if (messageLength > -1L)
            {
                buffer.putLong(messageLength);
            }
            this.outputStream.write((byte[])buffer.array());
        }
 public static void setKindAndTargetForEmptyStruct(java.nio.ByteBuffer buffer, int offset)
 {
     //# This pointer points at an empty struct. Assuming the
     //# WirePointer itself is in-bounds, we can set the target to
     //# point either at the WirePointer itself or immediately after
     //# it. The latter would cause the WirePointer to be "null"
     //# (since for an empty struct the upper 32 bits are going to
     //# be zero). So we set an offset of -1, as if the struct were
     //# allocated immediately before this pointer, to distinguish
     //# it from null.
     buffer.putInt(offset * 8, unchecked ((int)(0xfffffffc)));
 }
Exemple #6
0
        public void compressImage(java.awt.image.BufferedImage image, DXTCompressionAttributes attributes,
                                  java.nio.ByteBuffer buffer)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (attributes == null)
            {
                String message = Logging.getMessage("nullValue.AttributesIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.BufferNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            ColorBlock4x4       colorBlock          = new ColorBlock4x4();
            ColorBlockExtractor colorBlockExtractor = this.getColorBlockExtractor(image);

            BlockDXT3           dxt3Block      = new BlockDXT3();
            BlockDXT3Compressor dxt3Compressor = new BlockDXT3Compressor();

            int width  = image.getWidth();
            int height = image.getHeight();

            for (int j = 0; j < height; j += 4)
            {
                for (int i = 0; i < width; i += 4)
                {
                    colorBlockExtractor.extractColorBlock4x4(attributes, i, j, colorBlock);
                    dxt3Compressor.compressBlockDXT3(colorBlock, attributes, dxt3Block);

                    AlphaBlockDXT3 dxtAlphaBlock = dxt3Block.getAlphaBlock();
                    buffer.putLong(dxtAlphaBlock.alphaValueMask);

                    BlockDXT1 dxtColorBlock = dxt3Block.getColorBlock();
                    buffer.putShort((short)dxtColorBlock.color0);
                    buffer.putShort((short)dxtColorBlock.color1);
                    buffer.putInt((int)dxtColorBlock.colorIndexMask);
                }
            }
        }
Exemple #7
0
 public static void setInlineComposite(java.nio.ByteBuffer buffer, int offset, int wordCount)
 {
     //TODO: Length assertion.
     buffer.putInt(8 * offset + 4, (wordCount << 3) | Capnproto.ElementSize.INLINE_COMPOSITE);
 }
Exemple #8
0
 public static void set(java.nio.ByteBuffer buffer, int offset, byte elementSize, int elementCount)
 {
     //TODO: Length assertion.
     buffer.putInt(8 * offset + 4, (elementCount << 3) | elementSize);
 }
 public static void setSegmentId(java.nio.ByteBuffer buffer, int offset, int segmentId)
 {
     buffer.putInt(8 * offset + 4, segmentId);
 }
 public static void setKindAndInlineCompositeListElementCount(java.nio.ByteBuffer buffer, int offset, byte kind, int elementCount)
 {
     buffer.putInt(offset * 8, (elementCount << 2) | kind);
 }
 public static void setOffsetAndKind(java.nio.ByteBuffer buffer, int offset, int offsetAndKind)
 {
     buffer.putInt(offset * 8, offsetAndKind);
 }
 public static void setKindWithZeroOffset(java.nio.ByteBuffer buffer, int offset, byte kind)
 {
     buffer.putInt(offset * Capnproto.Constants.BYTES_PER_WORD, kind);
 }
 public static void setKindAndTarget(java.nio.ByteBuffer buffer, int offset, byte kind, int targetOffset)
 {
     buffer.putInt(offset * 8, (((targetOffset - offset) - 1) << 2) | kind);
 }
Exemple #14
0
 /// <seealso>[Hitchens2002] p.47: Accessing Unsigned Data</seealso>
 /// <param name="intBuffer"/>
 /// <returns/>
 public static void putUnsignedInt(java.nio.ByteBuffer intBuffer, int byteOffset,
                                   long value)
 {
     intBuffer.putInt(byteOffset, (int)(value & unchecked ((long)(0xffffffffl))));
 }
Exemple #15
0
 /// <seealso>[Hitchens2002] p.47: Accessing Unsigned Data</seealso>
 public static void putUnsignedInt(java.nio.ByteBuffer buffer, long v)
 {
     buffer.putInt((int)(v & unchecked ((long)(0xffffffffl))));
 }