Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It should be fairly straightforward to write this function using vector intrinsics. I don't know what processor, compiler, or packed pixel format you're using, so I'll give an example implementation using GCC and MMX intrinsics for x86. It should also be easy to translate this code into ARM NEON, PowerPC Altivec, or x86/x64 SSE code.</p> <p>This should convert RGB planar to 32-bit RGBA packed, although ARGB is actually more common. If you need 24-bit RGB you're going to have to get a bit creative. The "Software Developer Manual" for your processor will be your best friend when writing this small piece of code, and you'll also need to read the documentation for your compiler.</p> <p>SIMD handles this very well, you can tell by how short the code is below. Note that the code below is actually C99, not C++, as C99 gives access to the <code>restrict</code> keyword which can reduce the number of loads and stores generated.</p> <p>Also note that this code has strict alignment requirements.</p> <pre><code>#include &lt;stddef.h&gt; #if defined(USE_MMX) typedef char v8qi __attribute__ ((vector_size(8))); void pack_planes3(void *dest, const void *src[3], size_t n) { v8qi *restrict dp = dest, x, y, zero = { 0, 0, 0, 0, 0, 0, 0, 0 }; const v8qi *restrict sp1 = src[0]; const v8qi *restrict sp2 = src[1]; const v8qi *restrict sp3 = src[2]; size_t i; for (i = 0; i &lt; n; i += 8) { x = __builtin_ia32_punpckhbw(*sp1, *sp3); y = __builtin_ia32_punpckhbw(*sp2, zero); dp[0] = __builtin_ia32_punpckhbw(x, y); dp[1] = __builtin_ia32_punpcklbw(x, y); x = __builtin_ia32_punpcklbw(*sp1, *sp3); y = __builtin_ia32_punpcklbw(*sp2, zero); dp[2] = __builtin_ia32_punpckhbw(x, y); dp[3] = __builtin_ia32_punpcklbw(x, y); sp1++; sp2++; sp3++; dp += 4; } } #else /* Scalar implementation goes here */ #endif </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload