forked from Blendman974/faceclaw
More conservating locking around Android bluetooth APIs, to try to address SIGSEGV seen on Galaxy Tab A9+
This commit is contained in:
1 parent
aa0b1d6874
commit
7cbcbf7c90
5 files changed
+282
-115
No files matched your search
@@ -10,10 +10,7 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
const colors = Array.create("int", image.width * image.height) as number[];
|
||||
for (let i = 0; i < image.pixels.length; i++) {
|
||||
colors[i] = PREVIEW_COLOR_LUT[image.pixels[i] ?? 0]!;
|
||||
}
|
||||
const colors = grayImageToPreviewColors(image);
|
||||
|
||||
const bitmap = android.graphics.Bitmap.createBitmap(
|
||||
colors,
|
||||
@@ -24,6 +21,26 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
||||
return new ImageSource(bitmap);
|
||||
}
|
||||
|
||||
export async function grayImageToPreviewSourceWithBitmapFactory(
|
||||
image: GrayImage,
|
||||
createBitmap: (createColors: () => number[], width: number, height: number) => Promise<any>,
|
||||
): Promise<ImageSource | null> {
|
||||
if (!global.isAndroid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const bitmap = await createBitmap(() => grayImageToPreviewColors(image), image.width, image.height);
|
||||
return new ImageSource(bitmap);
|
||||
}
|
||||
|
||||
function grayImageToPreviewColors(image: GrayImage): number[] {
|
||||
const colors = Array.create("int", image.width * image.height) as number[];
|
||||
for (let i = 0; i < image.pixels.length; i++) {
|
||||
colors[i] = PREVIEW_COLOR_LUT[image.pixels[i] ?? 0]!;
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
function buildPreviewColorLookup(): number[] {
|
||||
const colors: number[] = [];
|
||||
for (let gray = 0; gray <= 255; gray++) {
|
||||
|
||||
Reference in new issue
Block a user