Don't assume max_h==max_w (a target aspect ratio of 1) when sending artwork

- Remote 4 will send max_w=128 and max_h=160 for artwork in the Album tab
This commit is contained in:
ejurgensen 2013-11-06 23:52:19 +01:00
parent 862cde3849
commit afa35ac55c

View File

@ -594,27 +594,21 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
need_rescale = 1; need_rescale = 1;
/* Determine width/height -- assuming max_w == max_h */ if ((src->width <= max_w) && (src->height <= max_h)) /* Smaller than target */
if ((src->width <= max_w) && (src->height <= max_h))
{ {
need_rescale = 0; need_rescale = 0;
target_w = src->width; target_w = src->width;
target_h = src->height; target_h = src->height;
} }
else if (src->width > src->height) else if (src->width * max_h > src->height * max_w) /* Wider aspect ratio than target */
{ {
target_w = max_w; target_w = max_w;
target_h = (double)max_h * ((double)src->height / (double)src->width); target_h = (double)max_w * ((double)src->height / (double)src->width);
} }
else if (src->height > src->width) else /* Taller or equal aspect ratio */
{ {
target_h = max_h; target_w = (double)max_h * ((double)src->width / (double)src->height);
target_w = (double)max_w * ((double)src->width / (double)src->height);
}
else
{
target_w = max_w;
target_h = max_h; target_h = max_h;
} }