media: vim2m: Fix RGB 565 BE/LE support

The support for those two formats are archtecture-dependent.
Use the endianness to CPU macros to do it right.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
Mauro Carvalho Chehab 2019-03-28 15:02:23 -04:00
parent b4a7113f84
commit 060162c1af
1 changed files with 17 additions and 13 deletions

View File

@ -302,7 +302,7 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in,
switch (in->fourcc) { switch (in->fourcc) {
case V4L2_PIX_FMT_RGB565: /* rrrrrggg gggbbbbb */ case V4L2_PIX_FMT_RGB565: /* rrrrrggg gggbbbbb */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
u16 pix = *(u16 *)(src[i]); u16 pix = le16_to_cpu(*(__le16 *)(src[i]));
*r++ = (u8)(((pix & 0xf800) >> 11) << 3) | 0x07; *r++ = (u8)(((pix & 0xf800) >> 11) << 3) | 0x07;
*g++ = (u8)((((pix & 0x07e0) >> 5)) << 2) | 0x03; *g++ = (u8)((((pix & 0x07e0) >> 5)) << 2) | 0x03;
@ -311,12 +311,11 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in,
break; break;
case V4L2_PIX_FMT_RGB565X: /* gggbbbbb rrrrrggg */ case V4L2_PIX_FMT_RGB565X: /* gggbbbbb rrrrrggg */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
u16 pix = *(u16 *)(src[i]); u16 pix = be16_to_cpu(*(__be16 *)(src[i]));
*r++ = (u8)(((0x00f8 & pix) >> 3) << 3) | 0x07; *r++ = (u8)(((pix & 0xf800) >> 11) << 3) | 0x07;
*g++ = (u8)(((pix & 0x7) << 2) | *g++ = (u8)((((pix & 0x07e0) >> 5)) << 2) | 0x03;
((pix & 0xe000) >> 5)) | 0x03; *b++ = (u8)((pix & 0x1f) << 3) | 0x07;
*b++ = (u8)(((pix & 0x1f00) >> 8) << 3) | 0x07;
} }
break; break;
default: default:
@ -345,21 +344,26 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in,
switch (out->fourcc) { switch (out->fourcc) {
case V4L2_PIX_FMT_RGB565: /* rrrrrggg gggbbbbb */ case V4L2_PIX_FMT_RGB565: /* rrrrrggg gggbbbbb */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
u16 *pix = (u16 *)*dst; u16 pix;
__le16 *dst_pix = (__le16 *)*dst;
*pix = ((*r << 8) & 0xf800) | ((*g << 3) & 0x07e0) | pix = ((*r << 8) & 0xf800) | ((*g << 3) & 0x07e0) |
(*b >> 3); (*b >> 3);
*dst_pix = cpu_to_le16(pix);
*dst += 2; *dst += 2;
} }
return; return;
case V4L2_PIX_FMT_RGB565X: /* gggbbbbb rrrrrggg */ case V4L2_PIX_FMT_RGB565X: /* gggbbbbb rrrrrggg */
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
u16 *pix = (u16 *)*dst; u16 pix;
u8 green = *g++ >> 2; __be16 *dst_pix = (__be16 *)*dst;
*pix = ((green << 8) & 0xe000) | (green & 0x07) | pix = ((*r << 8) & 0xf800) | ((*g << 3) & 0x07e0) |
((*b++ << 5) & 0x1f00) | ((*r++ & 0xf8)); (*b >> 3);
*dst_pix = cpu_to_be16(pix);
*dst += 2; *dst += 2;
} }