pmeerw's blog

Thu, 29 May 2008

Watermarking on Canon IXUS 70

Got first results with simple watermarking in camera firmware, see the seminar presentation (May 28, Univ. Salzburg).

Main problem is speed currently: just unpacking 9 MB of sensor data takes over 2 sec. The sensor data is stored 10 bits/pixel (packed).

p_row_buf = p_out_row_buf = (uint16 *) &buf_pos[PIXTOBYTES(RAW_LEFT_MAR$
        out_bit_buf = bit_buf = 0;

        for (c = 0; c < IMG_WIDTH - 8; c += 8) {
            bit_buf = *p_row_buf++;
            out_bit_buf = bit_buf >> 6;

            bit_buf = (bit_buf << 16) + *p_row_buf++;
            pixel = bit_buf >> 12 & 0x3ff; // process pixel
            WATERMARK_PIXEL(pixel);
            out_bit_buf = (out_bit_buf << 10) + pixel;
            *p_out_row_buf++ = out_bit_buf >> 4;

            out_bit_buf = (out_bit_buf << 10) + (bit_buf >> 2 & 0x3ff);
	    //... and so on, repeats after 8 pixels
        }
The ARM assembly language can handle shifts very efficiently; a mov instrution can have a third operand specifying an implicit shift! The following GCC-generated assembler code corresponds to the first statements above. Note the asr and asl -- shift right, shift left.
        ldrh    r3, [sl], #2
        mov     r6, r7, asr #6
        ldr     r5, [r2, #12]
        add     r7, r3, r7, asl #16
        tst     r9, r1
        mov     r3, r7, asr #12
        mov     r4, r3, asl #22

posted at: 21:30 | path: /projects/CHDK | permanent link

Made with PyBlosxom