import { Size } from '../Size'; import display from "@ohos.display"; import hilog from '@ohos.hilog'; function isCloselySize(u4, v4, w4) { let x4 = Math.abs(u4.width - w4.width) + Math.abs(u4.height - w4.height); let y4 = Math.abs(v4.width - w4.width) + Math.abs(v4.height - w4.height); return x4 > y4; } export class DefaultPreviewProfileSelector { selector(k4, l4) { let m4 = l4[0]; let n4 = k4.targetSize; let o4 = n4; let p4 = display.getDefaultDisplaySync(); let q4 = []; for (let r4 = 0; r4 < l4.length; r4++) { const s4 = l4[r4]; let t4 = new Size(s4.size.width, s4.size.height); if (t4.getRote() < 1 || (t4.width < o4.width && t4.height < o4.height)) { continue; } if (o4.equals(t4) && o4.getRote() == t4.getRote()) { hilog.info(0x0000, "CameraX", `PreviewProfileSelector selsect best profile: ${t4.toString()} format: ${s4.format}`); return s4; } if (Math.abs(t4.getRote() - o4.getRote()) <= 0.2) { q4.push(s4); if (isCloselySize(m4.size, t4, o4)) { m4 = s4; } } } hilog.info(0x0000, "CameraX", `PreviewProfileSelector selsect closely profile: ${m4.size.width} ${m4.size.height} format: ${m4.format}`); return m4; } } export class DefaultVideoProfileSelector { selector(a4, b4) { let c4 = a4.targetSize; let d4 = c4; let e4 = display.getDefaultDisplaySync(); let f4 = []; let g4 = b4[0]; for (let h4 = 0; h4 < b4.length; h4++) { const i4 = b4[h4]; let j4 = new Size(i4.size.width, i4.size.height); if (j4.getRote() < 1 || (j4.width < d4.width && j4.height < d4.height)) { continue; } if (d4.equals(j4) && d4.getRote() == j4.getRote()) { hilog.info(0x0000, "CameraX", `DefaultVideoProfileSelector selsect best profile: ${j4.toString()} format: ${i4.format}`); return i4; } if (Math.abs(j4.getRote() - d4.getRote()) <= 0.2) { f4.push(i4); if (isCloselySize(g4.size, j4, d4)) { g4 = i4; } } } hilog.info(0x0000, "CameraX", `DefaultVideoProfileSelector selsect closely profile: ${g4.size.width} ${g4.size.height} format: ${g4.format}`); return g4; } } 