Esempio n. 1
0
		public Bitmap this[ETextureSet _set, bool _isTerrain]
		{
			get
			{
				Image value;
				if (_isTerrain)
				{
					if (!m_ttextures.TryGetValue(_set, out value))
					{
						throw new NotImplementedException("А на хуа?");
						//var scale = 1;
						//Bitmap bmp;
						//switch (_set)
						//{
						//	case ETextureSet.RJ:
						//		bmp = Resources.redjack15v;
						//		break;
						//	case ETextureSet.RB1:
						//		bmp = Resources.RantingRodent_Brick_01;
						//		break;
						//	case ETextureSet.RB2:
						//		bmp = Resources.RantingRodent_Brick_02;
						//		break;
						//	case ETextureSet.RN1:
						//		bmp = Resources.RantingRodent_Natural_01;
						//		break;
						//	case ETextureSet.RN2:
						//		bmp = Resources.RantingRodent_Natural_02;
						//		break;
						//	case ETextureSet.GP:
						//		bmp = Resources.gold_plated_16x16;
						//		break;
						//	case ETextureSet.NH:
						//		bmp = Resources.nethack;
						//		break;
						//	case ETextureSet.HM:
						//		bmp = Resources.aq;
						//		break;
						//	case ETextureSet.PH:
						//		bmp = Resources.Phoebus_16x16;
						//		break;
						//	case ETextureSet.U4:
						//		bmp = Resources.Ultima4;
						//		break;
						//	case ETextureSet.U5:
						//		bmp = Resources.Ultima5;
						//		break;
						//	case ETextureSet.WC_WS:
						//		bmp = Resources.wintersnow;
						//		break;
						//	case ETextureSet.WC_SG:
						//		bmp = Resources.summergrass;
						//		break;
						//	case ETextureSet.WC_SW:
						//		bmp = Resources.summerwater;
						//		break;
						//	case ETextureSet.dg_armor32:
						//		bmp = Resources.dg_armor32;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster1:
						//		bmp = Resources.dg_monster132;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster2:
						//		bmp = Resources.dg_monster232;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster3:
						//		bmp = Resources.dg_monster332;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster4:
						//		bmp = Resources.dg_monster432;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster5:
						//		bmp = Resources.dg_monster532;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster6:
						//		bmp = Resources.dg_monster632;
						//		scale = 2;
						//		break;
						//	case ETextureSet.dg_monster7:
						//		bmp = Resources.dg_monster732;
						//		scale = 2;
						//		break;
						//	default:
						//		throw new ArgumentOutOfRangeException();
						//}
						//if(scale==2)
						//{
						//	bmp = Scale(bmp);
						//}

						//value = new Image(bmp, false, false);

						//m_ttextures[_set] = value;
					}
				}
				else
				{
					if (!m_textures.TryGetValue(_set, out value))
					{
						var bmp = this[_set, true];
						value = new Image(bmp, true, false);
						m_textures[_set] = value;
					}
				}

				return value.Bitmap;
			}
		}
Esempio n. 2
0
		private static Bitmap Scale(Bitmap _bmp, byte _tileSize = 32)
		{
			if (Constants.TILE_SIZE == _tileSize) return _bmp;
			var k = ((double) Constants.TILE_SIZE)/_tileSize;
			var srcImage = new Image(_bmp, true, false);
			var result = new Bitmap((int)(_bmp.Width * k), (int)(_bmp.Height * k), PixelFormat.Format32bppPArgb);

			using (var gr = Graphics.FromImage(result))
			{
				gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
				var tile = new Bitmap(_tileSize + 2, _tileSize + 2, PixelFormat.Format32bppPArgb);
				using (var grTile = Graphics.FromImage(tile))
				{
					grTile.InterpolationMode = InterpolationMode.Default;
					for (var i = 0; i < _bmp.Width/_tileSize; i++)
					{
						for (var j = 0; j < _bmp.Height/_tileSize; j++)
						{
							grTile.Clear(Color.Empty);
							grTile.DrawImage(srcImage.Bitmap, new Rectangle(1, 1, _tileSize, _tileSize), (float) i*_tileSize, (float) j*_tileSize, _tileSize, _tileSize, GraphicsUnit.Pixel);


							grTile.DrawImage(srcImage.Bitmap, new Rectangle(1, 0, _tileSize, 1), (float) i*_tileSize, (float) j*_tileSize, _tileSize, 1, GraphicsUnit.Pixel); //top
							grTile.DrawImage(srcImage.Bitmap, new Rectangle(0, 1, 1, _tileSize), (float) i*_tileSize, (float) j*_tileSize, 1, _tileSize, GraphicsUnit.Pixel); //left

							grTile.DrawImage(srcImage.Bitmap, new Rectangle(1, _tileSize + 1, _tileSize, 1), (float) i*_tileSize, (float) j*_tileSize + _tileSize - 1, _tileSize, 1, GraphicsUnit.Pixel); //bottom
							grTile.DrawImage(srcImage.Bitmap, new Rectangle(_tileSize + 1, 1, 1, _tileSize), (float) i*_tileSize + _tileSize - 1, (float) j*_tileSize, 1, _tileSize, GraphicsUnit.Pixel); //right

							gr.DrawImage(tile, new Rectangle(i*Constants.TILE_SIZE, j*Constants.TILE_SIZE, Constants.TILE_SIZE, Constants.TILE_SIZE), new Rectangle(1, 1, _tileSize, _tileSize), GraphicsUnit.Pixel);
						}
					}
				}
			}
			return result;
		}
