Exemplo n.º 1
0
        internal void UpdateImage()
        {
            if (Table == null)
            {
                return;
            }

            Bitmap bm      = new Bitmap(1, Scanlines);
            int    counter = 0;

            foreach (HDMATableEntry entry in Table)
            {
                if (entry.ValueType == TableValueType.End)
                {
                    break;
                }
                if (entry.ValueType == TableValueType.Single)
                {
                    for (int y = counter; y < counter + entry.Scanlines - 0x80 && y < Scanlines; y++)
                    {
                        for (int x = 0; x < bm.Width; x++)
                        {
                            bm.SetPixel(x, y, Color.FromArgb(
                                            ColorEffect.HasFlag(ColorHDMAValues.Red) ? (entry.Values[y] & 0x1F) * 8 : 0,
                                            ColorEffect.HasFlag(ColorHDMAValues.Green) ? (entry.Values[y] & 0x1F) * 8 : 0,
                                            ColorEffect.HasFlag(ColorHDMAValues.Blue) ? (entry.Values[y] & 0x1F) * 8 : 0));
                        }
                    }
                    counter += entry.Scanlines - 0x80;
                }
                else if (entry.ValueType == TableValueType.db)
                {
                    for (int y = counter; y < counter + entry.Scanlines && y < Scanlines; y++)
                    {
                        for (int x = 0; x < bm.Width; x++)
                        {
                            bm.SetPixel(x, y, Color.FromArgb(
                                            ColorEffect.HasFlag(ColorHDMAValues.Red) ? (entry.Values[0] & 0x1F) * 8 : 0,
                                            ColorEffect.HasFlag(ColorHDMAValues.Green) ? (entry.Values[0] & 0x1F) * 8 : 0,
                                            ColorEffect.HasFlag(ColorHDMAValues.Blue) ? (entry.Values[0] & 0x1F) * 8 : 0));
                        }
                    }
                    counter += entry.Scanlines;
                }
                else
                {
                    //fixme exception
                    throw new HDMAException();
                }
            }

            Bitmap retImg = new Bitmap(256, Scanlines);

            using (TextureBrush brush = new TextureBrush(bm, WrapMode.Tile))
                using (Graphics gr = Graphics.FromImage(retImg))
                    gr.FillRectangle(brush, 0, 0, retImg.Width, retImg.Height);
            EffectImage = retImg;
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public override string Code(int Channel, HDMATable Table, bool SA1)
        {
            string tablename = "";

            if (ColorEffect.HasFlag(ColorHDMAValues.Red))
            {
                tablename += "Red";
            }
            if (ColorEffect.HasFlag(ColorHDMAValues.Green))
            {
                tablename += "Green";
            }
            if (ColorEffect.HasFlag(ColorHDMAValues.Blue))
            {
                tablename += "Blue";
            }

            return(ColorHDMA.Code(Channel, Table, SA1, "." + tablename + "Table"));
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        internal void UseCollection()
        {
            //http://www.codeproject.com/Articles/20018/Gradients-made-easy
            List <ColorPosition> _list = new List <ColorPosition>(ColorsPositions);

            if (_list.Count < 2)
            {
                return;
            }

            _list.Sort();

            if (_list[0].Position != 0)
            {
                _list.Insert(0, new ColorPosition(0, 0));
            }
            if (_list[_list.Count - 1].Position < Scanlines)
            {
                _list.Add(new ColorPosition(Scanlines, 0));
            }

            List <float> positions = new List <float>();
            //positions.Add(0.0f);

            int maxpos = _list.Max(cp => cp.Position);

            foreach (ColorPosition cp in _list)
            {
                positions.Add((float)cp.Position / (float)maxpos);
            }
            //positions.Add(1.0f);

            List <float> factors = new List <float>();

            //factors.Add(0.0f);
            foreach (ColorPosition cp in _list)
            {
                factors.Add((float)cp.Value8Bit / 248.0f);
            }
            //factors.Add(1.0f);

            Bitmap bm = new Bitmap(1, maxpos);

            using (Graphics g = Graphics.FromImage(bm))
            {
                Rectangle r = new Rectangle(0, 0, bm.Width, maxpos);
                using (LinearGradientBrush lgb = new LinearGradientBrush(r, Color.FromArgb(_list.Min(cp => cp.Orignal8Bit), 0, 0), Color.FromArgb(_list.Max(cp => cp.Orignal8Bit), 0, 0), 90.0f))
                {
                    Blend blend = new Blend();
                    blend.Factors   = factors.ToArray();
                    blend.Positions = positions.ToArray();
                    lgb.Blend       = blend;
                    g.FillRectangle(lgb, r);
                }
            }

            byte Compare = (byte)(bm.GetPixel(0, 0).R / 8);

            Table = new HDMATable();

            for (int y = 0, scan = 1; y < maxpos; y++, scan++)
            {
                byte fivebit = (byte)(bm.GetPixel(0, y).R / 8);
                if (Compare != fivebit || scan >= 0x80 || y == maxpos - 1)
                {
                    Table.Add(new HDMATableEntry(TableValueType.db, (byte)scan, (byte)((byte)ColorEffect | Compare)));
                    Compare = fivebit;
                    scan    = 0;
                }

                //fixme
                for (int x = 0; x < bm.Width; x++)
                {
                    bm.SetPixel(x, y, Color.FromArgb(
                                    ColorEffect.HasFlag(ColorHDMAValues.Red) ? fivebit * 8 : 0,
                                    ColorEffect.HasFlag(ColorHDMAValues.Green) ? fivebit * 8 : 0,
                                    ColorEffect.HasFlag(ColorHDMAValues.Blue) ? fivebit * 8 : 0));
                }
            }

            Table.Add(HDMATableEntry.End);

            Bitmap retImg = new Bitmap(256, maxpos);

            using (TextureBrush brush = new TextureBrush(bm, WrapMode.Tile))
                using (Graphics gr = Graphics.FromImage(retImg))
                    gr.FillRectangle(brush, 0, 0, retImg.Width, retImg.Height);

            bm.Dispose();
            EffectImage = retImg;
        }