Example #1
0
        public static void DrawSpectrum(Bitmap bitmap, Hues hues, int index)
        {
            if (bitmap == null) throw new ArgumentNullException("bitmap");
            if (hues == null) throw new ArgumentNullException("hues");

            if (index < hues.MinIndex || index > hues.MaxIndex)
                throw new ArgumentOutOfRangeException("index");

            HueEntry hue = hues.Get(index);

            BitmapData data = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);

            float colorWidth = (float)bitmap.Width / 32.0f;
            short[] line = new short[bitmap.Width];

            for (int x = 0; x < bitmap.Width; x++)
            {
                int id = (int)(x / colorWidth);
                if (id < 32)
                {
                    line[x] = (short)(hue.Colors[id] | 0x8000);
                }
            }

            for (int y = 0; y < bitmap.Height; y++)
            {
                int offset = (int)data.Scan0 + y * data.Stride;
                Marshal.Copy(line, 0, (IntPtr)offset, line.Length);
            }

            bitmap.UnlockBits(data);
        }
Example #2
0
        public HueSpectrum()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.Selectable, true);
            SetStyle(ControlStyles.StandardClick, true);
            SetStyle(ControlStyles.UserPaint, true);

            cache = null;
            hues = null;
            hueIndex = 1;
        }
Example #3
0
        public static void DrawField(Bitmap bitmap, Hues hues, int startHueIndex, int endHueIndex, Size hueSize, int brightness)
        {
            // Check arguments
            if (bitmap == null) throw new ArgumentNullException("bitmap");
            if (hues == null) throw new ArgumentNullException("hues");

            if (bitmap.PixelFormat != PixelFormat.Format16bppArgb1555)
                throw new ArgumentException("Invalid bitmap pixel format.", "bitmap");

            if (startHueIndex != 0)
                startHueIndex = HuesRenderer.Range(startHueIndex, hues.MinIndex, hues.MaxIndex);
            if (endHueIndex != 0)
                endHueIndex = HuesRenderer.Range(endHueIndex, hues.MinIndex, hues.MaxIndex);
            hueSize.Width = HuesRenderer.Range(hueSize.Width, 1, 64);
            hueSize.Height = HuesRenderer.Range(hueSize.Height, 1, 64);
            brightness = HuesRenderer.Range(brightness, 0, 31);

            int columns = bitmap.Size.Width / hueSize.Width;
            int rows = bitmap.Size.Height / hueSize.Height;

            BitmapData data = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);

            for (int y = 0; y < rows; y++)
            {
                short[] line = new short[bitmap.Size.Width];

                for (int x = 0; x < columns; x++)
                {
                    int id = startHueIndex + x * rows + y + 1;

                    if (id <= hues.MaxIndex && (endHueIndex == 0 || id <= endHueIndex))
                    {
                        ushort color = hues.Get(id).Colors[brightness];

                        for (int i = 0; i < hueSize.Width; i++)
                        {
                            line[x * hueSize.Width + i] = (short)(color | 0x8000);
                        }
                    }
                }

                for (int i = 0; i < hueSize.Height; i++)
                {
                    int offset = (int)data.Scan0 + (y * hueSize.Height + i) * data.Stride;
                    Marshal.Copy(line, 0, (IntPtr)offset, line.Length);
                }
            }

            bitmap.UnlockBits(data);
        }
Example #4
0
        public HuesField()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.Selectable, true);
            SetStyle(ControlStyles.StandardClick, true);
            SetStyle(ControlStyles.UserPaint, true);

            bitmapCache = new Bitmap[32];
            hues = null;
            hueSize = new Size(8, 8);
            brightness = 24;
            showAllColors = false;
            selectedColorIndex = 1;

            InitializeComponent();
        }
