Skip to content

KwzParser

Defined in: src/parsers/KwzParser.ts:246

Parser class for Flipnote Studio 3D’s KWZ animation format. KWZ format docs: https://github.com/Flipnote-Collective/flipnote-studio-3d-docs/wiki/KWZ-Format

Extends

  • BaseParser

Constructors

new KwzParser()

new KwzParser(arrayBuffer, settings): KwzParser

Defined in: src/parsers/KwzParser.ts:426

Create a new KWZ file parser instance

Parameters

ParameterTypeDescription
arrayBufferArrayBufferLikean ArrayBuffer containing file data
settingsPartial<KwzParserSettings>parser settings

Returns

KwzParser

Overrides

BaseParser.constructor

Accessors

bytes

Get Signature

get bytes(): Uint8Array

Defined in: src/utils/DataStream.ts:41

Returns the data as an Uint8Array of bytes.

Returns

Uint8Array

Inherited from

BaseParser.bytes


numBytes

Get Signature

get numBytes(): number

Defined in: src/utils/DataStream.ts:48

Returns the total number of bytes in the data.

Returns

number

Inherited from

BaseParser.numBytes

Properties

defaultSettings

static defaultSettings: KwzParserSettings

Defined in: src/parsers/KwzParser.ts:251

Default KWZ parser settings


format

static format: FlipnoteFormat = FlipnoteFormat.KWZ

Defined in: src/parsers/KwzParser.ts:264

File format type

Overrides

BaseParser.format


width

static width: number = 320

Defined in: src/parsers/KwzParser.ts:268

Animation frame width

Overrides

BaseParser.width


height

static height: number = 240

Defined in: src/parsers/KwzParser.ts:272

Animation frame height

Overrides

BaseParser.height


aspect

static aspect: number

Defined in: src/parsers/KwzParser.ts:276

Animation frame aspect ratio

Overrides

BaseParser.aspect


numLayers

static numLayers: number = 3

Defined in: src/parsers/KwzParser.ts:280

Number of animation frame layers

Overrides

BaseParser.numLayers


numLayerColors

static numLayerColors: number = 2

Defined in: src/parsers/KwzParser.ts:284

Number of colors per layer (aside from transparent)

Overrides

BaseParser.numLayerColors


rawSampleRate

static rawSampleRate: number = 16364

Defined in: src/parsers/KwzParser.ts:288

Audio track base sample rate

Overrides

BaseParser.rawSampleRate


sampleRate

static sampleRate: number = 32768

Defined in: src/parsers/KwzParser.ts:292

Audio output sample rate

Overrides

BaseParser.sampleRate


audioTracks

static audioTracks: FlipnoteAudioTrack[]

Defined in: src/parsers/KwzParser.ts:296

Which audio tracks are available in this format

Overrides

BaseParser.audioTracks


soundEffectTracks

static soundEffectTracks: FlipnoteSoundEffectTrack[]

Defined in: src/parsers/KwzParser.ts:306

Which sound effect tracks are available in this format

Overrides

BaseParser.soundEffectTracks


globalPalette

static globalPalette: FlipnotePaletteColor[]

Defined in: src/parsers/KwzParser.ts:315

Global animation frame color palette

Overrides

BaseParser.globalPalette


publicKey

static publicKey: string = KWZ_PUBLIC_KEY

Defined in: src/parsers/KwzParser.ts:327

Public key used for Flipnote verification, in PEM format

Overrides

BaseParser.publicKey


format

format: FlipnoteFormat = FlipnoteFormat.KWZ

Defined in: src/parsers/KwzParser.ts:340

File format type, reflects KwzParser.format

Overrides

BaseParser.format


[toStringTag]

[toStringTag]: string = 'Flipnote Studio 3D KWZ animation file'

Defined in: src/parsers/KwzParser.ts:344

Custom object tag

Overrides

BaseParser.[toStringTag]


imageWidth

imageWidth: number = KwzParser.width

Defined in: src/parsers/KwzParser.ts:348

Animation frame width, reflects KwzParser.width

Overrides

BaseParser.imageWidth


imageHeight

imageHeight: number = KwzParser.height

Defined in: src/parsers/KwzParser.ts:352

Animation frame height, reflects KwzParser.height

Overrides

BaseParser.imageHeight


aspect

aspect: number = KwzParser.aspect

Defined in: src/parsers/KwzParser.ts:356

Animation frame aspect ratio, reflects KwzParser.aspect

Overrides

BaseParser.aspect


imageOffsetX

imageOffsetX: number = 0

Defined in: src/parsers/KwzParser.ts:360

X offset for the top-left corner of the animation frame

Overrides

BaseParser.imageOffsetX


imageOffsetY

imageOffsetY: number = 0

Defined in: src/parsers/KwzParser.ts:364

Y offset for the top-left corner of the animation frame

Overrides

BaseParser.imageOffsetY


numLayers

numLayers: number = KwzParser.numLayers

Defined in: src/parsers/KwzParser.ts:368

Number of animation frame layers, reflects KwzParser.numLayers

Overrides

BaseParser.numLayers


numLayerColors

numLayerColors: number = KwzParser.numLayerColors

Defined in: src/parsers/KwzParser.ts:372

Number of colors per layer (aside from transparent), reflects KwzParser.numLayerColors

Overrides

BaseParser.numLayerColors


publicKey

publicKey: string = KwzParser.publicKey

Defined in: src/parsers/KwzParser.ts:376

key used for Flipnote verification, in PEM format

Overrides

BaseParser.publicKey


audioTracks

audioTracks: FlipnoteAudioTrack[] = KwzParser.audioTracks

Defined in: src/parsers/KwzParser.ts:384

Which audio tracks are available in this format, reflects KwzParser.audioTracks

Overrides

BaseParser.audioTracks


soundEffectTracks

soundEffectTracks: FlipnoteSoundEffectTrack[] = KwzParser.soundEffectTracks

Defined in: src/parsers/KwzParser.ts:388

Which sound effect tracks are available in this format, reflects KwzParser.soundEffectTracks

Overrides

BaseParser.soundEffectTracks


rawSampleRate

rawSampleRate: number = KwzParser.rawSampleRate

Defined in: src/parsers/KwzParser.ts:392

Audio track base sample rate, reflects KwzParser.rawSampleRate

Overrides

BaseParser.rawSampleRate


sampleRate

sampleRate: number = KwzParser.sampleRate

Defined in: src/parsers/KwzParser.ts:396

Audio output sample rate, reflects KwzParser.sampleRate

Overrides

BaseParser.sampleRate


globalPalette

globalPalette: FlipnotePaletteColor[] = KwzParser.globalPalette

Defined in: src/parsers/KwzParser.ts:400

Global animation frame color palette, reflects KwzParser.globalPalette

Overrides

BaseParser.globalPalette

Methods

matchBuffer()

static matchBuffer(buffer): boolean

Defined in: src/parsers/KwzParser.ts:329

Parameters

ParameterType
bufferArrayBufferLike

Returns

boolean


getFrameDiffingFlag()

getFrameDiffingFlag(frameIndex): number

Defined in: src/parsers/KwzParser.ts:777

Parameters

ParameterType
frameIndexnumber

Returns

number


decodeFrameSoundFlags()

decodeFrameSoundFlags(frameIndex): boolean[]

Defined in: src/parsers/KwzParser.ts:1068

Parameters

ParameterType
frameIndexnumber

Returns

boolean[]


decodeAdpcm()

decodeAdpcm(src, dst, predictor, stepIndex): number

Defined in: src/parsers/KwzParser.ts:1132

Parameters

ParameterTypeDefault value
srcUint8Arrayundefined
dstInt16Arrayundefined
predictornumber0
stepIndexnumber40

Returns

number


pcmAudioMix()

pcmAudioMix(src, dst, dstOffset): void

Defined in: src/parsers/KwzParser.ts:1265

Parameters

ParameterTypeDefault value
srcInt16Arrayundefined
dstInt16Arrayundefined
dstOffsetnumber0

Returns

void


end()

end(): boolean

Defined in: src/utils/DataStream.ts:253

Returns

boolean

Inherited from

BaseParser.end

Meta

titleFormats

titleFormats: object

Defined in: src/parsers/BaseParser.ts:111

