Re: Image Scaling
Johannes Hofmann <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Jun 16, 2013 at 11:42:35AM +0200, Sebastian Geerken wrote: > 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. I don't know, but we could cache the values as in attached patch. Johannes _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
gamma_corr_img_scaling1.diff
(text/plain, 1.3 KB)
diff -r 91fdbc0feb68 dw/fltkimgbuf.cc
--- a/dw/fltkimgbuf.cc Sun Jun 16 21:23:19 2013 +0200
+++ b/dw/fltkimgbuf.cc Sun Jun 16 22:27:23 2013 +0200
@@ -22,6 +22,7 @@
#include "../lout/misc.hh"
#include <FL/fl_draw.H>
+#include <math.h>
#define IMAGE_MAX_AREA (6000 * 6000)
@@ -210,6 +211,33 @@
}
}
+static int gamma (int x, double gamma, int table[256])
+{
+ if (x < 0 || x >= 256) {
+ assert (0);
+ return 0;
+ }
+
+ if (table[x] <= 0)
+ table[x] = 256 * pow((double)x / 256, gamma);
+
+ return table[x];
+}
+
+static int gamma_22 (int x)
+{
+ static int table[256] = {0};
+
+ return gamma (x, 2.2, table);
+}
+
+static int gamma_1_div_22 (int x)
+{
+ static int table[256] = {0};
+
+ return gamma (x, 1 / 2.2, table);
+}
+
/**
* General method to scale an image buffer. Used to scale single lines
* in scaleRowBeautiful.
@@ -247,12 +275,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_22 (ps[i]);
}
core::byte *pd = dest + bpp * (y * destWidth + x);
for(int i = 0; i < bpp; i++)
- pd[i] = v[i] / n;
+ pd[i] = gamma_1_div_22 (v[i] / n);
}
}