Ejemplo n.º 1
0
        private void MemoryPreset(SubCode subCode)
        {
            if (this.colorTable.Count <= 0)
            {
                return;
            }

            MemoryPreset memoryPreset = new MemoryPreset(subCode.Data.ToArray(), this.colorTable);

            if (memoryPreset.Repeat != 0)
            {
                return;
            }

            Console.WriteLine("Clearing screen to: {0}", memoryPreset.Color);
            int count = 0;

            for (int x = 0; x < FullWidth; x++)
            {
                for (int y = 0; y < FullHeight; y++)
                {
                    if (this.newPixels.Count <= count)
                    {
                        this.newPixels.Add(new Pixel(new Point(x, y), memoryPreset.Color));
                    }
                    else
                    {
                        this.newPixels[count] = new Pixel(new Point(x, y), memoryPreset.Color);
                    }

                    count++;
                }
            }
        }
Ejemplo n.º 2
0
        private void Scroll(SubCode subCode, bool preset)
        {
            Scroll scroll = new Scroll(subCode.Data.ToArray(), this.colorTable, preset);

            Console.WriteLine(
                "Scrolling color {0} to right {1} to bottom {2}",
                scroll.Color,
                scroll.PixelsToRight,
                scroll.PixelsToBottom);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Interprets the given <see cref="SubCode"/> and starts the operations associated with the interpretation.
        /// </summary>
        /// <param name="subCode">
        /// A <see cref="SubCode"/> to be interpreted.
        /// </param>
        private void InterpreteSubCode(SubCode subCode)
        {
            if ((subCode.Command & Mask) == Command)
            {
                try
                {
                    switch (subCode.Instruction)
                    {
                    case InstructionType.MemoryPreset:
                        this.MemoryPreset(subCode);
                        break;

                    case InstructionType.BorderPreset:
                        this.BorderPreset(subCode);
                        break;

                    case InstructionType.TitleBlock:
                        this.TileBlock(subCode, false);
                        break;

                    case InstructionType.ScrollPreset:
                        this.Scroll(subCode, true);
                        break;

                    case InstructionType.ScrollCopy:
                        this.Scroll(subCode, false);
                        break;

                    case InstructionType.DefineTransparentColor:
                        break;

                    case InstructionType.LoadColorTableLow:
                        this.LoadColorTable(subCode, ColorTableType.Low);
                        break;

                    case InstructionType.LoadColorTableHigh:
                        this.LoadColorTable(subCode, ColorTableType.High);
                        break;

                    case InstructionType.TitleBlockXor:
                        this.TileBlock(subCode, true);
                        break;
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads the next <see cref="SubCode"/> in the <see cref="FileStream"/>.
        /// </summary>
        /// <param name="subCode">
        /// A <see cref="SubCode"/> used to store the read information.
        /// </param>
        /// <returns>
        /// A value indicating if the reading operation was successful.
        /// </returns>
        private bool ReadSubCode(ref SubCode subCode)
        {
            if (this.stream == null || this.stream.Position >= this.stream.Length)
            {
                return(false);
            }

            byte[] data = new byte[24];
            if (this.stream.Read(data, 0, PacketSize) != PacketSize)
            {
                return(false);
            }

            subCode = new SubCode(data);
            return(true);
        }
Ejemplo n.º 5
0
        private void BorderPreset(SubCode subCode)
        {
            if (this.colorTable.Count > 0)
            {
                MemoryPreset memoryPreset = new MemoryPreset(subCode.Data.ToArray(), this.colorTable);
                Console.WriteLine("Clearing border to: {0}", memoryPreset.Color);
                int count = 0;
                for (int x = 0; x < FullWidth; x++)
                {
                    for (int y = 0; y < FullHeight; y++)
                    {
                        Pixel pixel = new Pixel(new Point(x, y), memoryPreset.Color);
                        if (this.innerFrame.Contains(pixel.Location))
                        {
                            continue;
                        }

                        this.newPixels.Add(pixel);
                        count++;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads the next frame of <see cref="SubCode"/> and processes them.
        /// </summary>
        /// <returns>
        /// The processed <see cref="Bitmap"/> or NULL, if the <see cref="CurrentFrame"/> is the last of this <see cref="CdgFile"/>.
        /// </returns>
        public Bitmap Next()
        {
            SubCode subCode = null;

            try
            {
                if (this.ReadSubCode(ref subCode))
                {
                    this.InterpreteSubCode(subCode);
                    this.UpdateImage();
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            return(this.CurrentFrame);
        }
Ejemplo n.º 7
0
        private void TileBlock(SubCode subCode, bool xor)
        {
            Tile tile = new Tile(subCode.Data.ToArray(), this.colorTable);

            if (xor)
            {
                for (int i = 0; i < tile.TilePixels.Count; i++)
                {
                    //TODO: Read pixels from this.image
                    foreach (var pixel in this.newPixels.Where(p => p.Equals(tile.TilePixels[i])))
                    {
                        int index    = this.colorTable.IndexOf(pixel.Color);
                        int newIndex = i ^ index;
                        this.newPixels[this.newPixels.IndexOf(pixel)] = new Pixel(
                            pixel.Location,
                            this.colorTable[newIndex]);
                    }
                }
            }
            else
            {
                this.newPixels.AddRange(tile.TilePixels);
            }
        }
Ejemplo n.º 8
0
        private void LoadColorTable(SubCode subCode, ColorTableType tableType)
        {
            Console.WriteLine("Loading {0} colors", tableType);
            List <byte> colors = new List <byte>();

            switch (tableType)
            {
            case ColorTableType.High:
                foreach (byte color in subCode.Data)
                {
                    colors.Add((byte)(color & 0x3F3F));
                    if (colors.Count == 8)
                    {
                        break;
                    }
                }

                for (int i = 0; i < colors.Count; i++)
                {
                    byte color     = colors[i];
                    int  red       = (color & 0x3F3F) >> 2;
                    int  halfGreen = (color & 0x3) << 2;
                    if (this.colorTable.Count < i)
                    {
                        this.colorTable.Add(Color.FromArgb(red, halfGreen, 0));
                    }
                    else
                    {
                        int preRed   = this.colorTable[i].R;
                        int preGreen = this.colorTable[i].G;
                        this.colorTable[i] = Color.FromArgb(
                            preRed        += (byte)red,
                            preGreen      += (byte)halfGreen,
                            this.colorTable[i].B);
                    }
                }
                break;

            case ColorTableType.Low:
                subCode.Data.Reverse();
                foreach (byte color in subCode.Data)
                {
                    colors.Add(color);
                    if (colors.Count == 8)
                    {
                        break;
                    }
                }

                subCode.Data.Reverse();
                for (int i = 0; i < colors.Count; i++)
                {
                    byte color     = colors[i];
                    int  halfGreen = (color & 0x3) >> 4;
                    int  blue      = (color & 0x3F3F) << 2;
                    if (this.colorTable.Count <= i)
                    {
                        this.colorTable.Add(Color.FromArgb(0, halfGreen, blue));
                    }
                    else
                    {
                        int preGreen = this.colorTable[i].G;
                        int preBlue  = this.colorTable[i].B;
                        if (preBlue + blue > 255)
                        {
                            int temp = (blue + preBlue) - 255;
                            preGreen += temp;
                            preBlue  -= temp;
                        }
                        this.colorTable[i] = Color.FromArgb(
                            this.colorTable[i].R,
                            preGreen += (byte)halfGreen,
                            preBlue  += (byte)blue);
                    }
                }
                break;
            }
        }