/// <summary> /// Import a single color into the palette. /// </summary> /// <param name="nIndex"></param> /// <param name="color"></param> public void ImportColor(int nIndex, int color) { int cRed, cGreen, cBlue; Color555.ExtractColors(color, out cRed, out cGreen, out cBlue); UpdateColor(nIndex, cRed, cGreen, cBlue); }
public void Save(System.IO.TextWriter tw) { tw.Write("\t\t<bgimage_pal8"); tw.Write(String.Format(" name=\"{0}\"", Name)); tw.Write(String.Format(" id=\"{0}\"", ExportId)); tw.Write(String.Format(" desc=\"{0}\"", Description)); tw.Write(" size=\"{0}x{1}\"", m_width, m_height); tw.WriteLine(">"); tw.Write("\t\t\t<palette256"); tw.Write(String.Format(" name=\"{0}\"", Name)); tw.Write(String.Format(" id=\"{0}\"", ExportId)); tw.WriteLine(">"); int nPerLine = 8; string strIndent = "\t\t\t\t"; StringBuilder sb = null; for (short i = 0; i < 256; i++) { if ((i % nPerLine) == 0) { if (sb != null) { tw.WriteLine(sb.ToString()); } sb = new StringBuilder(strIndent); } Color c = m_mapId2Color[i]; int r, g, b; Color555.ExtractColors(c, out r, out g, out b); sb.Append(String.Format("<color rgb=\"{0:x2}{1:x2}{2:x2}\"/>", r, g, b)); } if (sb != null) { tw.WriteLine(sb.ToString()); } tw.WriteLine("\t\t\t</palette256>"); tw.Write("\t\t\t<bgimagedata"); tw.Write(String.Format(" id=\"{0}\"", m_id)); tw.WriteLine(">"); for (int iy = 0; iy < m_height; iy++) { sb = new StringBuilder(strIndent); sb.Append("<bgimagerow>"); for (int ix = 0; ix < m_width - 1; ix++) { sb.Append(String.Format("{0:x2},", m_ImageData[ix, iy])); } sb.Append(String.Format("{0:x2}", m_ImageData[m_width - 1, iy])); sb.Append("</bgimagerow>"); tw.WriteLine(sb.ToString()); } tw.WriteLine("\t\t\t</bgimagedata>"); tw.WriteLine("\t\t</bgimage_pal8>"); }