[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/khtml/rendering
From:       Allan Sandfeld Jensen <kde () carewolf ! com>
Date:       2005-02-15 16:40:21
Message-ID: 20050215164021.68D341D1FC () office ! kde ! org
[Download RAW message or body]

CVS commit by carewolf: 

Faster and better looking text-shadow


  M +29 -29    render_text.cpp   1.263


--- kdelibs/khtml/rendering/render_text.cpp  #1.262:1.263
@@ -5,5 +5,5 @@
  *           (C) 2000-2003 Dirk Mueller (mueller@kde.org)
  *           (C) 2003 Apple Computer, Inc.
- *           (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
+ *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
  *
  * This library is free software; you can redistribute it and/or
@@ -209,26 +209,28 @@ void InlineTextBox::paintShadow(QPainter
         QImage img = pixmap.convertToImage().convertDepth(32);
 
-        // blur map (optimization)
-        int bmapw = 2*thickness+1;
-        float *bmap = new float[bmapw*bmapw];
-        float md = thickness*thickness; // max-distē
-        float strength = 1.0/(sqrt(thickness));
-        if (strength > 1.0) strength = 1.0;
-        for(int n=-thickness; n<thickness; n++) {
-            for(int m=-thickness; m<thickness; m++) {
-                float f, d = (m*m+n*n); // distē
-                if (d > md)
-                    f = 0.0;
-                else {
-                    f = (1+md-d)/md;
-                    f = f*f*f*f; // square-root of distance
-                }
-                bmap[(m+thickness)+(n+thickness)*bmapw] = f*strength;;
+        int md = thickness*thickness; // max-distē
+
+        // blur map (division cache)
+        float *bmap = (float*)alloca(sizeof(float)*(md+1));
+        for(int n=0; n<=md; n++) {
+            float f;
+            f = n/(float)(md+1);
+            f = 1.0 - f*f;
+            bmap[n] = f;
             }
+
+        float factor = 0.0; // maximal opacity-sum
+        for(int n=-thickness; n<=thickness; n++)
+            for(int m=-thickness; m<=thickness; m++) {
+                int d = n*n+m*m;
+                if (d<=md)
+                    factor += bmap[d];
         }
 
+        factor = 1.0/factor;
+
         // alpha map
-        unsigned char* amap = new unsigned char[h*w];
-        memset(amap, 0, h*w);
+        float* amap = (float*)alloca(sizeof(float)*(h*w));
+        memset(amap, 0, h*w*(sizeof(float)));
         for(int j=thickness; j<h-thickness; j++) {
             for(int i=thickness; i<w-thickness; i++) {
@@ -240,10 +242,10 @@ void InlineTextBox::paintShadow(QPainter
                 else
                     g = g/gray;
-                for(int n=-thickness; n<thickness; n++) {
-                    for(int m=-thickness; m<thickness; m++) {
-                        float f = bmap[(m+thickness)+(n+thickness)*bmapw];
-                        unsigned int anew = (unsigned int)(f*g*255);
-                        unsigned int aold = amap[(i+m)+(j+n)*w];
-                        if (aold < anew) amap[(i+m)+(j+n)*w] = anew;
+                for(int n=-thickness; n<=thickness; n++) {
+                    for(int m=-thickness; m<=thickness; m++) {
+                        int d = n*n+m*m;
+                        if (d>md) continue;
+                        float f = bmap[d];
+                        amap[(i+m)+(j+n)*w] += (g*f);
                     }
                 }
@@ -259,9 +261,7 @@ void InlineTextBox::paintShadow(QPainter
         for(int j=0; j<h; j++) {
             for(int i=0; i<w; i++) {
-                res.setPixel(i,j, qRgba(r,g,b,amap[i+j*w]));
+                res.setPixel(i,j, qRgba(r,g,b,(int)(amap[i+j*w]*factor*255.0)));
             }
         }
-        delete[] amap;
-        delete[] bmap;
 
         pt->drawImage(x-thickness, y-thickness, res, 0, 0, -1, -1, \
Qt::DiffuseAlphaDither | Qt::ColorOnly | Qt::PreferDither);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic