Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The ktx-parse npm package is a utility for parsing KTX (Khronos Texture) files, which are used for storing textures in a standardized format. This package allows developers to read and manipulate KTX files in JavaScript, making it useful for applications that need to handle texture data, such as game engines, 3D rendering applications, and other graphics-related software.
Parsing KTX Files
This feature allows you to parse a KTX file and extract its contents. The code sample demonstrates how to read a KTX file from the filesystem and parse it using the ktx-parse package.
const ktxParse = require('ktx-parse');
const fs = require('fs');
const ktxData = fs.readFileSync('path/to/texture.ktx');
const parsedKTX = ktxParse(ktxData);
console.log(parsedKTX);
Accessing Texture Data
This feature allows you to access the raw texture data from a parsed KTX file. The code sample shows how to extract the texture data from the first mip level of the parsed KTX file.
const ktxParse = require('ktx-parse');
const fs = require('fs');
const ktxData = fs.readFileSync('path/to/texture.ktx');
const parsedKTX = ktxParse(ktxData);
const textureData = parsedKTX.levels[0].levelData;
console.log(textureData);
Extracting Metadata
This feature allows you to extract metadata from a KTX file. The code sample demonstrates how to read the key-value metadata pairs from a parsed KTX file.
const ktxParse = require('ktx-parse');
const fs = require('fs');
const ktxData = fs.readFileSync('path/to/texture.ktx');
const parsedKTX = ktxParse(ktxData);
const metadata = parsedKTX.keyValue;
console.log(metadata);
The ktx package is another utility for working with KTX files. It provides similar functionality to ktx-parse, including parsing and manipulating KTX files. However, ktx-parse is often preferred for its simplicity and ease of use.
The three package is a popular 3D library that includes support for loading and using KTX textures. While it offers a broader range of features for 3D rendering, it may be more complex to use if you only need to work with KTX files.
The gl-texture2d package is a WebGL utility for handling 2D textures, including KTX files. It provides functionality for creating and managing textures in WebGL, making it a good choice for web-based graphics applications.
KTX 2.0 (.ktx2) parser and serializer.
Install:
npm install --save ktx-parse
Import:
// ES Modules:
import { read, write } from 'ktx-parse';
// CommonJS:
const { read, write } = require('ktx-parse');
Usage:
// Parse texture container from file:
const texture = read(data /* ← Uint8Array or Buffer */);
// Write texture container to file:
const data = write(texture); // → Uint8Array
See API documentation for more details.
KTX-Parse reads/writes KTX 2.0 containers, and provides access to the compressed texture data within the container. To decompress that texture data, or to compress existing texture data into GPU texture formats used by KTX 2.0, you'll need to use additional libraries such as encoders or transcoders.
Encoding:
Encoding GPU textures is a slow process, and should be completed at development/authoring time so that the compressed texture can be transmitted to the viewing device. GPU textures require much less GPU memory than image formats like PNG or JPEG, and can be uploaded to the GPU quickly with less impact on framerate. GPU textures can also have smaller filesizes in many, but not all, cases. See the Basis documentation for details on this process.
basisu
CLI tool does not provide the data necessary for writing a KTX 2.0 file.ktx-parse
can then read or edit. While probably easier than using the basis_universal encoders directly, the KTX-Software library is somewhat larger and has more dependencies.Transcoding / Decoding:
Basis Universal texture formats (ETC1S and UASTC) cannot be directly read by a GPU, but are designed to be very efficiently rewritten into many of the specific GPU texture formats that different GPUs require. This process is called transcoding, and typically happens on the viewing device after a target output format (e.g. ETC1, ASTC, BC1, ...) is chosen. These transcoders can also fully decode texture data to uncompressed RGBA formats, if raw pixel data is required.
The transcoders above cannot read KTX 2.0 files directly. Instead, unpack the KTX 2.0 files with ktx-parse
first, then transcode the mip levels using a low-level transcoder.
▸ read(data
: Uint8Array): KTX2Container
Defined in src/read.ts:14
Parses a KTX 2.0 file, returning an unpacked KTX2Container
instance with all associated
data. The container's mip levels and other binary data are pointers into the original file, not
copies, so the original file should not be overwritten after reading.
Name | Type | Description |
---|---|---|
data | Uint8Array | Bytes of KTX 2.0 file, as Uint8Array or Buffer. |
Returns: KTX2Container
▸ write(container
: KTX2Container
, options?
: WriteOptions
): Uint8Array
Defined in src/write.ts:21
Serializes a KTX2Container
instance to a KTX 2.0 file. Mip levels and other binary data
are copied into the resulting Uint8Array, so the original container can safely be edited or
destroyed after it is serialized.
Options:
Name | Type | Default value | Description |
---|---|---|---|
container | KTX2Container | - | |
options | WriteOptions | {} |
Returns: Uint8Array
Represents an unpacked KTX 2.0 texture container. Data for individual mip levels are stored in
the .levels
array, typically compressed in Basis Universal formats. Additional properties
provide metadata required to process, transcode, and upload these textures.
• dataFormatDescriptor: KTX2DataFormatDescriptorBasicFormat
[] = [{ vendorId: KHR_DF_VENDORID_KHRONOS, descriptorType: KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT, descriptorBlockSize: 0, versionNumber: KHR_DF_VERSION, colorModel: KHR_DF_MODEL_UNSPECIFIED, colorPrimaries: KHR_DF_PRIMARIES_BT709, transferFunction: KHR_DF_TRANSFER_SRGB, flags: KHR_DF_FLAG_ALPHA_STRAIGHT, texelBlockDimension: [0, 0, 0, 0], bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0], samples: [], }]
Defined in src/container.ts:47
Data Format Descriptor.
• faceCount: number = 1
Defined in src/container.ts:38
Number of cubemap faces. For cubemaps and cubemap arrays, faceCount
must be 6. For all
other textures, faceCount
must be 1. Cubemap faces are stored in +X, -X, +Y, -Y, +Z, -Z
order.
• globalData: KTX2GlobalDataBasisLZ
| null = null
Defined in src/container.ts:65
Supercompression Global Data.
• keyValue: { [key:string]: string | Uint8Array; }
Defined in src/container.ts:62
Key/Value Data.
• layerCount: number = 0
Defined in src/container.ts:31
Number of array elements (array textures only).
• levels: KTX2Level
[] = []
Defined in src/container.ts:44
Mip levels, ordered largest (original) to smallest (~1px).
• pixelDepth: number = 0
Defined in src/container.ts:28
Depth of the texture image for level 0, in pixels (3D textures only).
• pixelHeight: number = 0
Defined in src/container.ts:25
Height of the texture image for level 0, in pixels.
• pixelWidth: number = 0
Defined in src/container.ts:22
Width of the texture image for level 0, in pixels.
• supercompressionScheme: number = KHR_SUPERCOMPRESSION_NONE
Defined in src/container.ts:41
Indicates which supercompression scheme has been applied to mip level images, if any.
• typeSize: number = 1
Defined in src/container.ts:19
Size of the data type in bytes used to upload the data to a graphics API. When vkFormat
is
VK_FORMAT_UNDEFINED, typeSize
must be 1.
• vkFormat: number = VK_FORMAT_UNDEFINED
Defined in src/container.ts:13
Specifies the image format using Vulkan VkFormat enum values. When using Basis Universal
texture formats, vkFormat
must be VK_FORMAT_UNDEFINED.
FAQs
KTX 2.0 (.ktx2) parser and serializer.
The npm package ktx-parse receives a total of 87,167 weekly downloads. As such, ktx-parse popularity was classified as popular.
We found that ktx-parse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.