Default formats used for getTitle.

NameTypeDefault value
COMMENTstring’Comment by $USERNAME’
FLIPNOTEstring’Flipnote by $USERNAME’
ICONstring’Folder icon’

Inherited from

BaseParser.titleFormats


soundMeta

soundMeta: Map<FlipnoteAudioTrack, FlipnoteAudioTrackInfo>

Defined in: src/parsers/BaseParser.ts:194

File audio track info, see FlipnoteAudioTrackInfo.

Inherited from

BaseParser.soundMeta


isSpinoff

isSpinoff: boolean

Defined in: src/parsers/BaseParser.ts:210

Spinoffs are remixes of another user’s Flipnote.

Inherited from

BaseParser.isSpinoff


isFolderIcon

isFolderIcon: boolean = false

Defined in: src/parsers/BaseParser.ts:215

(KWZ only) Indicates whether or not this file is a Flipnote Studio 3D folder icon.

Inherited from

BaseParser.isFolderIcon


isComment

isComment: boolean = false

Defined in: src/parsers/BaseParser.ts:220

(KWZ only) Indicates whether or not this file is a handwritten comment from Flipnote Gallery World.

Inherited from

BaseParser.isComment


isDsiLibraryNote

isDsiLibraryNote: boolean = false

Defined in: src/parsers/BaseParser.ts:225

(KWZ only) Indicates whether or not this Flipnote is a PPM to KWZ conversion from Flipnote Studio 3D’s DSi Library service.

Inherited from

BaseParser.isDsiLibraryNote


meta

meta: KwzMeta

Defined in: src/parsers/KwzParser.ts:405

File metadata, see KwzMeta for structure.

Overrides

BaseParser.meta


getTitle()

getTitle(formats): string

Defined in: src/parsers/BaseParser.ts:279

Get file default title - e.g. “Flipnote by Y”, “Comment by X”, etc. A format object can be passed for localization, where $USERNAME gets replaced by author name:

{
COMMENT: 'Comment by $USERNAME',
FLIPNOTE: 'Flipnote by $USERNAME',
ICON: 'Folder icon'
}

Parameters

ParameterType
formats{ COMMENT: string; FLIPNOTE: string; ICON: string; }
formats.COMMENTstring
formats.FLIPNOTEstring
formats.ICONstring

Returns

string

Inherited from

BaseParser.getTitle


getThumbnailImage()

getThumbnailImage(): object

Defined in: src/parsers/KwzParser.ts:691

Decodes the thumbnail image embedded in the Flipnote. Will return a FlipnoteThumbImage containing JPEG data.

Note: For most purposes, you should probably just decode the thumbnail frame to get a higher resolution image.

Returns

object

format

format: FlipnoteThumbImageFormat = FlipnoteThumbImageFormat.Jpeg

width

width: number = 80

height

height: number = 64

data

data: ArrayBuffer

Overrides

BaseParser.getThumbnailImage


getMemoryMeterLevel()

getMemoryMeterLevel(): number

Defined in: src/parsers/KwzParser.ts:712

Get the memory meter level for the Flipnote. This is a value between 0 and 1 indicating how “full” the Flipnote is, based on the size calculation formula inside Flipnote Studio 3D.

Values will never be below 0, but can be above 1 if the Flipnote is larger than the size limit - it is technically possible to exceed the size limit by one frame.

Returns

number

Overrides

BaseParser.getMemoryMeterLevel


getFrameAuthor()

getFrameAuthor(frameIndex): string

Defined in: src/parsers/KwzParser.ts:817

Get the FSID for a given frame’s original author.

Parameters

ParameterTypeDescription
frameIndexnumber

Returns

string

Overrides

BaseParser.getFrameAuthor

Image

palette

palette: FlipnotePaletteDefinition

Defined in: src/parsers/BaseParser.ts:184

Flipnote palette.

Inherited from

BaseParser.palette


layerVisibility

layerVisibility: FlipnoteLayerVisibility

Defined in: src/parsers/BaseParser.ts:199

Animation frame global layer visibility.

Inherited from

BaseParser.layerVisibility


frameCount

frameCount: number

