@bis-toolkit/paa 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @bis-toolkit/paa
2
+
3
+ A library for reading PAA (Real Virtuality texture format) files.
4
+
5
+ Part of the [BIS Toolkit TypeScript](../../README.md) monorepo.
6
+
7
+ ## Features
8
+
9
+ - Read PAA files
10
+ - Support for multiple texture formats (DXT1-5, RGBA variants, AI88)
11
+ - Mipmap handling
12
+ - Channel swizzling
13
+ - Compression support (LZSS, LZO)
14
+ - Format conversion utilities
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @bis-toolkit/paa
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```typescript
25
+ import { Paa } from '@bis-toolkit/paa';
26
+ import * as fs from 'fs';
27
+
28
+ // Read a PAA file
29
+ const buffer = fs.readFileSync('texture.paa');
30
+ const paa = new Paa();
31
+ paa.read(buffer);
32
+
33
+ // Get RGBA pixel data
34
+ const pixelData = paa.getArgb32PixelData(buffer, 0); // mipLevel 0
35
+
36
+ // Access properties
37
+ console.log(`Type: ${paa.type}`);
38
+ console.log(`Mipmaps: ${paa.mipmaps.length}`);
39
+ console.log(`Has Alpha: ${paa.isAlpha}`);
40
+ ```
41
+
42
+ ## Supported Formats
43
+
44
+ - DXT1, DXT2, DXT3, DXT4, DXT5
45
+ - RGBA_5551
46
+ - RGBA_4444
47
+ - RGBA_8888
48
+ - AI88
49
+
50
+ ## API
51
+
52
+ ### Reading PAA Files
53
+
54
+ ```typescript
55
+ import { Paa } from 'bis-toolkit/paa';
56
+ import * as fs from 'fs';
57
+
58
+ const buffer = fs.readFileSync('texture.paa');
59
+ const paa = new Paa();
60
+ paa.read(buffer);
61
+
62
+ // Get pixel data for specific mipmap level
63
+ const pixelData = paa.getArgb32PixelData(buffer, 0);
64
+
65
+ // Access mipmap information
66
+ for (let i = 0; i < paa.mipmaps.length; i++) {
67
+ const mip = paa.mipmaps[i];
68
+ console.log(`Mipmap ${i}: ${mip.width}x${mip.height}`);
69
+ }
70
+ ```
71
+
72
+ ### Channel Swizzling
73
+
74
+ ```typescript
75
+ import { RgbaSwizzle, ChannelSwizzle, ChannelSwizzler } from '@bis-toolkit/paa';
76
+
77
+ // Define custom channel mapping
78
+ const swizzle = new RgbaSwizzle();
79
+ swizzle.swizRed = ChannelSwizzle.Blue;
80
+ swizzle.swizBlue = ChannelSwizzle.Red;
81
+ swizzle.swizGreen = ChannelSwizzle.Green;
82
+ swizzle.swizAlpha = ChannelSwizzle.One; // Force alpha to 255
83
+
84
+ // Apply to RGBA data
85
+ ChannelSwizzler.apply(rgbaData, swizzle);
86
+ ```
87
+
88
+ ## License
89
+
90
+ GPLv3 © Alpine Labs - see [LICENSE](LICENSE).
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Channel swizzle operations
3
+ */
4
+ export declare enum ChannelSwizzle {
5
+ Alpha = 0,
6
+ Red = 1,
7
+ Green = 2,
8
+ Blue = 3,
9
+ InvertedAlpha = 4,
10
+ InvertedRed = 5,
11
+ InvertedGreen = 6,
12
+ InvertedBlue = 7,
13
+ One = 8
14
+ }
15
+ /**
16
+ * RGBA swizzle configuration
17
+ */
18
+ export declare class RgbaSwizzle {
19
+ swizBlue: ChannelSwizzle;
20
+ swizGreen: ChannelSwizzle;
21
+ swizRed: ChannelSwizzle;
22
+ swizAlpha: ChannelSwizzle;
23
+ static readonly Default: RgbaSwizzle;
24
+ equals(other: RgbaSwizzle): boolean;
25
+ }
26
+ /**
27
+ * Utility class for applying channel swizzling to RGBA data
28
+ */
29
+ export declare class ChannelSwizzler {
30
+ static apply(rgbaData: Uint8Array, swizzle: RgbaSwizzle): void;
31
+ private static transformChannel;
32
+ }
@@ -0,0 +1,14 @@
1
+ import { PaaType } from './PaaType';
2
+ import { Palette } from './Palette';
3
+ /**
4
+ * Pixel format conversion utilities
5
+ */
6
+ export declare class PixelFormatConversion {
7
+ private static setColor;
8
+ static argb16ToArgb32(src: Buffer | Uint8Array): Uint8Array;
9
+ static argb1555ToArgb32(src: Buffer | Uint8Array): Uint8Array;
10
+ static ai88ToArgb32(src: Buffer | Uint8Array): Uint8Array;
11
+ static p8ToARGB32(src: Buffer | Uint8Array, palette: Palette): Uint8Array;
12
+ static dxtToRgba32(data: Buffer | Uint8Array, width: number, height: number, format: string, useAlpha?: boolean): Uint8Array;
13
+ static convertToARGB32(data: Buffer | Uint8Array, width: number, height: number, type: PaaType): Uint8Array;
14
+ }
@@ -0,0 +1,20 @@
1
+ import { PaaType } from './PaaType';
2
+ import { BinaryReader } from '@bis-toolkit/utils';
3
+ /**
4
+ * Represents a single mipmap level in a PAA texture
5
+ */
6
+ export declare class Mipmap {
7
+ width: number;
8
+ height: number;
9
+ isLzss: boolean;
10
+ isLzo: boolean;
11
+ private dataOffset;
12
+ private dataSize;
13
+ private rawData;
14
+ private format;
15
+ constructor(format: PaaType);
16
+ constructor(width: number, height: number, data: Buffer | Uint8Array, format: PaaType);
17
+ read(br: BinaryReader): void;
18
+ getRawPixelData(buffer: Buffer | Uint8Array): Uint8Array;
19
+ getRgba32PixelData(buffer: Buffer | Uint8Array): Uint8Array;
20
+ }
package/dist/Paa.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { PaaType } from './PaaType';
2
+ import { PaaColor } from './PaaColor';
3
+ import { Palette } from './Palette';
4
+ import { Mipmap } from './Mipmap';
5
+ import { RgbaSwizzle } from './ChannelSwizzler';
6
+ /**
7
+ * Main PAA file reader/writer class
8
+ */
9
+ export declare class Paa {
10
+ type: PaaType;
11
+ isAlpha: boolean;
12
+ isTransparent: boolean;
13
+ averageColor: PaaColor | null;
14
+ maxColor: PaaColor | null;
15
+ palette: Palette;
16
+ mipmaps: Mipmap[];
17
+ channelSwizzle: RgbaSwizzle;
18
+ private procedure;
19
+ /**
20
+ * Read a PAA file from a buffer
21
+ */
22
+ read(buffer: Buffer | Uint8Array): void;
23
+ /**
24
+ * Get ARGB32 pixel data for a specific mipmap level
25
+ */
26
+ getArgb32PixelData(buffer: Buffer | Uint8Array, mipLevel?: number): Uint8Array;
27
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Represents a color in PAA format (ARGB)
3
+ */
4
+ export declare class PaaColor {
5
+ private _value;
6
+ constructor(value: number);
7
+ constructor(red: number, green: number, blue: number, alpha?: number);
8
+ get alpha(): number;
9
+ get red(): number;
10
+ get green(): number;
11
+ get blue(): number;
12
+ get color(): number;
13
+ private static colorToUint;
14
+ static fromFloat(red: number, green: number, blue: number, alpha: number): PaaColor;
15
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * PAA texture format types
3
+ */
4
+ export declare enum PaaType {
5
+ DXT1 = 65281,
6
+ DXT2 = 65282,
7
+ DXT3 = 65283,
8
+ DXT4 = 65284,
9
+ DXT5 = 65285,
10
+ RGBA_5551 = 5461,
11
+ RGBA_4444 = 17476,
12
+ RGBA_8888 = 34952,
13
+ AI88 = 32896
14
+ }
@@ -0,0 +1,9 @@
1
+ import { PaaColor } from './PaaColor';
2
+ import { BinaryReader } from '@bis-toolkit/utils';
3
+ /**
4
+ * Represents a color palette for indexed PAA formats
5
+ */
6
+ export declare class Palette {
7
+ colors: PaaColor[];
8
+ read(br: BinaryReader): void;
9
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * PAA (Bohemia Interactive texture format) library
3
+ */
4
+ export { Paa } from './Paa';
5
+ export { PaaType } from './PaaType';
6
+ export { PaaColor } from './PaaColor';
7
+ export { Palette } from './Palette';
8
+ export { Mipmap } from './Mipmap';
9
+ export { ChannelSwizzle, RgbaSwizzle, ChannelSwizzler } from './ChannelSwizzler';
10
+ export { PixelFormatConversion } from './FormatConverter';
11
+ export { BinaryReader, lzoDecompress, lzssDecompress, calculateChecksum } from '@bis-toolkit/utils';