Esempio n. 1
0
        /// <summary>
        ///    Reads all metadata blocks starting from the current
        ///    instance, starting at a specified position.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="long" /> value reference specifying the
        ///    position at which to start searching for the blocks. This
        ///    will be updated to the position of the first block.
        /// </param>
        /// <param name="end">
        ///    A <see cref="long" /> value reference updated to the
        ///    position at which the last block ends.
        /// </param>
        /// <param name="mode">
        ///    A <see cref="BlockMode" /> value indicating whether to
        ///    white-list or black-list the contents of <paramref
        ///    name="types" />.
        /// </param>
        /// <param name="types">
        ///    A <see cref="BlockType[]" /> containing the types to look
        ///    for or not look for as specified by <paramref name="mode"
        ///    />.
        /// </param>
        /// <returns>
        ///    A <see cref="T:System.Collections.Generic.IList`1" /> object containing the blocks
        ///    read from the current instance.
        /// </returns>
        /// <exception cref="CorruptFileException">
        ///    "<c>fLaC</c>" could not be found.
        /// </exception>
        private IList <Block> ReadBlocks(ref long start, out long end,
                                         BlockMode mode,
                                         params BlockType[] types)
        {
            List <Block> blocks = new List <Block> ();

            long start_position = Find("fLaC", start);

            if (start_position < 0)
            {
                throw new CorruptFileException(
                          "FLAC stream not found at starting position.");
            }

            end = start = start_position + 4;

            Seek(start);

            BlockHeader header;

            do
            {
                header = new BlockHeader(ReadBlock((int)
                                                   BlockHeader.Size));

                bool found = false;
                foreach (BlockType type in types)
                {
                    if (header.BlockType == type)
                    {
                        found = true;
                        break;
                    }
                }

                if ((mode == BlockMode.Whitelist && found) ||
                    (mode == BlockMode.Blacklist && !found))
                {
                    blocks.Add(new Block(header,
                                         ReadBlock((int)
                                                   header.BlockSize)));
                }
                else
                {
                    Seek(header.BlockSize,
                         System.IO.SeekOrigin.Current);
                }

                end += header.BlockSize + BlockHeader.Size;
            } while (!header.IsLastBlock);

            return(blocks);
        }
Esempio n. 2
0
 public ComplexFifoStream(BlockMode blockMode, int maxSize)
 {
     if (blockMode == BlockMode.BlockingRead || blockMode == BlockMode.BlockingReadWrite)
     this._readEvent = new SharpEvent(false);
       if (blockMode == BlockMode.BlockingWrite || blockMode == BlockMode.BlockingReadWrite)
       {
     if (maxSize <= 0)
       throw new ArgumentException("MaxSize should be greater than zero when in blocking write mode", "maxSize");
     this._writeEvent = new SharpEvent(false);
       }
       this._maxSize = maxSize;
 }
Esempio n. 3
0
 public Profile(string name, bool[] days, TimeUnit[] startTimes, TimeUnit[] endTimes, bool active, bool allowed, BlockMode mode, List <string> phoneNumbersAsStrings, List <long> phoneNumbersAsLongs, List <string> contactNames)
 {
     Name                  = name;
     Days                  = days;
     StartTimes            = startTimes;
     EndTimes              = endTimes;
     Active                = active;
     Allowed               = allowed;
     Mode                  = mode;
     PhoneNumbersAsStrings = phoneNumbersAsStrings;
     PhoneNumbersAsLongs   = phoneNumbersAsLongs;
     ContactNames          = contactNames;
 }
Esempio n. 4
0
        //private
        private static byte[] encryptDecrypt(byte[] input, byte[] key, byte[] iv, BlockMode mode, BlockPadding padding, bool encrypt)
        {
            DesEdeEngine        engine = new DesEdeEngine();
            IBlockCipher        cipherMode;
            BufferedBlockCipher cipher;
            KeyParameter        keyP      = new KeyParameter(key);
            ParametersWithIV    keyParams = new ParametersWithIV(keyP, iv);

            if (mode == BlockMode.CBC)
            {
                cipherMode = new CbcBlockCipher(engine);
            }
            else if (mode == BlockMode.CFB)
            {
                cipherMode = new CfbBlockCipher(engine, iv.Length);
            }
            else if (mode == BlockMode.OFB)
            {
                cipherMode = new OfbBlockCipher(engine, iv.Length);
            }
            else
            {
                throw new Exception("mode must be a valid BlockMode.");
            }

            if (padding == BlockPadding.PKCS7Padding)
            {
                cipher = new PaddedBufferedBlockCipher(cipherMode, new Pkcs7Padding());
            }
            else if (padding == BlockPadding.ZeroBytePadding)
            {
                cipher = new PaddedBufferedBlockCipher(cipherMode, new ZeroBytePadding());
            }
            else if (padding == BlockPadding.NoPadding)
            {
                cipher = new BufferedBlockCipher(cipherMode);
            }
            else
            {
                throw new Exception("padding must be a valid BlockPadding.");
            }

            cipher.Init(encrypt, keyParams);
            byte[] output = new byte[cipher.GetOutputSize(input.Length)];
            int    length = cipher.ProcessBytes(input, output, 0);

            cipher.DoFinal(output, length);

            return(output);
        }
Esempio n. 5
0
        private IList <Color> DecodeSinglePartition(BitReader br, BlockMode blockMode)
        {
            var colorEndpointMode = DecodeColorEndpointModes(br, blockMode, 1)[0];

            if (colorEndpointMode.EndpointValueCount > 18 || blockMode.IsHdr != colorEndpointMode.IsHdr)
            {
                return(ErrorColors);
            }

            var colorBits         = ColorHelper.CalculateColorBits(1, blockMode.WeightBitCount, blockMode.IsDualPlane);
            var quantizationLevel = ColorHelper.QuantizationModeTable[colorEndpointMode.EndpointValueCount >> 1][colorBits];

            if (quantizationLevel < 4)
            {
                return(ErrorColors);
            }

            var colorValues    = IntegerSequenceEncoding.Decode(br, quantizationLevel, colorEndpointMode.EndpointValueCount);
            var colorEndpoints = ColorUnquantization.DecodeColorEndpoints(colorValues, colorEndpointMode.Format, quantizationLevel);

            // Weights decoding
            br.Position = 128 - blockMode.WeightBitCount;

            var result = new Color[_x * _y * _z];

            if (blockMode.IsDualPlane)
            {
                br.Position = 128 - blockMode.WeightBitCount - 2;
                var plane2ColorComponent = br.ReadBits <int>(2);

                var indices = IntegerSequenceEncoding.Decode(br, blockMode.QuantizationMode, blockMode.WeightCount);
                for (var i = 0; i < blockMode.WeightCount; i++)
                {
                    var plane1Weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i * 2]];
                    var plane2Weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i * 2 + 1]];
                    result[i] = ColorHelper.InterpolateColor(colorEndpoints, plane1Weight, plane2Weight, plane2ColorComponent);
                }
            }
            else
            {
                var indices = IntegerSequenceEncoding.Decode(br, blockMode.QuantizationMode, blockMode.WeightCount);
                for (var i = 0; i < blockMode.WeightCount; i++)
                {
                    var weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i]];
                    result[i] = ColorHelper.InterpolateColor(colorEndpoints, weight, -1, -1);
                }
            }

            return(result);
        }
Esempio n. 6
0
    public void Commence()
    {
        mode = BlockMode.Play;
        Rigidbody rB = gameObject.AddComponent <Rigidbody>();

        if (blockType < 2)
        {
            rB.mass = 3.0f;
        }
        else
        {
            rB.mass = 5.0f;
        }
        rB.collisionDetectionMode = CollisionDetectionMode.Continuous;
    }
            public TraversalProvider(BlockManager blockManager, BlockMode mode, List <SingleNodeBlocker> selector)
            {
                if (blockManager == null)
                {
                    throw new System.ArgumentNullException("blockManager");
                }
                if (selector == null)
                {
                    throw new System.ArgumentNullException("selector");
                }

                this.blockManager = blockManager;
                this.mode         = mode;
                this.selector     = selector;
            }
Esempio n. 8
0
 private void onModeSelectChanged(object sender, EventArgs e)
 {
     if (modeSelect.SelectedIndex == 0)
     {
         encryptMode = BlockMode.CBC;
     }
     else if (modeSelect.SelectedIndex == 1)
     {
         encryptMode = BlockMode.CFB;
     }
     else if (modeSelect.SelectedIndex == 2)
     {
         encryptMode = BlockMode.OFB;
     }
 }
Esempio n. 9
0
 public ComplexFifoStream(BlockMode blockMode, int maxSize)
 {
     if (blockMode == BlockMode.BlockingRead || blockMode == BlockMode.BlockingReadWrite)
     {
         this._readEvent = new SharpEvent(false);
     }
     if (blockMode == BlockMode.BlockingWrite || blockMode == BlockMode.BlockingReadWrite)
     {
         if (maxSize <= 0)
         {
             throw new ArgumentException("MaxSize should be greater than zero when in blocking write mode", "maxSize");
         }
         this._writeEvent = new SharpEvent(false);
     }
     this._maxSize = maxSize;
 }
Esempio n. 10
0
        public IEnumerable <Color> DecodeBlocks(byte[] block)
        {
            // Find block containing texel
            var br = CreateReader(block);

            // Read block mode
            var blockMode = BlockMode.Create(br);

            // If void-extent, return single color (optimization)
            if (blockMode.IsVoidExtent)
            {
                var voidExtentColor = CreateVoidExtentColor(br, blockMode.IsHdr);
                return(Enumerable.Repeat(voidExtentColor, _x * _y * _z));
            }

            // If a reserved block is used, return error color
            if (blockMode.UsesReserved)
            {
                return(ErrorColors);
            }

            // If invalid weight ranges
            if (blockMode.WeightCount > Constants.MaxWeightsPerBlock ||
                blockMode.WeightBitCount < Constants.MinWeightBitsPerBlock ||
                blockMode.WeightBitCount > Constants.MaxWeightBitsPerBlock)
            {
                return(ErrorColors);
            }

            var partitions = br.ReadBits <int>(2) + 1;

            if (blockMode.IsDualPlane && partitions == 4)
            {
                return(ErrorColors);
            }

            if (partitions == 1)
            {
                return(DecodeSinglePartition(br, blockMode));
            }

            // TODO: Implement multi partition
            return(DecodeMultiPartition(br, blockMode, partitions));
        }
Esempio n. 11
0
    /// <summary>
    /// 블럭과 블럭을 합칩니다.
    /// </summary>
    /// <param name="target">합쳐지기 전의 블럭</param>
    /// <returns>합쳐진 문자열 (정답 판별용)</returns>
    public string Incorporation(Block target)
    {
        ScoreMng.Instance.mergeCnt += 1;
        currentMode        = BlockMode.MERGE;
        target.currentMode = BlockMode.DESTROYIMMEDIATE;

        string margeWord = this.displayWord.text + target.displayWord.text;

        if (margeWord.Length <= 18)
        {
            this.displayWord.text = margeWord;
        }
        else
        {
            this.displayWord.text = target.displayWord.text;
        }

        target.endPosition = originPosition;
        return(this.displayWord.text);
    }
Esempio n. 12
0
        private IList <ColorEndpointMode> DecodeColorEndpointModes(BitReader br, BlockMode blockMode, int partitions)
        {
            if (partitions == 1)
            {
                br.Position = 13;
                return(new[] { new ColorEndpointMode(br.ReadBits <int>(4)) });
            }

            br.Position = 13 + Constants.PartitionBits;
            var encodedType = br.ReadBits <int>(6);

            var encodedTypeHighSize = 3 * partitions - 4;

            br.Position  = 128 - blockMode.WeightBitCount - encodedTypeHighSize;
            encodedType |= br.ReadBits <int>(encodedTypeHighSize) << 6;

            var result = new ColorEndpointMode[partitions];

            var baseClass = encodedType & 0x3;

            if (baseClass == 0)
            {
                for (var i = 0; i < partitions; i++)
                {
                    result[i] = new ColorEndpointMode((encodedType >> 2) & 0xF);
                }
            }
            else
            {
                baseClass--;

                for (var i = 0; i < partitions; i++)
                {
                    var highPart = ((encodedType >> (2 + i)) & 1) + baseClass;
                    var lowPart  = (encodedType >> (2 + partitions + i * 2)) & 3;
                    result[i] = new ColorEndpointMode((highPart << 2) | lowPart);
                }
            }

            return(result);
        }
Esempio n. 13
0
        // Our callback to change sequences
        public void coreFunctionality(AnimaPart part)
        {
            bool status = block.IsWorking;

            if (!lastStatus && status)
            {
                // Powering on
                m_part_1.Sequence = Seq_SC_Radar_Part1_powerOn.Adquire();
                m_part_2.Sequence = Seq_SC_Radar_Part2_powerOn.Adquire();
                m_part_3.Sequence = Seq_SC_Radar_Part3_powerOn.Adquire();
                blockMode         = BlockMode.POWER_ON;
            }
            else if (lastStatus && !status)
            {
                // Powering off
                m_part_1.Sequence = Seq_SC_Radar_Part1_powerOff.Adquire();
                m_part_2.Sequence = Seq_SC_Radar_Part2_powerOff.Adquire();
                m_part_3.Sequence = Seq_SC_Radar_Part3_powerOff.Adquire();
                blockMode         = BlockMode.POWER_OFF;
            }
            else if (status)
            {
                // While active
                m_part_1.Sequence = Seq_SC_Radar_Part1_active.Adquire();
                m_part_2.Sequence = Seq_SC_Radar_Part2_active.Adquire();
                m_part_3.Sequence = Seq_SC_Radar_Part3_active.Adquire();
                blockMode         = BlockMode.ACTIVE;
            }
            else
            {
                // While inactive
                m_part_1.Sequence = Seq_SC_Radar_Part1_inactive.Adquire();
                m_part_2.Sequence = Seq_SC_Radar_Part2_inactive.Adquire();
                m_part_3.Sequence = Seq_SC_Radar_Part3_inactive.Adquire();
                blockMode         = BlockMode.INACTIVE;
            }
            lastStatus = status;
        }
Esempio n. 14
0
        private bool ShouldBlock(string number)
        {
            if (shouldBlockAbsolutely)
            {
                return(true);
            }

            if (number == null)
            {
                return(false);
            }

            ProfileManager mgr = new ProfileManager();

            Profile[] allProfiles = mgr.GetAllProfiles();

            foreach (Profile prof in allProfiles)
            {
                if (!prof.Allowed)
                {
                    BlockMode mode = prof.Mode;
                    switch (mode)
                    {
                    case BlockMode.All:
                        return(true);

                    case BlockMode.BlackList:
                        return(prof.PhoneNumbersAsStrings.Contains(number));

                    case BlockMode.WhiteList:
                        return(!prof.PhoneNumbersAsStrings.Contains(number));
                    }
                }
            }
            return(false);
        }
Esempio n. 15
0
 private IList<Block> ReadBlocks(ref long start, out long end, BlockMode mode, params BlockType[] types)
 {
     BlockHeader header;
     List<Block> list = new List<Block>();
     long num = base.Find("fLaC", start);
     if (num < 0L)
     {
         throw new CorruptFileException("FLAC stream not found at starting position.");
     }
     end = start = num + 4L;
     base.Seek(start);
     do
     {
         header = new BlockHeader(base.ReadBlock(4));
         bool flag = false;
         foreach (BlockType type in types)
         {
             if (header.BlockType == type)
             {
                 flag = true;
                 break;
             }
         }
         if (((mode == BlockMode.Whitelist) && flag) || ((mode == BlockMode.Blacklist) && !flag))
         {
             list.Add(new Block(header, base.ReadBlock((int) header.BlockSize)));
         }
         else
         {
             base.Seek((long) header.BlockSize, SeekOrigin.Current);
         }
         end += header.BlockSize + 4;
     }
     while (!header.IsLastBlock);
     return list;
 }
Esempio n. 16
0
 public static byte[] decrypt(byte[] input, byte[] key, byte[] iv, BlockMode mode, BlockPadding padding)
 {
     return(encryptDecrypt(input, key, iv, mode, padding, false));
 }
Esempio n. 17
0
        public static void DoBlock(ConnectionInformation connectionInformation, bool endlessBlock, BlockMode blockMode)
        {
            if (connectionInformation == null)
            {
                return;
            }
            var sRemIp = connectionInformation.ShowIp.ToString();

            if (sRemIp != "")
            {
                var blockName = sRemIp + (endlessBlock ? EndlessBlockSuffix : BlockSuffix);

                if (blockMode == BlockMode.BlockAll || blockMode == BlockMode.BlockInput)
                {
                    AddRule(blockName, sRemIp, NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN);
                }
                if (blockMode == BlockMode.BlockAll || blockMode == BlockMode.BlockOutput)
                {
                    AddRule(blockName, sRemIp, NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT);
                }
                connectionInformation.Blocked = true;
            }
        }
Esempio n. 18
0
 private void SetupConversion(string from, string to, BlockMode blockMode)
 {
     NativeCalls.SetBlockMode(_context, blockMode);
     NativeCalls.SetInputFile(_context, from);
     NativeCalls.SetOutputFile(_context, to);
 }
Esempio n. 19
0
    public float GenerateOneLine(float fromX, float blocks, float y,
                                 DrawLineFlags drawLineFlags)
    {
        GameObject[] objs     = new GameObject[10];
        Cint         cooldown = 0;

        bool[] holes = new bool[(int)blocks + 1];

        if (drawLineFlags.HasFlag(DrawLineFlags.DontMakeHoles) == false && makeHole && blocks >= 3)
        {
            for (int x = 2; x < blocks - 2; x++)
            {
                if (cooldown == 0 && Chance(chanceForHole))
                {
                    holes[x] = true;
                    cooldown = minHoleBreak;
                }
                else
                {
                    cooldown--;
                }
            }
        }

        for (int x = 0; x < blocks; x++)
        {
            BlockMode mode    = BlockMode.Center;
            bool      dontPut = drawLineFlags.HasFlag(DrawLineFlags.DontPutActiveItems);
            bool      anyMode = false;
            if (drawLineFlags.HasFlag(DrawLineFlags.DontMakeEdge) == false)
            {
                anyMode = true;
                if (x == 0)
                {
                    mode    = BlockMode.Left;
                    dontPut = true;
                }

                else if (x == blocks - 1)
                {
                    mode    = BlockMode.Right;
                    dontPut = true;
                }
                else
                {
                    anyMode = false;
                }
            }
            if (anyMode == false)
            {
                if (holes[x + 1])
                {
                    mode = BlockMode.Right;
                }
                else if (x > 0 && holes[x - 1])
                {
                    mode = BlockMode.Left;
                }
            }

            if (holes[x] == false)
            {
                GameObject block;
                objs[x] = block = PutBlock(new Vector2(fromX + x, y), dontPut, mode);
                if (drawLineFlags.HasFlag(DrawLineFlags.Flip))
                {
                    block.GetComponent <SpriteRenderer>().flipY = true;
                }
            }
        }
        blocksPacks.Enqueue(objs);
        return(fromX + blockInOneShoot);
    }
