示例#1
0
		public bool AddData(ByteBuffer data) {
			if (data.Limit == 0)
				return false;// Empty buffer
			if (!CanHandleData(data))
				return false;
			data.Get();
			UpdateSize(data);
			int idx = 0;
			int pos = 0;
			byte[] tmpData = new byte[_blockDataSize];

			int countBlocks = _blockCount;
			while (data.Remaining > 0 && countBlocks > 0) {
				short size = data.GetShort();
				countBlocks--;
				if (size == 0) {
					// Block has not been modified
					idx += 1;
					pos += _blockDataSize;
					continue;
				}
				// Store new block data
				_blockSize[idx] = size;
				data.Read(tmpData, 0, size);
				Array.Copy(tmpData, 0, _blockData, pos, size);
				idx += 1;
				pos += _blockDataSize;
			}
			data.Rewind();
			return true;
		}
示例#2
0
		/// <summary>
		/// Update total block size.
		/// </summary>
		/// <param name="data"></param>
		private void UpdateSize(ByteBuffer data) {
			_widthInfo = data.GetShort();
			_heightInfo = data.GetShort();
			// extract width and height of the frame
			_width = _widthInfo & 0xfff;
			_height = _heightInfo & 0xfff;
			// calculate size of blocks
			_blockWidth = _widthInfo & 0xf000;
			_blockWidth = (_blockWidth >> 12) + 1;
			_blockWidth <<= 4;

			_blockHeight = _heightInfo & 0xf000;
			_blockHeight = (_blockHeight >> 12) + 1;
			_blockHeight <<= 4;

			int xblocks = _width / _blockWidth;
			if ((_width % _blockWidth) != 0) {
				// partial block
				xblocks += 1;
			}

			int yblocks = _height / _blockHeight;
			if ((_height % _blockHeight) != 0) {
				// partial block
				yblocks += 1;
			}

			_blockCount = xblocks * yblocks;

			int blockSize = GetMaxCompressedSize(_blockWidth * _blockHeight * 3);
			int totalBlockSize = blockSize * _blockCount;
			if (_totalBlockDataSize != totalBlockSize) {
				//log.Debug("Allocating memory for {} compressed blocks.", this.blockCount);
				_blockDataSize = blockSize;
				_totalBlockDataSize = totalBlockSize;
				_blockData = new byte[blockSize * _blockCount];
				_blockSize = new int[blockSize * _blockCount];
				// Reset the sizes to zero
				for (int idx = 0; idx < _blockCount; idx++) {
					_blockSize[idx] = 0;
				}
			}
		}
示例#3
0
		static Ping DecodePing(ByteBuffer stream) {
			Ping ping = new Ping();
			ping.PingType = stream.GetShort();
			ping.Value2 = stream.GetInt();
			if (stream.HasRemaining)
				ping.Value3 = stream.GetInt();
			if (stream.HasRemaining)
				ping.Value4 = stream.GetInt();
			return ping;
		}