Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions apps/mobile/src/apps/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Camera as VisionCamera, CommonResolutions, useCameraDevices, useCameraP
import { DELIVERIES, FORMATS, PRIMES, opticsFrame } from "@openclapper/fov-math";
import { CONTROLS, focalsOf, REFERENCE_STEPS, type Bar, type ControlId, type Distribution, type Edge, type LayoutBody, type LayoutItem, type PresetBody } from "@openclapper/model";
import { canCall, putFile } from "../api";
import { lenses as lensStore, measureCamera } from "../device";
import { measureCamera, useLensSet } from "../device";
import type { Lens } from "../lenses";
import { leavePreview } from "../link";
import { log } from "../log";
Expand All @@ -22,7 +22,8 @@ import { allLayouts, chooseLayout, useLayout } from "../camera/layouts";
import { captureFact, collecting, endCollection, frameBox, frames, liveView, nextFolder, startCollection, toggles, type FrameChoice } from "../camera/state";
import { Button, Empty, FIXED, Hint, Icon, ListRow, makeStyles, num, RADIUS, SectionLabel, Seg, Sheet, SheetList, SIZE, Slider, toast, type, useTheme, Block, type IconName } from "../ui";
import { registerApp } from "./registry";
import { useCameraButtons } from "../settings";
import * as ScreenOrientation from "expo-screen-orientation";
import { settings, useCameraButtons } from "../settings";

/**
* The camera (docs/features/camera-layouts.md, docs/rewrite/03-capture.md): the phone takes photos; everything else
Expand All @@ -36,13 +37,21 @@ const JUSTIFY: Record<Distribution, "flex-start" | "center" | "flex-end" | "spac

function Camera({ active }: { active: boolean }) {
const sizes = useCameraButtons();
// The Camera tab's own orientation (#426, this device's setting): held in landscape or portrait while the tab is
// open, whatever way the device is held; the app turns freely again when another tab comes to the front.
const orient = settings.use().cameraOrientation ?? "auto";
useEffect(() => {
if (!active || orient === "auto") return;
void ScreenOrientation.lockAsync(orient === "landscape" ? ScreenOrientation.OrientationLock.LANDSCAPE : ScreenOrientation.OrientationLock.PORTRAIT_UP).catch((e) => log("warn", "camera: orientation not locked", e));
return () => { void ScreenOrientation.unlockAsync().catch(() => undefined); };
}, [active, orient]);
const s = useStyles();
const { width, height } = useWindowDimensions();
const project = useProject();
const prefs = usePrefs();
const perm = useCameraPermission();
const devices = useCameraDevices();
const set = lensStore.use();
const set = useLensSet();
const chosen = lensChoice.use();
const presets = usePresets();
const lib = useLibrary();
Expand Down Expand Up @@ -180,7 +189,7 @@ function Camera({ active }: { active: boolean }) {
}
if (i.control === "focal") {
if (!frame || frame.kind === "aspect") return null;
if (preset?.lenses.kind === "zoom") return <View key="focal" style={{ width: vertical ? 64 : 220 }}><Slider label="Focal length" value={frame.focal} min={preset.lenses.from} max={preset.lenses.to} format={(v) => `${v} mm`} onChange={setFocal} /></View>;
if (preset?.lenses.kind === "zoom") return <ZoomRange key="focal" vertical={vertical} value={frame.focal} min={preset.lenses.from} max={preset.lenses.to} onChange={setFocal} />;
if (i.display === "stepped" || frame.kind === "free") return <Stepped key="focal" vertical={vertical} value={`${frame.focal}`} label="Focal length" onStep={(d) => { const k = focals.indexOf(frame.focal), n = focals[k < 0 ? 0 : k + d]; if (n) setFocal(n); }} />;
return <View key="focal" style={[s.strip, vertical && s.stripV]}>{focals.map((mm) => <CamButton key={mm} label={`${mm} mm`} on={mm === frame.focal} onPress={() => setFocal(mm)} text={String(mm)} />)}</View>;
}
Expand Down Expand Up @@ -282,6 +291,38 @@ function Blackout({ box, w, h, color }: { box: { left: number; top: number; widt
}

/** A strip shown one value at a time: back, the value, on; three parts a thumb can hit, stacked in an upright bar. */
/**
* A zoom lens's focal length on the camera (#426): along its bar, horizontal in a top or bottom bar, vertical in a side
* bar (longer at the top); − and + step one millimetre, the track is dragged. Never wider or taller than its bar allows.
*/
function ZoomRange({ vertical, value, min, max, onChange }: { vertical: boolean; value: number; min: number; max: number; onChange: (mm: number) => void }) {
const s = useStyles();
const sizes = useCameraButtons();
const LEN = 150;
const frac = max > min ? (value - min) / (max - min) : 0;
const at = (x: number, y: number) => {
const f = Math.min(1, Math.max(0, vertical ? 1 - y / LEN : x / LEN));
const mm = Math.round(min + f * (max - min));
if (mm !== value) onChange(mm);
};
const track = (
<View style={[s.zoomTrack, vertical ? { width: 32, height: LEN } : { width: LEN, height: 32 }]}
onStartShouldSetResponder={() => true} onMoveShouldSetResponder={() => true} onResponderTerminationRequest={() => false}
onResponderGrant={(e) => at(e.nativeEvent.locationX, e.nativeEvent.locationY)} onResponderMove={(e) => at(e.nativeEvent.locationX, e.nativeEvent.locationY)}>
<View pointerEvents="none" style={[s.zoomRail, vertical ? { width: 4, height: LEN, left: 14 } : { height: 4, width: LEN, top: 14 }]} />
<View pointerEvents="none" style={[s.zoomThumb, vertical ? { left: 6, top: (1 - frac) * LEN - 10 } : { top: 6, left: frac * LEN - 10 }]} />
</View>
);
const less = <CamButton icon="minus" label="Shorter focal length" disabled={value <= min} onPress={() => onChange(Math.max(min, value - 1))} />;
const more = <CamButton icon="plus" label="Longer focal length" disabled={value >= max} onPress={() => onChange(Math.min(max, value + 1))} />;
return (
<View style={[s.zoom, vertical && s.zoomV, { gap: Math.round(sizes.size / 4) }]} accessibilityLabel={`Focal length ${value} mm`}>
{vertical ? <>{more}{track}{less}</> : <>{less}{track}{more}</>}
<Text style={s.zoomValue}>{`${value} mm`}</Text>
</View>
);
}

