public void drawPixmap(Pixmap pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight) { if (srcWidth == dstWidth && srcHeight == dstHeight) { for (var x = 0; x < srcWidth; x++) { for (var y = 0; y < srcHeight; y++) { drawPixel(dstX + x, dstY + y, (uint)pixmap.getPixel(srcX + x, srcY + y)); } } } else if (_filter == PixmapFilter.NEAREST_NEIGHBOUR) { var xRatio = (float)srcWidth / dstWidth; var yRatio = (float)srcHeight / dstHeight; for (var x = dstX; x < dstX + dstWidth; x++) { for (var y = dstY; y < dstY + dstWidth; y++) { var srcPixX = (int)Math.Round((x - dstX + srcX) * xRatio, MidpointRounding.AwayFromZero); var srcPixY = (int)Math.Round((y - dstY + srcY) * yRatio, MidpointRounding.AwayFromZero); drawPixel(x, y, (uint)pixmap.getPixel(srcPixX, srcPixY)); } } } else { for (int x = 0; x < dstWidth; ++x) { for (int y = 0; y < dstWidth; ++y) { float gx = ((float)x) / dstWidth * (srcWidth - 1); float gy = ((float)y) / dstWidth * (srcWidth - 1); int gxi = (int)gx; int gyi = (int)gy; var c00 = (uint)pixmap.getPixel(gxi, gyi); var c10 = (uint)pixmap.getPixel(gxi + 1, gyi); var c01 = (uint)pixmap.getPixel(gxi, gyi + 1); var c11 = (uint)pixmap.getPixel(gxi + 1, gyi + 1); UInt32 red = (byte)blerp(MonoGameColor.getRAsByte(c00), MonoGameColor.getRAsByte(c10), MonoGameColor.getRAsByte(c01), MonoGameColor.getRAsByte(c11), gx - gxi, gy - gyi); UInt32 green = (byte)blerp(MonoGameColor.getGAsByte(c00), MonoGameColor.getGAsByte(c10), MonoGameColor.getGAsByte(c01), MonoGameColor.getGAsByte(c11), gx - gxi, gy - gyi); UInt32 blue = (byte)blerp(MonoGameColor.getBAsByte(c00), MonoGameColor.getBAsByte(c10), MonoGameColor.getBAsByte(c01), MonoGameColor.getBAsByte(c11), gx - gxi, gy - gyi); UInt32 alpha = (byte)blerp(MonoGameColor.getAAsByte(c00), MonoGameColor.getAAsByte(c10), MonoGameColor.getAAsByte(c01), MonoGameColor.getAAsByte(c11), gx - gxi, gy - gyi); var color = ((red << 24) & 0xff000000) | ((green << 16) & 0xff0000) | ((blue << 8) & 0xff00) | alpha; drawPixel(dstX + x, dstY + y, color); } } } }
public void drawPixel(int x, int y, UInt32 color, bool blend = true) { var colorAlpha = MonoGameColor.getAAsByte(color); if (x < getWidth() && y < getHeight() && x >= 0 && y >= 0 && colorAlpha > 0) { if (colorAlpha == 255 || !blend) { _pixmap[x, y] = color; } else { var newR = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha)); var newG = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha)); var newB = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha)); _pixmap[x, y] = MonoGameColor.toRGBA8888(newR, newG, newB, colorAlpha); } } }