Defined in: src/parsers/BaseParser.ts:230

Animation frame count.

Inherited from

BaseParser.frameCount


frameSpeed

frameSpeed: number

Defined in: src/parsers/BaseParser.ts:235

In-app animation playback speed.

Inherited from

BaseParser.frameSpeed


duration

duration: number

Defined in: src/parsers/BaseParser.ts:240

Animation duration, in seconds.

Inherited from

BaseParser.duration


bgmSpeed

bgmSpeed: number

Defined in: src/parsers/BaseParser.ts:245

In-app animation playback speed when the BGM track was recorded.

Inherited from

BaseParser.bgmSpeed


framerate

framerate: number

Defined in: src/parsers/BaseParser.ts:250

Animation framerate, measured as frames per second.

Inherited from

BaseParser.framerate


thumbFrameIndex

thumbFrameIndex: number

Defined in: src/parsers/BaseParser.ts:260

Index of the animation frame used as the Flipnote’s thumbnail image.

Inherited from

BaseParser.thumbFrameIndex


getLayerPixels()

getLayerPixels(frameIndex, layerIndex, imageBuffer, depthStrength, depthEye): Uint8Array

Defined in: src/parsers/BaseParser.ts:351

Get the pixels for a given frame layer, as palette indices

Parameters

ParameterTypeDefault value
frameIndexnumberundefined
layerIndexnumberundefined
imageBufferUint8Array...
depthStrengthnumber0
depthEyeFlipnoteStereoscopicEyeFlipnoteStereoscopicEye.Left

Returns

Uint8Array

Inherited from

BaseParser.getLayerPixels


getLayerPixelsRgba()

getLayerPixelsRgba(frameIndex, layerIndex, imageBuffer, paletteBuffer, depthStrength, depthEye): Uint32Array

Defined in: src/parsers/BaseParser.ts:406

Get the pixels for a given frame layer, as RGBA pixels

Parameters

ParameterTypeDefault value
frameIndexnumberundefined
layerIndexnumberundefined
imageBufferUint32Array...
paletteBufferUint32Array...
depthStrengthnumber0
depthEyeFlipnoteStereoscopicEyeFlipnoteStereoscopicEye.Left

Returns

Uint32Array

Inherited from

BaseParser.getLayerPixelsRgba


getFramePixels()

getFramePixels(frameIndex, imageBuffer, depthStrength, depthEye): Uint8Array

Defined in: src/parsers/BaseParser.ts:488

Get the image for a given frame, as palette indices

Parameters

ParameterTypeDefault value
frameIndexnumberundefined
imageBufferUint8Array...
depthStrengthnumber0
depthEyeFlipnoteStereoscopicEyeFlipnoteStereoscopicEye.Left

Returns

Uint8Array

Inherited from

BaseParser.getFramePixels


getFramePixelsRgba()

getFramePixelsRgba(frameIndex, imageBuffer, paletteBuffer, depthStrength, depthEye): Uint32Array

Defined in: src/parsers/BaseParser.ts:538

Get the image for a given frame as an uint32 array of RGBA pixels

Parameters

ParameterTypeDefault value
frameIndexnumberundefined
imageBufferUint32Array...
paletteBufferUint32Array...
depthStrengthnumber0
depthEyeFlipnoteStereoscopicEyeFlipnoteStereoscopicEye.Left

Returns

Uint32Array

Inherited from

BaseParser.getFramePixelsRgba


getFramePaletteUint32()

getFramePaletteUint32(frameIndex, paletteBuffer): Uint32Array

Defined in: src/parsers/BaseParser.ts:603

Get the color palette for a given frame, as an uint32 array

Parameters

ParameterType
frameIndexnumber
paletteBufferUint32Array

Returns

Uint32Array

Inherited from

BaseParser.getFramePaletteUint32


getFramePaletteIndices()

getFramePaletteIndices(frameIndex): number[]

Defined in: src/parsers/KwzParser.ts:743

Get the color palette indices for a given frame. RGBA colors for these values can be indexed from KwzParser.globalPalette

