public void drawPixmap(Pixmap pixmap, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) { for (var pixmapX = 0; pixmapX < srcWidth; pixmapX++) { for (var pixmapY = 0; pixmapY < srcWidth; pixmapY++) { drawPixel(x + pixmapX, y + pixmapY, (uint)pixmap.getPixel(srcX + pixmapX, srcY + pixmapY)); } } }
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 draw(Pixmap pixmap, int x, int y) { var rawTexture = new UInt32[texture2D.Width * texture2D.Height]; texture2D.GetData(rawTexture); for (var pixmapX = 0; pixmapX < pixmap.getWidth(); pixmapX++) { for (var pixmapY = 0; pixmapY < pixmap.getHeight(); pixmapY++) { rawTexture[x + pixmapX + (y + pixmapY) * texture2D.Width] = (uint)pixmap.getPixel(pixmapX, pixmapY); } } texture2D.SetData(rawTexture); }
public static Pixel getPixel(Pixmap pixmap, int x, int y) { return pixmap.getPixel(x, y); }