Exemplo n.º 1
0
                public Header(BinaryReader br)
                {
                    var magicNumber = br.ReadMagicNumber();

                    if (magicNumber != MagicNumber)
                    {
                        throw new InvalidDataException($"Unexpected magic number '{magicNumber}'. (expected: {MagicNumber})");
                    }

                    TotalLength    = br.ReadUInt32();
                    TilesPerColumn = br.ReadUInt16();
                    TilesPerRow    = br.ReadUInt16();
                    BitsPerPixel   = (BitsPerPixel)br.ReadUInt32();
                    Unknown1       = br.ReadUInt16();
                    Unknown2       = br.ReadUInt16();
                    TiledFlag      = br.ReadUInt32();
                    if ((TiledFlag & 0xFF) == 0x0)
                    {
                        Order = TileForm.Horizontal;
                    }
                    else
                    {
                        Order = TileForm.Lineal;
                    }
                    DataLength = br.ReadInt32();
                    Unknown3   = br.ReadUInt32();
                }
Exemplo n.º 2
0
        /// <summary>
        /// Creates image data entries from the provided stream for the given BPP
        /// </summary>
        public static ImageDataEntry[] CreateImageDataEntry(
            List <ushort> frameBufferPixels, BitsPerPixel bitsPerPixel)
        {
            switch (bitsPerPixel)
            {
            case BitsPerPixel.FOUR: {
                ImageDataEntry[] imageDataEntries = new ImageDataEntry[4];
                ushort           data             = frameBufferPixels[0];

                imageDataEntries[0]
                    = new IndexedColourDataEntry((byte)(data & 0x0F));
                imageDataEntries[1]
                    = new IndexedColourDataEntry((byte)((data >> 4) & 0x0F));
                imageDataEntries[2]
                    = new IndexedColourDataEntry((byte)((data >> 8) & 0x0F));
                imageDataEntries[3]
                    = new IndexedColourDataEntry((byte)((data >> 12) & 0x0F));

                return(imageDataEntries);
            }

            case BitsPerPixel.EIGHT: {
                ImageDataEntry[] imageDataEntries = new ImageDataEntry[2];
                ushort           data             = frameBufferPixels[0];

                imageDataEntries[0]
                    = new IndexedColourDataEntry((byte)(data & 0xFF));
                imageDataEntries[1]
                    = new IndexedColourDataEntry((byte)((data >> 8) & 0xFF));

                return(imageDataEntries);
            }

            case BitsPerPixel.SIXTEEN: {
                ImageDataEntry[] imageDataEntries = new ImageDataEntry[1];

                imageDataEntries[0] = new RealColourDataEntry(frameBufferPixels[0]);

                return(imageDataEntries);
            }

            case BitsPerPixel.TWENTY_FOUR: {
                ImageDataEntry[] imageDataEntries = new ImageDataEntry[1];

                imageDataEntries[0]
                    = new RealColourDataEntry(
                          frameBufferPixels[0],
                          frameBufferPixels[1],
                          frameBufferPixels[2]);

                return(imageDataEntries);
            }

            default:
                throw new InvalidOperationException(
                          $"No factory method found for BitsPerPixel value " +
                          $"'{bitsPerPixel}'");
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Return a user friendly representation of this class
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("DisplaySettingsInfo { width : " + Width.ToString() +
            " / height : " + Height.ToString() +
            " / bpp : " + BitsPerPixel.ToString() +
            " / frequency : " + Frequency.ToString() +
            " / PositionX: " + PositionX.ToString() +
            " / PositionY: " + PositionY.ToString() + " }");
 }
Exemplo n.º 4
0
 public AviVideoStream(int index, IAviStreamWriteHandler writeHandler,
                       int width, int height, BitsPerPixel bitsPerPixel)
     : base(index)
 {
     this.writeHandler = writeHandler;
     this.width        = width;
     this.height       = height;
     this.bitsPerPixel = bitsPerPixel;
     this.streamCodec  = KnownFourCC.Codecs.Uncompressed;
 }
        public UniversalUncompressedVideoEncoder(int width, int height, BitsPerPixel bitsPerPixel)
        {
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);

            _width         = width;
            _height        = height;
            _bitsPerPixel  = bitsPerPixel;
            _bytesPerPixel = (int)bitsPerPixel / 8;
        }
        public UniversalUncompressedVideoEncoder(int width, int height, BitsPerPixel bitsPerPixel)
        {
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);

            _width = width;
            _height = height;
            _bitsPerPixel = bitsPerPixel;
            _bytesPerPixel = (int)bitsPerPixel / 8;
        }
Exemplo n.º 7
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 13;
         hash = (hash * 7) + BitsPerPixel.GetHashCode();
         hash = (hash * 7) + Masks.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 8
0
            public override int GetHashCode()
            {
                var result = 17;

                result = result * 13 + BitsPerPixel.GetHashCode();
                result = result * 13 + RBitMask.GetHashCode();
                result = result * 13 + GBitMask.GetHashCode();
                result = result * 13 + BBitMask.GetHashCode();
                result = result * 13 + ABitMask.GetHashCode();
                result = result * 13 + FourCc.GetHashCode();
                return(result);
            }
Exemplo n.º 9
0
        /// <summary>Adds new video stream.</summary>
        /// <param name="width">Frame's width.</param>
        /// <param name="height">Frame's height.</param>
        /// <param name="bitsPerPixel">Bits per pixel.</param>
        /// <returns>Newly added video stream.</returns>
        /// <remarks>
        /// Stream is initialized to be ready for uncompressed video (bottom-up BGR) with specified parameters.
        /// However, properties (such as <see cref="IAviVideoStream.Codec"/>) can be changed later if the stream is
        /// to be fed with pre-compressed data.
        /// </remarks>
        public IAviVideoStream AddVideoStream(int width = 1, int height = 1, BitsPerPixel bitsPerPixel = BitsPerPixel.Bpp32)
        {
            Argument.IsPositive(width, nameof(width));
            Argument.IsPositive(height, nameof(height));
            Argument.IsEnumMember(bitsPerPixel, nameof(bitsPerPixel));

            return(AddStream <IAviVideoStreamInternal>(index =>
            {
                var stream = new AviVideoStream(index, this, width, height, bitsPerPixel);
                var asyncStream = new AsyncVideoStreamWrapper(stream);
                return asyncStream;
            }));
        }
Exemplo n.º 10
0
        public int CompareTo(WicPixelFormat other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (BitsPerPixel != other.BitsPerPixel)
            {
                return(BitsPerPixel.CompareTo(other.BitsPerPixel));
            }

            return(ChannelCount.CompareTo(other.ChannelCount));
        }
Exemplo n.º 11
0
        /// <summary>Adds new video stream.</summary>
        /// <param name="width">Frame's width.</param>
        /// <param name="height">Frame's height.</param>
        /// <param name="bitsPerPixel">Bits per pixel.</param>
        /// <returns>Newly added video stream.</returns>
        /// <remarks>
        /// Stream is initialized to be ready for uncompressed video (bottom-up BGR) with specified parameters.
        /// However, properties (such as <see cref="IAviVideoStream.Codec"/>) can be changed later if the stream is
        /// to be fed with pre-compressed data.
        /// </remarks>
        public IAviVideoStream AddVideoStream(int width = 1, int height = 1, BitsPerPixel bitsPerPixel = BitsPerPixel.Bpp32)
        {
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);
            Contract.Requires(Enum.IsDefined(typeof(BitsPerPixel), bitsPerPixel));
            Contract.Requires(Streams.Count < 100);
            Contract.Ensures(Contract.Result <IAviVideoStream>() != null);

            return(AddStream <IAviVideoStreamInternal>(index =>
            {
                var stream = new AviVideoStream(index, this, width, height, bitsPerPixel);
                var asyncStream = new AsyncVideoStreamWrapper(stream);
                return asyncStream;
            }));
        }
Exemplo n.º 12
0
        public AviVideoStream(int index, IAviStreamWriteHandler writeHandler,
                              int width, int height, BitsPerPixel bitsPerPixel)
            : base(index)
        {
            Argument.IsNotNull(writeHandler, nameof(writeHandler));
            Argument.IsPositive(width, nameof(width));
            Argument.IsPositive(height, nameof(height));
            Argument.IsEnumMember(bitsPerPixel, nameof(bitsPerPixel));

            this.writeHandler = writeHandler;
            this.width        = width;
            this.height       = height;
            this.bitsPerPixel = bitsPerPixel;
            this.streamCodec  = CodecIds.Uncompressed;
        }
Exemplo n.º 13
0
        public AviVideoStream(int index, IAviStreamWriteHandler writeHandler, 
            int width, int height, BitsPerPixel bitsPerPixel)
            : base(index)
        {
            Contract.Requires(index >= 0);
            Contract.Requires(writeHandler != null);
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);
            Contract.Requires(Enum.IsDefined(typeof(BitsPerPixel), bitsPerPixel));

            this.writeHandler = writeHandler;
            this.width = width;
            this.height = height;
            this.bitsPerPixel = bitsPerPixel;
            this.streamCodec = KnownFourCCs.Codecs.Uncompressed;
        }
