[patch] - bbsplash

Denys Vlasenko vda.linux at googlemail.com
Sat Mar 1 21:08:59 UTC 2008


On Thursday 28 February 2008 14:42, Michele Sanges wrote:
> Please, consider the new version of the patch.

Somebody said it works for them, but slowly.
Let's take a look.

+static void fb_drawrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos,
+       unsigned char nred24, unsigned char ngreen24, unsigned char nblue24)
+{
+       int x, y, idx;
+       unsigned char nred16   = (nred24)   >> 3;  // 5-bit red
+       unsigned char ngreen16 = (ngreen24) >> 2;  // 6-bit green
+       unsigned char nblue16  = (nblue24)  >> 3;  // 5-bit blue
+
+       unsigned nrgb_2bytes = nblue16 + (ngreen16<<5) + (nred16<<(5+6));
+       DATA thispix = nrgb_2bytes;
+
+       // horizontal lines
+       for (x = nx1pos; x <= nx2pos; x++) {
+               idx = (ny1pos * G.screen_infovar.xres + x) * (G.screen_infovar.bits_per_pixel / 8);
+               *(DATA *)(G.addr + idx) = thispix;
+
+               idx = (ny2pos * G.screen_infovar.xres  + x) * (G.screen_infovar.bits_per_pixel / 8);
+               *(DATA *)(G.addr + idx) = thispix;
+       }

gcc compiles it into this (x86 asm, use "make miscutils/bbsplash.s" to see it):

.L11:
        movl    %edi, %eax      # D.6492, tmp104
        imull   72(%ebx), %eax  # <variable>.screen_infovar.xres, tmp104
        leal    (%esi,%eax), %eax       #, tmp105
        movl    96(%ebx), %edx  # <variable>.screen_infovar.bits_per_pixel, tmp106
        shrl    $3, %edx        #, tmp106
        imull   %edx, %eax      # tmp106, tmp105
        movl    8(%ebx), %ecx   # <variable>.addr, <variable>.addr
        movw    %bp, (%ecx,%eax)        # thispix,
        movl    16(%esp), %eax  # D.6494, tmp110
        imull   72(%ebx), %eax  # <variable>.screen_infovar.xres, tmp110
        leal    (%esi,%eax), %eax       #, tmp111
        imull   %edx, %eax      # tmp106, tmp111
        movw    %bp, (%ecx,%eax)        # thispix,
        incl    %esi    # x
.L10:
        cmpl    24(%esp), %esi  # D.6498, x
        jle     .L11    #,

*four* multiplications!

Using the fact that cuurently there is only support for 16 bits per pixel,
it can be rewritten as follows:

        int cnt;
        DATA thispix;
        DATA *ptr1, *ptr2;

        nred   >>= 3;  // 5-bit red
        ngreen >>= 2;  // 6-bit green
        nblue  >>= 3;  // 5-bit blue
        thispix = nblue + (ngreen << 5) + (nred << (5+6));

        // horizontal lines
        ptr1 = (DATA*)(G.addr + (ny1pos * G.screen_infovar.xres + nx1pos) * BYTES_PER_PIXEL);
        ptr2 = (DATA*)(G.addr + (ny2pos * G.screen_infovar.xres + nx1pos) * BYTES_PER_PIXEL);
        cnt = nx2pos - nx1pos;
        do {
                *ptr1++ = thispix;
                *ptr2++ = thispix;
        } while (--cnt >= 0);

No multiplications now, likely x10 faster or so:

.L10:
        movw    %bp, (%eax)     # thispix,* ptr1
        addl    $2, %eax        #, ptr1
        movw    %bp, (%esi)     # thispix,* ptr2
        addl    $2, %esi        #, ptr2
        decl    %ecx    # cnt
        jns     .L10    #,


Please speed up "filled rectangle" function similarly.


        pinifile = xfopen("/etc/bbsplash/bbsplash.ini", "r");

Can this be a command line switch?
"bbsplash -i <inifile> -f <fifo> -d <device>" etc...


        sprintf(G.strsplash_theme, "/etc/bbsplash/%s", pvalue);

Use char *str  instead of char str[FIXED_SIZE] for it, and do

        G.strsplash_theme = xasprintf(...);

This way you use as much memory as needed, and don't have artificial
size limit.

I rebased the patch to current svn, please see it attached.
fb_drawrectangle() is edited, the rest is not touched
(except for s/PTR_TO_GLOBALS/SET_PTR_TO_GLOBALS/).

You can download current svn and base your work on it
using this command:

svn co svn://busybox.net/trunk/busybox

--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1.patch
Type: text/x-diff
Size: 15342 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20080301/dc70b14b/attachment-0002.bin 


More information about the busybox mailing list