npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@webxr-jp/texture-compression

v0.1.0

Published

Texture compression utilities for avatar-optimizer using WebAssembly

Readme

@webxr-jp/texture-compression

avatar-optimizer向けのテクスチャ圧縮ユーティリティパッケージ。Basis Universal WASMを使用してKTX2形式(UASTC)でテクスチャを圧縮します。

特徴

  • KTX2形式出力: GPU対応の圧縮テクスチャフォーマット
  • UASTC圧縮: 高品質なユニバーサルテクスチャ圧縮
  • Zstandard超圧縮: オプションでさらなるファイルサイズ削減
  • ブラウザ専用: WebAssemblyベースで高速処理

インストール

pnpm add @webxr-jp/texture-compression

使用方法

基本的な圧縮

import { compressToKtx2, initBasisEncoder } from '@webxr-jp/texture-compression'

// WASMモジュールを初期化(初回のみ)
const initResult = await initBasisEncoder()
if (initResult.isErr()) {
  console.error('初期化エラー:', initResult.error)
  return
}

// RGBAピクセルデータを圧縮
const imageData = new Uint8Array(width * height * 4) // RGBA
const result = await compressToKtx2(imageData, width, height)

if (result.isOk()) {
  const ktx2Data = result.value.data // Uint8Array
  console.log(
    `圧縮完了: ${result.value.originalSize} → ${result.value.compressedSize} bytes`,
  )
}

オプション設定

import { compressToKtx2, UastcQuality } from '@webxr-jp/texture-compression'

const result = await compressToKtx2(imageData, width, height, {
  quality: UastcQuality.Default, // 品質レベル (0-4)
  compressionLevel: 3, // 圧縮レベル (0-5)
  generateMipmaps: false, // ミップマップ生成
  supercompression: true, // Zstandard超圧縮
})

Y軸反転

WebGLテクスチャ座標系(左下原点)からKTX2座標系(左上原点)への変換が必要な場合:

import { flipImageY, compressToKtx2 } from '@webxr-jp/texture-compression'

const flippedData = flipImageY(imageData, width, height)
const result = await compressToKtx2(flippedData, width, height)

エンコーダー管理

import {
  initBasisEncoder,
  disposeBasisEncoder,
  isBasisEncoderReady,
} from '@webxr-jp/texture-compression'

// 初期化確認
if (!isBasisEncoderReady()) {
  await initBasisEncoder()
}

// 使用後にリソース解放(オプション)
disposeBasisEncoder()

API

compressToKtx2(imageData, width, height, options?)

RGBAピクセルデータをKTX2形式に圧縮します。

  • imageData: Uint8Array - RGBAピクセルデータ(width × height × 4 bytes)
  • width: number - 画像の幅
  • height: number - 画像の高さ
  • options: Ktx2CompressionOptions - 圧縮オプション(省略可)

戻り値: ResultAsync<Ktx2CompressionResult, CompressionError>

flipImageY(imageData, width, height)

Y軸を反転したピクセルデータを生成します。

initBasisEncoder(wasmDir?)

BasisEncoder WASMモジュールを初期化します。

  • wasmDir: string - WASMファイルのディレクトリURL(省略時はパッケージ内のwasmディレクトリ)

disposeBasisEncoder()

キャッシュされたモジュールを解放します。

isBasisEncoderReady()

WASMモジュールが初期化済みかどうかを返します。

型定義

Ktx2CompressionOptions

interface Ktx2CompressionOptions {
  quality?: UastcQuality // UASTC品質レベル (デフォルト: Default)
  compressionLevel?: number // 圧縮レベル 0-5 (デフォルト: 3)
  generateMipmaps?: boolean // ミップマップ生成 (デフォルト: false)
  supercompression?: boolean // Zstandard超圧縮 (デフォルト: true)
}

UastcQuality

enum UastcQuality {
  Fastest = 0, // 最速、最低品質
  Faster = 1, // 高速
  Default = 2, // デフォルト
  Slower = 3, // 低速、高品質
  VerySlow = 4, // 最高品質
}

Ktx2CompressionResult

interface Ktx2CompressionResult {
  data: Uint8Array // 圧縮後のKTX2バイナリデータ
  originalSize: number // 元のサイズ (bytes)
  compressedSize: number // 圧縮後のサイズ (bytes)
  width: number // 画像の幅
  height: number // 画像の高さ
}

注意事項

  • ブラウザ環境専用です(Node.js非対応)
  • 2のべき乗でないサイズの画像は警告が出ますが処理は継続します
  • 大きなテクスチャの場合、出力バッファは最大24MBに制限されています