Class in reactor_core.js

Bitmap

77 functions in 7 groups · hide internal

Core runtime: data, input and the ReactorEvents feed.

Familiar territory. Bitmap keeps the RPG Maker MZ API, so existing MZ knowledge, tutorials and plugin code apply. Reactor's additions are marked with descriptions below.

The basic object that represents an image.

@class
@param
width number The width of the bitmap.
@param
height number The height of the bitmap.
function Bitmap()

Quick Reference

Setup & Creation 9

initialize() Sets up a new instance.
load() Loads a image file.
_makeFontNameText() Makes the font name text.
_createCanvas() Creates the canvas.
_ensureCanvas() Ensure canvas.
_createBaseTexture() Creates the base texture.
_buildFramePng() Build frame png.
_buildFrameGif() Build frame gif.
_loadAnimationFrames() Loads the animation frames.

Getting Information 4

getPixel() Returns pixel color at the specified point.
getAlphaPixel() Returns alpha pixel value at the specified point.
measureTextWidth() Returns the width of the specified text.
textShadow() System.json advanced.rrTextShadow: text casts a sharp 1 px drop shadow instead of an outline, as 2000/2003 dr…

Checks (True / False) 7

isReady() Checks whether the bitmap is ready to render.
isError() Checks whether a loading error has occurred.
_hasPngSignature() Whether it has the png signature.
_isAnimatedImage() Whether a url names a format whose frames the engine decodes itself.
hasApngAnimation() Whether an image file carries APNG animation, i.e.
isAnimated() Whether this bitmap is playing a decoded animation.
isAnimationPaused() Whether the animation is held.

Actions 15

destroy() Destroys the bitmap.
clearRect() Clears the specified rectangle.
clear() Clears the entire bitmap.
addLoadListener() Adds a callback function that will be called when the bitmap is loaded.
_destroyCanvas() Destroy canvas.
_startLoading() Starts the loading.
_startDecrypting() Starts the decrypting.
_dropPendingRequest() Drop pending request.
_requestEncrypted() Requests the encrypted.
_requestBytes() Requests the bytes.
_startAnimation() Starts the animation.
pauseAnimation() Holds the animation on the frame it is showing.
playAnimation() Resumes a held animation from the frame it is showing.
setAnimationLoopCount() Overrides how many times the animation plays, ignoring the count the file asked for.
_callLoadListeners() Call load listeners.

Events, Commands & Input 5

_onXhrLoad() Called when xhr load happens.
_onImageBytes() Called when image bytes happens.
_onEncryptedError() Called when encrypted error happens.
_onLoad() Called when load happens.
_onError() Called when error happens.

Updating & Drawing 12

drawCircle() Draws a bitmap in the shape of a circle.
drawText() Draws the outline text to the bitmap.
_drawTextOutline() Draws the text outline.
_drawTextBody() Draws the text body.
paintLegacyGlyph() Paint one source System colour cell through a monochrome glyph mask.
_drawLegacyPaletteRun() Native legacy text draws each glyph's shadow and body before the next glyph.
_drawLegacyPaletteText() Draws the legacy palette text.
_drawLegacyPixelText() 2000/2003 used monochrome glyph masks.
_drawingContext() The context for the ops in this file, without marking it lent.
_updateScaleMode() Updates the scale mode each frame.
_updateAnimatedImage() Updates the animated image each frame.
_renderAnimationFrame() Composites one frame onto the canvas.

Other 25

defaultOutlineWidth() System.json advanced.textOutlineWidth (a 16 px game draws a 1 px shadow); 3 when the data is not loaded.
snap() Takes a snapshot of the game screen.
_sweepStalledLoads() Sweep stalled loads.
resize() Resizes the bitmap.
blt() Performs a block transfer.
fillRect() Fills the specified rectangle.
fillAll() Fills the entire bitmap.
strokeRect() Draws the specified rectangular frame.
retry() Tries to load the image again.
pixelText() System.json advanced.pixelatedRendering: text is placed on whole pixels.
legacyFontInfo() RPG Maker 2000/2003 (System.json rrLegacyWindows): every text is drawn at the font's own size (advanced.fontS…
fixedFontSize() Fixed font size.
_touchUpload() Touch upload.
_revokeObjectUrl() Revoke object url.
_mimeType() Mime type.
_crc32() Crc32.
_asUint8() As uint8.
_concatBytes() Concat bytes.
_parseAnimation() Splits an animated image into its frames, choosing a parser by url.
parseApng() Splits an APNG into one standalone PNG per frame.
parseGif() Splits an animated GIF into one standalone single-frame GIF per frame.
_animationHoldTime() Animation hold time.
_advanceAnimation() Advance animation.
seekAnimation() Jumps to a frame. Earlier frames are replayed rather than skipped, because a frame in either format is a diff…
restartAnimation() Replays the animation from its first frame, loop count included.

