api: ImageUtil sprite additions and random bits and bobs
This commit is contained in:
@@ -1819,4 +1819,24 @@ public interface Client extends GameShell
|
|||||||
void setSelectedSpellWidget(int widgetID);
|
void setSelectedSpellWidget(int widgetID);
|
||||||
|
|
||||||
void setSelectedSpellChildIndex(int index);
|
void setSelectedSpellChildIndex(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scales values from pixels onto canvas
|
||||||
|
*
|
||||||
|
* @see net.runelite.client.util.ImageUtil#resizeSprite(Client, Sprite, int, int)
|
||||||
|
*
|
||||||
|
* @param canvas the array we're writing to
|
||||||
|
* @param pixels pixels to draw
|
||||||
|
* @param color should be 0
|
||||||
|
* @param pixelX x index
|
||||||
|
* @param pixelY y index
|
||||||
|
* @param canvasIdx index in canvas (canvas[canvasIdx])
|
||||||
|
* @param canvasOffset x offset
|
||||||
|
* @param newWidth new width
|
||||||
|
* @param newHeight new height
|
||||||
|
* @param pixelWidth pretty much horizontal scale
|
||||||
|
* @param pixelHeight pretty much vertical scale
|
||||||
|
* @param oldWidth old width
|
||||||
|
*/
|
||||||
|
void scaleSprite(int[] canvas, int[] pixels, int color, int pixelX, int pixelY, int canvasIdx, int canvasOffset, int newWidth, int newHeight, int pixelWidth, int pixelHeight, int oldWidth);
|
||||||
}
|
}
|
||||||
@@ -92,4 +92,20 @@ public interface Sprite
|
|||||||
* @param color target color
|
* @param color target color
|
||||||
*/
|
*/
|
||||||
void toBufferedOutline(BufferedImage img, int color);
|
void toBufferedOutline(BufferedImage img, int color);
|
||||||
|
|
||||||
|
int getMaxWidth();
|
||||||
|
|
||||||
|
void setMaxWidth(int maxWidth);
|
||||||
|
|
||||||
|
int getMaxHeight();
|
||||||
|
|
||||||
|
void setMaxHeight(int maxHeight);
|
||||||
|
|
||||||
|
int getOffsetX();
|
||||||
|
|
||||||
|
void setOffsetX(int offsetX);
|
||||||
|
|
||||||
|
int getOffsetY();
|
||||||
|
|
||||||
|
void setOffsetY(int offsetY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1573,6 +1573,8 @@ public final class SpriteID
|
|||||||
/* Unmapped: 1709, 1710 */
|
/* Unmapped: 1709, 1710 */
|
||||||
public static final int TAB_MAGIC_SPELLBOOK_ARCEUUS = 1711;
|
public static final int TAB_MAGIC_SPELLBOOK_ARCEUUS = 1711;
|
||||||
public static final int BIG_ASS_GUTHIX_SPELL = 1774;
|
public static final int BIG_ASS_GUTHIX_SPELL = 1774;
|
||||||
|
public static final int BIG_ASS_GREY_ENTANGLE = 1788;
|
||||||
|
public static final int BIG_ASS_WHITE_ENTANGLE = 1789;
|
||||||
public static final int BIG_SUPERHEAT = 1800;
|
public static final int BIG_SUPERHEAT = 1800;
|
||||||
public static final int BIG_SPEC_TRANSFER = 1959;
|
public static final int BIG_SPEC_TRANSFER = 1959;
|
||||||
/* Unmapped: 1712~2175 */
|
/* Unmapped: 1712~2175 */
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ public enum VarPlayer
|
|||||||
|
|
||||||
NMZ_REWARD_POINTS(1060),
|
NMZ_REWARD_POINTS(1060),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The 11 least significant bits of this var correspond to the player
|
||||||
|
* you're currently fighting. Value is -1 when not fighting any player.
|
||||||
|
*
|
||||||
|
* Client.getVar(ATTACKING_PLAYER) & 2047 == Client.getLocalInteractingIndex();
|
||||||
|
*/
|
||||||
ATTACKING_PLAYER(1075),
|
ATTACKING_PLAYER(1075),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -688,7 +688,9 @@ public enum Varbits
|
|||||||
*/
|
*/
|
||||||
GAUNTLET_ENTERED(9178),
|
GAUNTLET_ENTERED(9178),
|
||||||
|
|
||||||
WITHDRAW_X_AMOUNT(3960);
|
WITHDRAW_X_AMOUNT(3960),
|
||||||
|
|
||||||
|
IN_PVP_AREA(8121);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw varbit ID.
|
* The raw varbit ID.
|
||||||
|
|||||||
@@ -579,4 +579,134 @@ public class ImageUtil
|
|||||||
|
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resize Sprite sprite to given width (newW) and height (newH)
|
||||||
|
*/
|
||||||
|
public static Sprite resizeSprite(final Client client, final Sprite sprite, int newW, int newH)
|
||||||
|
{
|
||||||
|
assert newW > 0 && newH > 0;
|
||||||
|
|
||||||
|
final int oldW = sprite.getWidth();
|
||||||
|
final int oldH = sprite.getHeight();
|
||||||
|
|
||||||
|
if (oldW == newW && oldH == newH)
|
||||||
|
{
|
||||||
|
return sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int[] canvas = new int[newW * newH];
|
||||||
|
final int[] pixels = sprite.getPixels();
|
||||||
|
|
||||||
|
final Sprite result = client.createSprite(canvas, newW, newH);
|
||||||
|
|
||||||
|
int pixelX = 0;
|
||||||
|
int pixelY = 0;
|
||||||
|
|
||||||
|
final int oldMaxW = sprite.getMaxWidth();
|
||||||
|
final int oldMaxH = sprite.getMaxHeight();
|
||||||
|
|
||||||
|
final int pixelW = (oldMaxW << 16) / newW;
|
||||||
|
final int pixelH = (oldMaxH << 16) / newH;
|
||||||
|
|
||||||
|
int xOffset = 0;
|
||||||
|
int yOffset = 0;
|
||||||
|
|
||||||
|
int canvasIdx;
|
||||||
|
if (sprite.getOffsetX() > 0)
|
||||||
|
{
|
||||||
|
canvasIdx = (pixelW + (sprite.getOffsetX() << 16) - 1) / pixelW;
|
||||||
|
xOffset += canvasIdx;
|
||||||
|
pixelX += canvasIdx * pixelW - (sprite.getOffsetX() << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sprite.getOffsetY() > 0)
|
||||||
|
{
|
||||||
|
canvasIdx = (pixelH + (sprite.getOffsetY() << 16) - 1) / pixelH;
|
||||||
|
yOffset += canvasIdx;
|
||||||
|
pixelY += canvasIdx * pixelH - (sprite.getOffsetY() << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldW < oldMaxW)
|
||||||
|
{
|
||||||
|
newW = (pixelW + ((oldW << 16) - pixelX) - 1) / pixelW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldH < oldMaxH)
|
||||||
|
{
|
||||||
|
newH = (pixelH + ((oldH << 16) - pixelY) - 1) / pixelH;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvasIdx = xOffset + yOffset * newW;
|
||||||
|
int canvasOffset = 0;
|
||||||
|
if (yOffset + newH > newH)
|
||||||
|
{
|
||||||
|
newH -= yOffset + newH - newH;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tmp;
|
||||||
|
if (yOffset < 0)
|
||||||
|
{
|
||||||
|
tmp = -yOffset;
|
||||||
|
newH -= tmp;
|
||||||
|
canvasIdx += tmp * newW;
|
||||||
|
pixelY += pixelH * tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newW + xOffset > newW)
|
||||||
|
{
|
||||||
|
tmp = newW + xOffset - newW;
|
||||||
|
newW -= tmp;
|
||||||
|
canvasOffset += tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xOffset < 0)
|
||||||
|
{
|
||||||
|
tmp = -xOffset;
|
||||||
|
newW -= tmp;
|
||||||
|
canvasIdx += tmp;
|
||||||
|
pixelX += pixelW * tmp;
|
||||||
|
canvasOffset += tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
client.scaleSprite(canvas, pixels, 0, pixelX, pixelY, canvasIdx, canvasOffset, newW, newH, pixelW, pixelH, oldW);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw fg centered on top of bg
|
||||||
|
*/
|
||||||
|
public static Sprite mergeSprites(final Client client, final Sprite bg, final Sprite fg)
|
||||||
|
{
|
||||||
|
assert fg.getHeight() <= bg.getHeight() && fg.getWidth() <= bg.getWidth() : "Background has to be larger than foreground";
|
||||||
|
|
||||||
|
final int[] canvas = Arrays.copyOf(bg.getPixels(), bg.getWidth() * bg.getHeight());
|
||||||
|
final Sprite result = client.createSprite(canvas, bg.getWidth(), bg.getHeight());
|
||||||
|
|
||||||
|
final int bgWid = bg.getWidth();
|
||||||
|
final int fgHgt = fg.getHeight();
|
||||||
|
final int fgWid = fg.getWidth();
|
||||||
|
|
||||||
|
final int xOffset = (bgWid - fgWid) / 2;
|
||||||
|
final int yOffset = (bg.getHeight() - fgHgt) / 2;
|
||||||
|
|
||||||
|
final int[] fgPixels = fg.getPixels();
|
||||||
|
|
||||||
|
for (int y1 = yOffset, y2 = 0; y2 < fgHgt; y1++, y2++)
|
||||||
|
{
|
||||||
|
int i1 = y1 * bgWid + xOffset;
|
||||||
|
int i2 = y2 * fgWid;
|
||||||
|
|
||||||
|
for (int x = 0; x < fgWid; x++, i1++, i2++)
|
||||||
|
{
|
||||||
|
if (fgPixels[i2] > 0)
|
||||||
|
{
|
||||||
|
canvas[i1] = fgPixels[i2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1086,4 +1086,8 @@ public interface RSClient extends RSGameShell, Client
|
|||||||
@Import("selectedSpellChildIndex")
|
@Import("selectedSpellChildIndex")
|
||||||
@Override
|
@Override
|
||||||
void setSelectedSpellChildIndex(int index);
|
void setSelectedSpellChildIndex(int index);
|
||||||
|
|
||||||
|
@Import("Sprite_drawScaled")
|
||||||
|
@Override
|
||||||
|
void scaleSprite(int[] canvas, int[] pixels, int color, int pixelX, int pixelY, int canvasIdx, int canvasOffset, int newWidth, int newHeight, int pixelWidth, int pixelHeight, int oldWidth);
|
||||||
}
|
}
|
||||||
@@ -25,14 +25,34 @@ public interface RSSprite extends Sprite
|
|||||||
void setRaster();
|
void setRaster();
|
||||||
|
|
||||||
@Import("width")
|
@Import("width")
|
||||||
|
@Override
|
||||||
|
int getMaxWidth();
|
||||||
|
|
||||||
|
@Import("width")
|
||||||
|
@Override
|
||||||
void setMaxWidth(int maxWidth);
|
void setMaxWidth(int maxWidth);
|
||||||
|
|
||||||
@Import("height")
|
@Import("height")
|
||||||
|
@Override
|
||||||
|
int getMaxHeight();
|
||||||
|
|
||||||
|
@Import("height")
|
||||||
|
@Override
|
||||||
void setMaxHeight(int maxHeight);
|
void setMaxHeight(int maxHeight);
|
||||||
|
|
||||||
@Import("xOffset")
|
@Import("xOffset")
|
||||||
|
@Override
|
||||||
|
int getOffsetX(); ;
|
||||||
|
|
||||||
|
@Import("xOffset")
|
||||||
|
@Override
|
||||||
void setOffsetX(int offsetX);
|
void setOffsetX(int offsetX);
|
||||||
|
|
||||||
@Import("yOffset")
|
@Import("yOffset")
|
||||||
|
@Override
|
||||||
|
int getOffsetY(); ;
|
||||||
|
|
||||||
|
@Import("yOffset")
|
||||||
|
@Override
|
||||||
void setOffsetY(int offsetY);
|
void setOffsetY(int offsetY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user