Returns an array where:

  • index 0 is the paper color index
  • index 1 is the layer A color 1 index
  • index 2 is the layer A color 2 index
  • index 3 is the layer B color 1 index
  • index 4 is the layer B color 2 index
  • index 5 is the layer C color 1 index
  • index 6 is the layer C color 2 index

Parameters

ParameterType
frameIndexnumber

Returns

number[]

Overrides

BaseParser.getFramePaletteIndices


getFramePalette()

getFramePalette(frameIndex): FlipnotePaletteColor[]

Defined in: src/parsers/KwzParser.ts:771

Get the RGBA colors for a given frame

Returns an array where:

  • index 0 is the paper color
  • index 1 is the layer A color 1
  • index 2 is the layer A color 2
  • index 3 is the layer B color 1
  • index 4 is the layer B color 2
  • index 5 is the layer C color 1
  • index 6 is the layer C color 2

Parameters

ParameterType
frameIndexnumber

Returns

FlipnotePaletteColor[]

Overrides

BaseParser.getFramePalette


getIsKeyFrame()

getIsKeyFrame(frameIndex): boolean[]

Defined in: src/parsers/KwzParser.ts:788

Determines if a given frame is a video key frame or not. This returns an array of booleans for each layer, since keyframe encoding is done on a per-layer basis.

Parameters

ParameterTypeDescription
frameIndexnumber

Returns

boolean[]

Overrides

BaseParser.getIsKeyFrame


getFrameLayerDepths()

getFrameLayerDepths(frameIndex): number[]

Defined in: src/parsers/KwzParser.ts:802

Get the 3D depths for each layer in a given frame.

Parameters

ParameterTypeDescription
frameIndexnumber

Returns

number[]

Overrides

BaseParser.getFrameLayerDepths


getFrameCameraFlags()

getFrameCameraFlags(frameIndex): boolean[]

Defined in: src/parsers/KwzParser.ts:828

Get the camera flags for a given frame

Parameters

ParameterType
frameIndexnumber

Returns

boolean[]

Array of booleans, indicating whether each layer uses a photo or not

Overrides

BaseParser.getFrameCameraFlags


getFrameLayerOrder()

getFrameLayerOrder(frameIndex): number[]

Defined in: src/parsers/KwzParser.ts:842

Get the layer draw order for a given frame

Parameters

ParameterType
frameIndexnumber

Returns

number[]

Overrides

BaseParser.getFrameLayerOrder


decodeFrame()

decodeFrame(frameIndex, diffingFlag, isPrevFrame): [Uint8Array, Uint8Array, Uint8Array]

Defined in: src/parsers/KwzParser.ts:852

Decode a frame, returning the raw pixel buffers for each layer

Parameters

ParameterTypeDefault value
frameIndexnumberundefined
diffingFlagnumber0x7
isPrevFramebooleanfalse

Returns

[Uint8Array, Uint8Array, Uint8Array]

Overrides

BaseParser.decodeFrame

Audio

bgmrate

bgmrate: number

Defined in: src/parsers/BaseParser.ts:255

Animation framerate when the BGM track was recorded, measured as frames per second.

Inherited from

BaseParser.bgmrate


audioClipRatio

audioClipRatio: number

Defined in: src/parsers/BaseParser.ts:265

Get the amount of clipping in the master audio track, useful for determining if a Flipnote’s audio is corrupted. Closer to 1.0 = more clipping. Only available after getAudioMasterPcm has been called.

Inherited from

BaseParser.audioClipRatio


getSoundEffectFlagsForTrack()

getSoundEffectFlagsForTrack(trackId): boolean[]

Defined in: src/parsers/BaseParser.ts:637

Get the usage flags for a given track across every frame

Parameters

ParameterType
trackIdFlipnoteSoundEffectTrack

Returns

boolean[]

an array of booleans for every frame, indicating whether the track is used on that frame

Inherited from

BaseParser.getSoundEffectFlagsForTrack


isSoundEffectUsedOnFrame()

isSoundEffectUsedOnFrame(trackId, frameIndex): boolean

Defined in: src/parsers/BaseParser.ts:645

Is a given track used on a given frame

Parameters

ParameterType
trackIdFlipnoteSoundEffectTrack
frameIndexnumber

Returns

boolean

Inherited from