Setup & Creation

initialize

method source
Bitmap.prototype.initialize(width, height)

Sets up a new instance. (Same as the RPG Maker MZ method of this name.)

load

static source
Bitmap.load(url, fallbackUrls)

Loads a image file.

Details

Loads a image file.

@param
url string The image url of the texture.
@returns
Bitmap The new bitmap object.

_makeFontNameText

method internal source
Bitmap.prototype._makeFontNameText()

Makes the font name text. (Same as the RPG Maker MZ method of this name.)

_createCanvas

method internal source
Bitmap.prototype._createCanvas(width, height)

Creates the canvas. (Same as the RPG Maker MZ method of this name.)

_ensureCanvas

method internal source
Bitmap.prototype._ensureCanvas()

Ensure canvas. (Same as the RPG Maker MZ method of this name.)

_createBaseTexture

method internal source
Bitmap.prototype._createBaseTexture(source)

Creates the base texture. (Same as the RPG Maker MZ method of this name.)

_buildFramePng

static internal source
Bitmap._buildFramePng(header, shared, frame)

Build frame png. (Same as the RPG Maker MZ method of this name.)

_buildFrameGif

static internal source
Bitmap._buildFrameGif(frame)

Build frame gif. (Same as the RPG Maker MZ method of this name.)

_loadAnimationFrames

method internal source
Bitmap.prototype._loadAnimationFrames(animation)

Loads the animation frames. (Same as the RPG Maker MZ method of this name.)

Getting Information

getPixel

method source
Bitmap.prototype.getPixel(x, y)

Returns pixel color at the specified point.

Details

Returns pixel color at the specified point.

@param
x number The x coordinate of the pixel in the bitmap.
@param
y number The y coordinate of the pixel in the bitmap.
@returns
string The pixel color (hex format).

getAlphaPixel

method source
Bitmap.prototype.getAlphaPixel(x, y)

Returns alpha pixel value at the specified point.

Details

Returns alpha pixel value at the specified point.

@param
x number The x coordinate of the pixel in the bitmap.
@param
y number The y coordinate of the pixel in the bitmap.
@returns
string The alpha value.

measureTextWidth

method source
Bitmap.prototype.measureTextWidth(text)

Returns the width of the specified text.

Details

Returns the width of the specified text.

@param
text string The text to be measured.
@returns
number The width of the text in pixels.

textShadow

static source
Bitmap.textShadow()

System.json advanced.rrTextShadow: text casts a sharp 1 px drop shadow instead of an outline, as 2000/2003 drew it.

Checks (True / False)

isReady

method source
Bitmap.prototype.isReady()

Checks whether the bitmap is ready to render.

Details

Checks whether the bitmap is ready to render.

@returns
boolean True if the bitmap is ready to render.

isError

method source
Bitmap.prototype.isError()

Checks whether a loading error has occurred.

Details

Checks whether a loading error has occurred.

@returns
boolean True if a loading error has occurred.

_hasPngSignature

static internal source
Bitmap._hasPngSignature(bytes)

Whether it has the png signature. (Same as the RPG Maker MZ method of this name.)

_isAnimatedImage

static internal source
Bitmap._isAnimatedImage(url)

Whether a url names a format whose frames the engine decodes itself.

Details

Whether a url names a format whose frames the engine decodes itself. Keyed on the extension rather than the file's contents: sniffing every image would cost a byte read per file the game loads.

@param
url string The image url, encrypted suffix and query allowed.
@returns
boolean True for an .apng or .gif url.

hasApngAnimation

static source
Bitmap.hasApngAnimation(source)

Whether an image file carries APNG animation, i.e.

Details

Whether an image file carries APNG animation, i.e. an acTL chunk ahead of the first IDAT. A file with acTL after IDAT is malformed and reads as a plain PNG, which is what the specification asks for.

@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
boolean True if the file is an animated PNG.

isAnimated

method source
Bitmap.prototype.isAnimated()

Whether this bitmap is playing a decoded animation.

Details

Whether this bitmap is playing a decoded animation.

@returns
boolean True while frames are being composited.

isAnimationPaused

method source
Bitmap.prototype.isAnimationPaused()

Whether the animation is held.

Details

Whether the animation is held.

@returns
boolean True if paused.

Actions

destroy

method source
Bitmap.prototype.destroy()

Destroys the bitmap.

clearRect

method source
Bitmap.prototype.clearRect(x, y, width, height)

Clears the specified rectangle.

Details

Clears the specified rectangle.

@param
x number The x coordinate for the upper-left corner.
@param
y number The y coordinate for the upper-left corner.
@param
width number The width of the rectangle to clear.
@param
height number The height of the rectangle to clear.

clear

method source
Bitmap.prototype.clear()

Clears the entire bitmap.

addLoadListener

method source
Bitmap.prototype.addLoadListener(listner)

Adds a callback function that will be called when the bitmap is loaded.

Details

Adds a callback function that will be called when the bitmap is loaded.

@param
listner function The callback function.

_destroyCanvas

method internal source
Bitmap.prototype._destroyCanvas()

Destroy canvas. (Same as the RPG Maker MZ method of this name.)

_startLoading

method internal source
Bitmap.prototype._startLoading()

Starts the loading. (Same as the RPG Maker MZ method of this name.)

_startDecrypting

method internal source
Bitmap.prototype._startDecrypting()

Starts the decrypting. (Same as the RPG Maker MZ method of this name.)

_dropPendingRequest

method internal source
Bitmap.prototype._dropPendingRequest()

Drop pending request. (Same as the RPG Maker MZ method of this name.)

_requestEncrypted

method internal source
Bitmap.prototype._requestEncrypted(url)

Requests the encrypted. (Same as the RPG Maker MZ method of this name.)

_requestBytes

method internal source
Bitmap.prototype._requestBytes(url)

Requests the bytes. (Same as the RPG Maker MZ method of this name.)

_startAnimation

method internal source
Bitmap.prototype._startAnimation(animation, images)

Starts the animation. (Same as the RPG Maker MZ method of this name.)

pauseAnimation

method source
Bitmap.prototype.pauseAnimation()

Holds the animation on the frame it is showing.

playAnimation

method source
Bitmap.prototype.playAnimation()

Resumes a held animation from the frame it is showing.

setAnimationLoopCount

method source
Bitmap.prototype.setAnimationLoopCount(count)

Overrides how many times the animation plays, ignoring the count the file asked for.

Details

Overrides how many times the animation plays, ignoring the count the file asked for. A GIF with no loop block asks to be shown once; this is how a plugin makes one loop forever.

@param
count number Passes to play; 0 loops forever.

_callLoadListeners

method internal source
Bitmap.prototype._callLoadListeners()

Call load listeners. (Same as the RPG Maker MZ method of this name.)

Events, Commands & Input

_onXhrLoad

method internal source
Bitmap.prototype._onXhrLoad(xhr)

Called when xhr load happens. (Same as the RPG Maker MZ method of this name.)

_onImageBytes

method internal source
Bitmap.prototype._onImageBytes(arrayBuffer)

Called when image bytes happens. (Same as the RPG Maker MZ method of this name.)

_onEncryptedError

method internal source
Bitmap.prototype._onEncryptedError()

Called when encrypted error happens. (Same as the RPG Maker MZ method of this name.)

_onLoad

method internal source
Bitmap.prototype._onLoad()

Called when load happens. (Same as the RPG Maker MZ method of this name.)

_onError

method internal source
Bitmap.prototype._onError()

Called when error happens. (Same as the RPG Maker MZ method of this name.)

Updating & Drawing

drawCircle

method source
Bitmap.prototype.drawCircle(x, y, radius, color)

Draws a bitmap in the shape of a circle.

Details

Draws a bitmap in the shape of a circle.

@param
x number The x coordinate based on the circle center.
@param
y number The y coordinate based on the circle center.
@param
radius number The radius of the circle.
@param
color string The color of the circle in CSS format.

