LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] fbdev: make the best-fit section of fb_find_mode return the closest matching mode
@ 2008-01-27 11:31 Michal Januszewski
  2008-01-27 12:25 ` [Linux-fbdev-devel] " Krzysztof Helt
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Januszewski @ 2008-01-27 11:31 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: linux-kernel

From: Michal Januszewski <spock@gentoo.org>

Currently, if a perfect match in terms of resolution is not found,
fb_find_mode() only looks for a best-fit mode among modes with a
higher resolution than the one requested.  Thus, if the user
requests a resolution higher than the largest supported one, they
are dropped to the default mode (usually a low resolution one).

Change this behaviour so that the true closest match in terms
of the city-block metric is returned.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
---
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 08d0725..bc29ef3 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -655,15 +655,15 @@ done:
 	best = -1;
 	DPRINTK("Trying best-fit modes\n");
 	for (i = 0; i < dbsize; i++) {
-	    if (xres <= db[i].xres && yres <= db[i].yres) {
 		DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
 		if (!fb_try_mode(var, info, &db[i], bpp)) {
-		    if (diff > (db[i].xres - xres) + (db[i].yres - yres)) {
-			diff = (db[i].xres - xres) + (db[i].yres - yres);
-			best = i;
-		    }
+			if (diff > abs(db[i].xres - xres) +
+				   abs(db[i].yres - yres)) {
+				diff = abs(db[i].xres - xres) +
+				       abs(db[i].yres - yres);
+				best = i;
+			}
 		}
-	    }
 	}
 	if (best != -1) {
 	    fb_try_mode(var, info, &db[best], bpp);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-fbdev-devel] [PATCH] fbdev: make the best-fit section of fb_find_mode return the closest matching mode
  2008-01-27 11:31 [PATCH] fbdev: make the best-fit section of fb_find_mode return the closest matching mode Michal Januszewski
@ 2008-01-27 12:25 ` Krzysztof Helt
  2008-02-10 18:46   ` Michal Januszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Helt @ 2008-01-27 12:25 UTC (permalink / raw)
  To: spock, linux-fbdev-devel; +Cc: linux-kernel

On Sun, 27 Jan 2008 12:31:16 +0100
Michal Januszewski <spock@gentoo.org> wrote:

> From: Michal Januszewski <spock@gentoo.org>
> 
> Currently, if a perfect match in terms of resolution is not found,
> fb_find_mode() only looks for a best-fit mode among modes with a
> higher resolution than the one requested.  Thus, if the user
> requests a resolution higher than the largest supported one, they
> are dropped to the default mode (usually a low resolution one).
> 

> Change this behaviour so that the true closest match in terms
> of the city-block metric is returned.
> 

This may be not ideal solution in case there exist both lower and
higher matches. If given resolution is closer (even by few pixels)
to lower one, your method will choose the lower one.
It may be incorrect for e.g. picture viewer (the higher resolution
shows the whole picture with margins, the smaller one shows
rescaled or cut picture).

IMHO, the choice of higher resolution (if possible) should be
preferred. It is also closer to the old solution.

Kind regards,
Krzysztof


----------------------------------------------------------------------
Nadchodzi galaktyczna wojna!
Sprawdz >> http://link.interia.pl/f1ce0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] fbdev: make the best-fit section of fb_find_mode return the closest matching mode
  2008-01-27 12:25 ` [Linux-fbdev-devel] " Krzysztof Helt
@ 2008-02-10 18:46   ` Michal Januszewski
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Januszewski @ 2008-02-10 18:46 UTC (permalink / raw)
  To: Krzysztof Helt; +Cc: linux-fbdev-devel, linux-kernel

From: Michal Januszewski <spock@gentoo.org>

Currently, if a perfect match in terms of resolution is not found,
fb_find_mode() only looks for a best-fit mode among modes with a
higher resolution than the one requested.  Thus, if the user
requests a resolution higher than the largest supported one, they
are dropped to the default mode (usually a low resolution one).

Change this behaviour so that all valid video modes are considered
when looking for a best-fit mode, while still preferring modes
with a higher resolution.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
---
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 08d0725..0b6a45f 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -522,7 +522,7 @@ int fb_find_mode(struct fb_var_screeninfo *var,
 	int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
 	unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
 	int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
-	u32 best, diff;
+	u32 best, diff, tdiff;
 
 	for (i = namelen-1; i >= 0; i--) {
 	    switch (name[i]) {
@@ -651,19 +651,27 @@ done:
 		return (refresh_specified) ? 2 : 1;
 	}
 
-	diff = xres + yres;
+	diff = 2 * (xres + yres);
 	best = -1;
 	DPRINTK("Trying best-fit modes\n");
 	for (i = 0; i < dbsize; i++) {
-	    if (xres <= db[i].xres && yres <= db[i].yres) {
 		DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
 		if (!fb_try_mode(var, info, &db[i], bpp)) {
-		    if (diff > (db[i].xres - xres) + (db[i].yres - yres)) {
-			diff = (db[i].xres - xres) + (db[i].yres - yres);
-			best = i;
-		    }
+			tdiff = abs(db[i].xres - xres) +
+				abs(db[i].yres - yres);
+
+			/*
+			 * Penalize modes with resolutions smaller
+			 * than requested.
+			 */
+			if (xres > db[i].xres || yres > db[i].yres)
+				tdiff += xres + yres;
+
+			if (diff > tdiff) {
+				diff = tdiff;
+				best = i;
+			}
 		}
-	    }
 	}
 	if (best != -1) {
 	    fb_try_mode(var, info, &db[best], bpp);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-10 18:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-27 11:31 [PATCH] fbdev: make the best-fit section of fb_find_mode return the closest matching mode Michal Januszewski
2008-01-27 12:25 ` [Linux-fbdev-devel] " Krzysztof Helt
2008-02-10 18:46   ` Michal Januszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).