Image detection in Alt1
Images in can be in one of two different locations in memory, either in js memory or Alt1 memory. They both have their advantages. You can move between them but that comes at a slight cost. A captured image in Alt1 starts in the Alt1 memory, you can do several optimized search and bruteforce operations on it while it's there. You can however only access the raw pixel data when it is in js memory. Pasted images in the browser also start in js memory. There is also a third type, Webkit render memory, you only use that show the images. There are two important classes in the libraries to deal with all this.
First up is the ImgRef class. This class can contain an image in any type of memory. Most image detection function accept this type as input and choose what operation is most efficient for the image type.
The second class is ImageData. This class represents raw image data in js memory. It is a very simple class with three properties; width, height and data. Width and height are the size of the image. Data contains a one dimensional UInt8ClampedArray with all pixels in it, this is mostly like any other js array but more efficient and only holds values between 0 and 255. The length of the array is 4*width*height, this means that it has 4 indexes for every pixel, one each for red, green, blue and alpha. You can get the index of any pixel with i=4*x+4*width*y. More info elsewhere soon.
JS Libraries
All detection libraries need to following two libraries.
-
/alt1lib.js
Wrapper library around the Alt1 API. Deals with communicating complex information like images with Alt1. It also ensures compatibility with different versions and fallbacks when used in a normal browser.
-
/imagedetect.js
Used for image processing. It contains a set of utility functions and the extends the ImageData and ImgRef classes which contain all images during processing. It also holds the PasteInput class which is used to receive pasted images in a normal browser.
These libraries are used to detect different interfaces. You generally have to call xxReader.find() before you can read the contents by calling xxReader.read().
-
actionbar.js
Reads the current hp, prayer points, sum points and dren from the action bar
-
artisansworkshop.js
Simple code to get the current requested item in the Artisan's Workshop. It only returns a unique hash for every item.
-
buffs.js
Reads the buf bar for all current buffs. It returns the buff image, time left and has the option to compare buff images with partially transparent backgrounds and can be used to remove transparent pixels from the template buff image.
Currently outdated and will only detect either buffs or debuffs.
-
castlewars.js
Reads the current state in castle wars games. It detects the lobby times, game timer and possibly respawn room warning.
-
chatbox.js
Finds and reads the chat box. You have to tell it what types of colors to read.
-
craftmenu.js
Reads the state and progress of the progress bar interface.
-
dialog.js
Reads the options in the standard dialog question interface.
-
dialogtext.js
Detects whether or not a text dialog is visible on screen. Similar to dialog.js.
-
fightkiln.js
Reads the current wave number in the Fight Kiln.
-
minimap.js
Finds the position and reads the direction of the compass.
-
sheathe.js
Specific for AfkWarden, can be used to detect the stance in the worn items interface.
-
xpcounter.js
Used to read the skills and current xp in the runemetrics xp counters.