BaseParser.isSoundEffectUsedOnFrame


hasAudioTrack()

hasAudioTrack(trackId): boolean

Defined in: src/parsers/BaseParser.ts:657

Does an audio track exist in the Flipnote?

Parameters

ParameterType
trackIdFlipnoteAudioTrack

Returns

boolean

boolean

Inherited from

BaseParser.hasAudioTrack


decodeSoundFlags()

decodeSoundFlags(): boolean[][]

Defined in: src/parsers/KwzParser.ts:1084

Get the sound effect flags for every frame in the Flipnote

Returns

boolean[][]

Overrides

BaseParser.decodeSoundFlags


getSoundEffectFlags()

getSoundEffectFlags(): FlipnoteSoundEffectFlags[]

Defined in: src/parsers/KwzParser.ts:1097

Get the sound effect usage flags for every frame

Returns

FlipnoteSoundEffectFlags[]

Overrides

BaseParser.getSoundEffectFlags


getFrameSoundEffectFlags()

getFrameSoundEffectFlags(frameIndex): FlipnoteSoundEffectFlags

Defined in: src/parsers/KwzParser.ts:1111

Get the sound effect usage for a given frame

Parameters

ParameterTypeDescription
frameIndexnumber

Returns

FlipnoteSoundEffectFlags

Overrides

BaseParser.getFrameSoundEffectFlags


getAudioTrackRaw()

getAudioTrackRaw(trackId): Uint8Array

Defined in: src/parsers/KwzParser.ts:1126

Get the raw compressed audio data for a given track

Parameters

ParameterType
trackIdFlipnoteAudioTrack

Returns

Uint8Array

Byte array

Overrides

BaseParser.getAudioTrackRaw


decodeAudioTrack()

decodeAudioTrack(trackId): Int16Array

Defined in: src/parsers/KwzParser.ts:1190

Get the decoded audio data for a given track, using the track’s native samplerate

Parameters

ParameterType
trackIdFlipnoteAudioTrack

Returns

Int16Array

Signed 16-bit PCM audio

Overrides

BaseParser.decodeAudioTrack


getAudioTrackPcm()

getAudioTrackPcm(trackId, dstFreq): Int16Array

Defined in: src/parsers/KwzParser.ts:1252

Get the decoded audio data for a given track, using the specified samplerate

Parameters

ParameterType
trackIdFlipnoteAudioTrack
dstFreqnumber

Returns

Int16Array

Signed 16-bit PCM audio

Overrides

BaseParser.getAudioTrackPcm


getAudioMasterPcm()

getAudioMasterPcm(dstFreq): Int16Array

Defined in: src/parsers/KwzParser.ts:1282

Get the full mixed audio for the Flipnote, using the specified samplerate

Parameters

ParameterType
dstFreqnumber

Returns

Int16Array

Signed 16-bit PCM audio

Overrides

BaseParser.getAudioMasterPcm

Verification

getBody()

getBody(): Uint8Array

Defined in: src/parsers/KwzParser.ts:1324

Get the body of the Flipnote - the data that is digested for the signature

Returns

Uint8Array

Overrides

BaseParser.getBody


getSignature()

getSignature(): Uint8Array

Defined in: src/parsers/KwzParser.ts:1333

Get the Flipnote’s signature data

Returns

Uint8Array

Overrides

BaseParser.getSignature


verify()

verify(): Promise<boolean>

Defined in: src/parsers/KwzParser.ts:1342

Verify whether this Flipnote’s signature is valid

Returns

Promise<boolean>

Overrides

BaseParser.verify

Utility

toString()

toString(): string

Defined in: src/parsers/BaseParser.ts:295

Returns the Flipnote title when casting a parser instance to a string.

const str = 'Title: ' + note;
// str === 'Title: Flipnote by username'

Returns

string

Inherited from

BaseParser.toString


[iterator]()

[iterator](): Generator<number, void, unknown>

Defined in: src/parsers/BaseParser.ts:309

Allows for frame index iteration when using the parser instance as a for..of iterator.

for (const frameIndex of note) {
// do something with frameIndex...
}

Returns

Generator<number, void, unknown>

Inherited from

BaseParser.[iterator]