Login

Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.

ARM Community: regarding NEON - RGB565 to 888 conversion - ARM Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

regarding NEON - RGB565 to 888 conversion Rate Topic: -----

#1 User is offline   prachi2607 

  • Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 29-June 12

Posted 03 July 2012 - 05:14 AM

Since arm-neon code intrinsic does not support bit-wise operations , I cannot perform operations n red, green and blue parts of RGB565 format..so .I am thinking of converting them to 888 .. how do I do that
0

#2 User is offline   sim 

  • Regular Contributor
  • PipPipPip
  • Group: Members.
  • Posts: 419
  • Joined: 04-October 06

Posted 03 July 2012 - 08:52 AM

Something like:

#include <arm_neon.h>

void rgb565to888(int n, const uint16_t *p565, uint8_t *p888)
{
  uint8x8_t mask5, mask6;
  int i;

  mask5 = vmov_n_u8(0xf8); 	// pre-construct masks
  mask6 = vmov_n_u8(0xfc);

  for(i=0;i<n/8;i++) {     	// 8 pixels per loop
	uint8x8_t red, grn, blu;
	uint16x8_t pix;
	uint8x8x3_t rgb;

	pix = vld1q_u16(p565+8*i); // load 8 pixels worth

	red = vshrn_n_u16(pix,8);  // narrow and shift red
	grn = vshrn_n_u16(pix,3);  // narrow and shift green
	blu = vmovn_u16(pix);  	// narrow blue

	red = vand_u8(red,mask5);  // mask shifted red
	grn = vand_u8(grn,mask6);  // mask shifted green
	blu = vshl_n_u8(blu,3);	// shift and mask blue

	rgb.val[0] = red;      	// ensure RGB is in three..
	rgb.val[1] = grn;      	// ..consecutive registers
	rgb.val[2] = blu;

	vst3_u8(p888+8*3*i,rgb);   // store 3 element structure
  }
}

hth
s.
1

#3 User is offline   sim 

  • Regular Contributor
  • PipPipPip
  • Group: Members.
  • Posts: 419
  • Joined: 04-October 06

Posted 03 July 2012 - 12:25 PM

Note that the 1% to 3% error in the computed full scale value can be worked around by re-inserting the most-significant-bits as the least-significant-bits (as shown below), though whether this is worth doing will depend on what else you plan to do with the original RGB565 value.

#include <arm_neon.h>

void rgb565to888(int n, const uint16_t *p565, uint8_t *p888)
{
  uint8x16_t mask5, mask6;
  int i;

  mask5 = vmovq_n_u8(0xf8);  	// pre-construct mask values
  mask6 = vmovq_n_u8(0xfc);

  for(i=0;i<n/16;i++) {      	// 16 pixels per loop

	uint16x8_t   p0, p1;
	uint8x8_t	r0, r1, g0, g1, b0, b1;
	uint8x16_t   red, rhi, rlo, grn, ghi, glo, blu, bhi, blo;
	uint8x16x3_t rgb;

	// start in D vectors, split RGB into individual bytes

	p0 = vld1q_u16(p565+16*i);   // load first 8 pixels worth
	p1 = vld1q_u16(p565+16*i+8); // load second 8 pixels worth

	r0 = vshrn_n_u16(p0,8);  	// narrow and shift red
	g0 = vshrn_n_u16(p0,3);  	// narrow and shift green
	b0 = vmovn_u16(p0);      	// narrow blue

	r1 = vshrn_n_u16(p1,8);  	// narrow and shift red
	g1 = vshrn_n_u16(p1,3);  	// narrow and shift green
	b1 = vmovn_u16(p1);      	// narrow blue

	// perform rest of conversion using Q vectors

	red = vcombine_u8(r0,r1);	// [NoOp] create 16-bytes of R
	grn = vcombine_u8(g0,g1);	// [NoOp] create 16-bytes of G
	blu = vcombine_u8(b0,b1);	// [NoOp] create 16-bytes of B

	rhi = vandq_u8(red,mask5);   // mask shifted red
	ghi = vandq_u8(grn,mask6);   // mask shifted green
	bhi = vshlq_n_u8(blu,3); 	// shift and mask blue

	rlo = vshrq_n_u8(red,5); 	// create lsbs for red
	glo = vshrq_n_u8(grn,6); 	// create lsbs for green
	blo = vshrq_n_u8(bhi,5); 	// create lsbs for blue (via bhi)

	red = vorrq_u8(rhi,rlo); 	// combine red msb and lsbs
	grn = vorrq_u8(ghi,glo); 	// combine green msb and lsbs
	blu = vorrq_u8(bhi,blo); 	// combine blue msb and lsbs

	// store result

	rgb.val[0] = red;        	// [NoOp] ensure RGB is in three
	rgb.val[1] = grn;        	// [NoOp] consecutive Q registers
	rgb.val[2] = blu;        	// [NoOp] to permit use of VST3

	vst3q_u8(p888+16*3*i,rgb);   // store 16x RGB structures
  }
}

hth
s.
1

#4 User is offline   Coomy 

  • Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 20-July 12

Posted 01 August 2012 - 03:16 AM

http://blogs.arm.com...left-and-right/

that topic would help you~!
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic