mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-05 11:54:38 -05:00
Bitmap: Allow pixel-based access (#1855)
This commit is contained in:
@@ -315,6 +315,23 @@ public final class Bitmap {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared code to check for illegal arguments passed to getPixel()
|
||||
* or setPixel()
|
||||
*
|
||||
* @param x x coordinate of the pixel
|
||||
* @param y y coordinate of the pixel
|
||||
*/
|
||||
private void checkPixelAccess(int x, int y) {
|
||||
checkXYSign(x, y);
|
||||
if (x >= getWidth()) {
|
||||
throw new IllegalArgumentException("x must be < bitmap.width()");
|
||||
}
|
||||
if (y >= getHeight()) {
|
||||
throw new IllegalArgumentException("y must be < bitmap.height()");
|
||||
}
|
||||
}
|
||||
|
||||
public void getPixels(@ColorInt int[] pixels, int offset, int stride,
|
||||
int x, int y, int width, int height) {
|
||||
checkPixelsAccess(x, y, width, height, offset, stride, pixels);
|
||||
@@ -322,6 +339,12 @@ public final class Bitmap {
|
||||
image.getRGB(x, y, width, height, pixels, offset, stride);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public int getPixel(int x, int y) {
|
||||
checkPixelAccess(x, y);
|
||||
return image.getRGB(x, y);
|
||||
}
|
||||
|
||||
public void eraseColor(int c) {
|
||||
java.awt.Color color = Color.valueOf(c).toJavaColor();
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
|
||||
Reference in New Issue
Block a user