Esempio n. 20
0
 public BlockEventArgs(int time, BlockMode mode)
 {
     this.Time = time;
     this.Mode = mode;
 }
Esempio n. 21
0
 public bool ShouldSerializeBlockMode() =>
 SerializeDefaults ||
 !BlockMode.Equals(ZPLForgeDefaults.Elements.Text.BlockMode);
Esempio n. 22
0
        // Returns null if an error occurs while reading.
        private Profile ReadProfile(string path)
        {
            _rwl.EnterReadLock();

            Profile result;

            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(path);

                reader.ReadToFollowing("Name");


                string profileName = reader.ReadElementContentAsString();

                bool[] days = new bool[7];
                reader.ReadStartElement();
                for (int i = 0; reader.Name == "Day" && i < 7; i++)
                {
                    days[i] = reader.ReadElementContentAsBoolean();
                }
                reader.ReadEndElement();

                TimeUnit[] startTimes = new TimeUnit[7];
                reader.ReadStartElement();
                for (int i = 0; reader.Name == "StartTime" && i < 7; i++)
                {
                    string startTimeString = reader.ReadElementContentAsString();
                    startTimes[i] = TimeUnit.Parse(startTimeString);
                }
                reader.ReadEndElement();

                TimeUnit[] endTimes = new TimeUnit[7];
                reader.ReadStartElement();
                for (int i = 0; reader.Name == "EndTime" && i < 7; i++)
                {
                    string endTimeString = reader.ReadElementContentAsString();
                    endTimes[i] = TimeUnit.Parse(endTimeString);
                }
                reader.ReadEndElement();

                bool active = reader.ReadElementContentAsBoolean();

                bool allowed = reader.ReadElementContentAsBoolean();

                BlockMode mode = (BlockMode)reader.ReadElementContentAsInt();

                List <string> phoneNumbersAsStrings = new List <string>();
                reader.ReadStartElement();
                while (reader.Name == "PhoneNumberString")
                {
                    string readNumber = reader.ReadElementContentAsString();
                    if (!string.IsNullOrEmpty(readNumber))
                    {
                        phoneNumbersAsStrings.Add(readNumber);
                    }
                }
                reader.ReadEndElement();

                List <long> phoneNumbersAsLongs = new List <long>();
                reader.ReadStartElement();
                while (reader.Name == "PhoneNumberLong")
                {
                    string readNumber = reader.ReadElementContentAsString();
                    if (!string.IsNullOrEmpty(readNumber))
                    {
                        phoneNumbersAsLongs.Add(long.Parse(readNumber));
                    }
                }
                reader.ReadEndElement();

                List <string> contactNames = new List <string>();
                reader.ReadStartElement();
                while (reader.Name == "ContactName")
                {
                    string readName = reader.ReadElementContentAsString();
                    if (!string.IsNullOrEmpty(readName))
                    {
                        contactNames.Add(readName);
                    }
                }
                reader.ReadEndElement();

                reader.ReadEndElement();


                result = new Profile(
                    profileName,
                    days,
                    startTimes,
                    endTimes,
                    active,
                    allowed,
                    mode,
                    phoneNumbersAsStrings,
                    phoneNumbersAsLongs,
                    contactNames
                    );
            } catch (Exception e) {
                Console.WriteLine(e);
                result = null;
            }
            reader?.Close();
            _rwl.ExitReadLock();

            return(result);
        }
Esempio n. 23
0
 public ComplexFifoStream(BlockMode blockMode)
     : this(blockMode, 0)
 {
 }
Esempio n. 24
0
 public FloatFifoStream(BlockMode blockMode) : this(blockMode, 0)
 {
 }
Esempio n. 25
0
 public ComplexFifoStream(BlockMode blockMode)
     : this(blockMode, 0)
 {
 }
Esempio n. 26
0
 internal static IntPtr SetBlockMode(IntPtr ctx, BlockMode blockSize) => SetBlockMode(ctx, (int)blockSize);
Esempio n. 27
0
 public BlockEventArgs(RoutedEvent routedEvent, int time, BlockMode mode) : base(routedEvent)
 {
     this.Time = time;
     this.Mode = mode;
 }
Esempio n. 28
0
 public static void DoInSecBlock(ConnectionInformation connectionInformation, int sec = 30, BlockMode blockMode = BlockMode.BlockAll)
 {
     if (connectionInformation.ShowIp.ToString() != "")
     {
         DoBlock(connectionInformation, false, blockMode);
         var td = new Thread(() => UnBlockInSeconds(connectionInformation, sec))
         {
             Name = "UnBlock30"
         };
         td.Start();
         TdList.Add(new ExThread(td, DateTime.Now));
     }
 }
Esempio n. 29
0
 public FloatFifoStream(BlockMode blockMode)
     : this(blockMode, 0)
 {
 }
Esempio n. 30
0
        /// <summary>
        ///    Reads all metadata blocks starting from the current
        ///    instance, starting at a specified position.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="long" /> value reference specifying the
        ///    position at which to start searching for the blocks. This
        ///    will be updated to the position of the first block.
        /// </param>
        /// <param name="end">
        ///    A <see cref="long" /> value reference updated to the
        ///    position at which the last block ends.
        /// </param>
        /// <param name="mode">
        ///    A <see cref="BlockMode" /> value indicating whether to
        ///    white-list or black-list the contents of <paramref
        ///    name="types" />.
        /// </param>
        /// <param name="types">
        ///    A <see cref="BlockType[]" /> containing the types to look
        ///    for or not look for as specified by <paramref name="mode"
        ///    />.
        /// </param>
        /// <returns>
        ///    A <see cref="T:System.Collections.Generic.IList`1" /> object containing the blocks
        ///    read from the current instance.
        /// </returns>
        /// <exception cref="CorruptFileException">
        ///    "<c>fLaC</c>" could not be found.
        /// </exception>
        private IList<Block> ReadBlocks(ref long start, out long end,
		                                 BlockMode mode,
		                                 params BlockType[] types)
        {
            List<Block> blocks = new List<Block> ();

            long start_position = Find ("fLaC", start);

            if (start_position < 0)
                throw new CorruptFileException (
                    "FLAC stream not found at starting position.");

            end = start = start_position + 4;

            Seek (start);

            BlockHeader header;

            do {
                header = new BlockHeader (ReadBlock ((int)
                    BlockHeader.Size));

                bool found = false;
                foreach (BlockType type in types)
                    if (header.BlockType == type) {
                        found = true;
                        break;
                    }

                if ((mode == BlockMode.Whitelist && found) ||
                    (mode == BlockMode.Blacklist && !found))
                    blocks.Add (new Block (header,
                        ReadBlock ((int)
                            header.BlockSize)));
                else
                    Seek (header.BlockSize,
                        System.IO.SeekOrigin.Current);

                end += header.BlockSize + BlockHeader.Size;
            } while (!header.IsLastBlock);

            return blocks;
        }
Esempio n. 31
0
 public BlockNode(BlockMode mode, bool doIndentFirstLine = true) : base(BlockType.Block)
 {
     //'doIndentFirstLine' exists because technically all nodes should implement 'Serialize'. I do not include this right now, but leaving this as residue that it exists
     this.Mode = mode;
 }
