Author: titmuss
Date: Fri Mar 28 09:30:14 2008
New Revision: 2154
URL: http://svn.slimdevices.com?rev=2154&root=Jive&view=rev
Log:
Bug: 7642
Description:
Fix rendering of artwork where height > width.
Store the compressed images in the artwork cache. A weak table is used as a
short term cache for artwork that has already been converted into image
surfaces.
Modified:
trunk/squeezeplay/src/squeezeplay/share/applets/DefaultSkin/DefaultSkinApplet.lua
trunk/squeezeplay/src/squeezeplay/share/jive/slim/ArtworkCache.lua
trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua
Modified:
trunk/squeezeplay/src/squeezeplay/share/applets/DefaultSkin/DefaultSkinApplet.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/applets/DefaultSkin/DefaultSkinApplet.lua?rev=2154&root=Jive&r1=2153&r2=2154&view=diff
==============================================================================
---
trunk/squeezeplay/src/squeezeplay/share/applets/DefaultSkin/DefaultSkinApplet.lua
(original)
+++
trunk/squeezeplay/src/squeezeplay/share/applets/DefaultSkin/DefaultSkinApplet.lua
Fri Mar 28 09:30:14 2008
@@ -962,10 +962,11 @@
s.albumitem.text.fg = TEXT_COLOR
s.albumitem.text.sh = TEXT_SH_COLOR
s.albumitem.icon = {}
+ s.albumitem.icon.w = 56
s.albumitem.icon.h = WH_FILL
- s.albumitem.icon.align = "left"
+ s.albumitem.icon.align = "center"
s.albumitem.icon.img = Surface:loadImage(imgpath ..
"menu_album_noartwork.png")
- s.albumitem.icon.padding = { 8, 0, 0, 0 }
+ s.albumitem.icon.border = { 8, 0, 0, 0 }
s.albumitemNoAction = {}
s.albumitemNoAction.order = { "text" }
@@ -1116,10 +1117,11 @@
s.albumcurrent.text.fg = TEXT_COLOR
s.albumcurrent.text.sh = TEXT_SH_COLOR
s.albumcurrent.icon = {}
+ s.albumcurrent.icon.w = 56
s.albumcurrent.icon.h = WH_FILL
- s.albumcurrent.icon.align = "left"
+ s.albumcurrent.icon.align = "center"
s.albumcurrent.icon.img = Surface:loadImage(imgpath ..
"menu_album_noartwork.png")
- s.albumcurrent.icon.padding = { 8, 0, 0, 0 }
+ s.albumcurrent.icon.border = { 8, 0, 0, 0 }
s.albumcurrent.play = {}
s.albumcurrent.play.img = Surface:loadImage(imgpath ..
"menu_nowplaying.png")
Modified: trunk/squeezeplay/src/squeezeplay/share/jive/slim/ArtworkCache.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/jive/slim/ArtworkCache.lua?rev=2154&root=Jive&r1=2153&r2=2154&view=diff
==============================================================================
--- trunk/squeezeplay/src/squeezeplay/share/jive/slim/ArtworkCache.lua
(original)
+++ trunk/squeezeplay/src/squeezeplay/share/jive/slim/ArtworkCache.lua Fri Mar
28 09:30:14 2008
@@ -80,7 +80,7 @@
end
-- loaded artwork
- local bytes = value:getBytes()
+ local bytes = #value
self.total = self.total + bytes
@@ -117,7 +117,7 @@
end
self.lru = entry.prev
- self.total = self.total - entry.value:getBytes()
+ self.total = self.total - #entry.value
end
if log:isDebug() then
Modified: trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua?rev=2154&root=Jive&r1=2153&r2=2154&view=diff
==============================================================================
--- trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua (original)
+++ trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua Fri Mar 28
09:30:14 2008
@@ -253,8 +253,13 @@
-- queue of artwork to fetch
artworkFetchQueue = {},
- artworkFetchCount = 0
+ artworkFetchCount = 0,
+
+ -- loaded images
+ imageCache = {},
})
+
+ setmetatable(obj.imageCache, { __mode = "kv" })
obj.id = obj:idFor(ip, port, name)
@@ -459,6 +464,38 @@
end
+-- convert artwork to a resized image
+local function _loadArtworkImage(self, cacheKey, chunk, size)
+ -- create a surface
+ local image = Surface:loadImageData(chunk, #chunk)
+
+ local w, h = image:getSize()
+
+ -- don't display empty artwork
+ if w == 0 or h == 0 then
+ self.imageCache[cacheKey] = true
+ return nil
+ end
+
+ -- Resize image
+ -- Note this allows for artwork to be resized to a larger
+ -- size than the original. This is intentional so smaller cover
+ -- art will still fill the space properly on the Now Playing screen
+ if w ~= size and h ~= size then
+ image = image:rotozoom(0, size / w, 1)
+ if logcache:isDebug() then
+ local wnew, hnew = image:getSize()
+ logcache:debug("Resized artwork from ", w, "x", h, " to
", wnew, "x", hnew)
+ end
+ end
+
+ -- cache image
+ self.imageCache[cacheKey] = image
+
+ return image
+end
+
+
-- _getArworkThumbSink
-- returns a sink for artwork so we can cache it as Surface before sending it
forward
local function _getArtworkThumbSink(self, cacheKey, size)
@@ -481,38 +518,19 @@
if chunk then
logcache:debug("_getArtworkThumbSink(", iconId, ", ",
size, ")")
- -- create a surface
- local artwork = Surface:loadImageData(chunk, #chunk)
-
- -- Resize image if we have a size arg
- -- Note this allows for artwork to be resized to a
larger
- -- size than the original. This is intentional so
smaller cover
- -- art will still fill the space properly on the Now
Playing screen
- local w, h = artwork:getSize()
- if w ~= size then
- artwork = artwork:rotozoom(0, size / w, 1)
- if logcache:isDebug() then
- local wnew, hnew = artwork:getSize()
- logcache:debug("Resized artwork from ",
w, "x", h, " to ", wnew, "x", hnew)
- end
- end
-
- -- don't display empty artwork
- if w == 0 or h == 0 then
- artwork = nil
- end
+ -- store the compressed artwork in the cache
+ self.artworkCache:set(cacheKey, chunk)
+
+ local image = _loadArtworkImage(self, cacheKey, chunk,
size)
-- set it to all icons waiting for it
local icons = self.artworkThumbIcons
for icon, key in pairs(icons) do
if key == cacheKey then
- icon:setValue(artwork)
+ icon:setValue(image)
icons[icon] = nil
end
end
-
- -- store the artwork in the cache
- self.artworkCache:set(cacheKey, artwork)
end
end
end
@@ -689,10 +707,31 @@
-- common parts of fetchArtworkThumb and fetchArtworkURL
function _fetchArtworkURL(self, icon, iconId, size, cacheKey, url)
- -- do we have the artwork in the cache
+
+ -- do we have an image cached
+ local image = self.imageCache[cacheKey]
+ if image then
+ logcache:debug("..image in cache")
+
+ -- are we requesting it already?
+ if image == true then
+ if icon then
+ icon:setValue(nil)
+ self.artworkThumbIcons[icon] = cacheKey
+ end
+ return
+ else
+ if icon then
+ icon:setValue(image)
+ self.artworkThumbIcons[icon] = nil
+ end
+ return
+ end
+ end
+
+ -- or do is the compressed artwork cached
local artwork = self.artworkCache:get(cacheKey)
if artwork then
- -- are we requesting it already?
if artwork == true then
logcache:debug("..artwork already requested")
if icon then
@@ -703,7 +742,8 @@
else
logcache:debug("..artwork in cache")
if icon then
- icon:setValue(artwork)
+ image = _loadArtworkImage(self, cacheKey,
artwork, size)
+ icon:setValue(image)
self.artworkThumbIcons[icon] = nil
end
return
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins