Minor improvements for rescale_needed()
This commit is contained in:
parent
4850423118
commit
e5c8128c9d
|
@ -111,27 +111,21 @@ artwork_read(char *path, struct evbuffer *evbuf)
|
||||||
static int
|
static int
|
||||||
rescale_needed(AVCodecContext *src, int max_w, int max_h, int *target_w, int *target_h)
|
rescale_needed(AVCodecContext *src, int max_w, int max_h, int *target_w, int *target_h)
|
||||||
{
|
{
|
||||||
int need_rescale;
|
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_ART, "Original image dimensions: w %d h %d\n", src->width, src->height);
|
DPRINTF(E_DBG, L_ART, "Original image dimensions: w %d h %d\n", src->width, src->height);
|
||||||
|
|
||||||
need_rescale = 1;
|
*target_w = src->width;
|
||||||
|
*target_h = src->height;
|
||||||
|
|
||||||
if ((max_w <= 0) || (max_h <= 0)) /* No valid dimensions, use original */
|
if ((src->width == 0) || (src->height == 0)) /* Unknown source size, can't rescale */
|
||||||
{
|
return 0;
|
||||||
need_rescale = 0;
|
|
||||||
|
|
||||||
*target_w = src->width;
|
if ((max_w <= 0) || (max_h <= 0)) /* No valid target dimensions, use original */
|
||||||
*target_h = src->height;
|
return 0;
|
||||||
}
|
|
||||||
else if ((src->width <= max_w) && (src->height <= max_h)) /* Smaller than target */
|
|
||||||
{
|
|
||||||
need_rescale = 0;
|
|
||||||
|
|
||||||
*target_w = src->width;
|
if ((src->width <= max_w) && (src->height <= max_h)) /* Smaller than target */
|
||||||
*target_h = src->height;
|
return 0;
|
||||||
}
|
|
||||||
else if (src->width * max_h > src->height * max_w) /* Wider aspect ratio than target */
|
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_w * ((double)src->height / (double)src->width);
|
*target_h = (double)max_w * ((double)src->height / (double)src->width);
|
||||||
|
@ -155,7 +149,7 @@ rescale_needed(AVCodecContext *src, int max_w, int max_h, int *target_w, int *ta
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_ART, "Destination width %d height %d\n", *target_w, *target_h);
|
DPRINTF(E_DBG, L_ART, "Destination width %d height %d\n", *target_w, *target_h);
|
||||||
|
|
||||||
return need_rescale;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in New Issue