Re: Image Scaling

"Sebastian Geerken" <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
On Sa, Jun 15, 2013, Johannes Hofmann wrote:
> On Fri, Jun 14, 2013 at 08:01:00PM +0200, Sebastian Geerken wrote:
> > Hi!
> > 
> > I've just push some changes for a better image scaling. See these two
> > examples for the effect:
> > 
> > - http://www.dillo.org/~sgeerken/grid.html
> > - http://www.dillo.org/~sgeerken/tenniel.html
> > 
> > I'm not completely sure about the side-effects. It should be slightly
> > slower (see comment: it can be improved), and it will not work with
> > other that RGB and RGBA data (for the case that Imgbuf is used for
> > other representations). The old code is still there; just look at
> > FltkImgbuf::scaleRow.
> 
> Nice! BTW, I have this page bookmarked for quite some time:
> http://www.4p8.com/eric.brasseur/gahttp://www.4p8.com/eric.brasseur/gamma.htmlmma.html
> I don't know whether this makes a difference in real life, but the
> examples are interesting.

Interesting!

I didn't read the whole article, but it made me wonder what effect a
gamma correction has on image scaling. See the test page
<http://www.4p8.com/eric.brasseur/gamma_dalai_lama.html> with:

1. dillo 3.0.3,
2. current version from the hg repository, and
3. latter with the attached patch applied.

The patch uses floating point arithmetics; perhaps there is a faster
algorithm based on integer arithmetics.

Sebastian

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
gamma_corr_img_scaling.diff (text/x-diff, 998 B)
diff -r 5fbb1dd423a6 dw/fltkimgbuf.cc
--- a/dw/fltkimgbuf.cc	Sun Jun 16 10:39:27 2013 +0200
+++ b/dw/fltkimgbuf.cc	Sun Jun 16 11:41:42 2013 +0200
@@ -22,6 +22,7 @@
 #include "../lout/misc.hh"
 
 #include <FL/fl_draw.H>
+#include <math.h>
 
 #define IMAGE_MAX_AREA (6000 * 6000)
 
@@ -206,6 +207,11 @@
    }
 }
 
+static int gamma (int x, double gamma)
+{
+   return 256 * pow((double)x / 256, gamma);
+}
+
 /**
  * General method to scale an image buffer. Used to scale single lines
  * in scaleRowBeautiful.
@@ -243,12 +249,12 @@
             for(int yo = yo1; yo < yo2; yo++) {
                const core::byte *ps = src + bpp * (yo * srcWidth + xo);
                for(int i = 0; i < bpp; i++)
-                  v[i] += ps[i];
+                  v[i] += gamma (ps[i], 2.2);
             }
          
          core::byte *pd = dest + bpp * (y * destWidth + x);
          for(int i = 0; i < bpp; i++)
-            pd[i] = v[i] / n;
+            pd[i] = gamma (v[i] / n, 1 / 2.2);
       }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.