Menu

Class KwzParser

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

Hierarchy

Index

Constructors

constructor

  • Create a new KWZ file parser instance

    Parameters

    • arrayBuffer: ArrayBuffer

      an ArrayBuffer containing file data

    • Default value settings: Partial<KwzParserSettings> = {}

      parser settings

    Returns KwzParser

Properties

[Symbol.toStringTag]

[Symbol.toStringTag]: string = "Flipnote Studio 3D KWZ animation file"

Custom object tag

aspect

aspect: number = KwzParser.aspect

Animation frame aspect ratio, reflects KwzParser.aspect

audioClipRatio

audioClipRatio: number

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

audioTracks

audioTracks: FlipnoteAudioTrack[] = KwzParser.audioTracks

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

bgmSpeed

bgmSpeed: number

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

bgmrate

bgmrate: number

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

buffer

buffer: ArrayBuffer

data

data: DataView

duration

duration: number

Animation duration, in seconds

format

format: FlipnoteFormat = FlipnoteFormat.KWZ

File format type, reflects KwzParser.format

frameCount

frameCount: number

Animation frame count

frameSpeed

frameSpeed: number

In-app animation playback speed

framerate

framerate: number

Animation framerate, measured as frames per second

globalPalette

globalPalette: FlipnotePaletteColor[] = KwzParser.globalPalette

Global animation frame color palette, reflects KwzParser.globalPalette

imageHeight

imageHeight: number = KwzParser.height

Animation frame height, reflects KwzParser.height

imageOffsetX

imageOffsetX: number = 0

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

imageOffsetY

imageOffsetY: number = 0

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

imageWidth

imageWidth: number = KwzParser.width

Animation frame width, reflects KwzParser.width

isComment

isComment: boolean = false

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

isDsiLibraryNote

isDsiLibraryNote: boolean = false

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

isFolderIcon

isFolderIcon: boolean = false

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

isSpinoff

isSpinoff: boolean

Spinoffs are remixes of another user's Flipnote

meta

meta: KwzMeta

File metadata, see KwzMeta for structure

numLayerColors

numLayerColors: number = KwzParser.numLayerColors

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

numLayers

numLayers: number = KwzParser.numLayers

Number of animation frame layers, reflects KwzParser.numLayers

palette

Flipnote palette

pointer

pointer: number

publicKey

publicKey: string = KwzParser.publicKey

key used for Flipnote verification, in PEM format

rawSampleRate

rawSampleRate: number = KwzParser.rawSampleRate

Audio track base sample rate, reflects KwzParser.rawSampleRate

sampleRate

sampleRate: number = KwzParser.sampleRate

Audio output sample rate, reflects KwzParser.sampleRate

soundEffectTracks

soundEffectTracks: FlipnoteSoundEffectTrack[] = KwzParser.soundEffectTracks

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

soundMeta

soundMeta: Map<FlipnoteAudioTrack, FlipnoteAudioTrackInfo> = new Map()

File audio track info, see FlipnoteAudioTrackInfo

thumbFrameIndex

thumbFrameIndex: number

Index of the animation frame used as the Flipnote's thumbnail image

Static aspect

aspect: number = 3 / 4

Animation frame aspect ratio

Static audioTracks

audioTracks: FlipnoteAudioTrack[] = [FlipnoteAudioTrack.BGM,FlipnoteAudioTrack.SE1,FlipnoteAudioTrack.SE2,FlipnoteAudioTrack.SE3,FlipnoteAudioTrack.SE4,]

Which audio tracks are available in this format

Static format

format: FlipnoteFormat = FlipnoteFormat.KWZ

File format type

Static globalPalette

globalPalette: FlipnotePaletteColor[] = [KWZ_PALETTE.WHITE,KWZ_PALETTE.BLACK,KWZ_PALETTE.RED,KWZ_PALETTE.YELLOW,KWZ_PALETTE.GREEN,KWZ_PALETTE.BLUE,KWZ_PALETTE.NONE,]

Global animation frame color palette

Static height

height: number = 240

Animation frame height

Static numLayerColors

numLayerColors: number = 2

Number of colors per layer (aside from transparent)

Static numLayers

numLayers: number = 3

Number of animation frame layers

Static publicKey

publicKey: string = KWZ_PUBLIC_KEY

Public key used for Flipnote verification, in PEM format

Static rawSampleRate

rawSampleRate: number = 16364

Audio track base sample rate

Static sampleRate

sampleRate: number = 32768

Audio output sample rate

Static soundEffectTracks

soundEffectTracks: FlipnoteSoundEffectTrack[] = [FlipnoteSoundEffectTrack.SE1,FlipnoteSoundEffectTrack.SE2,FlipnoteSoundEffectTrack.SE3,FlipnoteSoundEffectTrack.SE4,]

Which sound effect tracks are available in this format

Static width

width: number = 320

Animation frame width

Accessors

byteLength

  • get byteLength(): number

bytes

  • get bytes(): Uint8Array

Audio Methods

decodeAudioTrack

decodeSoundFlags

  • decodeSoundFlags(): boolean[][]

getAudioMasterPcm

  • getAudioMasterPcm(dstFreq?: number): Int16Array

getAudioTrackPcm

getAudioTrackRaw

getFrameSoundEffectFlags

getSoundEffectFlags

getSoundEffectFlagsForTrack

hasAudioTrack

isSoundEffectUsedOnFrame

Image Methods

decodeFrame

  • decodeFrame(frameIndex: number, diffingFlag?: number, isPrevFrame?: boolean): [Uint8Array, Uint8Array, Uint8Array]
  • Decode a frame, returning the raw pixel buffers for each layer

    Parameters

    • frameIndex: number
    • Default value diffingFlag: number = 7
    • Default value isPrevFrame: boolean = false

    Returns [Uint8Array, Uint8Array, Uint8Array]

getFrameCameraFlags

  • getFrameCameraFlags(frameIndex: number): boolean[]

getFrameLayerDepths

  • getFrameLayerDepths(frameIndex: number): number[]

getFrameLayerOrder

  • getFrameLayerOrder(frameIndex: number): number[]

getFramePalette

  • 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

    • frameIndex: number

    Returns FlipnotePaletteColor[]

getFramePaletteIndices

  • getFramePaletteIndices(frameIndex: number): number[]
  • 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

    • frameIndex: number

    Returns number[]

getFramePaletteUint32

  • getFramePaletteUint32(frameIndex: number, paletteBuffer?: Uint32Array): Uint32Array

getFramePixels

  • getFramePixels(frameIndex: number, imageBuffer?: Uint8Array, depthStrength?: number, depthEye?: FlipnoteStereoscopicEye): Uint8Array

getFramePixelsRgba

  • getFramePixelsRgba(frameIndex: number, imageBuffer?: Uint32Array, paletteBuffer?: Uint32Array, depthStrength?: number, depthEye?: FlipnoteStereoscopicEye): Uint32Array
  • Get the image for a given frame as an uint32 array of RGBA pixels

    Parameters

    • frameIndex: number
    • Default value imageBuffer: Uint32Array = new Uint32Array(this.imageWidth * this.imageHeight)
    • Default value paletteBuffer: Uint32Array = new Uint32Array(16)
    • Default value depthStrength: number = 0
    • Default value depthEye: FlipnoteStereoscopicEye = FlipnoteStereoscopicEye.Left

    Returns Uint32Array

getIsKeyFrame

  • getIsKeyFrame(frameIndex: number): boolean[]

getLayerPixels

  • getLayerPixels(frameIndex: number, layerIndex: number, imageBuffer?: Uint8Array, depthStrength?: number, depthEye?: FlipnoteStereoscopicEye): Uint8Array
  • Get the pixels for a given frame layer, as palette indices NOTE: layerIndex are not guaranteed to be sorted by 3D depth in KWZs, use getFrameLayerOrder to get the correct sort order first NOTE: if the visibility flag for this layer is turned off, the result will be empty

    Parameters

    • frameIndex: number
    • layerIndex: number
    • Default value imageBuffer: Uint8Array = new Uint8Array(this.imageWidth * this.imageHeight)
    • Default value depthStrength: number = 0
    • Default value depthEye: FlipnoteStereoscopicEye = FlipnoteStereoscopicEye.Left

    Returns Uint8Array

