/// <summary> /// Perform smoothing with or without dithering. /// </summary> /// <param name="srcMap">Source map.</param> /// <param name="destMap">Destination map.</param> /// <param name="dither">Function should apply dithering.</param> private static void smoothDitherMap(ByteMap2 srcMap, ByteMap2 destMap, bool dither) { if (dither) { int x, y = 0, z = 0, dir = 1; for (x = 0; x < srcMap.width; x++) { for (; y != srcMap.height && y != -1; y += dir) { z += srcMap.Get((x == 0) ? x : (x - 1), y) + srcMap.Get((x == srcMap.width - 1) ? x : (x + 1), y) + srcMap.Get(x, (y == 0) ? (0) : (y - 1)) + srcMap.Get(x, (y == (srcMap.height - 1)) ? y : (y + 1)) + srcMap.Get(x, y); Byte val = (Byte)(z / 4); destMap.Set(x, y, val); z &= 3; } dir = -dir; y += dir; } } else { int x, y, z; for (x = 0; x < srcMap.width; x++) { for (y = 0; y < srcMap.height; y++) { z = 0; if (x > 0) { z += srcMap.Get(x - 1, y); } if (x < srcMap.width - 1) { z += srcMap.Get(x + 1, y); } if (y > 0) { z += srcMap.Get(x, y - 1); } if (y < (srcMap.height - 1)) { z += srcMap.Get(x, y + 1); } z = (z + srcMap.Get(x, y)) >> 2; if (z > 255) { z = 255; } destMap.Set(x, y, (Byte)z); } } } }