December 7th, 2005

diesel, learning, evil, sweeti

What needs to be done for EventQueue

After my last excursions in AJAX and DHTML I feel slightly more confident about hacking together the last bits of EventQueue to make it full functional.

However, before I release it I really want to make it so that it can have multiple backends (mod_perl 1 & 2, cgi, static) which shouldn't be too hard but means that it's become suspiciously Framework like.


Framework - the verboten word.

diesel, learning, evil, sweeti

I also had the idea for where people could upload all their slides and notes from wherever they gave them. They could be viewed by author, date, keywords (or 'tags' in Web2.0 parlance), event, format etc etc all with a licence attached to them (such as "This talk may only be given by me", "This talk may be given by someone else as long as they don't change it" etc etc)

Of course I can't be arsed to do it, not at the moment, and for some reasons I suspect nobody else will get round to it.

diesel, learning, evil, sweeti

The Darkness

I had a problem loading TIFF's with alpha channels in Imlib2 as they seemed to be coming out very dark. I noticed in the source code that, on saving, there was a comment about premultiplying if there's an alpha component but no corrollary in the loading method.

        if (has_alpha)
                  /* TIFF makes you pre-mutiply the rgb components by alpha */
                  a = (pixel >> 24) & 0xff;
                  alpha_factor = ((double)a / 255.0);
                  r *= alpha_factor;
                  g *= alpha_factor;
                  b *= alpha_factor;

But surely that would mean that our images would be too bright since, in loading, we'd divide by this alpha factor. In my defence I was heavily dosed up on cold medicine at the time but I eventually twigged that if the alpha was, say, 150 then 150/255 is smaller than 1 and therefore dividing would actually make it larger and hence brighter. One swift patch later and everything is hunky dory.

             for (j = 0; j < w; j++)
        +         int a, r, g, b;
        +         a = TIFFGetA(pixel_value);
        +         r = TIFFGetR(pixel_value);
        +         g = TIFFGetG(pixel_value);
        +         b = TIFFGetB(pixel_value);
                  pixel_value = (*(pixel++));
        -             (*(buffer_pixel++)) =
        -                 (TIFFGetA(pixel_value) << 24) |
        -                 (TIFFGetR(pixel_value) << 16) | (TIFFGetG(pixel_value) << 8) |
        -                 TIFFGetB(pixel_value);
        +         if ((a > 0) && (a < 255))
        +           {
        +              r = (r * 255) / a;
        +              g = (g * 255) / a;
        +              b = (b * 255) / a;
        +           }
        +             (*(buffer_pixel++)) = (a << 24) | (r << 16) | (g << 8) | b;

Or is it? A user was still reporting the same bug - images were too dark. Again it took a while for the lightbulb to turn on depsite extensive tracing in Totalview and GDB. The problem was that I'd stretched the image to fit a new aspect ration and then composited it onto a black background of the original size to make the black bars thus producing a darker image. Doh. Turning off alpha blending fixed it.