Improve image size handling

This commit is contained in:
MrTimscampi 2020-03-11 21:31:04 +01:00
parent 0397283599
commit 8646b66f6c
11 changed files with 24 additions and 26 deletions

View file

@ -2,7 +2,6 @@ define(['datetime', 'imageLoader', 'connectionManager', 'itemHelper', 'focusMana
function (datetime, imageLoader, connectionManager, itemHelper, focusManager, indicators, globalize, layoutManager, appHost, dom, browser, playbackManager, itemShortcuts, imageHelper) {
'use strict';
var devicePixelRatio = window.devicePixelRatio || 1;
var enableFocusTransform = !browser.slow && !browser.edge;
function getCardsHtml(items, options) {
@ -592,7 +591,7 @@ define(['datetime', 'imageLoader', 'connectionManager', 'itemHelper', 'focusMana
});
} else if (item.AlbumId && item.AlbumPrimaryImageTag) {
width = primaryImageAspectRatio ? Math.round(height * primaryImageAspectRatio) : null;
height = width && primaryImageAspectRatio ? Math.round(width / primaryImageAspectRatio) : null;
imgUrl = apiClient.getScaledImageUrl(item.AlbumId, {
type: "Primary",

View file

@ -68,7 +68,7 @@ define(['datetime', 'imageLoader', 'connectionManager', 'layoutManager', 'browse
return apiClient.getScaledImageUrl(item.Id, {
maxWidth: maxWidth,
maxWidth: maxWidth * 2,
tag: chapter.ImageTag,
type: "Chapter",
index: index

View file

@ -114,8 +114,8 @@ define([], function () {
var standardWidths = [480, 720, 1280, 1440, 1920, 2560, 3840, 5120, 7680];
function getScreenWidth() {
var width = window.innerWidth * window.devicePixelRatio;
var height = window.innerHeight * window.devicePixelRatio;
var width = window.innerWidth;
var height = window.innerHeight;
if (height > width) {
/* If we're in portrait, compute the proper width for this height,

View file

@ -106,7 +106,7 @@ define(["apphost", "appSettings", "dom", "connectionManager", "loading", "layout
if (user.PrimaryImageTag) {
imgUrl = apiClient.getUserImageUrl(user.Id, {
width: 300 * window.devicePixelRatio,
width: 300,
tag: user.PrimaryImageTag,
type: "Primary"
});

View file

@ -493,15 +493,15 @@ define(["datetime", "events", "itemHelper", "serverNotifications", "dom", "globa
if (nowPlayingItem.ImageTags && nowPlayingItem.ImageTags.Logo) {
imgUrl = ApiClient.getScaledImageUrl(nowPlayingItem.Id, {
tag: nowPlayingItem.ImageTags.Logo,
maxHeight: 24 * window.devicePixelRatio,
maxWidth: 130 * window.devicePixelRatio,
maxHeight: 24,
maxWidth: 130,
type: "Logo"
});
} else if (nowPlayingItem.ParentLogoImageTag) {
imgUrl = ApiClient.getScaledImageUrl(nowPlayingItem.ParentLogoItemId, {
tag: nowPlayingItem.ParentLogoImageTag,
maxHeight: 24 * window.devicePixelRatio,
maxWidth: 130 * window.devicePixelRatio,
maxHeight: 24,
maxWidth: 130,
type: "Logo"
});
}

View file

@ -334,24 +334,24 @@ define(["playbackManager", "dom", "inputManager", "datetime", "itemHelper", "med
if (item) {
var imgUrl = seriesImageUrl(item, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
maxWidth: osdPoster.clientWidth * 2,
type: "Primary"
}) || seriesImageUrl(item, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
maxWidth: osdPoster.clientWidth * 2,
type: "Thumb"
}) || imageUrl(item, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
maxWidth: osdPoster.clientWidth * 2,
type: "Primary"
});
if (!imgUrl && secondaryItem && (imgUrl = seriesImageUrl(secondaryItem, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
maxWidth: osdPoster.clientWidth * 2,
type: "Primary"
}) || seriesImageUrl(secondaryItem, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
maxWidth: osdPoster.clientWidth * 2,
type: "Thumb"
}) || imageUrl(secondaryItem, {
maxWidth: Math.round(dom.getScreenWidth() * 0.20),
maxWidth: osdPoster.clientWidth * 2,
type: "Primary"
})), imgUrl) {
return void (osdPoster.innerHTML = '<img src="' + imgUrl + '" />');

View file

@ -88,7 +88,7 @@ define(["loading", "dom", "globalize", "humanedate", "paper-icon-button-light",
if (user.PrimaryImageTag) {
imgUrl = ApiClient.getUserImageUrl(user.Id, {
width: 300 * window.devicePixelRatio,
width: 300,
tag: user.PrimaryImageTag,
type: "Primary"
});

View file

@ -59,8 +59,8 @@ define(["libraries/apiclient/apiclientcore", "localassetmanager"], function(ApiC
})
}
function ApiClientEx(serverAddress, clientName, applicationVersion, deviceName, deviceId, devicePixelRatio) {
ApiClient.call(this, serverAddress, clientName, applicationVersion, deviceName, deviceId, devicePixelRatio)
function ApiClientEx(serverAddress, clientName, applicationVersion, deviceName, deviceId) {
ApiClient.call(this, serverAddress, clientName, applicationVersion, deviceName, deviceId)
}
var localPrefix = "local:",
localViewPrefix = "localview:";

View file

@ -58,7 +58,7 @@ define(["events", "appStorage"], function(events, appStorage) {
return request.data && ("string" == typeof request.data ? fetchRequest.body = request.data : (fetchRequest.body = paramsToString(request.data), contentType = contentType || "application/x-www-form-urlencoded; charset=UTF-8")), contentType && (headers["Content-Type"] = contentType), request.timeout ? fetchWithTimeout(request.url, fetchRequest, request.timeout) : fetch(request.url, fetchRequest)
}
function ApiClient(serverAddress, appName, appVersion, deviceName, deviceId, devicePixelRatio) {
function ApiClient(serverAddress, appName, appVersion, deviceName, deviceId) {
if (!serverAddress) {
throw new Error("Must supply a serverAddress");
}
@ -75,7 +75,6 @@ define(["events", "appStorage"], function(events, appStorage) {
this._deviceName = deviceName;
this._appName = appName;
this._appVersion = appVersion;
this._devicePixelRatio = devicePixelRatio;
}
function setSavedEndpointInfo(instance, info) {
@ -218,7 +217,7 @@ define(["events", "appStorage"], function(events, appStorage) {
}
function normalizeImageOptions(instance, options) {
var ratio = instance._devicePixelRatio || 1;
var ratio = window.devicePixelRatio;
ratio && (options.minScale && (ratio = Math.max(options.minScale, ratio)), options.width && (options.width = Math.round(options.width * ratio)), options.height && (options.height = Math.round(options.height * ratio)), options.maxWidth && (options.maxWidth = Math.round(options.maxWidth * ratio)), options.maxHeight && (options.maxHeight = Math.round(options.maxHeight * ratio))), options.quality = options.quality || instance.getDefaultImageQuality(options.type), instance.normalizeImageOptions && instance.normalizeImageOptions(options)
}

View file

@ -186,7 +186,7 @@ define(["events", "apiclient", "appStorage"], function (events, apiClientFactory
Manual: 2
};
var ConnectionManager = function (credentialProvider, appName, appVersion, deviceName, deviceId, capabilities, devicePixelRatio) {
var ConnectionManager = function (credentialProvider, appName, appVersion, deviceName, deviceId, capabilities) {
function onAuthenticated(apiClient, result, options, saveCredentials) {
var credentials = credentialProvider.credentials();
@ -540,7 +540,7 @@ define(["events", "apiclient", "appStorage"], function (events, apiClientFactory
var apiClient = self.getApiClient(server.Id);
if (!apiClient) {
apiClient = new apiClientFactory(serverUrl, appName, appVersion, deviceName, deviceId, devicePixelRatio);
apiClient = new apiClientFactory(serverUrl, appName, appVersion, deviceName, deviceId);
self._apiClients.push(apiClient);
apiClient.serverInfo(server);
apiClient.onAuthenticated = function (instance, result) {

View file

@ -280,7 +280,7 @@ var AppInfo = {};
capabilities.DeviceProfile = deviceProfile;
var connectionManager = new ConnectionManager(credentialProviderInstance, apphost.appName(), apphost.appVersion(), apphost.deviceName(), apphost.deviceId(), capabilities, window.devicePixelRatio);
var connectionManager = new ConnectionManager(credentialProviderInstance, apphost.appName(), apphost.appVersion(), apphost.deviceName(), apphost.deviceId(), capabilities);
defineConnectionManager(connectionManager);
bindConnectionManagerEvents(connectionManager, events, userSettings);
@ -291,7 +291,7 @@ var AppInfo = {};
return require(["apiclient"], function (apiClientFactory) {
console.debug("creating ApiClient singleton");
var apiClient = new apiClientFactory(Dashboard.serverAddress(), apphost.appName(), apphost.appVersion(), apphost.deviceName(), apphost.deviceId(), window.devicePixelRatio);
var apiClient = new apiClientFactory(Dashboard.serverAddress(), apphost.appName(), apphost.appVersion(), apphost.deviceName(), apphost.deviceId());
apiClient.enableAutomaticNetworking = false;
apiClient.manualAddressOnly = true;