Beispiel #1
0
 public void SetOriginalColor(CLUTEntry[] clutEntries)
 {
     foreach (CLUTEntry entry in ClutEntries)
     {
         CLUTEntry nearest    = new CLUTEntry();
         int       difference = 765;
         foreach (CLUTEntry e in clutEntries)
         {
             int diff = Graphic.ColorDifference(entry.Color, e.Color);
             if (diff < difference)
             {
                 nearest    = e;
                 difference = diff;
             }
         }
         entry.Color = nearest.Color;
         entry.SemiTransparentBit = nearest.SemiTransparentBit;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Generate CLUT from given bitmap and encoding settings
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="settings">Encoding Settings</param>
        public void GenerateClut(Bitmap bitmap, TIMEncodingSettings settings)
        {
            if (BPP > 8)
            {
                return;
            }
            if (bitmap.Width != ImageWidthPixels || bitmap.Height != ImageHeight)
            {
                throw new ArgumentOutOfRangeException("bitmap", "The given bitmap has not the correct width or height!");
            }

            if (BPP == 4)
            {
                if (bitmap.PixelFormat != PixelFormat.Format4bppIndexed)
                {
                    throw new ArgumentException("The given bitmap has the wrong pixel format! Needed is 4 BPP.", "bitmap");
                }

                Color[] palette = bitmap.Palette.Entries;

                for (int i = 0; i < 16; i++)
                {
                    ClutEntries[i] = new CLUTEntry(bitmap.Palette.Entries[i], settings);
                }
            }
            else if (BPP == 8)
            {
                if (bitmap.PixelFormat != PixelFormat.Format8bppIndexed)
                {
                    throw new ArgumentException("The given bitmap has the wrong pixel format! Needed is 8 BPP", "bitmap");
                }

                for (int i = 0; i < 255; i++)
                {
                    ClutEntries[i] = new CLUTEntry(bitmap.Palette.Entries[i], settings);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Loads the header from a stream.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public bool Load(BinaryReader reader)
        {
            byte[] signature = reader.ReadBytes(4);
            if (!signature.SequenceEqual(Signature))
            {
                return(false);
            }

            Mode = reader.ReadUInt32();

            if (HasClut)
            {
                //Skipping ClutBlockSize cause it will be generated
                reader.ReadUInt32();

                ClutX      = reader.ReadUInt16();
                ClutY      = reader.ReadUInt16();
                ClutWidth  = reader.ReadUInt16();
                ClutHeight = reader.ReadUInt16();

                ClutEntries = new CLUTEntry[ClutWidth * ClutHeight];
                for (int i = 0; i < ClutWidth * ClutHeight; i++)
                {
                    ClutEntries[i] = new CLUTEntry(reader.ReadUInt16());
                }
            }
            //Skipping ImageBlockSize cause it will be generated
            reader.ReadUInt32();

            ImageFrameBufferX = reader.ReadUInt16();
            ImageFrameBufferY = reader.ReadUInt16();
            ImageWidth        = reader.ReadUInt16();
            ImageHeight       = reader.ReadUInt16();

            DataOffset = (uint)reader.BaseStream.Position;
            return(true);
        }