drawText

method source
Bitmap.prototype.drawText(text, x, y, maxWidth, lineHeight, align)

Draws the outline text to the bitmap.

Details

Draws the outline text to the bitmap.

@param
text string The text that will be drawn.
@param
x number The x coordinate for the left of the text.
@param
y number The y coordinate for the top of the text.
@param
maxWidth number The maximum allowed width of the text.
@param
lineHeight number The height of the text line.
@param
align string The alignment of the text.

_drawTextOutline

method internal source
Bitmap.prototype._drawTextOutline(text, tx, ty, maxWidth)

Draws the text outline. (Same as the RPG Maker MZ method of this name.)

_drawTextBody

method internal source
Bitmap.prototype._drawTextBody(text, tx, ty, maxWidth)

Draws the text body. (Same as the RPG Maker MZ method of this name.)

paintLegacyGlyph

static source
Bitmap.paintLegacyGlyph(pixels, width, height, pad, ascent, paint, shadow)

Paint one source System colour cell through a monochrome glyph mask.

_drawLegacyPaletteRun

method internal source
Bitmap.prototype._drawLegacyPaletteRun(text, tx, ty)

Native legacy text draws each glyph's shadow and body before the next glyph.

_drawLegacyPaletteText

method internal source
Bitmap.prototype._drawLegacyPaletteText(text, tx, ty, paint, shadow, pairedBodyPaint)

Draws the legacy palette text. (Same as the RPG Maker MZ method of this name.)

_drawLegacyPixelText

method internal source
Bitmap.prototype._drawLegacyPixelText(text, tx, ty, color, outline = 0)

2000/2003 used monochrome glyph masks.

Details

2000/2003 used monochrome glyph masks. Nearest texture sampling cannot remove antialiasing already baked into a browser-rendered fallback font. Cache native-size, hard-edged masks for these projects only; modern text and legacy projects with Pixelated Rendering disabled retain canvas text.

_drawingContext

method internal source
Bitmap.prototype._drawingContext()

The context for the ops in this file, without marking it lent.

_updateScaleMode

method internal source
Bitmap.prototype._updateScaleMode()

Updates the scale mode each frame. (Same as the RPG Maker MZ method of this name.)

_updateAnimatedImage

method internal source
Bitmap.prototype._updateAnimatedImage()

Updates the animated image each frame. (Same as the RPG Maker MZ method of this name.)

_renderAnimationFrame

method internal source
Bitmap.prototype._renderAnimationFrame(index)

Composites one frame onto the canvas.

Details

Composites one frame onto the canvas. Deliberately does not upload: callers batch that, so a seek replaying N frames still costs one texture update.

Other

defaultOutlineWidth

static source
Bitmap.defaultOutlineWidth()

System.json advanced.textOutlineWidth (a 16 px game draws a 1 px shadow); 3 when the data is not loaded.

snap

static source
Bitmap.snap(stage)

Takes a snapshot of the game screen.

Details

Takes a snapshot of the game screen.

@param
stage Stage The stage object.
@returns
Bitmap The new bitmap object.

_sweepStalledLoads

static internal source
Bitmap._sweepStalledLoads()

Sweep stalled loads. (Same as the RPG Maker MZ method of this name.)

resize

method source
Bitmap.prototype.resize(width, height)

Resizes the bitmap.

Details

Resizes the bitmap.

@param
width number The new width of the bitmap.
@param
height number The new height of the bitmap.

blt

method source
Bitmap.prototype.blt(source, sx, sy, sw, sh, dx, dy, dw, dh)

Performs a block transfer.

Details

Performs a block transfer.

@param
source Bitmap The bitmap to draw.
@param
sx number The x coordinate in the source.
@param
sy number The y coordinate in the source.
@param
sw number The width of the source image.
@param
sh number The height of the source image.
@param
dx number The x coordinate in the destination.
@param
dy number The y coordinate in the destination.
@param
[dw=sw] number The width to draw the image in the destination.
@param
[dh=sh] number The height to draw the image in the destination.

fillRect

method source
Bitmap.prototype.fillRect(x, y, width, height, color)

Fills the specified rectangle.

Details

Fills the specified rectangle.

@param
x number The x coordinate for the upper-left corner.
@param
y number The y coordinate for the upper-left corner.
@param
width number The width of the rectangle to fill.
@param
height number The height of the rectangle to fill.
@param
color string The color of the rectangle in CSS format.