Esempio n. 32
0
        private IList <Color> DecodeMultiPartition(BitReader br, BlockMode blockMode, int partitions)
        {
            var colorEndpointModes = DecodeColorEndpointModes(br, blockMode, partitions);
            var colorValueCount    = colorEndpointModes.Sum(x => x.EndpointValueCount);

            if (colorValueCount > 18 || colorEndpointModes.Any(x => x.IsHdr != blockMode.IsHdr))
            {
                return(ErrorColors);
            }

            var colorBits         = ColorHelper.CalculateColorBits(partitions, blockMode.WeightBitCount, blockMode.IsDualPlane);
            var quantizationLevel = ColorHelper.QuantizationModeTable[colorValueCount >> 1][colorBits];

            if (quantizationLevel < 4)
            {
                return(ErrorColors);
            }

            br.Position = 19 + Constants.PartitionBits;
            var colorValues = IntegerSequenceEncoding.Decode(br, quantizationLevel, colorValueCount);

            var colorEndpoints = new UInt4[partitions][];

            for (var i = 0; i < partitions; i++)
            {
                colorEndpoints[i] = ColorUnquantization.DecodeColorEndpoints(colorValues, colorEndpointModes[i].Format, quantizationLevel);
            }

            br.Position = 13;
            var partitionIndex = br.ReadBits <uint>(10);

            var elementsInBlock  = _x * _y * _z;
            var partitionIndices = new int[elementsInBlock];

            for (int z = 0; z < _z; z++)
            {
                for (int y = 0; y < _y; y++)
                {
                    for (int x = 0; x < _x; x++)
                    {
                        partitionIndices[x * y * z] =
                            PartitionSelection.SelectPartition(partitionIndex, x, y, z, partitions, elementsInBlock < 32);
                    }
                }
            }

            var result = new Color[elementsInBlock];

            if (blockMode.IsDualPlane)
            {
                // TODO: Should those 2 bits below the weights be here for multi partition due to encodedType high part?
                br.Position = 128 - blockMode.WeightBitCount - 2;
                var plane2ColorComponent = br.ReadBits <int>(2);

                var indices = IntegerSequenceEncoding.Decode(br, blockMode.QuantizationMode, blockMode.WeightCount);
                for (var i = 0; i < blockMode.WeightCount; i++)
                {
                    var plane1Weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i * 2]];
                    var plane2Weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i * 2 + 1]];
                    result[i] = ColorHelper.InterpolateColor(colorEndpoints[partitionIndices[i]], plane1Weight, plane2Weight, plane2ColorComponent);
                }
            }
            else
            {
                var indices = IntegerSequenceEncoding.Decode(br, blockMode.QuantizationMode, blockMode.WeightCount);
                for (var i = 0; i < blockMode.WeightCount; i++)
                {
                    var weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i]];
                    result[i] = ColorHelper.InterpolateColor(colorEndpoints[partitionIndices[i]], weight, -1, -1);
                }
            }

            return(result);
        }
        static public Color[] AlphaBleed(Color[] pixels, int width, int height)
        {
            Color[] np          = new Color[height * width];
            int     blockHeight = (int)(height - 1) / BlockSize + 1;
            int     blockWidth  = (int)(width - 1) / BlockSize + 1;

            Color[]     bc        = new Color[blockHeight * blockWidth];
            BlockMode[] bf        = new BlockMode[blockHeight * blockWidth];
            int         remaining = 0;
            bool        exitFlag  = true;

            for (var yb = 0; yb < blockHeight; yb++)
            {
                for (var xb = 0; xb < blockWidth; xb++)
                {
                    float r = 0.0f;
                    float g = 0.0f;
                    float b = 0.0f;
                    float c = 0.0f;
                    int   n = 0;
                    for (var y = 0; y < BlockSize; y++)
                    {
                        for (var x = 0; x < BlockSize; x++)
                        {
                            int xpos = xb * BlockSize + x;
                            int ypos = yb * BlockSize + y;
                            if (xpos < width && ypos < height)
                            {
                                int   pos = ypos * width + xpos;
                                float ad  = pixels [pos].a;
                                r += pixels [pos].r * ad;
                                g += pixels [pos].g * ad;
                                b += pixels [pos].b * ad;
                                c += ad;
                                if (ad <= 0.02f)
                                {
                                    n++;
                                }
                            }
                        }
                    }
                    var block = yb * blockWidth + xb;
                    if (n > 0)
                    {
                        bf [block] = BlockMode.Processing;
                        remaining++;
                    }
                    else
                    {
                        bf [block] = BlockMode.Termination;
                    }
                    if (c <= 0.02f)
                    {
                        bc [block] = new Color(0.0f, 0.0f, 0.0f, 0.0f);
                        bf [block] = BlockMode.Untreated;
                    }
                    else
                    {
                        bc [block] = new Color(r / c, g / c, b / c, c / (float)(BlockSize * BlockSize));
                        exitFlag   = false;
                    }
                }
            }
            if (exitFlag || remaining == 0)
            {
                return(pixels);
            }
            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    int pos = y * width + x;
                    np [pos] = pixels [pos];
                }
            }
            BlockMode[] be = new BlockMode[blockHeight * blockWidth];
            for (int count = 16; count > 0 && remaining > 0; count--)
            {
                for (int i = 0; i < blockHeight * blockWidth; i++)
                {
                    be[i] = bf[i];
                }
                for (var yb = 0; yb < blockHeight; yb++)
                {
                    for (var xb = 0; xb < blockWidth; xb++)
                    {
                        var block = yb * blockWidth + xb;
                        if (be [block] == BlockMode.Termination)
                        {
                            continue;
                        }
                        float r    = 0.0f;
                        float g    = 0.0f;
                        float b    = 0.0f;
                        float c    = 0.0f;
                        Color ccol = bc [yb * blockWidth + xb];
                        r += (ccol.r * ccol.a * 16.0f);
                        g += (ccol.g * ccol.a * 16.0f);
                        b += (ccol.b * ccol.a * 16.0f);
                        c += (ccol.a * 16.0f);
                        int n = 0;
                        for (var yp = yb - 1; yp <= yb + 1; yp++)
                        {
                            for (var xp = xb - 1; xp <= xb + 1; xp++)
                            {
                                var x = (xp + blockWidth) % blockWidth;
                                var y = (yp + blockHeight) % blockHeight;
                                if (be [y * blockWidth + x] != BlockMode.Untreated)
                                {
                                    n++;
                                }
                                Color col = bc [y * blockWidth + x];
                                r += col.r * col.a;
                                g += col.g * col.a;
                                b += col.b * col.a;
                                c += col.a;
                            }
                        }
                        if (n > 0)
                        {
                            if (c > 0.0f)
                            {
                                r /= c; g /= c; b /= c; c /= 24.0f;
                            }
                            else
                            {
                                r = 0.0f; g = 0.0f; b = 0.0f; c = 0.0f;
                            }
                            for (var y = 0; y < BlockSize; y++)
                            {
                                for (var x = 0; x < BlockSize; x++)
                                {
                                    int xpos = xb * BlockSize + x;
                                    int ypos = yb * BlockSize + y;
                                    if (xpos < width && ypos < height)
                                    {
                                        int pos = ypos * width + xpos;
                                        if (pixels [pos].a <= 0.02f)
                                        {
                                            float ar = 1.0f - pixels [pos].a;
                                            np [pos] = new Color(r * ar + pixels [pos].r * (1.0f - ar)
                                                                 , g * ar + pixels [pos].g * (1.0f - ar)
                                                                 , b * ar + pixels [pos].b * (1.0f - ar)
                                                                 , pixels [pos].a);
                                        }
                                        else
                                        {
                                            np [pos] = pixels[pos];
                                        }
                                    }
                                }
                            }
                            if (be [yb * blockWidth + xb] == BlockMode.Untreated)
                            {
                                bc [yb * blockWidth + xb] = new Color(r, g, b, c);
                            }
                            bf [yb * blockWidth + xb] = BlockMode.Termination;
                            remaining--;
                        }
                    }
                }
            }
            return(np);
        }
