Beispiel #1
0
        private Bitmap CreateBitmap(FruaTlbImage image, BinaryReader reader)
        {
            var pixelsToRead = image.Header.ImageHeight * image.Header.ImageWidth;
            var buffer       = new byte[pixelsToRead];

            buffer = reader.ReadBytes(pixelsToRead);
            buffer = DeinterlacePixels(buffer);
            return(CreateBitmapFromBuffer(image, buffer));
        }
Beispiel #2
0
        private Bitmap CreateBitmapFromBuffer(FruaTlbImage image, byte[] buffer)
        {
            var bitmap = new Bitmap(image.Header.ImageWidth, image.Header.ImageHeight);

            for (int y = 0; y < image.Header.ImageHeight; y++)
            {
                for (int x = 0; x < image.Header.ImageWidth; x++)
                {
                    var pixelIndex = buffer[y * image.Header.ImageWidth + x];
                    bitmap.SetPixel(x, y, _colorTable.Palette[pixelIndex]);
                }
            }

            return(bitmap);
        }
Beispiel #3
0
        // TODO not working right yet
        private void CreateBitmap23(FruaTlbImage image, BinaryReader reader)
        {
            var buffer     = new byte[image.Header.ImageHeight * image.Header.ImageWidth];
            var rowsToPlot = image.Header.ImageHeight;
            var row        = 0;
            var pos        = 0;

            while (row < rowsToPlot)
            {
                var value = reader.ReadByte();
                if (value == 0)
                {
                    row++;
                    pos = 0;
                }
                else
                {
                    if (value >= 128)
                    {
                        var x = (257 - value) * 4;
                        pos += x;
                    }
                    else
                    {
                        for (int i = 0; i < value; i++)
                        {
                            var pixel = reader.ReadByte();
                            buffer[row * image.Header.ImageWidth + pos] = pixel;
                            // pos += 4; ??
                        }
                    }
                }
            }

            var bitmap = CreateBitmapFromBuffer(image, buffer);

            Bitmaps.Add(bitmap);
        }
Beispiel #4
0
        private void ReadTileLibrary(BinaryReader reader, int imageCount, uint startingPointForSeek)
        {
            _offsets.Clear();

            for (int i = 0; i < imageCount; i++)
            {
                var offset = reader.ReadUInt32();
                _offsets.Add(offset);
            }

            ReadColorTable(reader, startingPointForSeek);

            // read images
            for (var entry = 0; entry < imageCount; entry++)
            {
                var offset = _offsets[entry];
                reader.BaseStream.Seek(offset + startingPointForSeek, SeekOrigin.Begin);

                var image = new FruaTlbImage
                    {
                        Header =
                            {
                                ImageHeight = reader.ReadUInt16(),
                                VerticalOffset = reader.ReadInt16(),
                                HorizontalOffset = reader.ReadInt16(),
                                ImageWidth = reader.ReadByte()*4,
                                DrawingMethod = reader.ReadByte()
                            }
                    };

                // read image if we can
                switch (image.Header.DrawingMethod)
                {
                    case 16:
                        CreateBitmap16(image, reader);
                        break;

                    case 17:
                        CreateBitmap17(image, reader);
                        break;

                    case 18:
                        CreateBitmap18(image, reader);
                        break;

                    case 21:
                        CreateBitmap21(image, reader);
                        break;

                    case 23:
                        // TODO not working right yet
                        //CreateBitmap23(image, reader);
                        break;

                    case 24:
                        // TODO don't know how to read this yet
                        break;

                    case 25:
                        // TODO don't know how to read this yet
                        break;

                    default:
                        throw new Exception(string.Format("Unknown Drawing Method \"{0}\"", image.Header.DrawingMethod));
                }

                _images.Add(image);
            }
        }
Beispiel #5
0
        private Bitmap CreateBitmapFromBuffer(FruaTlbImage image, byte[] buffer)
        {
            var bitmap = new Bitmap(image.Header.ImageWidth, image.Header.ImageHeight);

            for (int y = 0; y < image.Header.ImageHeight; y++)
            {
                for (int x = 0; x < image.Header.ImageWidth; x++)
                {
                    var pixelIndex = buffer[y*image.Header.ImageWidth + x];
                    bitmap.SetPixel(x, y, _colorTable.Palette[pixelIndex]);
                }
            }

            return bitmap;
        }
