tx2 camera not set rgb888

Hi I am currently developing a camera on TX2.
But there is one thing that is not good. My camera is set to “RGB888” so I made the following modification and it showed wrong value. The output value is “AR24”. I know that “AR24” is not “RGB888” as far as I know. Could you tell me why? I’ll wait for your reply. Thanks

v4l2-ctl command :

v4l2-ctl --all -d /dev/video0

result
Driver Info (not using libv4l2):
Driver name : tegra-video
Card type : vi-output, ov491 2-0024
Bus info : platform:15700000.vi:0
Driver version: 4.4.38
Capabilities : 0x84200001
Video Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Priority: 2
Video input : 0 (Camera 0: no power)
Format Video Capture:
Width/Height : 1824/940
Pixel Format : ‘AR24’
Field : None
Bytes per Line : 7296
Size Image : 6858240
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Full Range)
Flags :

camera_common.c

static const struct camera_common_colorfmt camera_common_color_fmts[] = {
	{
		MEDIA_BUS_FMT_SRGGB12_1X12,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_SRGGB12,
	},
	{
		MEDIA_BUS_FMT_SRGGB10_1X10,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_SRGGB10,
	},
	{
		MEDIA_BUS_FMT_SBGGR10_1X10,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_SBGGR10,
	},
	{
		MEDIA_BUS_FMT_SRGGB8_1X8,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_SRGGB8,
	},
	/*
	 * The below two formats are not supported by VI4,
	 * keep them at the last to ensure they get discarded
	 */
	{
		MEDIA_BUS_FMT_XRGGB10P_3X10,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_XRGGB10P,
	},
	{
		MEDIA_BUS_FMT_XBGGR10P_3X10,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_XRGGB10P,
	},
	{
		 MEDIA_BUS_FMT_YUYV8_2X8,
	         V4L2_COLORSPACE_SRGB,
	         V4L2_PIX_FMT_YUYV,
	}, 
	{
	    	MEDIA_BUS_FMT_UYVY8_2X8,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_UYVY,
	},
	{// this setting i want 24bit rgb 888
		MEDIA_BUS_FMT_RGB888_1X24,
		V4L2_COLORSPACE_SRGB,
		V4L2_PIX_FMT_RGB24 ,
	},
};

sensor_common.c

static int extract_pixel_format(
	const char *pixel_t, u32 *format)
{
	size_t size = strnlen(pixel_t, OF_MAX_STR_LEN);

	if (strncmp(pixel_t, "bayer_bggr10", size) == 0)
		*format = V4L2_PIX_FMT_SBGGR10;
	else if (strncmp(pixel_t, "bayer_rggb10", size) == 0)
		*format = V4L2_PIX_FMT_SRGGB10;
	else if (strncmp(pixel_t, "bayer_bggr12", size) == 0)
		*format = V4L2_PIX_FMT_SBGGR12;
	else if (strncmp(pixel_t, "bayer_rggb12", size) == 0)
		*format = V4L2_PIX_FMT_SRGGB12;
	else if (strncmp(pixel_t, "bayer_wdr_pwl_rggb12", size) == 0)
		*format = V4L2_PIX_FMT_SRGGB12;
	else if (strncmp(pixel_t, "bayer_wdr_dol_rggb10", size) == 0)
		*format = V4L2_PIX_FMT_SRGGB10;
	else if (strncmp(pixel_t, "bayer_xbggr10p", size) == 0)
		*format = V4L2_PIX_FMT_XBGGR10P;
	else if (strncmp(pixel_t, "bayer_xrggb10p", size) == 0)
		*format = V4L2_PIX_FMT_XRGGB10P;
	else if (strncmp(pixel_t, "uyvy", size) == 0)
		*format = V4L2_PIX_FMT_UYVY;
	else if (strncmp(pixel_t, "yuyv", size) == 0)
		*format = V4L2_PIX_FMT_YUYV; 
	else if (strncmp(pixel_t, "rgb3", size) == 0)
		*format = V4L2_PIX_FMT_RGB24;
	else {
		pr_err("%s: Need to extend format%s\n", __func__, pixel_t);
		return -EINVAL;
	}

	return 0;
}