fillAll

method source
Bitmap.prototype.fillAll(color)

Fills the entire bitmap.

Details

Fills the entire bitmap.

@param
color string The color of the rectangle in CSS format.

strokeRect

method source
Bitmap.prototype.strokeRect(x, y, width, height, color)

Draws the specified rectangular frame.

Details

Draws the specified rectangular frame.

@param
x number The x coordinate for the upper-left corner.
@param
y number The y coordinate for the upper-left corner.
@param
width number The width of the rectangle to fill.
@param
height number The height of the rectangle to fill.
@param
color string The color of the rectangle in CSS format.

retry

method source
Bitmap.prototype.retry()

Tries to load the image again.

pixelText

static source
Bitmap.pixelText()

System.json advanced.pixelatedRendering: text is placed on whole pixels.

legacyFontInfo

static source
Bitmap.legacyFontInfo()

RPG Maker 2000/2003 (System.json rrLegacyWindows): every text is drawn at the font's own size (advanced.fontSize) and at its natural width, never squeezed; a pixel font at any other size blurs.

fixedFontSize

static source
Bitmap.fixedFontSize()

Fixed font size. (Same as the RPG Maker MZ method of this name.)

_touchUpload

method internal source
Bitmap.prototype._touchUpload(x, y, width, height)

Touch upload. (Same as the RPG Maker MZ method of this name.)

_revokeObjectUrl

method internal source
Bitmap.prototype._revokeObjectUrl()

Revoke object url. (Same as the RPG Maker MZ method of this name.)

_mimeType

static internal source
Bitmap._mimeType(url)

Mime type. (Same as the RPG Maker MZ method of this name.)

_crc32

static internal source
Bitmap._crc32(bytes)

Crc32. (Same as the RPG Maker MZ method of this name.)

_asUint8

static internal source
Bitmap._asUint8(source)

As uint8. (Same as the RPG Maker MZ method of this name.)

_concatBytes

static internal source
Bitmap._concatBytes(pieces)

Concat bytes. (Same as the RPG Maker MZ method of this name.)

_parseAnimation

static internal source
Bitmap._parseAnimation(url, source)

Splits an animated image into its frames, choosing a parser by url.

Details

Splits an animated image into its frames, choosing a parser by url.

@param
url string The url the bytes came from.
@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
?object The animation, or null if there is nothing to animate.

parseApng

static source
Bitmap.parseApng(source)

Splits an APNG into one standalone PNG per frame.

Details

Splits an APNG into one standalone PNG per frame.

Returns null for anything that is not a usable animation -- not a PNG, no acTL, a single frame, a frame with no data -- so callers fall back to the ordinary static path rather than failing on a file the engine can still show.

@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
?object {width, height, playCount, mimeType, frames}, playCount 0 meaning loop forever; each frame is {x, y, width, height, delayMs, disposeOp, blendOp, bytes} where bytes is a complete one-frame file.

parseGif

static source
Bitmap.parseGif(source)

Splits an animated GIF into one standalone single-frame GIF per frame.

Details

Splits an animated GIF into one standalone single-frame GIF per frame.

The LZW data is copied across byte for byte, interlace flag included, so no decompression happens here -- each frame is handed back to the browser as a tiny GIF of its own. Returns null for a still GIF or anything unreadable, so callers fall back to the ordinary static path.

@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
?object The animation, shaped exactly as parseApng returns.

_animationHoldTime

method internal source
Bitmap.prototype._animationHoldTime(index)

Animation hold time. (Same as the RPG Maker MZ method of this name.)

_advanceAnimation

method internal source
Bitmap.prototype._advanceAnimation()

Advance animation. (Same as the RPG Maker MZ method of this name.)

seekAnimation

method source
Bitmap.prototype.seekAnimation(index)

Jumps to a frame. Earlier frames are replayed rather than skipped, because a frame in either format is a difference against the ones before it, not a whole picture.

Details

Jumps to a frame. Earlier frames are replayed rather than skipped, because a frame in either format is a difference against the ones before it, not a whole picture.

@param
index number The frame to show.

restartAnimation

method source
Bitmap.prototype.restartAnimation()

Replays the animation from its first frame, loop count included.