mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
feat(photos): a photo knows its colours and its calm areas
Photo signals move to version 3: a deterministic palette, a busy grid and the point of most detail, stored as measured values, never as image bytes.
This commit is contained in:
@@ -16,6 +16,10 @@ export class TrekPhotoSignals {
|
||||
orig_width?: number | null;
|
||||
orig_height?: number | null;
|
||||
computed_at!: string & Opt;
|
||||
palette?: string | null;
|
||||
busy?: string | null;
|
||||
sal_x?: number | null;
|
||||
sal_y?: number | null;
|
||||
}
|
||||
|
||||
export const TrekPhotoSignalsSchema = defineEntity({
|
||||
@@ -34,5 +38,9 @@ export const TrekPhotoSignalsSchema = defineEntity({
|
||||
orig_width: p.integer().nullable(),
|
||||
orig_height: p.integer().nullable(),
|
||||
computed_at: p.type(DbTimestampType).defaultRaw(`CURRENT_TIMESTAMP`),
|
||||
palette: p.text().nullable(),
|
||||
busy: p.text().nullable(),
|
||||
sal_x: p.double().nullable(),
|
||||
sal_y: p.double().nullable(),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,4 +13,8 @@ export interface TrekPhotoSignalsTable {
|
||||
orig_width: InsertOptional<number | null>;
|
||||
orig_height: InsertOptional<number | null>;
|
||||
computed_at: InsertOptional<string>;
|
||||
palette: InsertOptional<string | null>;
|
||||
busy: InsertOptional<string | null>;
|
||||
sal_x: InsertOptional<number | null>;
|
||||
sal_y: InsertOptional<number | null>;
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
* What else a photo's pixels say, for the assistant's book design: its main
|
||||
* colours (`palette`, JSON of up to five `"#rrggbb:share"`), where it is busy
|
||||
* and where calm (`busy`, an 8 x 8 grid of edge density, one hex digit per
|
||||
* cell, row by row) and where its detail gathers (`sal_x`, `sal_y`, 0 to 1 of
|
||||
* each side; an estimate, no face detection). Measured with the rest of the
|
||||
* signals; a row of an older measurement is measured again.
|
||||
*/
|
||||
export class Migration20200101046270_a_photo_knows_its_colours_and_calm_areas extends Migration {
|
||||
override name = 'Migration20200101046270_a_photo_knows_its_colours_and_calm_areas';
|
||||
|
||||
override up(): void {
|
||||
this.addSql('ALTER TABLE trek_photo_signals ADD COLUMN palette TEXT');
|
||||
this.addSql('ALTER TABLE trek_photo_signals ADD COLUMN busy TEXT');
|
||||
this.addSql('ALTER TABLE trek_photo_signals ADD COLUMN sal_x REAL');
|
||||
this.addSql('ALTER TABLE trek_photo_signals ADD COLUMN sal_y REAL');
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,13 @@ export interface TrekPhotoSignalWrite {
|
||||
clipped: number | null;
|
||||
orig_width: number | null;
|
||||
orig_height: number | null;
|
||||
/** The main colours as JSON of up to five `"#rrggbb:share"`; absent or null when not measured. */
|
||||
palette?: string | null;
|
||||
/** An 8 x 8 grid of edge density, one hex digit per cell, row by row. */
|
||||
busy?: string | null;
|
||||
/** Where the detail gathers, 0 to 1 of each side. */
|
||||
sal_x?: number | null;
|
||||
sal_y?: number | null;
|
||||
}
|
||||
|
||||
/** A stored measurement, with when it was made. */
|
||||
@@ -68,6 +75,10 @@ export class TrekPhotoSignalsRepository extends TrekRepository<TrekPhotoSignals>
|
||||
'orig_width',
|
||||
'orig_height',
|
||||
'computed_at',
|
||||
'palette',
|
||||
'busy',
|
||||
'sal_x',
|
||||
'sal_y',
|
||||
])
|
||||
.where('photo_id', 'in', chunk)
|
||||
.execute(),
|
||||
@@ -81,7 +92,7 @@ export class TrekPhotoSignalsRepository extends TrekRepository<TrekPhotoSignals>
|
||||
const computedAt = dbNow();
|
||||
await this.db()
|
||||
.insertInto('trek_photo_signals')
|
||||
.values({ ...row, computed_at: computedAt })
|
||||
.values({ ...row, ...colours(row), computed_at: computedAt })
|
||||
.onConflict((oc) =>
|
||||
oc.column('photo_id').doUpdateSet({
|
||||
algo: row.algo,
|
||||
@@ -91,6 +102,7 @@ export class TrekPhotoSignalsRepository extends TrekRepository<TrekPhotoSignals>
|
||||
clipped: row.clipped,
|
||||
orig_width: row.orig_width,
|
||||
orig_height: row.orig_height,
|
||||
...colours(row),
|
||||
computed_at: computedAt,
|
||||
}),
|
||||
)
|
||||
@@ -124,3 +136,13 @@ export class TrekPhotoSignalsRepository extends TrekRepository<TrekPhotoSignals>
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
/** The colour signals of a measurement, null where it has none, so an update never keeps an older one's. */
|
||||
function colours(row: TrekPhotoSignalWrite) {
|
||||
return {
|
||||
palette: row.palette ?? null,
|
||||
busy: row.busy ?? null,
|
||||
sal_x: row.sal_x ?? null,
|
||||
sal_y: row.sal_y ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user