libv4l: Add support for BAYER10P format conversion
PATCH 1/1 libv4l: Add support for BAYER10P format conversion
Add support for 10 bit packet Bayer formats:
-V4L2_PIX_FMT_SBGGR10P
-V4L2_PIX_FMT_SGBRG10P
-V4L2_PIX_FMT_SGRBG10P
-V4L2_PIX_FMT_SRGGB10P
These formats pack the 2 LSBs for every 4 pixels in an indeppendent byte.
--- lib/libv4lconvert/bayer.c | 15 +++++++++++ lib/libv4lconvert/libv4lconvert-priv.h | 4 +++ lib/libv4lconvert/libv4lconvert.c | 35 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+)
lib/libv4lconvert/bayer.c +15 -0
@@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,v4lconvert_border_bayer_line_to_y (bayer + stride, bayer, ydst, width, !start_with_green, !blue_line); } + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height) +{ +long i, len = width * height; +uint32_t *src, *dst; + + src = (uint32_t *)bayer10p; + dst = (uint32_t *)bayer8; +for (i =0 ; i < len ; i +=4 ) { + *dst = *src; + dst++; + src = (uint32_t *)(((uint8_t *)src) +5 ); + } +}
lib/libv4lconvert/libv4lconvert-priv.h +4 -0
@@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,void v4lconvert_bayer_to_yuv420 (const unsigned char *bayer,unsigned char *yuv,int width,int height,const unsigned int stride,unsigned int src_pixfmt,int yvu); + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height); +void v4lconvert_hm12_to_rgb24 (const unsigned char *src,unsigned char *dst,int width,int height);
lib/libv4lconvert/libv4lconvert.c +35 -0
@@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { { V4L2_PIX_FMT_SRGGB8, 8, 8, 8, 0 }, { V4L2_PIX_FMT_STV0680, 8, 8, 8, 1 }, { V4L2_PIX_FMT_SGRBG10, 16, 8, 8, 1 }, + { V4L2_PIX_FMT_SBGGR10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGBRG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGRBG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SRGGB10P, 10, 8, 8, 1 },/* compressed bayer */ { V4L2_PIX_FMT_SPCA561, 0, 9, 9, 1 }, { V4L2_PIX_FMT_SN9C10X, 0, 9, 9, 1 },
@@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion(case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :case V4L2_PIX_FMT_SRGGB8 : +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P :case V4L2_PIX_FMT_STV0680 :return 0 ; }
@@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, }/* Raw bayer formats */ +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P : +if (src_size < ((width * height *10 )/8 )) { +V4LCONVERT_ERR ("short raw bayer10 data frame\n" ); + errno =EPIPE ; + result =-1 ; + } +switch (src_pix_fmt) { +case V4L2_PIX_FMT_SBGGR10P : + src_pix_fmt =V4L2_PIX_FMT_SBGGR8 ; +break ; +case V4L2_PIX_FMT_SGBRG10P : + src_pix_fmt =V4L2_PIX_FMT_SGBRG8 ; +break ; +case V4L2_PIX_FMT_SGRBG10P : + src_pix_fmt =V4L2_PIX_FMT_SGRBG8 ; +break ; +case V4L2_PIX_FMT_SRGGB10P : + src_pix_fmt =V4L2_PIX_FMT_SRGGB8 ; +break ; + } +v4lconvert_bayer10p_to_bayer8 (src, src, width, height); + bytesperline = width; + +/* Fall-through*/ case V4L2_PIX_FMT_SBGGR8 :case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :
Signature · 1 line
2.18.0
Hi,
Quoted 27 lines · Ricardo Ribalda Delgado
Add support for 10 bit packet Bayer formats:
(quoted diff) +0
-4-V4L2_PIX_FMT_SBGGR10P -V4L2_PIX_FMT_SGBRG10P -V4L2_PIX_FMT_SGRBG10P -V4L2_PIX_FMT_SRGGB10PThese formats pack the 2 LSBs for every 4 pixels in an indeppendent byte.
Signed-off-by Ricardo Ribalda Delgado <[email protected]>--- lib/libv4lconvert/bayer.c | 15 +++++++++++ lib/libv4lconvert/libv4lconvert-priv.h | 4 +++ lib/libv4lconvert/libv4lconvert.c | 35 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+)lib/libv4lconvert/bayer.c +3
-0@@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,v4lconvert_border_bayer_line_to_y (bayer + stride, bayer, ydst, width, !start_with_green, !blue_line); } + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height)
lib/libv4lconvert/bayer.c void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, · line 646
Quoted 10 lines
lib/libv4lconvert/bayer.c +10
-0+{ +long i, len = width * height; +uint32_t *src, *dst; + + src = (uint32_t *)bayer10p; + dst = (uint32_t *)bayer8; +for (i =0 ; i < len ; i +=4 ) { + *dst = *src; + dst++; + src = (uint32_t *)(((uint8_t *)src) +5 );
This will lead to unaligned 32 bit integer accesses which will terminate the program with an illegal instruction on pretty much all architectures except for x86.
You will need to copy the 4 components 1 by 1 so that you only use byte accesses.
Also you seem to simply be throwing away the extra 2 bits, although that will work I wonder if that is the best we can do?
Regards,
Hans
Quoted 81 lines
lib/libv4lconvert/bayer.c +2
-0+ } +}lib/libv4lconvert/libv4lconvert-priv.h +4
-0@@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,void v4lconvert_bayer_to_yuv420 (const unsigned char *bayer,unsigned char *yuv,int width,int height,const unsigned int stride,unsigned int src_pixfmt,int yvu); + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height); +void v4lconvert_hm12_to_rgb24 (const unsigned char *src,unsigned char *dst,int width,int height);lib/libv4lconvert/libv4lconvert.c +35
-0@@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { { V4L2_PIX_FMT_SRGGB8, 8, 8, 8, 0 }, { V4L2_PIX_FMT_STV0680, 8, 8, 8, 1 }, { V4L2_PIX_FMT_SGRBG10, 16, 8, 8, 1 }, + { V4L2_PIX_FMT_SBGGR10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGBRG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGRBG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SRGGB10P, 10, 8, 8, 1 },/* compressed bayer */ { V4L2_PIX_FMT_SPCA561, 0, 9, 9, 1 }, { V4L2_PIX_FMT_SN9C10X, 0, 9, 9, 1 },@@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion(case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :case V4L2_PIX_FMT_SRGGB8 : +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P :case V4L2_PIX_FMT_STV0680 :return 0 ; }@@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, }/* Raw bayer formats */ +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P : +if (src_size < ((width * height *10 )/8 )) { +V4LCONVERT_ERR ("short raw bayer10 data frame\n" ); + errno =EPIPE ; + result =-1 ; + } +switch (src_pix_fmt) { +case V4L2_PIX_FMT_SBGGR10P : + src_pix_fmt =V4L2_PIX_FMT_SBGGR8 ; +break ; +case V4L2_PIX_FMT_SGBRG10P : + src_pix_fmt =V4L2_PIX_FMT_SGBRG8 ; +break ; +case V4L2_PIX_FMT_SGRBG10P : + src_pix_fmt =V4L2_PIX_FMT_SGRBG8 ; +break ; +case V4L2_PIX_FMT_SRGGB10P : + src_pix_fmt =V4L2_PIX_FMT_SRGGB8 ; +break ; + } +v4lconvert_bayer10p_to_bayer8 (src, src, width, height); + bytesperline = width; + +/* Fall-through*/ case V4L2_PIX_FMT_SBGGR8 :case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :
Hi Hans
Quoted 37 lines · Hans de Goede
Hi,
Quoted 33 lines · Ricardo Ribalda Delgado
Add support for 10 bit packet Bayer formats:
(quoted diff) +0
-4-V4L2_PIX_FMT_SBGGR10P -V4L2_PIX_FMT_SGBRG10P -V4L2_PIX_FMT_SGRBG10P -V4L2_PIX_FMT_SRGGB10PThese formats pack the 2 LSBs for every 4 pixels in an indeppendent byte.
Signed-off-by Ricardo Ribalda Delgado <[email protected]>--- lib/libv4lconvert/bayer.c | 15 +++++++++++ lib/libv4lconvert/libv4lconvert-priv.h | 4 +++ lib/libv4lconvert/libv4lconvert.c | 35 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+)lib/libv4lconvert/bayer.c +9
-0@@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,v4lconvert_border_bayer_line_to_y (bayer + stride, bayer, ydst, width, !start_with_green, !blue_line); } + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height) +{ +long i, len = width * height; +uint32_t *src, *dst; + + src = (uint32_t *)bayer10p; + dst = (uint32_t *)bayer8;
Quoted 8 lines
lib/libv4lconvert/bayer.c void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, · line 646
Quoted 4 lines
lib/libv4lconvert/bayer.c +4
-0+for (i =0 ; i < len ; i +=4 ) { + *dst = *src; + dst++; + src = (uint32_t *)(((uint8_t *)src) +5 );This will lead to unaligned 32 bit integer accesses which will terminate the program with an illegal instruction on pretty much all architectures except for x86.
I see your point, but I am actually using this code on ARM64 with no issues.
I will change it.
Quoted 6 lines
You will need to copy the 4 components 1 by 1 so that you only use byte accesses.
Also you seem to simply be throwing away the extra 2 bits, although that will work I wonder if that is the best we can do?
Those are the LSB. If the user want the extra resolution has to use the bayer mode.
Quoted 88 lines
Regards,
Hans
Quoted 81 lines
lib/libv4lconvert/bayer.c +2
-0+ } +}lib/libv4lconvert/libv4lconvert-priv.h +4
-0@@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,void v4lconvert_bayer_to_yuv420 (const unsigned char *bayer,unsigned char *yuv,int width,int height,const unsigned int stride,unsigned int src_pixfmt,int yvu); + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height); +void v4lconvert_hm12_to_rgb24 (const unsigned char *src,unsigned char *dst,int width,int height);lib/libv4lconvert/libv4lconvert.c +35
-0@@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { { V4L2_PIX_FMT_SRGGB8, 8, 8, 8, 0 }, { V4L2_PIX_FMT_STV0680, 8, 8, 8, 1 }, { V4L2_PIX_FMT_SGRBG10, 16, 8, 8, 1 }, + { V4L2_PIX_FMT_SBGGR10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGBRG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGRBG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SRGGB10P, 10, 8, 8, 1 },/* compressed bayer */ { V4L2_PIX_FMT_SPCA561, 0, 9, 9, 1 }, { V4L2_PIX_FMT_SN9C10X, 0, 9, 9, 1 },@@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion(case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :case V4L2_PIX_FMT_SRGGB8 : +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P :case V4L2_PIX_FMT_STV0680 :return 0 ; }@@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, }/* Raw bayer formats */ +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P : +if (src_size < ((width * height *10 )/8 )) { +V4LCONVERT_ERR ("short raw bayer10 data frame\n" ); + errno =EPIPE ; + result =-1 ; + } +switch (src_pix_fmt) { +case V4L2_PIX_FMT_SBGGR10P : + src_pix_fmt =V4L2_PIX_FMT_SBGGR8 ; +break ; +case V4L2_PIX_FMT_SGBRG10P : + src_pix_fmt =V4L2_PIX_FMT_SGBRG8 ; +break ; +case V4L2_PIX_FMT_SGRBG10P : + src_pix_fmt =V4L2_PIX_FMT_SGRBG8 ; +break ; +case V4L2_PIX_FMT_SRGGB10P : + src_pix_fmt =V4L2_PIX_FMT_SRGGB8 ; +break ; + } +v4lconvert_bayer10p_to_bayer8 (src, src, width, height); + bytesperline = width; + +/* Fall-through*/ case V4L2_PIX_FMT_SBGGR8 :case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :
Signature · 1 line
Ricardo Ribalda
Hi,
Quoted 49 lines · Ricardo Ribalda Delgado
Hi Hans
Quoted 37 lines · Hans de Goede
Hi,
Quoted 33 lines · Ricardo Ribalda Delgado
Add support for 10 bit packet Bayer formats:
(quoted diff) +0
-4-V4L2_PIX_FMT_SBGGR10P -V4L2_PIX_FMT_SGBRG10P -V4L2_PIX_FMT_SGRBG10P -V4L2_PIX_FMT_SRGGB10PThese formats pack the 2 LSBs for every 4 pixels in an indeppendent byte.
Signed-off-by Ricardo Ribalda Delgado <[email protected]>--- lib/libv4lconvert/bayer.c | 15 +++++++++++ lib/libv4lconvert/libv4lconvert-priv.h | 4 +++ lib/libv4lconvert/libv4lconvert.c | 35 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+)lib/libv4lconvert/bayer.c +9
-0@@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,v4lconvert_border_bayer_line_to_y (bayer + stride, bayer, ydst, width, !start_with_green, !blue_line); } + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height) +{ +long i, len = width * height; +uint32_t *src, *dst; + + src = (uint32_t *)bayer10p; + dst = (uint32_t *)bayer8;Quoted 8 lines
lib/libv4lconvert/bayer.c void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, · line 646
Quoted 4 lines
lib/libv4lconvert/bayer.c +4
-0+for (i =0 ; i < len ; i +=4 ) { + *dst = *src; + dst++; + src = (uint32_t *)(((uint8_t *)src) +5 );This will lead to unaligned 32 bit integer accesses which will terminate the program with an illegal instruction on pretty much all architectures except for x86.
Quoted 1 line
I see your point, but I am actually using this code on ARM64 with no issues.
That is weird, this is definitely illegal on armv7 perhaps the compiler recognizes the problem and fixes it in the generated code?
Quoted 1 line
I will change it.
Thanks.
Quoted 9 lines
Quoted 6 lines
You will need to copy the 4 components 1 by 1 so that you only use byte accesses.
Also you seem to simply be throwing away the extra 2 bits, although that will work I wonder if that is the best we can do?
Those are the LSB. If the user want the extra resolution has to use the bayer mode.
Ok.
Regards,
Hans
Quoted 92 lines
Quoted 89 lines
Regards,
Hans
Quoted 81 lines
lib/libv4lconvert/bayer.c +2
-0+ } +}lib/libv4lconvert/libv4lconvert-priv.h +4
-0@@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,void v4lconvert_bayer_to_yuv420 (const unsigned char *bayer,unsigned char *yuv,int width,int height,const unsigned int stride,unsigned int src_pixfmt,int yvu); + +void v4lconvert_bayer10p_to_bayer8 (unsigned char *bayer10p, +unsigned char *bayer8,int width,int height); +void v4lconvert_hm12_to_rgb24 (const unsigned char *src,unsigned char *dst,int width,int height);lib/libv4lconvert/libv4lconvert.c +35
-0@@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { { V4L2_PIX_FMT_SRGGB8, 8, 8, 8, 0 }, { V4L2_PIX_FMT_STV0680, 8, 8, 8, 1 }, { V4L2_PIX_FMT_SGRBG10, 16, 8, 8, 1 }, + { V4L2_PIX_FMT_SBGGR10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGBRG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGRBG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SRGGB10P, 10, 8, 8, 1 },/* compressed bayer */ { V4L2_PIX_FMT_SPCA561, 0, 9, 9, 1 }, { V4L2_PIX_FMT_SN9C10X, 0, 9, 9, 1 },@@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion(case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :case V4L2_PIX_FMT_SRGGB8 : +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P :case V4L2_PIX_FMT_STV0680 :return 0 ; }@@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, }/* Raw bayer formats */ +case V4L2_PIX_FMT_SBGGR10P : +case V4L2_PIX_FMT_SGBRG10P : +case V4L2_PIX_FMT_SGRBG10P : +case V4L2_PIX_FMT_SRGGB10P : +if (src_size < ((width * height *10 )/8 )) { +V4LCONVERT_ERR ("short raw bayer10 data frame\n" ); + errno =EPIPE ; + result =-1 ; + } +switch (src_pix_fmt) { +case V4L2_PIX_FMT_SBGGR10P : + src_pix_fmt =V4L2_PIX_FMT_SBGGR8 ; +break ; +case V4L2_PIX_FMT_SGBRG10P : + src_pix_fmt =V4L2_PIX_FMT_SGBRG8 ; +break ; +case V4L2_PIX_FMT_SGRBG10P : + src_pix_fmt =V4L2_PIX_FMT_SGRBG8 ; +break ; +case V4L2_PIX_FMT_SRGGB10P : + src_pix_fmt =V4L2_PIX_FMT_SRGGB8 ; +break ; + } +v4lconvert_bayer10p_to_bayer8 (src, src, width, height); + bytesperline = width; + +/* Fall-through*/ case V4L2_PIX_FMT_SBGGR8 :case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :