Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blurhashes #1482

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion components/ItemGrid/GridItem.bs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ sub itemContentChanged()

' Set Random background colors from pallet
posterBackgrounds = m.global.constants.poster_bg_pallet
m.backdrop.blendColor = posterBackgrounds[rnd(posterBackgrounds.count()) - 1]
if isValidAndNotEmpty(m.top.itemContent.posterBlurhashUrl):
m.backdrop.uri = m.top.itemContent.posterBlurhashUrl
else
m.backdrop.blendColor = posterBackgrounds[rnd(posterBackgrounds.count()) - 1]
end if

itemData = m.top.itemContent

Expand Down
7 changes: 6 additions & 1 deletion components/ItemGrid/GridItemSmall.bs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "pkg:/source/utils/misc.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub init()
m.itemPoster = m.top.findNode("itemPoster")
Expand All @@ -23,7 +24,11 @@ sub init()
end sub

sub itemContentChanged()
m.backdrop.blendColor = "#101010"
if isValidAndNotEmpty(m.top.itemContent.posterBlurhashUrl):
m.backdrop.uri = m.top.itemContent.posterBlurhashUrl
else
m.backdrop.blendColor = "#101010"
end if

m.title.visible = false

Expand Down
9 changes: 9 additions & 0 deletions components/data/ChannelData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -20,5 +21,13 @@ sub setPoster()

imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in ChannelData."
end if
end if
end if
end sub
10 changes: 10 additions & 0 deletions components/data/CollectionData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"


sub setFields()
json = m.top.json
Expand All @@ -24,6 +26,14 @@ sub setPoster()
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in CollectionData."
end if
end if
else if m.top.json.BackdropImageTags <> invalid
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/FolderData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -27,6 +28,14 @@ sub setPoster()
else if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in FolderData."
end if
end if
end if
end sub

Expand Down
1 change: 1 addition & 0 deletions components/data/JFContentItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<field id="favorite" type="boolean" />
<field id="watched" type="boolean" />
<field id="posterUrl" type="string" />
<field id="posterBlurhashUrl" type="string" />
<field id="backdropUrl" type="string" />
<field id="SubTitle" type="string" value="" />
<field id="iconUrl" type="string" value="" />
Expand Down
9 changes: 9 additions & 0 deletions components/data/MovieData.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/misc.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand Down Expand Up @@ -47,6 +48,14 @@ sub setPoster()
if isValid(m.top.json.ImageTags) and isValid(m.top.json.ImageTags.Primary)
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in MoviesData."
end if
end if
else if isValid(m.top.json.BackdropImageTags) and isValid(m.top.json.BackdropImageTags[0])
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/MusicAlbumSongListData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -18,6 +19,14 @@ sub setPoster()
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295 }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in MusicAlbumSongListData."
end if
end if
else if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 440 }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/MusicArtistData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -21,6 +22,14 @@ sub setPoster()
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 440 }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in MusicArtistData."
end if
end if
else if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 440 }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/PersonData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -18,6 +19,14 @@ sub setPoster()
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in PersonData."
end if
end if
else if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/PhotoData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -20,6 +21,14 @@ sub setPoster()
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in PhotoData."
end if
end if
else if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/ScheduleProgramData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand Down Expand Up @@ -42,6 +43,14 @@ sub setPoster()
if m.top.json.ImageTags <> invalid and m.top.json.ImageTags.Thumb <> invalid
imgParams = { "maxHeight": 500, "maxWidth": 500, "Tag": m.top.json.ImageTags.Thumb }
m.top.posterURL = ImageURL(m.top.json.id, "Thumb", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in ScheduleProgramData."
end if
end if
end if
end if
end sub
9 changes: 9 additions & 0 deletions components/data/SeriesData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand Down Expand Up @@ -38,6 +39,14 @@ sub setPoster()

imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in SeriesData."
end if
end if
else if m.top.json.BackdropImageTags <> invalid
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
Expand Down
9 changes: 9 additions & 0 deletions components/data/TVEpisode.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -21,5 +22,13 @@ sub setPoster()
else if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295 }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in TVEpisode.bs."
end if
end if
end if
end sub
9 changes: 9 additions & 0 deletions components/data/VideoData.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "pkg:/source/api/Image.bs"
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/fakeBlurhash.bs"

sub setFields()
json = m.top.json
Expand All @@ -21,5 +22,13 @@ sub setPoster()
else if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
if isValidAndNotEmpty(m.top.json.ImageBlurHashes.Primary)
blurhash = m.top.json.ImageBlurHashes.Primary[m.top.json.ImageTags.Primary]
if get_user_setting("ui.design.renderblurhashes") = "true" and isValidAndNotEmpty(blurhash)
timer = CreateObject("roTimeSpan")
m.top.posterBlurHashUrl = renderFakeBlurhash(blurhash, imgParams.maxWidth, imgParams.maxHeight)
print "Took " + Str(timer.totalMilliseconds()) + " milliseconds to render a blurhash in VideoData."
end if
end if
end if
end sub
7 changes: 7 additions & 0 deletions settings/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@
"type": "integer",
"default": "365"
},
{
"title": "Render blurhashes",
"description": "Use an EXPERIMENTAL algorithm to render image blurhashes. This may slow down page loading and cause the app the crash.",
"settingName": "ui.design.renderblurhashes",
"type": "bool",
"default": "false"
},
{
"title": "Show What's New Popup",
"description": "Show What's New popup when Jellyfin is updated to a new version.",
Expand Down
Loading
Loading