Exemplo n.º 14
0
        public AviVideoStream(int index, IAviStreamWriteHandler writeHandler,
                              int width, int height, BitsPerPixel bitsPerPixel)
            : base(index)
        {
            Contract.Requires(index >= 0);
            Contract.Requires(writeHandler != null);
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);
            Contract.Requires(Enum.IsDefined(typeof(BitsPerPixel), bitsPerPixel));

            this.writeHandler = writeHandler;
            this.width        = width;
            this.height       = height;
            this.bitsPerPixel = bitsPerPixel;
            this.streamCodec  = KnownFourCCs.Codecs.Uncompressed;
        }
Exemplo n.º 15
0
                public Header(BinaryReader br)
                {
                    var magicNumber = br.ReadMagicNumber();

                    if (magicNumber != MagicNumber)
                    {
                        throw new InvalidDataException($"Unexpected magic number '{magicNumber}'. (expected: {MagicNumber})");
                    }

                    TotalLength  = br.ReadUInt32();
                    BitsPerPixel = (BitsPerPixel)br.ReadUInt16();
                    Unknown1     = br.ReadUInt16();
                    Unknown2     = br.ReadUInt32();
                    DataLength   = br.ReadInt32();
                    DataOffset   = br.ReadUInt32();
                }
Exemplo n.º 16
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (BitsPerPixel != 0)
            {
                hash ^= BitsPerPixel.GetHashCode();
            }
            if (size_ != null)
            {
                hash ^= Size.GetHashCode();
            }
            if (Data.Length != 0)
            {
                hash ^= Data.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 17
0
        private void Load_TIM(EndianBinaryReader reader)
        {
            Debug.Assert(reader.ReadInt32() == 16, "TIM file did not have the correct magic!");

            int flags = reader.ReadInt32();

            BitsPerPixel bits_per_pixel = (BitsPerPixel)(flags & 3);
            bool         has_clut       = (flags & 8) == 0 ? false : true;

            if (has_clut)
            {
                Load_TIM_With_CLUT(reader, bits_per_pixel);
            }
            else
            {
                Load_TIM_No_CLUT(reader, bits_per_pixel);
            }
        }
Exemplo n.º 18
0
        private PixelFormat TIM_bpp_To_PixelFormat(BitsPerPixel bpp)
        {
            switch (bpp)
            {
            case BitsPerPixel.bpp_4:
                return(PixelFormat.Format4bppIndexed);

            case BitsPerPixel.bpp_8:
                return(PixelFormat.Format8bppIndexed);

            case BitsPerPixel.bpp_16:
                return(PixelFormat.Format16bppRgb555);

            case BitsPerPixel.bpp_24:
                return(PixelFormat.Format24bppRgb);

            default:
                return(PixelFormat.DontCare);
            }
        }
Exemplo n.º 19
0
        private float Get_Width_Modifier(BitsPerPixel bpp)
        {
            switch (bpp)
            {
            case BitsPerPixel.bpp_4:
                return(4.0f);

            case BitsPerPixel.bpp_8:
                return(2.0f);

            case BitsPerPixel.bpp_16:
                return(1.0f);

            case BitsPerPixel.bpp_24:
                return(0.5f);

            default:
                return(1.0f);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Loads a Bitmap into the BitmapX
        /// </summary>
        /// <param name="bitmap">Bitmap Source</param>
        public void LoadBitmap(Bitmap bitmap)
        {
            // Dispose the Original if exists
            BitmapSource?.Dispose();

            // Get Bpp
            _BitsPerPixel = Image.GetPixelFormatSize(bitmap.PixelFormat);

            // Check for supported Bpp
            if (!AcceptedBitsPerPixel.Contains(BitsPerPixel))
            {
                throw new ArgumentException("Unsupported Bitmap Pixel Size: " + BitsPerPixel.ToString());
            }

            // Set Bitmap
            BitmapSource = bitmap;

            // Set Width + Height
            _Width  = BitmapSource.Width;
            _Height = BitmapSource.Height;

            LockBits();
        }
Exemplo n.º 21
0
 private void Load_TIM_No_CLUT(EndianBinaryReader reader, BitsPerPixel bpp)
 {
     Debug.Assert(false, "Found a 16 or 24bpp image!");
 }
Exemplo n.º 22
0
        public void Save_TIM(string file_name)
        {
            BitsPerPixel bpp = PixelFormat_To_TIM_BPP(m_Image.PixelFormat);

            using (FileStream strm = new FileStream(file_name, FileMode.Create))
            {
                EndianBinaryWriter writer   = new EndianBinaryWriter(strm, Endian.Little);
                int          color_count    = 0;
                int          width_modifier = 0;
                List <Color> palette_colors = new List <Color>(m_Image.Palette.Entries);

                writer.Write(16);

                switch (m_Image.PixelFormat)
                {
                case PixelFormat.Format4bppIndexed:
                    writer.Write(8 | (int)BitsPerPixel.bpp_4);
                    color_count    = 16;
                    width_modifier = 4;
                    break;

                case PixelFormat.Format8bppIndexed:
                    writer.Write(8 | (int)BitsPerPixel.bpp_8);
                    color_count    = 256;
                    width_modifier = 2;
                    break;

                default:
                    return;
                }

                writer.Write(12 + (color_count * 2));
                writer.Write(0);
                writer.Write((short)color_count);
                writer.Write((short)1);

                for (int i = 0; i < m_Image.Palette.Entries.Length; i++)
                {
                    Color col = m_Image.Palette.Entries[i];

                    int final_color = col.R / 8;
                    final_color |= (col.G / 8) << 5;
                    final_color |= (col.B / 8) << 10;

                    writer.Write((short)final_color);
                }

                for (int i = 0; i < color_count - m_Image.Palette.Entries.Length; i++)
                {
                    writer.Write((short)0);
                }

                writer.Write(12 + ((m_Image.Width / 2) * m_Image.Height));
                writer.Write(0);

                writer.Write((short)(m_Image.Width / width_modifier));
                writer.Write((short)m_Image.Height);

                for (int y = 0; y < m_Image.Height; y++)
                {
                    for (int x = 0; x < m_Image.Width; x += 2)
                    {
                        switch (m_Image.PixelFormat)
                        {
                        case PixelFormat.Format4bppIndexed:
                            Color pix4_1 = m_Image.GetPixel(x, y);
                            Color pix4_2 = m_Image.GetPixel(x + 1, y);

                            byte final_pix4 = (byte)palette_colors.IndexOf(pix4_1);
                            final_pix4 |= (byte)((palette_colors.IndexOf(pix4_2)) << 4);

                            writer.Write(final_pix4);
                            break;

                        case PixelFormat.Format8bppIndexed:
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        private void Load_TIM_With_CLUT(EndianBinaryReader reader, BitsPerPixel bpp)
        {
            PixelFormat pix_fmt = TIM_bpp_To_PixelFormat(bpp);

            int   clut_size     = reader.ReadInt32();
            short clut_origin_x = reader.ReadInt16();
            short clut_origin_y = reader.ReadInt16();

            int color_count = reader.ReadInt16();
            int pal_count   = reader.ReadInt16();

            List <Color>[] palettes = new List <Color> [pal_count];

            for (int i = 0; i < pal_count; i++)
            {
                palettes[i] = Load_CLUT(reader, color_count);
            }

            int   image_index    = 0;
            float width_modifier = Get_Width_Modifier(bpp);

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                int   image_size     = reader.ReadInt32();
                short image_origin_x = reader.ReadInt16();
                short image_origin_y = reader.ReadInt16();

                int image_width  = reader.ReadInt16();
                int image_height = reader.ReadInt16();

                m_Image = new Bitmap((int)(image_width * width_modifier), image_height, pix_fmt);
                ColorPalette pal = m_Image.Palette;

                for (int i = 0; i < color_count; i++)
                {
                    pal.Entries[i] = palettes[image_index][i];
                }

                m_Image.Palette = pal;
                BitmapData img_data = m_Image.LockBits(new Rectangle(0, 0, (int)(image_width * width_modifier), image_height),
                                                       ImageLockMode.ReadWrite, pix_fmt);

                for (int y = 0; y < image_height; y++)
                {
                    for (int x = 0; x < image_width * 2; x++)
                    {
                        byte src = reader.ReadByte();

                        if (bpp == BitsPerPixel.bpp_4)
                        {
                            byte temp = (byte)((src & 0x0F) << 4);
                            src >>= 4;
                            src  |= temp;
                        }

                        System.Runtime.InteropServices.Marshal.WriteByte(img_data.Scan0, (y * img_data.Stride) + x, src);
                    }
                }

                m_Image.UnlockBits(img_data);
                image_index++;
            }
        }