function Stepped({ vertical, value, label, onStep }: { vertical: boolean; value: string; label: string; onStep: (d: -1 | 1) => void }) {
const s = useStyles();
return (
Expand Down Expand Up @@ -408,6 +449,12 @@ const useStyles = makeStyles(() => ({
strip: { flexDirection: "row", gap: 8, alignItems: "center" },
stripV: { flexDirection: "column" },
stepped: { flexDirection: "row", alignItems: "center", gap: 4, padding: 3, borderRadius: 28, borderWidth: 2, borderColor: FIXED.white, backgroundColor: FIXED.black },
zoom: { flexDirection: "row", alignItems: "center", padding: 4, borderRadius: 28, backgroundColor: FIXED.black, borderWidth: 2, borderColor: FIXED.white },
zoomV: { flexDirection: "column" },
zoomTrack: { position: "relative" },
zoomRail: { position: "absolute", borderRadius: 2, backgroundColor: FIXED.white, opacity: 0.6 },
zoomThumb: { position: "absolute", width: 20, height: 20, borderRadius: 10, backgroundColor: FIXED.white },
zoomValue: { ...type("caption", "bold"), color: FIXED.white, ...num, minWidth: 44, textAlign: "center" },
steppedValue: { ...type("label", "bold"), color: FIXED.white, minWidth: 44, textAlign: "center", ...num },
ctl: { alignItems: "center", gap: 2 },
ctlLabel: { ...type("caption", "bold"), fontSize: 10, color: FIXED.white, opacity: 0.85 },
Expand Down
11 changes: 8 additions & 3 deletions apps/mobile/src/apps/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Pressable, Share, Text, View } from "react-native";
import { changePassword, signOut } from "../api";
import { isSignedIn, onAuthChange, signedInEmail } from "../auth";
import { API_URL, isConfigured } from "../config";
import { device, lenses, renameDevice, reportedModel, setTabs } from "../device";
import { device, lenses, lensesOff, renameDevice, reportedModel, setLensOff, setTabs } from "../device";
import { clearLog, logCount, logText } from "../log";
import { setPrefs, usePrefs, usePrefsPending, type Prefs } from "../prefs";
import { useExtensionsOn, useProject } from "../projects";
Expand Down Expand Up @@ -162,6 +162,7 @@ const hAov = (f: number) => Math.round((2 * Math.atan(36 / (2 * f)) * 180) / Mat
function DevicePage({ back }: { back: () => void }) {
const dev = device.use();
const set = lenses.use();
const off = lensesOff.use();
const email = useEmail();
const [naming, setNaming] = useState<string | null>(null);
const body = dev.file?.body as { kind?: string; screen?: { portrait: { w: number; h: number } } | null } | undefined;
Expand All @@ -172,9 +173,10 @@ function DevicePage({ back }: { back: () => void }) {
{body?.kind && <FieldRow label="Kind" value={body.kind === "tablet" ? "Tablet" : "Phone"} />}
{body?.screen && <FieldRow label="Screen" value={`${body.screen.portrait.w} × ${body.screen.portrait.h} dp`} />}
{email && <FieldRow label="Belongs to" value={email} />}
<Block><SectionLabel>Real lenses, as the camera reports them</SectionLabel></Block>
<Block><SectionLabel>Real lenses, as the camera reports them</SectionLabel><Hint>Switch off a lens the camera reports but the device does not have: no app offers it any more.</Hint></Block>
{set.lenses.length ? set.lenses.map((l) => (
<FieldRow key={l.id} icon="lens" label={l.name + (l.main ? " · main" : "")} value={l.focal35 ? `${l.focal35} mm equivalent · ${hAov(l.focal35)}° wide` : "No focal length reported: no optics frame on this lens"} />
<Toggle key={l.id} icon="lens" label={l.name + (l.main ? " · main" : "")} meta={(l.focal35 ? `${l.focal35} mm equivalent · ${hAov(l.focal35)}° wide` : "No focal length reported: no optics frame on this lens") + (l.main ? " · the main lens is always on" : off.includes(l.id) ? " · switched off: no app offers it" : "")}
value={l.main || !off.includes(l.id)} disabled={l.main} onChange={(on) => setLensOff(l.id, !on)} />
)) : <Block><Hint>Not read yet: open the camera once.</Hint></Block>}
<Block><Hint>No digital zoom: every photo is the full picture of one real lens.</Hint></Block>
<Sheet visible={naming !== null} title="Name of this device" onClose={() => setNaming(null)} doneLabel="Save" onDone={() => { renameDevice(naming ?? ""); setNaming(null); }}>
Expand Down Expand Up @@ -249,6 +251,9 @@ function CameraPage({ back }: { back: () => void }) {
<SectionLabel>Buttons on this device</SectionLabel>
<Seg accessibilityLabel="Camera button size" block value={local.cameraButtons ?? "m"} onChange={(v) => setSettings({ cameraButtons: v })} options={[{ id: "s", label: "Small" }, { id: "m", label: "Medium" }, { id: "l", label: "Large" }]} />
<Hint>The size of the camera's buttons and shutter here only: small suits a phone, large a tablet.</Hint>
<SectionLabel>Orientation of the camera</SectionLabel>
<Seg accessibilityLabel="Camera orientation" block value={local.cameraOrientation ?? "auto"} onChange={(v) => setSettings({ cameraOrientation: v })} options={[{ id: "auto", label: "As held" }, { id: "landscape", label: "Landscape" }, { id: "portrait", label: "Portrait" }]} />
<Hint>While the Camera tab is open the app keeps this orientation, however the device is held; the other tabs turn as usual.</Hint>
</Block>
<Block><SectionLabel>Camera layout on this device</SectionLabel></Block>
{allLayouts().map((l) => <ListRow key={l.id} icon={l.builtin ? "lock" : "camera-layout"} title={l.name} meta={l.builtin ? "Built in" : undefined} selected={layout.id === l.id} trailing={null} onPress={() => chooseLayout(l.id)} />)}
Expand Down
16 changes: 15 additions & 1 deletion apps/mobile/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ export const device = persisted<DeviceState>("device.v2", { userId: null, file:

/** The real lenses as last read from the camera (persisted, so Setup can list them with the camera closed). */
export const lenses = persisted<LensSet>("lenses.v1", { lenses: [], torch: false });
/**
* Lenses switched off on this device (#426): a driver may report a lens that is not there (a 0.8× beside the 0.5×).
* Gone for every app here, and marked `off` in the device file so the Studio leaves it out too. The main lens stays.
*/
export const lensesOff = persisted<string[]>("lensesOff.v1", [], (v) => Array.isArray(v) && v.every((x) => typeof x === "string"));
export function setLensOff(id: string, off: boolean) {
lensesOff.set((all) => (off ? [...new Set([...all, id])] : all.filter((x) => x !== id)));
void syncDevice();
}
/** The lenses the apps offer: the real ones without those switched off. */
export function useLensSet(): LensSet {
const set = lenses.use(), off = lensesOff.use();
return { ...set, lenses: set.lenses.filter((l) => l.main || !off.includes(l.id)) };
}
let lensesRead = false;
function readLenses() {
const set = lensSet(getAllCameraDevices() as unknown as CamLike[]);
Expand Down Expand Up @@ -75,7 +89,7 @@ function report(): DeviceReport {
kind: short >= 600 ? "tablet" : "phone",
make: make.charAt(0).toUpperCase() + make.slice(1),
model: (k.Model ?? k.model ?? "").slice(0, 120),
lenses: lenses.get().lenses.map(deviceLens),
lenses: lenses.get().lenses.map((l) => ({ ...deviceLens(l), ...(!l.main && lensesOff.get().includes(l.id) ? { off: true } : {}) })),
screen: short > 0 ? { portrait: { w: short, h: long }, landscape: { w: long, h: short } } : null,
// Both orientations once both were measured; until then the other one is the first turned round.
...(() => { const a = cameraArea.get(), p = a.portrait ?? (a.landscape && { w: a.landscape.h, h: a.landscape.w }), l = a.landscape ?? (a.portrait && { w: a.portrait.h, h: a.portrait.w }); return p && l ? { camera: { portrait: p, landscape: l } } : {}; })(),
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface LocalSettings {
logging: boolean;
/** How large the camera's buttons are on this device (#426): small on a phone, large on a tablet. */
cameraButtons?: CameraButtonSize;
/** How the app turns while the Camera tab is open (#426): as the device is held, or always landscape or portrait. */
cameraOrientation?: "auto" | "landscape" | "portrait";
}
export type CameraButtonSize = "s" | "m" | "l";
/** The camera's button sizes (dp): the button, its icon, the shutter. */
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/src/apps/DevicesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function PhoneCard({ d, devices, layouts, connected }: { d: FileRec; devices: Fi
<div className="dev-part">
<h4>What it reported</h4>
<p className="dev-fact">Screen {b.screen ? `${b.screen.portrait.w} × ${b.screen.portrait.h}` : "unknown"}{b.camera ? ` · camera area ${b.camera.portrait.w} × ${b.camera.portrait.h}` : ""}</p>
<p className="dev-fact">{b.lenses.length ? b.lenses.map((l) => `${l.name}${l.focal35 ? ` (${l.focal35} mm)` : " (no focal length)"}`).join(", ") : "No lenses reported yet"}</p>
<p className="dev-fact">{b.lenses.length ? b.lenses.map((l) => `${l.name}${l.focal35 ? ` (${l.focal35} mm)` : " (no focal length)"}${(l as { off?: boolean }).off ? ", switched off" : ""}`).join(", ") : "No lenses reported yet"}</p>
</div>
<div className="dev-part">
<h4>Tabs</h4>
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/src/apps/LayoutsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File
const k = Math.min(1, 620 / h, 860 / w);
const placed = bars.flatMap((b) => b.items.map((i) => i.control));
const lensNames = (body.options.lensNames === "account" ? "phone" : body.options.lensNames);
const devLenses = db.lenses?.length ? db.lenses : [{ id: "w", name: "0.5×", focal35: 13 }, { id: "m", name: "1×", focal35: 24, main: true }, { id: "t", name: "5×", focal35: 120 }];
const devLenses = db.lenses?.length ? db.lenses.filter((l) => !(l as { off?: boolean }).off) : [{ id: "w", name: "0.5×", focal35: 13 }, { id: "m", name: "1×", focal35: 24, main: true }, { id: "t", name: "5×", focal35: 120 }];
const lenses = (body.options.lenses.mode === "main" ? devLenses.filter((l) => l.main ?? l.name === "1×").slice(0, 1) : body.options.lenses.mode === "pick" ? devLenses.filter((l) => body.options.lenses.pick.includes(l.id)) : devLenses)
.map((l) => (lensNames === "focal" && l.focal35 ? String(Math.round(l.focal35)) : l.name));
const framed = placed.some((c) => ["frame", "focal", "fit", "blackout", "reference", "upright"].includes(c));
Expand Down
4 changes: 2 additions & 2 deletions docs/features/capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ The phone takes photos. A capture is one photo: queued at once, visible in Media
## Camera (`apps/mobile/src/apps/Camera.tsx`)

- `react-native-vision-camera` 5.2.3: photo output `HIGHEST_4_3` (the sensor's largest 4:3 picture), JPEG quality 1, quality prioritised over speed (#426), preview drawn whole (`contain`) on black, the camera released while another tab is in front or the app is in the background.
- **Real lenses only** ([phone app](phone-app.md#this-device-srcdevicets-srclensests)): a lens is opened as the logical camera at the lens's zoom, or as a camera of its own. No digital zoom, so every photo is the full picture of one real lens and its EXIF describes it. A phone with one lens shows no lens rail.
- **Real lenses only** ([phone app](phone-app.md#this-device-srcdevicets-srclensests); a lens a driver reports but the device does not have is switched off in Setup › This device, #426: no app offers it and the device file marks it `off`): a lens is opened as the logical camera at the lens's zoom, or as a camera of its own. No digital zoom, so every photo is the full picture of one real lens and its EXIF describes it. A phone with one lens shows no lens rail.
- **Lens names**: as the phone calls them (0.5×, 1×, 5×), or by the reported full-frame focal length (Setup, Camera; the account's preference).
- **Built-in layout**: held upright, the lens rail above the control row; in landscape the control row stands at the right (beside the tab bar), the lens rail at the far left. Control row: uploads (count, red when something is stuck; opens Setup, Uploads), the last photo (opens it in Media), the shutter, the torch (filled when on). A strip over the picture names the project and the lens in use.
- Camera buttons are black with a white outline and a white icon when off, so they read over any picture, and filled in the accent colour when on (#426). Their size (with the shutter and the last-photo thumbnail) is chosen per device in Setup › Camera: small (40 dp), medium (48), large (60), kept in this device's settings (`cameraButtons`).
- Camera buttons are black with a white outline and a white icon when off, so they read over any picture, and filled in the accent colour when on (#426). Their size (with the shutter and the last-photo thumbnail) is chosen per device in Setup › Camera: small (40 dp), medium (48), large (60), kept in this device's settings (`cameraButtons`). The **orientation** of the Camera tab is chosen there too (#426): as held, landscape or portrait; while the tab is open the app keeps it (`expo-screen-orientation`), the other tabs turn as usual. A zoom preset's **focal length** control follows its bar: horizontal in a top or bottom bar, vertical in a side bar with + at the top; − and + step a millimetre, the track is dragged.

## What a capture produces (`src/media/pipeline.ts`)

Expand Down
3 changes: 3 additions & 0 deletions packages/model/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ export interface DeviceLens {
focal35: number | null;
/** The zoom factor of the logical camera at which this lens takes over, where the camera reports one. */
zoom: number | null;
/** Switched off on the device (#426): a lens a driver reports that is not there; no app offers it. */
off?: boolean;
}

/**
Expand All @@ -208,6 +210,7 @@ export const DEVICE: FileType = {
if (!isRecord(l) || !short(l.id, 60) || !short(l.name, 20)) return "a lens has an id and a name";
if (!(l.focal35 === null || (typeof l.focal35 === "number" && l.focal35 > 0 && l.focal35 < 2000))) return "a lens's focal35 is a positive number or null";
if (!(l.zoom === null || (typeof l.zoom === "number" && l.zoom > 0 && l.zoom < 1000))) return "a lens's zoom is a positive number or null";
if (l.off !== undefined && typeof l.off !== "boolean") return "a lens's off is true or false";
}
if (!(body.screen === null || (isRecord(body.screen) && size(body.screen.portrait) && size(body.screen.landscape)))) return "screen holds portrait and landscape sizes";
if (!Array.isArray(body.tabs) || body.tabs.length > 20 || !body.tabs.every((t) => typeof t === "string" && APP_ID.test(t))) return "tabs must be a list of app ids";
Expand Down
Loading