Beispiel #6
0
 private Bitmap CreateBitmap(FruaTlbImage image, BinaryReader reader)
 {
     var pixelsToRead = image.Header.ImageHeight*image.Header.ImageWidth;
     var buffer = new byte[pixelsToRead];
     buffer = reader.ReadBytes(pixelsToRead);
     buffer = DeinterlacePixels(buffer);
     return CreateBitmapFromBuffer(image, buffer);
 }
Beispiel #7
0
        // TODO not working right yet
        private void CreateBitmap23(FruaTlbImage image, BinaryReader reader)
        {
            var buffer = new byte[image.Header.ImageHeight*image.Header.ImageWidth];
            var rowsToPlot = image.Header.ImageHeight;
            var row = 0;
            var pos = 0;

            while (row < rowsToPlot)
            {
                var value = reader.ReadByte();
                if (value == 0)
                {
                    row++;
                    pos = 0;
                }
                else
                {
                    if (value >= 128)
                    {
                        var x = (257 - value)*4;
                        pos += x;
                    }
                    else
                    {
                        for (int i = 0; i < value; i++)
                        {
                            var pixel = reader.ReadByte();
                            buffer[row*image.Header.ImageWidth+pos] = pixel;
                            // pos += 4; ??
                        }
                    }
                }
            }

            var bitmap = CreateBitmapFromBuffer(image, buffer);
            Bitmaps.Add(bitmap);
        }
Beispiel #8
0
 /// <summary>
 /// Uncompressed, transparent
 /// In transparent images, color 255 is not drawn to the screen
 /// </summary>
 /// <param name="image"></param>
 /// <param name="reader"></param>
 private void CreateBitmap21(FruaTlbImage image, BinaryReader reader)
 {
     var bitmap = CreateBitmap(image, reader);
     Bitmaps.Add(bitmap);
 }
Beispiel #9
0
        private void CreateBitmap18(FruaTlbImage image, BinaryReader reader)
        {
            var targetPixelCountToPlot = image.Header.ImageWidth*image.Header.ImageHeight;
            var width = image.Header.ImageWidth;
            var actualPixelsPlotted = 0;
            var pixels = new byte[targetPixelCountToPlot];
            var screenOffset = 0;
            var runCount = 0;

            while (actualPixelsPlotted < targetPixelCountToPlot)
            {
                // figure out how many pixels are represented by run
                var x = reader.ReadByte();

                if (x < 128)
                {
                    // run of non-consecutive colours
                    var length = x + 1;
                    for (int i = 0; i < length; i++)
                    {
                        var value = reader.ReadByte();
                        pixels[screenOffset] = value;
                        screenOffset += 4;
                        if (screenOffset >= width)
                        {
                            runCount++;
                            screenOffset = runCount;
                        }
                        actualPixelsPlotted++;
                    }
                }
                else
                {
                    // run of consecutive colours
                    var value = reader.ReadByte();
                    var length = 257 - x;
                    for (var i = 0; i < length; i++)
                    {
                        pixels[screenOffset] = value;
                        screenOffset += 4;
                        if (screenOffset >= width)
                        {
                            runCount++;
                            screenOffset = runCount;
                        }
                        actualPixelsPlotted++;
                    }
                }
            }

            /*
            var buffer = new byte[pixels.Length];
            var count = 0;
            for (int y = 0; y < image.Header.ImageHeight; y++)
            {
                for (int i = 0; i < 4; i++)
                {
                    var offset = 0;
                    for (int w = 0; w < width / 4; w++)
                    {
                        offset = offset + i*width/4;
                        var value = pixels[offset];
                        buffer[count++] = value;
                        offset += 4;
                    }
                }
            }
            */

            var bitmap = CreateBitmapFromBuffer(image, pixels);
            Bitmaps.Add(bitmap);
        }