device tree setting

pixel_t = "rgb3";

hello withmarine,

looks like some erroneous with format reporting.
please dump the V4L2 pixel format FCC identifier result for checking. thanks

chan->fmtinfo->fourcc

and compare the expect result with RGB888,

#define V4L2_PIX_FMT_RGB24   v4l2_fourcc('R', 'G', 'B', '3') /* 24  RGB-8-8-8     */
#define v4l2_fourcc(a, b, c, d)\
	((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))

thank you for the reply JerryChang.
I have the following results, what do I need to check?

[ 4.818366] (null): tegra_channel_update_format: fourcc 875713089
[ 4.818367] (null): tegra_channel_fmt_align: set bytesperline 7296

#define V4L2_PIX_FMT_BGR24   v4l2_fourcc('B', 'G', 'R', '3') /* 24  BGR-8-8-8     */
#define V4L2_PIX_FMT_RGB24   v4l2_fourcc('R', 'G', 'B', '3') /* 24  RGB-8-8-8     */
#define V4L2_PIX_FMT_BGR32   v4l2_fourcc('B', 'G', 'R', '4') /* 32  BGR-8-8-8-8   */
#define V4L2_PIX_FMT_ABGR32  v4l2_fourcc('A', 'R', '2', '4') /* 32  BGRA-8-8-8-8  */

#define v4l2_fourcc(a, b, c, d)\
        ((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))

hello I’ll ask another question. Does TX2 support 24bit RGB888 on mipi? How can I configure if TX2 supports it?

hello withmarine,

  1. please confirm the return values of chan->fmtinfo->fourcc and V4L2_PIX_FMT_RGB24.
  2. according to tegra TRM, chapter 27 [Video Input (VI)]-> [27.10.1 Input Data Formats], RGB888 is supported.
  3. you should extended the camera_common_color_fmts structure to include RGB888 definitions.

hello JerryChang.
thank you for your support.
I solved this problem. The camera company gave me the wrong firmware.

int main(int argc, char **argv)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include <libv4l2.h>

#define CLEAR(x) memset(&(x), 0, sizeof(x))

struct buffer {
void *start;
size_t length;
};

static void xioctl(int fh, int request, void *arg)
{
int r;

    do {
            r = v4l2_ioctl(fh, request, arg);
    } while (r == -1 && ((errno == EINTR) || (errno == EAGAIN)));

    if (r == -1) {
            fprintf(stderr, "error %d, %s\\n", errno, strerror(errno));
            exit(EXIT_FAILURE);
    }

}

int main(int argc, char **argv)
{
struct v4l2_format fmt;
struct v4l2_buffer buf;
struct v4l2_requestbuffers req;
enum v4l2_buf_type type;
fd_set fds;
struct timeval tv;
int r, fd = -1;
unsigned int i, n_buffers;
char *dev_name = “/dev/video0”;
char out_name[256];
FILE *fout;
struct buffer *buffers;

    fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
    if (fd < 0) {
            perror("Cannot open device");
            exit(EXIT_FAILURE);
    }

    CLEAR(fmt);
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width       = 2592;
    fmt.fmt.pix.height      = 1458;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SRGGB10;
    fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
    xioctl(fd, VIDIOC_S_FMT, &fmt);
    if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_SRGGB10) {
            printf("Libv4l didn't accept RGB24 format. Can't proceed.\\n");
            exit(EXIT_FAILURE);
    }
    if ((fmt.fmt.pix.width != 2592) || (fmt.fmt.pix.height != 480))
            printf("Warning: driver is sending image at %dx%d\\n",
                    fmt.fmt.pix.width, fmt.fmt.pix.height);

    CLEAR(req);
    req.count = 2;
    req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    req.memory = V4L2_MEMORY_MMAP;
    xioctl(fd, VIDIOC_REQBUFS, &req);

    buffers = calloc(req.count, sizeof(*buffers));
    for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
            CLEAR(buf);

            buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory      = V4L2_MEMORY_MMAP;
            buf.index       = n_buffers;

            xioctl(fd, VIDIOC_QUERYBUF, &buf);

            buffers[n_buffers].length = buf.length;
            buffers[n_buffers].start = v4l2_mmap(NULL, buf.length,
                          PROT_READ | PROT_WRITE, MAP_SHARED,
                          fd, buf.m.offset);

            if (MAP_FAILED == buffers[n_buffers].start) {
                    perror("mmap");
                    exit(EXIT_FAILURE);
            }
    }

    for (i = 0; i < n_buffers; ++i) {
            CLEAR(buf);
            buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory = V4L2_MEMORY_MMAP;
            buf.index = i;
            xioctl(fd, VIDIOC_QBUF, &buf);
    }
    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    xioctl(fd, VIDIOC_STREAMON, &type);
    for (i = 0; i < 2; i++) {
            do {
                    FD_ZERO(&fds);
                    FD_SET(fd, &fds);

                    /* Timeout. */
                    tv.tv_sec = 2;
                    tv.tv_usec = 0;

                    r = select(fd + 1, &fds, NULL, NULL, &tv);
            } while ((r == -1 && (errno = EINTR)));
            if (r == -1) {
                    perror("select");
                    return errno;
            }

            CLEAR(buf);
            buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory = V4L2_MEMORY_MMAP;
            xioctl(fd, VIDIOC_DQBUF, &buf);

            sprintf(out_name, "out%03d.ppm", i);
            fout = fopen(out_name, "w");
            if (!fout) {
                    perror("Cannot open image");
                    exit(EXIT_FAILURE);
            }
            fprintf(fout, "P6\\n%d %d 255\\n",
                    fmt.fmt.pix.width, fmt.fmt.pix.height);
            fwrite(buffers[buf.index].start, buf.bytesused, 1, fout);
            fclose(fout);

            xioctl(fd, VIDIOC_QBUF, &buf);
    }

    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    xioctl(fd, VIDIOC_STREAMOFF, &type);
    for (i = 0; i < n_buffers; ++i)
            v4l2_munmap(buffers[i].start, buffers[i].length);
    v4l2_close(fd);

    return 0

}

i am try this code for open camera and capture image through .c program…

after run this program it show…

img.ppm …

how to convert ppm to jpg or any other from which can i see it…

hello gajananjadhav705,

A *.ppm image is one of common image formats. you should able to open the file by ubuntu’s default image viewer application.
or, try to download GIMP to access *.ppm image formats.
thanks

hi,

i am download the gimp…but i am unable to open through it…

can say how to open gimp through…

any command line utility?

i am not understanding ubuntus default image viewer application…

can you explain…

Opening ‘/home/sreop/out000.ppm’ failed:

PNM Image plug-In could not open image

in gimp software…after openning ppm image its show like this…

pls check above write code…

Gimp itself does work on a TX2, but gimp may be using plugins for various formats (not sure). It isn’t the Jetson which can’t open the format, it is the specific program gimp (but gimp should work with some PPM images on a TX2).

PPM itself has a couple of data formats. Can you provide a copy of the image you are using? Not sure if the forum will allow attaching, but if you want to try, then hover your mouse over the quote mark in the upper right corner of an existing post…you’ll see the pencil icon show up. This edits an existing post and you can try the picture icon…or if you instead hover the mouse over the quote you will see a paper clip icon…this can be used to directly attach some file formats (you might need to gzip or otherwise zip the file to get it to allow).

hello gajananjadhav705,

this topic is talking about RGB888 format support.
suggest you file another new topic since your issue now is not able to open *.ppm format.
thanks