Skip to content

Commit ffaf369

Browse files
committed
abstract-encoding
1 parent 2ce396d commit ffaf369

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/SLP.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ function SLP (buf) {
5959
* Parses the .SLP header.
6060
*/
6161
SLP.prototype.parseHeader = function () {
62-
const header = headerStruct(this.buf)
62+
const header = headerStruct.decode(this.buf)
6363
this.version = header.version
6464
this.numFrames = header.numFrames
6565
this.comment = header.comment
6666
this.frames = header.frames
6767

68-
this.bodyOffset = /* header */ 32 + /* frames */ 32 * header.numFrames
68+
this.bodyOffset = headerStruct.decode.bytes
6969
}
7070

7171
/**

src/SLPEncoder.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function pixelsToRenderCommands (palette, { width, height, data }) {
9090
const c = (r << 16) + (g << 8) + b
9191
const index = palette[c]
9292
if (!index) {
93-
throw new Error(`[${r} ${g} ${b}] is not in palette`)
93+
throw new Error(`Missing color: [${r} ${g} ${b}] is not in palette`)
9494
}
9595
if (prevCommand === RENDER_FILL && index === prevArg.color) {
9696
prevArg.pxCount++
@@ -187,7 +187,12 @@ function renderCommandsToSlpFrame ({ width, height, commands, baseOffset }) {
187187
return buffer.slice(0, offset)
188188
}
189189

190-
SLPEncoder.prototype.addFrame = function ({ width, height, data, hotspot }) {
190+
SLPEncoder.prototype.addFrame = function ({
191+
width,
192+
height,
193+
data,
194+
hotspot = { x: 0, y: 0 }
195+
}) {
191196
const commands = pixelsToRenderCommands(this.colorIndices, { width, height, data })
192197

193198
this.frames.push({
@@ -197,7 +202,7 @@ SLPEncoder.prototype.addFrame = function ({ width, height, data, hotspot }) {
197202
properties: 0,
198203
width,
199204
height,
200-
hotspot: hotspot || { x: 0, y: 0 },
205+
hotspot,
201206
data,
202207
commands
203208
})
@@ -213,7 +218,7 @@ SLPEncoder.prototype.encode = function () {
213218
frames: this.frames
214219
}
215220

216-
let offset = headerStruct.size(header)
221+
let offset = headerStruct.encodingLength(header)
217222
const frameBuffers = this.frames.map((frame) => {
218223
frame.outlineTableOffset = offset
219224
frame.cmdTableOffset = offset + frame.height * 4

0 commit comments

Comments
 (0)