The algorithm here could be to sort the images by width, and remove all
those that are wider than the available width (except for the widest one
if they're all too wide) or that don't have a width unless none have
widths, then sort them by height and remove all those that are taller than the available height (except the tallest one if they are all too tall) or
that don't have a height unless none have heights, then sort them by pixel density and remove all those that are for densities greater than the
current one (except the lowest one if they are all greater), then remove all those that are for densities less than the current one (except the
highest one if they are all lower), assuming that any without a specified density are implicitly 1x, then of the remaining images pick the widest
one, if any have a width, tie-breaking by picking the tallest one, if any have a height, finally tie-breaking by picking the first one, if none have
any dimensions.
Authoring-conformance-wise, that means that if any specify a width, they
all must; if any specify a height, they all must; and omitting the pixel
density is fine but is treated as 1x. At least one of the three must be
specified, since otherwise a comma after the value would be confused as
being part of the URL. No two entries can have the same descriptors.
For convenience we could say that there is an implicit entry with no
height and width and with resolution 1x that is the value of the src=""
attribute, so then to have a 1x/2x alternative we'd just write: