public bool LoadXML_bgimages(XmlNode xnode) { foreach (XmlNode xn in xnode.ChildNodes) { switch (xn.Name) { case "bgimage_pal8": string strName = XMLUtils.GetXMLAttribute(xn, "name"); int id = XMLUtils.GetXMLIntegerAttribute(xn, "id"); string strDesc = XMLUtils.GetXMLAttribute(xn, "desc"); string strSize = XMLUtils.GetXMLAttribute(xn, "size"); string[] aSize = strSize.Split('x'); int nWidth = XMLUtils.ParseInteger(aSize[0]); int nHeight = XMLUtils.ParseInteger(aSize[1]); if (m_bgimages.ContainsKey(id)) { m_doc.ErrorString("A background image with id={0} already exists.", id); return(false); } BgImage bgi = new BgImage(m_doc, strName, id, strDesc); if (!bgi.LoadXML_bgimage_pal8(xn, nWidth, nHeight)) { return(false); } m_bgimages.Add(id, bgi); CurrentImage = bgi; break; } } return(true); }
/// <summary> /// Generate the GBA/NDS formatted data from the bitmap image. /// </summary> /// <returns>True if the data was successfully converted.</returns> public bool LoadBitmap(Bitmap bm) { m_bm = bm; m_width = bm.Width; m_height = bm.Height; // Gather the colors from the bitap. m_mapColor2Id = new Dictionary <Color, short>(); m_mapId2Color = new Dictionary <short, Color>(); short nColorId = 0; // Add the transparent color to the Id map at index 0. m_mapId2Color.Add(nColorId++, Color.White); for (int ix = 0; ix < m_width; ix++) { for (int iy = 0; iy < m_height; iy++) { Color c = bm.GetPixel(ix, iy); if (c != Color.Transparent && !m_mapColor2Id.ContainsKey(c)) { m_mapColor2Id.Add(c, nColorId); m_mapId2Color.Add(nColorId, c); nColorId++; } } } // At this point, // nColorId = number of colors in image + 1 (for transparency color at index 0) if (nColorId > 257) { m_doc.ErrorString("Too many colors {0} in image. Imported images are restricted to 255 colors (+1 transparency color)", nColorId); return(false); } if (nColorId == 257) { // TODO: select transparency color m_doc.ErrorString("Exactly 256 colors - please choose one of the colors to be the transparent 'color'"); return(false); } while (nColorId < 256) { // Pad out palette with enough colors. m_mapId2Color.Add(nColorId++, Color.White); } m_ImageData = new byte[m_width, m_height]; for (int ix = 0; ix < m_width; ix++) { for (int iy = 0; iy < m_height; iy++) { Color c = m_bm.GetPixel(ix, iy); if (c == Color.Transparent) { m_ImageData[ix, iy] = 0; } else { m_ImageData[ix, iy] = (byte)m_mapColor2Id[c]; } } } m_mapColor2Id = null; return(true); }