@mentra/sdk 2.1.8 → 2.1.10
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.
@@ -66,13 +66,16 @@ export declare class BitmapUtils {
|
|
66
66
|
*
|
67
67
|
* @example
|
68
68
|
* ```typescript
|
69
|
-
* const
|
70
|
-
* session.layouts.showBitmapView(
|
69
|
+
* const bmpBase64 = await BitmapUtils.loadBmpFromFileAsBase64('./assets/icon.bmp');
|
70
|
+
* session.layouts.showBitmapView(bmpBase64);
|
71
71
|
* ```
|
72
72
|
*/
|
73
|
+
static loadBmpFromFileAsBase64(filePath: string): Promise<string>;
|
73
74
|
static loadBmpFromFileAsHex(filePath: string): Promise<string>;
|
74
75
|
static convert24BitTo1BitBMP(input24BitBmp: Buffer): Promise<Buffer>;
|
75
76
|
static loadBmpFromDataAsHex(bmpData: Buffer): Promise<string>;
|
77
|
+
static loadBmpFromDataAsBase64(bmpData: Buffer): Promise<string>;
|
78
|
+
static padBmpData(bmpData: Buffer): Promise<Buffer>;
|
76
79
|
/**
|
77
80
|
* Load multiple BMP frames as hex array for animations
|
78
81
|
*
|
@@ -110,7 +113,7 @@ export declare class BitmapUtils {
|
|
110
113
|
* }
|
111
114
|
* ```
|
112
115
|
*/
|
113
|
-
static
|
116
|
+
static validateBmpBase64(base64String: string): BitmapValidation;
|
114
117
|
/**
|
115
118
|
* Convert bitmap data between different formats
|
116
119
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"bitmap-utils.d.ts","sourceRoot":"","sources":["../../src/utils/bitmap-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,M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AE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GACpC,MAAM,GAAG,MAAM;IA+BlB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG;QACvC,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,OAAO,CAAC;KACrB;CAsCF"}
|
@@ -69,10 +69,22 @@ class BitmapUtils {
|
|
69
69
|
*
|
70
70
|
* @example
|
71
71
|
* ```typescript
|
72
|
-
* const
|
73
|
-
* session.layouts.showBitmapView(
|
72
|
+
* const bmpBase64 = await BitmapUtils.loadBmpFromFileAsBase64('./assets/icon.bmp');
|
73
|
+
* session.layouts.showBitmapView(bmpBase64);
|
74
74
|
* ```
|
75
75
|
*/
|
76
|
+
static async loadBmpFromFileAsBase64(filePath) {
|
77
|
+
try {
|
78
|
+
const bmpData = await fs.readFile(filePath);
|
79
|
+
return this.loadBmpFromDataAsBase64(bmpData);
|
80
|
+
}
|
81
|
+
catch (error) {
|
82
|
+
if (error instanceof Error) {
|
83
|
+
throw new Error(`Failed to load BMP file ${filePath}: ${error.message}`);
|
84
|
+
}
|
85
|
+
throw new Error(`Failed to load BMP file ${filePath}: Unknown error`);
|
86
|
+
}
|
87
|
+
}
|
76
88
|
static async loadBmpFromFileAsHex(filePath) {
|
77
89
|
try {
|
78
90
|
const bmpData = await fs.readFile(filePath);
|
@@ -180,6 +192,14 @@ class BitmapUtils {
|
|
180
192
|
return output1BitBmp;
|
181
193
|
}
|
182
194
|
static async loadBmpFromDataAsHex(bmpData) {
|
195
|
+
const paddedBmpData = await this.padBmpData(bmpData);
|
196
|
+
return paddedBmpData.toString("hex");
|
197
|
+
}
|
198
|
+
static async loadBmpFromDataAsBase64(bmpData) {
|
199
|
+
const paddedBmpData = await this.padBmpData(bmpData);
|
200
|
+
return paddedBmpData.toString("base64");
|
201
|
+
}
|
202
|
+
static async padBmpData(bmpData) {
|
183
203
|
try {
|
184
204
|
// Basic BMP validation - check for BMP signature
|
185
205
|
if (bmpData.length < 14 || bmpData[0] !== 0x42 || bmpData[1] !== 0x4d) {
|
@@ -195,18 +215,19 @@ class BitmapUtils {
|
|
195
215
|
const paddedImage = new jimp_1.Jimp({
|
196
216
|
width: 576,
|
197
217
|
height: 135,
|
198
|
-
color:
|
218
|
+
color: 0x00000000,
|
199
219
|
});
|
200
220
|
// // Calculate position to place the original image (with padding)
|
201
221
|
const leftPadding = 50; // 45px padding on left
|
202
222
|
const topPadding = 35; // 35px padding on top
|
203
223
|
// Composite the original image onto the white canvas
|
224
|
+
// paddedImage.composite(image, leftPadding, topPadding);
|
204
225
|
paddedImage.composite(image, leftPadding, topPadding);
|
205
226
|
finalBmpData = await this.convert24BitTo1BitBMP(await paddedImage.getBuffer("image/bmp"));
|
206
227
|
}
|
207
228
|
// No padding needed, just return as hex
|
208
229
|
console.log(`finalBmpData: ${finalBmpData.length} bytes`);
|
209
|
-
return finalBmpData
|
230
|
+
return finalBmpData;
|
210
231
|
}
|
211
232
|
catch (error) {
|
212
233
|
if (error instanceof Error) {
|
@@ -244,9 +265,9 @@ class BitmapUtils {
|
|
244
265
|
const fileName = filePattern.replace("{i}", frameNumber.toString());
|
245
266
|
const filePath = path.join(basePath, fileName);
|
246
267
|
try {
|
247
|
-
const frameHex = await this.
|
268
|
+
const frameHex = await this.loadBmpFromFileAsBase64(filePath);
|
248
269
|
if (validateFrames) {
|
249
|
-
const validation = this.
|
270
|
+
const validation = this.validateBmpBase64(frameHex);
|
250
271
|
if (!validation.isValid) {
|
251
272
|
const errorMsg = `Frame ${frameNumber} validation failed: ${validation.errors.join(", ")}`;
|
252
273
|
if (skipMissingFrames) {
|
@@ -297,12 +318,13 @@ class BitmapUtils {
|
|
297
318
|
* }
|
298
319
|
* ```
|
299
320
|
*/
|
300
|
-
static
|
321
|
+
static validateBmpBase64(base64String) {
|
301
322
|
const errors = [];
|
302
323
|
let byteCount = 0;
|
303
324
|
let blackPixels = 0;
|
304
325
|
const metadata = {};
|
305
326
|
try {
|
327
|
+
const hexString = Buffer.from(base64String, "base64").toString("hex");
|
306
328
|
// Basic hex validation
|
307
329
|
if (typeof hexString !== "string" || hexString.length === 0) {
|
308
330
|
errors.push("Hex string is empty or invalid");
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@mentra/sdk",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.10",
|
4
4
|
"description": "Build apps for MentraOS smartglasses. This SDK provides everything you need to create real-time smartglasses applications.",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"main": "dist/index.js",
|