Пример #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            TIMEncodingSettings settings = new TIMEncodingSettings();
            TIMFile             timFile  = new TIMFile(textBox2.Text);

            timFile.SetBitmap(new Bitmap(textBox1.Text), settings);
        }
Пример #2
0
        private ushort RGB24_To_RGBPSX(Color color, TIMEncodingSettings settings)
        {
            ushort result;

            result  = (ushort)(color.R >> 3);
            result |= (ushort)((color.G >> 3) << 5);
            result |= (ushort)((color.B >> 3) << 10);

            if (result == 0 && settings.BlackTransparent)
            {
                result |= 0x8000;
            }
            if (result == ((31) | (31 << 10)) && settings.MagicPinkTransparent)
            {
                result = 0;
            }

            if (settings.SetSemiTransparencyBit)
            {
                if (settings.BlackTransparent && result == 0)
                {
                    return(result);
                }
                if (settings.MagicPinkTransparent && result == ((31) | (31 << 10)))
                {
                    return(result);
                }
                result |= 0x8000;
            }
            return(result);
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
        private void button_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "*.bmp|*.bmp";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                TIMEncodingSettings settings = new TIMEncodingSettings();
                TIMEncodingWindow   window   = new TIMEncodingWindow();
                if (window.ShowDialog() == DialogResult.OK)
                {
                    settings = window.Settings;

                    using (FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open))
                    {
                        Bitmap bitmap = new Bitmap(fileStream);
                        _timFile.SetBitmap(bitmap, settings);
                        bitmap.Dispose();
                    }
                    pictureBox_Image.Image = _timFile.GetBitmap();
                }
            }
        }
Пример #5
0
 public CLUTEntry(Color color, TIMEncodingSettings settings)
 {
     Data = RGB24_To_RGBPSX(color, settings);
 }