Beispiel #10
0
        private void ReadTileLibrary(BinaryReader reader, int imageCount, uint startingPointForSeek)
        {
            _offsets.Clear();

            for (int i = 0; i < imageCount; i++)
            {
                var offset = reader.ReadUInt32();
                _offsets.Add(offset);
            }

            ReadColorTable(reader, startingPointForSeek);

            // read images
            for (var entry = 0; entry < imageCount; entry++)
            {
                var offset = _offsets[entry];
                reader.BaseStream.Seek(offset + startingPointForSeek, SeekOrigin.Begin);

                var image = new FruaTlbImage
                {
                    Header =
                    {
                        ImageHeight      = reader.ReadUInt16(),
                        VerticalOffset   = reader.ReadInt16(),
                        HorizontalOffset = reader.ReadInt16(),
                        ImageWidth       = reader.ReadByte() * 4,
                        DrawingMethod    = reader.ReadByte()
                    }
                };

                // read image if we can
                switch (image.Header.DrawingMethod)
                {
                case 16:
                    CreateBitmap16(image, reader);
                    break;

                case 17:
                    CreateBitmap17(image, reader);
                    break;

                case 18:
                    CreateBitmap18(image, reader);
                    break;

                case 21:
                    CreateBitmap21(image, reader);
                    break;

                case 23:
                    // TODO not working right yet
                    //CreateBitmap23(image, reader);
                    break;

                case 24:
                    // TODO don't know how to read this yet
                    break;

                case 25:
                    // TODO don't know how to read this yet
                    break;

                default:
                    throw new Exception(string.Format("Unknown Drawing Method \"{0}\"", image.Header.DrawingMethod));
                }

                _images.Add(image);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Uncompressed, transparent
        /// In transparent images, color 255 is not drawn to the screen
        /// </summary>
        /// <param name="image"></param>
        /// <param name="reader"></param>
        private void CreateBitmap21(FruaTlbImage image, BinaryReader reader)
        {
            var bitmap = CreateBitmap(image, reader);

            Bitmaps.Add(bitmap);
        }
Beispiel #12
0
        private void CreateBitmap18(FruaTlbImage image, BinaryReader reader)
        {
            var targetPixelCountToPlot = image.Header.ImageWidth * image.Header.ImageHeight;
            var width = image.Header.ImageWidth;
            var actualPixelsPlotted = 0;
            var pixels       = new byte[targetPixelCountToPlot];
            var screenOffset = 0;
            var runCount     = 0;

            while (actualPixelsPlotted < targetPixelCountToPlot)
            {
                // figure out how many pixels are represented by run
                var x = reader.ReadByte();

                if (x < 128)
                {
                    // run of non-consecutive colours
                    var length = x + 1;
                    for (int i = 0; i < length; i++)
                    {
                        var value = reader.ReadByte();
                        pixels[screenOffset] = value;
                        screenOffset        += 4;
                        if (screenOffset >= width)
                        {
                            runCount++;
                            screenOffset = runCount;
                        }
                        actualPixelsPlotted++;
                    }
                }
                else
                {
                    // run of consecutive colours
                    var value  = reader.ReadByte();
                    var length = 257 - x;
                    for (var i = 0; i < length; i++)
                    {
                        pixels[screenOffset] = value;
                        screenOffset        += 4;
                        if (screenOffset >= width)
                        {
                            runCount++;
                            screenOffset = runCount;
                        }
                        actualPixelsPlotted++;
                    }
                }
            }

            /*
             * var buffer = new byte[pixels.Length];
             * var count = 0;
             * for (int y = 0; y < image.Header.ImageHeight; y++)
             * {
             *  for (int i = 0; i < 4; i++)
             *  {
             *      var offset = 0;
             *      for (int w = 0; w < width / 4; w++)
             *      {
             *          offset = offset + i*width/4;
             *          var value = pixels[offset];
             *          buffer[count++] = value;
             *          offset += 4;
             *      }
             *  }
             * }
             */

            var bitmap = CreateBitmapFromBuffer(image, pixels);

            Bitmaps.Add(bitmap);
        }