getLayerPixelsRgba

  • getLayerPixelsRgba(frameIndex: number, layerIndex: number, imageBuffer?: Uint32Array, paletteBuffer?: Uint32Array, depthStrength?: number, depthEye?: FlipnoteStereoscopicEye): Uint32Array
  • Get the pixels for a given frame layer, as RGBA pixels NOTE: layerIndex are not guaranteed to be sorted by 3D depth in KWZs, use getFrameLayerOrder to get the correct sort order first NOTE: if the visibility flag for this layer is turned off, the result will be empty

    Parameters

    • frameIndex: number
    • layerIndex: number
    • Default value imageBuffer: Uint32Array = new Uint32Array(this.imageWidth * this.imageHeight)
    • Default value paletteBuffer: Uint32Array = new Uint32Array(16)
    • Default value depthStrength: number = 0
    • Default value depthEye: FlipnoteStereoscopicEye = FlipnoteStereoscopicEye.Left

    Returns Uint32Array

Meta Methods

getFrameAuthor

  • getFrameAuthor(frameIndex: number): string

getThumbnailImage

Other Methods

readBytes

  • readBytes(count: number): Uint8Array

readChars

  • readChars(count: number): string

readHex

  • readHex(count: number, reverse?: boolean): string
  • Parameters

    • count: number
    • Default value reverse: boolean = false

    Returns string

readInt16

  • readInt16(littleEndian?: boolean): number
  • Parameters

    • Default value littleEndian: boolean = true

    Returns number

readInt32

  • readInt32(littleEndian?: boolean): number
  • Parameters

    • Default value littleEndian: boolean = true

    Returns number

readInt8

  • readInt8(): number

readUint16

  • readUint16(littleEndian?: boolean): number
  • Parameters

    • Default value littleEndian: boolean = true

    Returns number

readUint32

  • readUint32(littleEndian?: boolean): number
  • Parameters

    • Default value littleEndian: boolean = true

    Returns number

readUint8

  • readUint8(): number

readWideChars

  • readWideChars(count: number): string

seek

  • seek(offset: number, whence?: SeekOrigin): void
  • Parameters

    • offset: number
    • Optional whence: SeekOrigin

    Returns void

writeBytes

  • writeBytes(bytes: number[] | Uint8Array): void

writeChars

  • writeChars(string: string): void

writeInt16

  • writeInt16(value: number, littleEndian?: boolean): void
  • Parameters

    • value: number
    • Default value littleEndian: boolean = true

    Returns void

writeInt32

  • writeInt32(value: number, littleEndian?: boolean): void
  • Parameters

    • value: number
    • Default value littleEndian: boolean = true

    Returns void

writeInt8

  • writeInt8(value: number): void

writeUint16

  • writeUint16(value: number, littleEndian?: boolean): void
  • Parameters

    • value: number
    • Default value littleEndian: boolean = true

    Returns void

writeUint32

  • writeUint32(value: number, littleEndian?: boolean): void
  • Parameters

    • value: number
    • Default value littleEndian: boolean = true

    Returns void

writeUint8

  • writeUint8(value: number): void

Utility Methods

[Symbol.iterator]

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

getTitle

  • getTitle(formats?: { COMMENT: string; FLIPNOTE: string; ICON: string }): string
  • 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

    • Default value formats: { COMMENT: string; FLIPNOTE: string; ICON: string } = this.titleFormats
      • COMMENT: string
      • FLIPNOTE: string
      • ICON: string

    Returns string

toString

  • toString(): string

Verification Methods

getBody

  • getBody(): Uint8Array

getSignature

  • getSignature(): Uint8Array

verify

  • verify(): Promise<boolean>

Object literals

layerVisibility

layerVisibility: object

Animation frame global layer visibility

1

1: true = true

2

2: true = true

3

3: true = true

titleFormats

titleFormats: object

Default formats used for {@link getTitle()}

COMMENT

COMMENT: string = "Comment by $USERNAME"

FLIPNOTE

FLIPNOTE: string = "Flipnote by $USERNAME"

ICON

ICON: string = "Folder icon"

Static defaultSettings

defaultSettings: object

Default KWZ parser settings

borderCrop

borderCrop: false = false

dsiLibraryNote

dsiLibraryNote: false = false

guessInitialBgmState

guessInitialBgmState: true = true

initialBgmPredictor

initialBgmPredictor: null = null

initialBgmStepIndex

initialBgmStepIndex: null = null

initialSePredictors

initialSePredictors: null = null

initialSeStepIndices

initialSeStepIndices: null = null

quickMeta

quickMeta: false = false