RGB to Greyscale using Neon

Hi,

I’ve started to play a bit with the NEON intrinsics. For it, I tried to implement the algorithm for RGB to
greyscale conversation with NEON intrinsics. But I don’t know how to get on:

The code which should be rewritten using NEON:

converted[cnt]= (59 * raw[x] + 30 * raw[x+1] + 11 * raw[x+3])/100;

My try:

uint16x4_t a = {raw[x], raw[x+1], raw[x+2], 0};
const uint16x4_t cof = {59, 30, 11, 0};
uint16x4_t result;

//Multiply vectors
result = vmul_u16 (a, cof);

//Multiply with 0.1 (= /100)
//How?

//Sum all Elements of the result vector and save in a scalar
//How to solve?

Regards, Joern

rath wrote:

Hi,

I've started to play a bit with the NEON intrinsics. For it, I tried to implement the algorithm for RGB to
greyscale conversation with NEON intrinsics

Hi Joern,

I wrote a blog-post about exactly this topic a couple of weeks ago.

    http://hilbert-space.de/?p=22

            converted[cnt]= (59 * raw[x] + 30 * raw[x+1] + 11 * raw[x+3])/100;
        

It's much easier if you don't use 100 as your basis but something that
is a power of two. That turns all divides into shifts which are much
easier and faster to do.

Cheers,
    Nils Pipenbrinck

Your blog-post helped a lot. Thanks!