Esempio n. 34
0
 public BlockEventArgs(RoutedEvent routedEvent, object source, int time, BlockMode mode) : base(routedEvent, source)
 {
     this.Time = time;
     this.Mode = mode;
 }
Esempio n. 35
0
        public void UpdateBlockMove(FunctionBlockBase selectBlock)
        {
            if (currentBlockMode != BlockMode.Move)
            {
                return;
            }

            if (selectBlock != null)
            {
                _isSelectFunctionBlock   = true;
                selectBlock.currentState = FunctionBlockBase.BlockState.Move;
            }
            else
            {
                return;
            }

            if (_selectBlockStartPos != Config.GlobalConfigData.InfinityVector)
            {
                if (_isSelectFunctionBlock /*selectBlock == _selectStartRaycastBlock*/)
                {
                    Vector3 currentSelectPos = TryGetRaycastHitGround(Input.mousePosition);
                    if (Vector3.Distance(_selectBlockStartPos, currentSelectPos) >= _minMoveDistance)
                    {
                        ///Start Move
                        CameraEvent camera = new CameraEvent()
                        {
                            point     = currentSelectPos,
                            blockBase = selectBlock
                        };

                        if (!_isDragStart)
                        {
                            _isDragStart = true;
                            if (OnBlockDragStart != null)
                            {
                                OnBlockDragStart.Invoke(camera);
                            }
                        }
                        _isDraggingFunctionBlock = true;

                        if (OnBlockDrag != null)
                        {
                            OnBlockDrag.Invoke(camera);
                        }
                    }
                }
            }

            /// 按下 放置方块
            if (Input.GetMouseButtonDown(0))
            {
                Debug.Log("Place!");
                _selectBlockStartPos   = Config.GlobalConfigData.InfinityVector;
                _isSelectFunctionBlock = false;
                if (_isDragStart)
                {
                    _isDragStart             = false;
                    _isDraggingFunctionBlock = false;
                    if (OnBlockDragEnd != null)
                    {
                        OnBlockDragEnd.Invoke(null);
                    }
                    currentBlockMode = BlockMode.None;
                    MapManager.Instance.InitBlockBuildPanelSelect(-1, false);
                    MapManager.Instance._hasAddBlockToMap = false;
                    selectBlock.currentState = FunctionBlockBase.BlockState.Idle;
                }
            }


            //if (Input.GetMouseButtonUp(0))
            //{
            //    _selectBlockStartPos = TryGetRaycastHitGround(Input.mousePosition);
            //    _selectStartRaycastBlock = TryGetRaycastHitBlock(Input.mousePosition);
            //    _isDraggingFunctionBlock = false;
            //    _isDragStart = false;
            //}
        }