Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With a RGB888ToPlanar8 call you scatter the data and then gather it once again. This is very-very-very bad. If the memory overhead of 33% is affordable, try using the RGBA format and permute the B/R bytes in-place.</p> <p>If you want to save 33% percents, then I might suggest the following. Iterate all the pixels, but read only a multiple of 4 bytes (since lcm(3,4) is 12, that is 3 dwords).</p> <pre><code>uint8_t* src_image; uint8_t* dst_image; uint32_t* src = (uint32_t*)src_image; uint32_t* dst = (uint32_t*)dst_image; uint32_t v1, v2, v3; uint32_t nv1, nv2, nv3; for(int i = 0 ; i &lt; num_pixels / 12 ; i++) { // read 12 bytes v1 = *src++; v2 = *src++; v3 = *src++; // shuffle bits in the pixels // [R1 G1 B1 R2 | G2 B2 R3 G3 | B3 R4 G4 B4] nv1 = // [B1 G1 R1 B2] ((v1 &gt;&gt; 8) &amp; 0xFF) | (v1 &amp; 0x00FF0000) | ((v1 &gt;&gt; 16) &amp; 0xFF) | ((v2 &gt;&gt; 24) &amp; 0xFF); nv2 = // [G2 R2 B3 G3] ... nv3 = // [R3 B4 G4 R4] ... // write 12 bytes *dst++ = nv1; *dst++ = nv2; *dst++ = nv3; } </code></pre> <p>Even better can be done with NEON intrinsics. </p> <p>See this link <a href="http://blogs.arm.com/software-enablement/161-coding-for-neon-part-1-load-and-stores/" rel="nofollow">from ARM's website</a> to see how the 24-bit swapping is done.</p> <p>The BGR-to-RGB can be done in-place like this:</p> <pre><code>void neon_asm_convert_BGR_TO_RGB(uint8_t* img, int numPixels24) { // numPixels is divided by 24 __asm__ volatile( "0: \n" "# load 3 64-bit regs with interleave: \n" "vld3.8 {d0,d1,d2}, [%0] \n" "# swap d0 and d2 - R and B\n" "vswp d0, d2 \n" "# store 3 64-bit regs: \n" "vst3.8 {d0,d1,d2}, [%0]! \n" "subs %1, %1, #1 \n" "bne 0b \n" : : "r"(img), "r"(numPixels24) : "r4", "r5" ); } </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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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