Skip to content

Commit

Permalink
Merge pull request #47 from SmilyOrg/strip
Browse files Browse the repository at this point in the history
Add strip viewer, remove NaturalViewer
  • Loading branch information
SmilyOrg committed Jan 8, 2023
2 parents e3c6f02 + db75bad commit 8de9c74
Show file tree
Hide file tree
Showing 32 changed files with 2,392 additions and 1,476 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,9 @@ quirks that exist in the current version.
* `Escape` or pinch out to get back to the list of photos
* Zoom in/out directly with `Ctrl/Cmd`+`Wheel`
* Pinch-to-zoom on touch devices
* ⚠ You have to currently tap to zoom first - this is undesirable behavior, but
fixing it is a little tricky right now.
* Press/hold `Arrow Left` or `Arrow Right` to quickly switch between photos
* There is currently no other easy way to do this and that's not great,
especially on touch-only devices.
* Right-click or long-tap as usual to open context menu. It's custom due to the
fact that the native one is not useful for common use-cases as the images
aren't loaded individually.
* Right-click or long-tap as usual to open a custom context menu allowing you to
copy or download original photos or thumbnails.

![context menu](docs/assets/context-menu.png)

Expand Down
38 changes: 31 additions & 7 deletions api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ paths:
schema:
$ref: "#/components/schemas/CollectionId"

- name: scene_width
- name: viewport_width
in: query
schema:
$ref: "#/components/schemas/SceneWidth"
$ref: "#/components/schemas/ViewportWidth"

- name: viewport_height
in: query
schema:
$ref: "#/components/schemas/ViewportHeight"

- name: image_height
in: query
Expand Down Expand Up @@ -159,6 +164,12 @@ paths:
minimum: 1
example: 256

- name: background_color
in: query
schema:
type: string
example: "#000000"

- name: zoom
in: query
required: true
Expand Down Expand Up @@ -593,14 +604,16 @@ components:
type: object
required:
- collection_id
- scene_width
- image_height
- viewport_width
- viewport_height
- layout
properties:
collection_id:
$ref: "#/components/schemas/CollectionId"
scene_width:
$ref: "#/components/schemas/SceneWidth"
viewport_width:
$ref: "#/components/schemas/ViewportWidth"
viewport_height:
$ref: "#/components/schemas/ViewportHeight"
image_height:
$ref: "#/components/schemas/ImageHeight"
layout:
Expand Down Expand Up @@ -628,11 +641,21 @@ components:
type: string
example: Tqcqtc6h69

SceneWidth:
ViewportWidth:
type: number
minimum: 0
example: 1200

ViewportHeight:
type: number
minimum: 0
example: 800

ImageWidth:
type: number
minimum: 0
example: 400

ImageHeight:
type: number
minimum: 0
Expand Down Expand Up @@ -677,6 +700,7 @@ components:
- ALBUM
- SQUARE
- WALL
- STRIP

Problem:
type: object
Expand Down
11 changes: 11 additions & 0 deletions internal/image/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ type SimilarityInfo struct {
Similarity float32
}

func SimilarityInfosToSourcedInfos(sinfos <-chan SimilarityInfo) <-chan SourcedInfo {
out := make(chan SourcedInfo)
go func() {
for sinfo := range sinfos {
out <- sinfo.SourcedInfo
}
close(out)
}()
return out
}

type CacheConfig struct {
MaxSize string `json:"max_size"`
}
Expand Down
4 changes: 2 additions & 2 deletions internal/layout/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func LayoutAlbum(layout Layout, collection collection.Collection, scene *render.

sceneMargin := 10.

scene.Bounds.W = layout.SceneWidth
scene.Bounds.W = layout.ViewportWidth

event := AlbumEvent{
First: true,
Expand All @@ -96,7 +96,7 @@ func LayoutAlbum(layout Layout, collection collection.Collection, scene *render.

rect := render.Rect{
X: sceneMargin,
Y: sceneMargin,
Y: sceneMargin + 64,
W: scene.Bounds.W - sceneMargin*2,
H: 0,
}
Expand Down
12 changes: 7 additions & 5 deletions internal/layout/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ const (
Square Type = "SQUARE"
Wall Type = "WALL"
Search Type = "SEARCH"
Strip Type = "STRIP"
)

type Layout struct {
Type Type `json:"type"`
SceneWidth float64
ImageHeight float64
ImageSpacing float64
LineSpacing float64
Type Type `json:"type"`
ViewportWidth float64
ViewportHeight float64
ImageHeight float64
ImageSpacing float64
LineSpacing float64
}

type Section struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/layout/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func LayoutSearch(layout Layout, collection collection.Collection, scene *render
sceneMargin := 10.
falloff := 5.

scene.Bounds.W = layout.SceneWidth
scene.Bounds.W = layout.ViewportWidth

rect := render.Rect{
X: sceneMargin,
Expand Down
96 changes: 96 additions & 0 deletions internal/layout/strip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package layout

import (
// . "photofield/internal"

"log"
"photofield/internal/collection"
"photofield/internal/image"
"photofield/internal/metrics"
"photofield/internal/render"

"time"
)

func LayoutStrip(layout Layout, collection collection.Collection, scene *render.Scene, source *image.Source) {

limit := collection.Limit

var infos <-chan image.SourcedInfo

if scene.Search != "" {
infos = image.SimilarityInfosToSourcedInfos(
collection.GetSimilar(source, scene.SearchEmbedding, image.ListOptions{
Limit: limit,
}),
)
} else {
infos = collection.GetInfos(source, image.ListOptions{
OrderBy: image.DateAsc,
Limit: limit,
})
}

layout.ImageSpacing = 0.02 * layout.ViewportWidth

rect := render.Rect{
X: 0,
Y: 0,
W: layout.ViewportWidth,
H: layout.ViewportHeight,
}

scene.Bounds.H = float64(rect.H)

scene.Solids = make([]render.Solid, 0)
scene.Texts = make([]render.Text, 0)

layoutPlaced := metrics.Elapsed("layout placing")
layoutCounter := metrics.Counter{
Name: "layout",
Interval: 1 * time.Second,
}

lastLogTime := time.Now()

scene.Photos = scene.Photos[:0]
index := 0
for info := range infos {
if limit > 0 && index >= limit {
break
}

imageRect := render.Rect{
X: 0,
Y: 0,
W: float64(info.Width),
H: float64(info.Height),
}

scene.Photos = append(scene.Photos, render.Photo{
Id: info.Id,
Sprite: render.Sprite{
Rect: imageRect.FitInside(rect),
},
})

rect.X += float64(rect.W) + layout.ImageSpacing

now := time.Now()
if now.Sub(lastLogTime) > 1*time.Second {
lastLogTime = now
log.Printf("layout strip %d\n", index)
}

layoutCounter.Set(index)
index++
scene.FileCount = index
}
layoutPlaced()

scene.Bounds.W = rect.X

scene.RegionSource = PhotoRegionSource{
Source: source,
}
}
2 changes: 1 addition & 1 deletion internal/layout/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func LayoutTimeline(layout Layout, collection collection.Collection, scene *rend

sceneMargin := 10.

scene.Bounds.W = layout.SceneWidth
scene.Bounds.W = layout.ViewportWidth

event := TimelineEvent{}
eventCount := 0
Expand Down
4 changes: 2 additions & 2 deletions internal/layout/wall.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func LayoutWall(layout Layout, collection collection.Collection, scene *render.S

edgeCount := int(math.Sqrt(float64(photoCount)))

scene.Bounds.W = layout.SceneWidth
scene.Bounds.W = layout.ViewportWidth
cols := edgeCount

layoutConfig := Layout{}
layoutConfig.ImageSpacing = layout.SceneWidth / float64(edgeCount) * 0.02
layoutConfig.ImageSpacing = layout.ViewportWidth / float64(edgeCount) * 0.02
layoutConfig.LineSpacing = layoutConfig.ImageSpacing

log.Printf("layout wall width %v cols %v\n", scene.Bounds.W, cols)
Expand Down
Loading

0 comments on commit 8de9c74

Please sign in to comment.