@mentra/sdk 2.1.9 → 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,7 +215,7 @@ 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
|
@@ -207,7 +227,7 @@ class BitmapUtils {
|
|
207
227
|
}
|
208
228
|
// No padding needed, just return as hex
|
209
229
|
console.log(`finalBmpData: ${finalBmpData.length} bytes`);
|
210
|
-
return finalBmpData
|
230
|
+
return finalBmpData;
|
211
231
|
}
|
212
232
|
catch (error) {
|
213
233
|
if (error instanceof Error) {
|
@@ -245,9 +265,9 @@ class BitmapUtils {
|
|
245
265
|
const fileName = filePattern.replace("{i}", frameNumber.toString());
|
246
266
|
const filePath = path.join(basePath, fileName);
|
247
267
|
try {
|
248
|
-
const frameHex = await this.
|
268
|
+
const frameHex = await this.loadBmpFromFileAsBase64(filePath);
|
249
269
|
if (validateFrames) {
|
250
|
-
const validation = this.
|
270
|
+
const validation = this.validateBmpBase64(frameHex);
|
251
271
|
if (!validation.isValid) {
|
252
272
|
const errorMsg = `Frame ${frameNumber} validation failed: ${validation.errors.join(", ")}`;
|
253
273
|
if (skipMissingFrames) {
|
@@ -298,12 +318,13 @@ class BitmapUtils {
|
|
298
318
|
* }
|
299
319
|
* ```
|
300
320
|
*/
|
301
|
-
static
|
321
|
+
static validateBmpBase64(base64String) {
|
302
322
|
const errors = [];
|
303
323
|
let byteCount = 0;
|
304
324
|
let blackPixels = 0;
|
305
325
|
const metadata = {};
|
306
326
|
try {
|
327
|
+
const hexString = Buffer.from(base64String, "base64").toString("hex");
|
307
328
|
// Basic hex validation
|
308
329
|
if (typeof hexString !== "string" || hexString.length === 0) {
|
309
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",
|