Esempio n. 3
0
		static void Main(string[] args)
		{

			var bmps = new List<Bitmap>();
			foreach (var fileName in Directory.GetFiles(@"..\\RawTiles", "*.*"))
			{
				var bitmap = new Image((Bitmap)Bitmap.FromFile(fileName), true, false).Bitmap;


				var xx = new List<int>();
				var yy = new List<int>();
				{
					var empty = true;
					for (var x = 0; x < bitmap.Width; x++)
					{
						int y = 0;
						for (; y < bitmap.Height; y++)
						{

							if (empty)
							{
								if (bitmap.GetPixel(x, y) != m_transp)
								{
									xx.Add(x);
									empty = false;
									break;
								}
							}
							else
							{
								if (bitmap.GetPixel(x, y) != m_transp)
								{
									break;
								}
							}
						}
						if (!empty && y == bitmap.Height)
						{
							if (x - xx[xx.Count - 1] < TILE_SIZE)
							{
								break;
							}
							xx.Add(x);
							empty = true;
						}
					}
				}
				{
					var empty = true;
					for (var y = 0; y < bitmap.Height; y++)
					{
						int x = 0;
						for (; x < xx[xx.Count - 1]; x++)
						{

							if (empty)
							{
								if (bitmap.GetPixel(x, y) != m_transp)
								{
									yy.Add(y);
									empty = false;
									break;
								}
							}
							else
							{
								if (bitmap.GetPixel(x, y) != m_transp)
								{
									break;
								}
							}
						}
						if (!empty && x == xx[xx.Count - 1])
						{
							if (y - yy[yy.Count - 1] < TILE_SIZE)
							{
								break;
							}
							yy.Add(y);
							empty = true;
						}
					}
					yy.Add(bitmap.Height-1);
				}
				for (var ix = 0; ix < xx.Count-1; ix+=2)
				{
					for (var iy = 0; iy < yy.Count-1; iy+=2)
					{
						var rct = new Rectangle(xx[ix], yy[iy], xx[ix + 1] - xx[ix], yy[iy + 1] - yy[iy]);
						var bmp = GetTile(bitmap, rct);
						if (bmp != null)
						{
							bmps.Add(bmp);
						}
					}
				}

				#region vis

//using (var gr = Graphics.FromImage(bitmap))
				//{
				//	{
				//		var x = 0;
				//		for (var index = 0; index < xx.Count; index += 2)
				//		{
				//			var x1 = xx[index];
				//			gr.FillRectangle(Brushes.Aqua, x, 0, x1 - x, bitmap.Height);
				//			if (index == xx.Count - 1)
				//			{
				//				break;
				//			}
				//			x = xx[index + 1];
				//		}

				//	}
				//	{
				//		var y = 0;
				//		for (var index = 0; index < yy.Count; index += 2)
				//		{
				//			var y1 = yy[index];
				//			gr.FillRectangle(Brushes.Aquamarine, 0, y, bitmap.Width, y1 - y);
				//			if (index == yy.Count - 1)
				//			{
				//				break;
				//			}
				//			y = yy[index + 1];
				//		}

				//	}
				//}
				//bitmap.Save(@"d:\\bmp.png", ImageFormat.Png);

				#endregion

			}

			var ideal = bmps.Where(x => x.Width == TILE_SIZE && x.Height == TILE_SIZE).ToArray();
			var texture = new Bitmap(TILE_SIZE*2, TILE_SIZE*2, PixelFormat.Format32bppPArgb);
			for (var x = 0; x < TILE_SIZE; x++)
			{
				for (var y = 0; y < TILE_SIZE; y++)
				{
					var pixels = ideal.Select(b=>b.GetPixel(x,y)).Where(c=>c!=m_transp).ToArray();
					if (pixels.Length == 0) continue;
					var average = Average(pixels);
					var ordered = pixels.GroupBy(c => Distance(c, average)).OrderByDescending(g => g.Count());
					var first = ordered.First();
					if (first.Count() > 3)
					{
						texture.SetPixel(x + TILE_SIZE / 2, y + TILE_SIZE / 2, Average(first));
					}
				}
			}
			texture.Save(@"d:\\text.png", ImageFormat.Png);


			var arr = GameCore.Misc.Point.Zero.GetSpiral(7).ToArray();

			foreach (var bitmap in ideal)
			{
				var b = new Bitmap(TILE_SIZE, TILE_SIZE, PixelFormat.Format32bppPArgb);
				using (var gr = Graphics.FromImage(b))
				{
					gr.Clear(Color.Empty);
				}
				var fill = new bool[TILE_SIZE+2, TILE_SIZE+2];
				fill[1, 1] = true;
				fill[TILE_SIZE, 1] = true;
				fill[1, TILE_SIZE] = true;
				fill[TILE_SIZE, TILE_SIZE] = true;
				var aa = arr.OrderBy(a => Distance(texture, bitmap, a.X, a.Y)).First();
				var flag = false;
				do
				{
					flag = false;
					for (var x = 0; x < TILE_SIZE; x++)
					{
						for (var y = 0; y < TILE_SIZE; y++)
						{
							if (fill[x + 1, y + 1]) continue;
							if (!new GameCore.Misc.Point(x + 1, y + 1).AllNeighbours.Any(p => fill[p.X, p.Y])) continue;
							if (Distance(bitmap.GetPixel(x, y), texture.GetPixel(x + TILE_SIZE/2 + aa.X, y + TILE_SIZE/2 + aa.Y)) < 10)
							{
								fill[x + 1, y + 1] = true;
								flag = true;
							}
							else
							{
								b.SetPixel(x, y, bitmap.GetPixel(x, y));
							}
						}
					}
				} while (flag);

				for (var x = 0; x < TILE_SIZE; x++)
				{
					for (var y = 0; y < TILE_SIZE; y++)
					{
						if (fill[x + 1, y + 1]) continue;
						if (new GameCore.Misc.Point(x + 1, y + 1).AllNeighbours.All(p => fill[p.X, p.Y])) continue;
						b.SetPixel(x, y, bitmap.GetPixel(x, y));
					}
				}

				
				b.Save(@"d:\\u" + m_uu++ + ".png", ImageFormat.Png);
			}
		}