Beispiel #1
0
        /// <summary>
        /// Export the image as an array of direct 16-bit color values.
        /// </summary>
        /// <param name="tw"></param>
        public void Export_BgImageData_Direct(System.IO.TextWriter tw)
        {
            StringBuilder sb       = null;
            int           nPerLine = 32;

            for (int iy = 0; iy < m_height; iy++)
            {
                tw.WriteLine("\t// Row {0}", iy);
                for (int ix = 0; ix < m_width; ix++)
                {
                    if ((ix % nPerLine) == 0)
                    {
                        if (sb != null)
                        {
                            tw.WriteLine(sb.ToString());
                        }
                        sb = new StringBuilder("\t");
                    }
                    short palette_index = m_ImageData[ix, iy];
                    Color c             = m_mapId2Color[palette_index];
                    int   encoded       = Color555.Encode(c);
                    sb.Append(String.Format("0x{0:x4},", encoded));
                }
                if (sb != null)
                {
                    tw.WriteLine(sb.ToString());
                }
                sb = null;
            }
        }
Beispiel #2
0
        public static bool ParseRGBColorValue(string strRGB, out int nRGB)
        {
            Regex rxRGB = new Regex(@"([0-1][0-9A-Fa-f])([0-1][0-9A-Fa-f])([0-1][0-9A-Fa-f])");
            Match mxRGB = rxRGB.Match(strRGB);

            nRGB = 0;
            if (!mxRGB.Success)
            {
                return(false);
            }

            GroupCollection matchGroups = mxRGB.Groups;
            int             r           = Convert.ToInt32(matchGroups[1].Value, 16);
            int             g           = Convert.ToInt32(matchGroups[2].Value, 16);
            int             b           = Convert.ToInt32(matchGroups[3].Value, 16);

            nRGB = Color555.Encode(r, g, b);
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Export the 256-color palette for this image.
        /// </summary>
        /// <param name="tw"></param>
        public void Export_BgImagePaletteData(System.IO.TextWriter tw)
        {
            StringBuilder sb       = null;
            int           nPerLine = 8;

            for (short i = 0; i < 256; i++)
            {
                if ((i % nPerLine) == 0)
                {
                    if (sb != null)
                    {
                        tw.WriteLine(sb.ToString());
                    }
                    sb = new StringBuilder("\t");
                }
                sb.Append(String.Format("0x{0:x4},", Color555.Encode(m_mapId2Color[i])));
            }
            if (sb != null)
            {
                tw.WriteLine(sb.ToString());
            }
        }
        /// <summary>
        /// Does this UndoAction change the color of one of the palette entries?
        /// </summary>
        /// <param name="nColorIndex"></param>
        /// <returns></returns>
        public bool IsColorChange(out int nColorIndex, out int nColorValue1, out int nColorValue2)
        {
            nColorIndex  = -1;
            nColorValue1 = 0;
            nColorValue2 = 0;
            int nColors = m_before.numColors;

            for (int i = 0; i < nColors; i++)
            {
                // Note: this assumes that there is only 1 color change in an UndoAction
                if (m_before.cRed[i] != m_after.cRed[i] ||
                    m_before.cGreen[i] != m_after.cGreen[i] ||
                    m_before.cBlue[i] != m_after.cBlue[i]
                    )
                {
                    nColorIndex  = i;
                    nColorValue1 = Color555.Encode(m_before.cRed[i], m_before.cGreen[i], m_before.cBlue[i]);
                    nColorValue2 = Color555.Encode(m_after.cRed[i], m_after.cGreen[i], m_after.cBlue[i]);
                }
            }
            return(nColorIndex != -1);
        }
Beispiel #5
0
 /// <summary>
 /// Return the 16-bit encoding for the specified palette index.
 /// </summary>
 /// <param name="nIndex">The index of the palette entry</param>
 /// <returns>The encoding for the specified palette entry</returns>
 public int Encoding(int nIndex)
 {
     return(Color555.Encode(cRed[nIndex], cGreen[nIndex], cBlue[nIndex]));
 }