Example #5
0
        /// <summary>
        /// Builds Hues object from file in Hues.mul format.
        /// </summary>
        /// <param name="file">File path.</param>
        public static Hues Load(string file)
        {
            Stream       stream = null;
            BinaryReader reader = null;

            try
            {
                stream = File.OpenRead(file);
                reader = new BinaryReader(stream);

                Hues hues = new Hues();

                int blockCount = (int)(stream.Length / Block.Lenght);

                for (int i = 0; i < blockCount; i++)
                {
                    uint header = reader.ReadUInt32();

                    hues.AddBlock(header);

                    for (int b = 0; b < 8; b++)
                    {
                        HueEntry entry = new HueEntry();

                        for (int c = 0; c < 32; c++)
                        {
                            entry.Colors[c] = reader.ReadUInt16();
                        }

                        entry.TableStart = reader.ReadUInt16();
                        entry.TableEnd   = reader.ReadUInt16();

                        byte[] nameBytes = reader.ReadBytes(20);
                        string name      = Encoding.ASCII.GetString(nameBytes);
                        if (name.Contains("\0"))
                        {
                            name = name.Remove(name.IndexOf('\0'));
                        }

                        entry.Name = name;

                        hues.blockList[i].Entries[b] = entry;
                    }
                }

                Trace.WriteLine(String.Format("Hues: MaxIndex={0}.", hues.MaxIndex), "MulLib");

                Trace.WriteLine(String.Format("Hues: File \"{0}\" succesfully loaded.", file), "MulLib");
                return(hues);
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Hues.", e);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
Example #6
0
        /// <summary>
        /// Called by Phoenix.Initialize().
        /// </summary>
        /// <param name="param">Client directory.</param>
        internal static void Load(object param)
        {
            string dir = param.ToString();

            try {
                Trace.WriteLine("Loading ultima data files started..", "MulLib");

                tiledata = TileData.Load(Path.Combine(dir, "tiledata.mul"));
                hues = Hues.Load(Path.Combine(dir, "hues.mul"));
                radarCol = RadarCol.Load(Path.Combine(dir, "radarcol.mul"));
                skills = Skills.Load(Path.Combine(dir, "skills.idx"), Path.Combine(dir, "skills.mul"));
                art = Art.Load(Path.Combine(dir, "artidx.mul"), Path.Combine(dir, "art.mul"), MulFileAccessMode.ReadOnly);
                multi = Multi.Load(Path.Combine(dir, "multi.idx"), Path.Combine(dir, "multi.mul"), MulFileAccessMode.ReadOnly);

                Trace.WriteLine("Loading ultima data files finished.", "MulLib");
            }
            catch (Exception e) {
                string msg = String.Format("Unable to load ultima data files. Program will be terminated. Exception:\r\n{0}", e);
                Trace.WriteLine(msg, "MulLib");
                MessageBox.Show(msg, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Core.Terminate();
            }

            try {
                SyncEvent.Invoke(Loaded, null, EventArgs.Empty);
            }
            catch (Exception e) {
                Trace.WriteLine("Unhandled exception in DataFiles.Loaded event. Exception:\r\n" + e.ToString(), "MulLib");
            }
        }
Example #7
0
        /// <summary>
        /// Builds Hues object from file in Hues.mul format.
        /// </summary>
        /// <param name="file">File path.</param>
        public static Hues Load(string file)
        {
            Stream stream = null;
            BinaryReader reader = null;

            try
            {
                stream = File.OpenRead(file);
                reader = new BinaryReader(stream);

                Hues hues = new Hues();

                int blockCount = (int)(stream.Length / Block.Lenght);

                for (int i = 0; i < blockCount; i++)
                {
                    uint header = reader.ReadUInt32();

                    hues.AddBlock(header);

                    for (int b = 0; b < 8; b++)
                    {
                        HueEntry entry = new HueEntry();

                        for (int c = 0; c < 32; c++)
                            entry.Colors[c] = reader.ReadUInt16();

                        entry.TableStart = reader.ReadUInt16();
                        entry.TableEnd = reader.ReadUInt16();

                        byte[] nameBytes = reader.ReadBytes(20);
                        string name = Encoding.ASCII.GetString(nameBytes);
                        if (name.Contains("\0"))
                            name = name.Remove(name.IndexOf('\0'));

                        entry.Name = name;

                        hues.blockList[i].Entries[b] = entry;
                    }
                }

                Trace.WriteLine(String.Format("Hues: MaxIndex={0}.", hues.MaxIndex), "MulLib");

                Trace.WriteLine(String.Format("Hues: File \"{0}\" succesfully loaded.", file), "MulLib");
                return hues;
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Hues.", e);
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                if (stream != null)
                    stream.Close();
            }
        }