Help - Search - Members - Calendar
Full Version: Cover art aspect ratio in foo_looks
Hydrogenaudio Forums > Hosted Forums > foobar2000 > 3rd Party Plugins - (fb2k)
Elviz
I am making a small CD cover UI style for my foobar+TV player. I started modifying the SeeThroughCoverArt.ski and added the support for browsing through the different cover art in the folder.

My problem is that the cover images are not same size. I mean many times theres nice two-page images in the booklets, which cant be split into 2 different pages. Displaying that kind of images in static size area sucks. Of course I could add some space to the top and bottom of the image to make the aspect ratio of the actual image correct, but that sounds like too much work really...

Is there a way to get the original width and height of the image before loading the thumbnail with looks_loadThumbImage? I could determine correct width and height for smaller image.

I tried loading the image 1st with looks_loadImage but i could not figure out if theres a way to get any information out of the "image" structure. However, imo, it should not be required to load the image twice to get that information.

Give code, please smile.gif.

-e
upNorth
I'm also making a cover art look at the moment, as I wanted to have something that fits my needs. I resize some images to keep aspect ratio, but I do it inside the predefined area, hence adding space at the top and bottom (or right left). Resizing the whole look would be easy enough, but I want to keep everything inside the given area.

Here is the LUA function I use to find the new dimensions of the albumart sprite.
CODE
function resize()
local pic = look_loadImage(picture_path_full)
if pic ~= nil then  
 local ratio = image_getWidth(pic) / image_getHeight(pic)
 if ratio > 1 then
  r.height = r.height / ratio
 else
  r.width = r.width * ratio
 end
end
end

Some cut & paste to show how I use it:
CODE

picture_path   = "e:/pictures/"
picture_name   = "$replace(%artist%,'/',_).jpg"
picture_path_full = picture_path .. fb2k_formatTitle(fb2k_getNowPlaying(),picture_name)
resize()
look_setImage(sprite,look_loadThumbImage(picture_path_full,r.width,r.height))


Note: I don't keep aspect ratio for cover art, only for pictures of the artist/band, that will be shown if cover is missing (or if you right click look), but that doesn't really matter. This code is very similar to what I used in my "navigator" look, only simpler.

Anyway, here is the current version of the look I've been working on: simple_cover

Edit: Spelling
Elviz
Thanks! That solved my problem. In my case the script goes like this:

CODE

r = look_getRect(sprite)
art = look_getAlbumArtList()
if (getn(art) > 0 and artindex <= getn(art) and artindex > 0) then

  local pic = look_loadImage(art[artindex])
  local ratio = (image_getWidth(pic) / image_getHeight(pic))
   // multiply ratio with 3/4 if you are viewing the cover art on 16:9 TV
   // ratio = ratio *3 / 4

  local picw = 0
  local pich = 0
  if ratio > 1 then
     picw = r.width
     pich = r.height / ratio
  else
     picw = r.width * ratio
     pich = r.height
  end
  local sx = -(r.width - picw)/2
  local sy = -(r.height - pich)/2
  look_setSrcX(sprite, sx)
  look_setSrcY(sprite, sy)  
     
  look_setImage(sprite,look_loadThumbImage(art[artindex],picw,pich))
else  
  look_setSrcX(sprite, 0)
  look_setSrcY(sprite, 0)
  look_setImage(sprite,look_loadThumbImage(defaultArtFile,r.width,r.height))
end


That renders an image with correct aspect ratio into a static size area, as large as possible.
Hadda
This is part of code from foopilot one to browse image with mouse wheel maybe can be useful:
CODE

image_search=1

function onmousewheel(this,delta)

art = look_getAlbumArtList()
n=getn(art)
if delta<0 then image_search=image_search-1
else image_search=image_search+1 end

if  image_search <1 then  image_search=n
elseif  image_search>n  then  image_search=1 end

if n>1 then
 for ala=1,n do
 for a=1,image_search-1 do
  if art[a]==art[image_search] then
   if delta<0 then image_search=image_search-1
   else image_search=image_search+1 end

   if  image_search <1 then  image_search=n
   elseif  image_search>n  then  image_search=1 end
   break
  end
 end
 end
end
updateImage( fb2k_getNowPlaying(),image_search) -- or function what you have to refresh image (delay is not need here)
end

function onplaybacknewtrack(this)
image_search=1
--...... rest of your code
end


This double loop is using to scan if some images are the same in AlbumArtList

:edit : I'm not sure but before this opration in mousewheel function if you wont to display now playing cover then you mast set focus on now plaing .

PS. Maybe i'm too fast write this function i must check it
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.