Txzone

Musique, développement, bleh attitude.

Aller au contenu | Aller au menu | Aller à la recherche

lundi, décembre 21 2009

Color swapping and Python

For PyMT, Sharath need BGR support into PyMT, while his graphic card don't support GL_BGR. Well, after adapting swap code from Pyglet sourcecode, he say: "< patali> it works but very slow"

The goal is to swap a string from 'bgrbgrbgr' to 'rgbrgbrgb'. Just let's do a rapid benchmark.

import sys
import re
import time

swap1_pattern = re.compile('(.)(.)(.)', re.DOTALL)
swap1_repl = r'\3\2\1'
def swap1(bytes):
    return swap1_pattern.sub(swap1_repl, bytes)

def swap2(bytes):
    out = ''
    for i in xrange(0, len(bytes), 3):
        b, g, r = bytes[i:i+3]
        out += r
        out += g
        out += b
    return out

def swap3(bytes):
    bytes = list(bytes)
    for i in xrange(0, len(bytes), 3):
        b, g, r = bytes[i:i+3]
        bytes[i:i+3] = r, g, b
    return ''.join(bytes)

def swap4(bytes):
    blues = bytes[0::3]
    greens = bytes[1::3]
    reds = bytes[2::3]
    return ''.join(''.join(x) for x in zip(reds, greens, blues))

def swap5(bytes):
    from array import array
    a = array('b', bytes)
    a[0::3], a[2::3] = a[2::3], a[0::3]
    return a.tostring()

def swap6(bytes):
    import numpy
    a = numpy.array(bytes, 'c')
    b = a[...,::-1]
    return b.tostring()

def swap7(bytes):
    a = list(bytes)
    a[0::3], a[2::3] = a[2::3], a[0::3]
    return ''.join(a)


def bench(func, bytes):
    sys.stderr.write('Bench %s: ' % str(func))

    start = time.time()
    for i in xrange(20):
        sys.stderr.write('.')
        ret = func(bytes)
        if ret[:3] != 'rgb' or ret[-3:] != 'rgb':
            sys.stderr.write('INVALID DATA, start=%s, end=%s' %
                            (ret[:3], ret[-3:]))
            break

    end = time.time() - start
    sys.stderr.write('| Finished in %.4f\n' % end)
    return ret


bytes = 'bgr' * 256 * 256
bench(swap1, bytes)
bench(swap2, bytes)
bench(swap3, bytes)
bench(swap4, bytes)
bench(swap5, bytes)
bench(swap6, bytes)
bench(swap7, bytes)

Swap1() is actually the way of pyglet. swap2/swap3 is from me, and others is found on some threads in pygame mailing list.

So, who win ?

21:09 tito@ashaka ~ $ python benchmark.py 
Bench <function swap1 at 0x7f1d154632a8>: ....................| Finished in 3.2713
Bench <function swap2 at 0x7f1d15463230>: ....................| Finished in 1.2860
Bench <function swap3 at 0x7f1d15470cf8>: ....................| Finished in 0.6535
Bench <function swap4 at 0x7f1d15470e60>: ....................| Finished in 0.6475
Bench <function swap5 at 0x7f1d15470ed8>: ....................| Finished in 0.0367
Bench <function swap6 at 0x7f1d15470f50>: ....................| Finished in 0.1959
Bench <function swap7 at 0x7f1d15473050>: ....................| Finished in 0.1482

The array solution is a lot faster than any other implementation ! And it's python standard :) Let's take this...

jeudi, novembre 26 2009

Hacking the Dell SX2210T, part 2.

Tonight, i've tryed to analyse more the header part, and understand how data part work. And... found something !

Lire la suite...

mercredi, novembre 25 2009

Hacking the Dell SX2210T, part 1.

monitor-dell-sx2210t-overview2.jpg I've recently buy the Dell SX2210T, a dual touch monitor. And unfortunately, they are no linux support for the touchscreen part. So, i try to get it work, and it's a pain.

Lire la suite...

lundi, novembre 23 2009

Spreading PyMT toolkit

I've been some week without blogging, but lot of things happened ! Finally, i've been able to see Thomas in IRL at Google Mentor Summit in San Francisco. It was an awesome week-end, funny, creative and geeky ! Lot of ideas, and goal : making PyMT more stable and well designed : the roadmap of PyMT 0.4 is finally available. We've also done a little session too at summit.

Thomas is now 3 days to ITS 2009 in Banff Canada, for a conference about PyMT. The paper will be available for everyone soon :) And this week-end, i'm going to Edinburgh with Lucie to meet Mark, and see the awesome new multitouch room of Napier University. Sharath is also going next week to a FOSS in India to spread PyMT too :)

Theses days are really cool :)

vendredi, octobre 9 2009

San Francisco, i'm coming !

Here is a very good news, Christian, Pawel and Nuigroup support me to go on the Google Mentor Summit, in 23/24 October ! I'll finally meet all of them, and specially Thomas, the creator of awesome PyMT framework :)

This is the result to take care of Sharath during his GSOC :)

I'll stay 2 days more with Thomas, to hack the future PyMT :p (well, work isn't the real word... i want to see California a little :p)

Thanks Guys !

- page 1 de 9