add v4l2 test
This commit is contained in:
Executable
+18
@@ -0,0 +1,18 @@
|
||||
config BR2_PACKAGE_V4L2_TEST
|
||||
bool "v4l2_test"
|
||||
depends on BR2_TOOLCHAIN_HAS_THREADS # libv4l
|
||||
depends on BR2_USE_MMU # libv4l
|
||||
depends on !BR2_STATIC_LIBS # libv4l
|
||||
depends on BR2_INSTALL_LIBSTDCPP # libv4l
|
||||
depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_0 # libv4l
|
||||
select BR2_PACKAGE_JPEG
|
||||
select BR2_PACKAGE_LIBV4L
|
||||
help
|
||||
Utility for v4l2test JPEGs form V4L2 devices. This tool is
|
||||
similar to v4l2grab available from libv4l contrib directory,
|
||||
but provides additional features such as JPEG output.
|
||||
|
||||
comment "v4l2_test needs a toolchain w/ threads, dynamic library, C++ and headers >= 3.0"
|
||||
depends on BR2_USE_MMU
|
||||
depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS \
|
||||
|| !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_0
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the `getpagesize' function. */
|
||||
#undef HAVE_GETPAGESIZE
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `jpeg' library (-ljpeg). */
|
||||
#undef HAVE_LIBJPEG
|
||||
|
||||
/* Define to 1 if you have the `v4l2' library (-lv4l2). */
|
||||
#undef HAVE_LIBV4L2
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
#undef HAVE_MALLOC_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#undef HAVE_SELECT
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
#undef malloc
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
Executable
+823
@@ -0,0 +1,823 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <asm/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <linux/fb.h>
|
||||
|
||||
extern struct fb_var_screeninfo vinfo;
|
||||
extern struct fb_fix_screeninfo finfo;
|
||||
extern int screensize;
|
||||
|
||||
int yuyv_resize(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
unsigned char *YUVindata, *YUVoutdata; /* YUV和RGB数据指针 */
|
||||
int YUVinpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned int start_timems;
|
||||
unsigned int end_timems;
|
||||
struct timeval ts_start, ts_end;
|
||||
|
||||
if (!tmp)
|
||||
return -1;
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
YUVindata = inBuf;
|
||||
YUVoutdata = tmp;
|
||||
|
||||
if (imgWidth == vinfo.xres) {
|
||||
YUVinpos = (y_offset * vinfo.xres + x_offset) * 2;
|
||||
memcpy(&tmp[YUVinpos], inBuf, imgWidth * height * 2);
|
||||
memcpy(&outBuf[YUVinpos], &tmp[YUVinpos], imgWidth * height * 2);
|
||||
// memcpy(&outBuf[YUVinpos], inBuf, imgWidth * height * 2);
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_usec/1000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_usec/1000;
|
||||
// printf("%s: copy use %dms, sizeof(int) = %d\n", __func__, end_timems - start_timems, sizeof(int));
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 每个像素两个字节 */
|
||||
for(rows = 0; rows < height; rows++)
|
||||
{
|
||||
// vinfo.xres, vinfo.yres vinfo.bits_per_pixel
|
||||
YUVoutdata = tmp + ((rows + y_offset) * vinfo.xres + x_offset) * 2;
|
||||
YUVinpos = rows * imgWidth * 2;
|
||||
|
||||
memcpy(YUVoutdata, &YUVindata[YUVinpos], imgWidth * 2);
|
||||
}
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000000 + ts_start.tv_usec;
|
||||
end_timems = ts_end.tv_sec * 1000000 + ts_end.tv_usec;
|
||||
// printf("%s: convert use %dus\n", __func__, end_timems - start_timems);
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_usec/1000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_usec/1000;
|
||||
// printf("%s: copy use %dms, sizeof(int) = %d\n", __func__, end_timems - start_timems, sizeof(int));
|
||||
|
||||
free(tmp);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int convert_yuyv_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_yuyv)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
int y, u, v, r, g, b; /* yuv rgb 相关分量 */
|
||||
unsigned char *nv12data, *YUVdata; /* YUV和RGB数据指针 */
|
||||
int Ypos, Upos, Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
int fb_Ypos, fb_Upos, fb_Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned int start_timems;
|
||||
unsigned int end_timems;
|
||||
struct timeval ts_start, ts_end;
|
||||
|
||||
if (!tmp)
|
||||
return -1;
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
YUVdata = inBuf;
|
||||
nv12data = tmp;
|
||||
|
||||
/* 每个像素两个字节 */
|
||||
for(rows = 0; rows < height; rows++)
|
||||
{
|
||||
// vinfo.xres, vinfo.yres vinfo.bits_per_pixel
|
||||
fb_Ypos = ((rows + y_offset) * vinfo.xres + x_offset);
|
||||
fb_Upos = ((rows + y_offset) / 2 * vinfo.xres / 2 + x_offset / 2) * 2;
|
||||
fb_Upos = vinfo.xres * vinfo.yres + fb_Upos;
|
||||
fb_Vpos = fb_Upos + 1;
|
||||
|
||||
Ypos = rows * imgWidth * 2;
|
||||
|
||||
for (cols = 0; cols < width; cols += 2) {
|
||||
nv12data[fb_Ypos+cols] = YUVdata[Ypos+cols*2];
|
||||
nv12data[fb_Ypos+cols+1] = YUVdata[Ypos+cols*2+2];
|
||||
nv12data[fb_Upos+cols] = YUVdata[Ypos+cols*2+1];
|
||||
nv12data[fb_Vpos+cols] = YUVdata[Ypos+cols*2+3];
|
||||
}
|
||||
}
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000000 + ts_start.tv_usec;
|
||||
end_timems = ts_end.tv_sec * 1000000 + ts_end.tv_usec;
|
||||
// printf("%s: convert use %dus\n", __func__, end_timems - start_timems);
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_usec/1000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_usec/1000;
|
||||
// printf("%s: copy use %dms, sizeof(int) = %d\n", __func__, end_timems - start_timems, sizeof(int));
|
||||
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_nv21_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
int y, u, v, r, g, b; /* yuv rgb 相关分量 */
|
||||
unsigned char *nv12data, *nv21data; /* YUV和RGB数据指针 */
|
||||
int Ypos, Upos, Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
int fb_Ypos, fb_Upos, fb_Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned int start_timems;
|
||||
unsigned int end_timems;
|
||||
struct timeval ts_start, ts_end;
|
||||
|
||||
if (!tmp)
|
||||
return -1;
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
nv21data = inBuf;
|
||||
nv12data = tmp;
|
||||
|
||||
if (imgWidth == vinfo.xres) {
|
||||
fb_Ypos = y_offset * vinfo.xres + x_offset;
|
||||
fb_Upos = (y_offset / 2 * vinfo.xres / 2 + x_offset / 2) * 2;
|
||||
fb_Upos = vinfo.xres * vinfo.yres + fb_Upos;
|
||||
Upos = imgWidth * imgHeight;
|
||||
memcpy(&tmp[fb_Ypos], inBuf, imgWidth * height);
|
||||
memcpy(&tmp[fb_Upos], &inBuf[Upos], imgWidth * height / 2);
|
||||
memcpy(&outBuf[fb_Ypos], &tmp[fb_Ypos], imgWidth * height * 2);
|
||||
memcpy(&outBuf[fb_Upos], &tmp[fb_Upos], imgWidth * height / 2);
|
||||
// memcpy(&outBuf[fb_Ypos], inBuf, imgWidth * height);
|
||||
// memcpy(&outBuf[fb_Upos], inBuf, imgWidth * height / 2);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 每个像素两个字节 */
|
||||
for(rows = 0; rows < height; rows+=2)
|
||||
{
|
||||
// vinfo.xres, vinfo.yres vinfo.bits_per_pixel
|
||||
fb_Ypos = ((rows + y_offset) * vinfo.xres + x_offset);
|
||||
fb_Upos = ((rows + y_offset) / 2 * vinfo.xres / 2 + x_offset / 2) * 2;
|
||||
fb_Upos = vinfo.xres * vinfo.yres + fb_Upos;
|
||||
fb_Vpos = fb_Upos + 1;
|
||||
|
||||
Ypos = rows * imgWidth;
|
||||
Upos = imgWidth * imgHeight + Ypos / 2;
|
||||
Vpos = Upos + 1;
|
||||
memcpy(&nv12data[fb_Ypos], &nv21data[Ypos], width);
|
||||
memcpy(&nv12data[fb_Ypos+vinfo.xres], &nv21data[Ypos+imgWidth], width);
|
||||
|
||||
if (is_nv21) {
|
||||
for (cols = 0; cols < width; cols += 2) {
|
||||
nv12data[fb_Upos+cols] = nv21data[Vpos+cols];
|
||||
nv12data[fb_Vpos+cols] = nv21data[Upos+cols];
|
||||
}
|
||||
} else
|
||||
memcpy(&nv12data[fb_Upos], &nv21data[Upos], width);
|
||||
}
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000000 + ts_start.tv_usec;
|
||||
end_timems = ts_end.tv_sec * 1000000 + ts_end.tv_usec;
|
||||
// printf("%s: convert use %dus\n", __func__, end_timems - start_timems);
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_usec/1000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_usec/1000;
|
||||
// printf("%s: copy use %dms, sizeof(int) = %d\n", __func__, end_timems - start_timems, sizeof(int));
|
||||
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_nv21_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
int y, u, v, r, g, b; /* yuv rgb 相关分量 */
|
||||
unsigned char *YUVdata, *RGBdata; /* YUV和RGB数据指针 */
|
||||
int Ypos, Upos, Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned int start_timems;
|
||||
unsigned int end_timems;
|
||||
struct timeval ts_start, ts_end;
|
||||
|
||||
if (!tmp)
|
||||
return -1;
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
YUVdata = inBuf;
|
||||
RGBdata = tmp;
|
||||
|
||||
/* 每个像素两个字节 */
|
||||
for(rows = 0; rows < height; rows++)
|
||||
{
|
||||
// vinfo.xres, vinfo.yres vinfo.bits_per_pixel
|
||||
RGBdata = tmp + ((rows + y_offset) * vinfo.xres + x_offset) * vinfo.bits_per_pixel / 8;
|
||||
|
||||
Ypos = rows * imgWidth;
|
||||
Vpos = Upos = imgWidth * imgHeight + Ypos / 2;
|
||||
if (is_nv21)
|
||||
Vpos = Upos + 1;
|
||||
else
|
||||
Upos = Vpos + 1;
|
||||
i = 0;
|
||||
|
||||
for(cols = 0; cols < width; cols++)
|
||||
{
|
||||
/* 矩阵推到,百度 */
|
||||
y = YUVdata[Ypos];
|
||||
u = YUVdata[Upos] - 128;
|
||||
v = YUVdata[Vpos] - 128;
|
||||
|
||||
r = y + v + ((v * 103) >> 8);
|
||||
g = y - ((u * 88) >> 8) - ((v * 183) >> 8);
|
||||
b = y + u + ((u * 198) >> 8);
|
||||
|
||||
r = r > 255 ? 255 : (r < 0 ? 0 : r);
|
||||
g = g > 255 ? 255 : (g < 0 ? 0 : g);
|
||||
b = b > 255 ? 255 : (b < 0 ? 0 : b);
|
||||
|
||||
/* 从低到高r g b */
|
||||
if (vinfo.bits_per_pixel == 16) { // RGB565
|
||||
*(RGBdata ++) = (((g & 0x1c) << 3) | (b >> 3)); /* g低5位,b高5位 */
|
||||
*(RGBdata ++) = ((r & 0xf8) | (g >> 5)); /* r高5位,g高3位 */
|
||||
} else if (vinfo.bits_per_pixel == 24) { // RGB888
|
||||
*(RGBdata ++) = b;
|
||||
*(RGBdata ++) = g;
|
||||
*(RGBdata ++) = r;
|
||||
} else { // RGB8888
|
||||
*(RGBdata ++) = b;
|
||||
*(RGBdata ++) = g;
|
||||
*(RGBdata ++) = r;
|
||||
*(RGBdata ++) = 0xFF;
|
||||
}
|
||||
Ypos++;
|
||||
i++;
|
||||
/* 每4个Y更新一次UV */
|
||||
if(!(i & 0x03))
|
||||
{
|
||||
Vpos = Upos = imgWidth * imgHeight + Ypos/2;
|
||||
if (is_nv21)
|
||||
Vpos = Upos + 1;
|
||||
else
|
||||
Upos = Vpos + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000000 + ts_start.tv_usec;
|
||||
end_timems = ts_end.tv_sec * 1000000 + ts_end.tv_usec;
|
||||
// printf("%s: convert use %dus\n", __func__, end_timems - start_timems);
|
||||
|
||||
gettimeofday(&ts_start, NULL);
|
||||
|
||||
#if 1
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
#else
|
||||
int *p_outBuf, *p_tmp;
|
||||
int size = screensize/4;
|
||||
p_outBuf = outBuf;
|
||||
p_tmp = tmp;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
p_outBuf[i] = p_tmp[i];
|
||||
#endif
|
||||
gettimeofday(&ts_end, NULL);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_usec/1000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_usec/1000;
|
||||
// printf("%s: copy use %dms, sizeof(int) = %d\n", __func__, end_timems - start_timems, sizeof(int));
|
||||
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Y' = 0.257*R' + 0.504*G' + 0.098*B' + 16
|
||||
static int Rgb2Y(int r0, int g0, int b0)
|
||||
{
|
||||
// float y0 = 0.257f*r0 + 0.504f*g0 + 0.098f*b0 + 16.0f;
|
||||
// int y0 = (257*r0 + 504*g0 + 98*b0)/1000 + 16;
|
||||
// Y = (77*R + 150*G + 29*B)>>8;
|
||||
int y0 = (77*r0+150*g0+29*b0) >> 8;
|
||||
return y0;
|
||||
}
|
||||
|
||||
//U equals Cb'
|
||||
//Cb' = -0.148*R' - 0.291*G' + 0.439*B' + 128
|
||||
static int Rgb2U(int r0, int g0, int b0)
|
||||
{
|
||||
// float u0 = -0.148f*r0 - 0.291f*g0 + 0.439f*b0 + 128.0f;
|
||||
// int u0 = (-148*r0 - 291*g0 + 439*b0)/1000 + 128;
|
||||
// U = ((-44*R - 87*G + 131*B)>>8) + 128;
|
||||
int u0 = ((-44*r0 - 87*g0 + 131*b0)>>8) + 128;
|
||||
return u0;
|
||||
}
|
||||
|
||||
//V equals Cr'
|
||||
//Cr' = 0.439*R' - 0.368*G' - 0.071*B' + 128
|
||||
static int Rgb2V(int r0, int g0, int b0)
|
||||
{
|
||||
// float v0 = 0.439f*r0 - 0.368f*g0 - 0.071f*b0 + 128.0f;
|
||||
// int v0 = (439*r0 - 368*g0 - 71*b0)/1000 + 128;
|
||||
// V = ((131*R - 110*G - 21*B)>>8) + 128 ;
|
||||
int v0 = ((131*r0 - 110*g0 - 21*b0)>>8) + 128;
|
||||
return v0;
|
||||
}
|
||||
|
||||
//Convert two rows from RGB to two Y rows, and one row of interleaved U,V.
|
||||
//I0 and I1 points two sequential source rows.
|
||||
//I0 -> rgbrgbrgbrgbrgbrgb...
|
||||
//I1 -> rgbrgbrgbrgbrgbrgb...
|
||||
//Y0 and Y1 points two sequential destination rows of Y plane.
|
||||
//Y0 -> yyyyyy
|
||||
//Y1 -> yyyyyy
|
||||
//UV0 points destination rows of interleaved UV plane.
|
||||
//UV0 -> uvuvuv
|
||||
static void Rgb2NV12TwoRows(const unsigned char I0[],
|
||||
const unsigned char I1[],
|
||||
int step,
|
||||
const int image_width,
|
||||
unsigned char Y0[],
|
||||
unsigned char Y1[],
|
||||
unsigned char UV0[])
|
||||
{
|
||||
int x; //Column index
|
||||
|
||||
//Process 4 source pixels per iteration (2 pixels of row I0 and 2 pixels of row I1).
|
||||
for (x = 0; x < image_width; x += 2)
|
||||
{
|
||||
//Load R,G,B elements from first row (and convert to int).
|
||||
unsigned char b00 = (I0[x*step + 0] & 0x1F) << 3;
|
||||
unsigned char g00 = ((I0[x*step + 1] & 0x7) << 3 | I0[x*step + 0] >> 5) << 2;
|
||||
unsigned char r00 = I0[x*step + 1] & (~0x7);
|
||||
|
||||
//Load next R,G,B elements from first row (and convert to int).
|
||||
unsigned char b01 = (I0[x*step + step+0] & 0x1F) << 3;
|
||||
unsigned char g01 = ((I0[x*step + step+1] & 0x7) << 3 | I0[x*step + step+0] >> 5) << 2;
|
||||
unsigned char r01 = I0[x*step + step+1] & (~0x7);
|
||||
|
||||
//Load R,G,B elements from second row (and convert to int).
|
||||
unsigned char b10 = (I1[x*step + 0] & 0x1F) << 3;
|
||||
unsigned char g10 = ((I1[x*step + 1] & 0x7) << 3 | I1[x*step + 0] >> 5) << 2;
|
||||
unsigned char r10 = I1[x*step + 1] & (~0x7);
|
||||
|
||||
//Load next R,G,B elements from second row (and convert to int).
|
||||
unsigned char b11 = (I1[x*step + step+0] & 0x1F) << 3;
|
||||
unsigned char g11 = ((I1[x*step + step+1] & 0x7) << 3 | I1[x*step + step+0] >> 5) << 2;
|
||||
unsigned char r11 = I1[x*step + step+1] & (~0x7);
|
||||
|
||||
//Calculate 4 Y elements.
|
||||
unsigned char y00 = Rgb2Y(r00, g00, b00);
|
||||
unsigned char y01 = Rgb2Y(r01, g01, b01);
|
||||
unsigned char y10 = Rgb2Y(r10, g10, b10);
|
||||
unsigned char y11 = Rgb2Y(r11, g11, b11);
|
||||
|
||||
//Calculate 4 U elements.
|
||||
unsigned char u00 = Rgb2U(r00, g00, b00);
|
||||
unsigned char u01 = Rgb2U(r01, g01, b01);
|
||||
unsigned char u10 = Rgb2U(r10, g10, b10);
|
||||
unsigned char u11 = Rgb2U(r11, g11, b11);
|
||||
|
||||
//Calculate 4 V elements.
|
||||
unsigned char v00 = Rgb2V(r00, g00, b00);
|
||||
unsigned char v01 = Rgb2V(r01, g01, b01);
|
||||
unsigned char v10 = Rgb2V(r10, g10, b10);
|
||||
unsigned char v11 = Rgb2V(r11, g11, b11);
|
||||
|
||||
//Calculate destination U element: average of 2x2 "original" U elements.
|
||||
unsigned char u0 = (u00 + u01 + u10 + u11)/4;
|
||||
|
||||
//Calculate destination V element: average of 2x2 "original" V elements.
|
||||
unsigned char v0 = (v00 + v01 + v10 + v11)/4;
|
||||
|
||||
//Store 4 Y elements (two in first row and two in second row).
|
||||
Y0[x + 0] = y00;
|
||||
Y0[x + 1] = y01;
|
||||
Y1[x + 0] = y10;
|
||||
Y1[x + 1] = y11;
|
||||
|
||||
// //Store destination U element.
|
||||
UV0[x + 0] = u0;
|
||||
|
||||
// //Store destination V element (next to stored U element).
|
||||
UV0[x + 1] = v0;
|
||||
}
|
||||
}
|
||||
|
||||
//Convert image I from pixel ordered RGB to NV12 format.
|
||||
//I - Input image in pixel ordered RGB format
|
||||
//image_width - Number of columns of I
|
||||
//image_height - Number of rows of I
|
||||
//J - Destination "image" in NV12 format.
|
||||
|
||||
//I is pixel ordered RGB color format (size in bytes is image_width*image_height*3):
|
||||
//RGBRGBRGBRGBRGBRGB
|
||||
//RGBRGBRGBRGBRGBRGB
|
||||
//RGBRGBRGBRGBRGBRGB
|
||||
//RGBRGBRGBRGBRGBRGB
|
||||
//
|
||||
//J is in NV12 format (size in bytes is image_width*image_height*3/2):
|
||||
//YYYYYY
|
||||
//YYYYYY
|
||||
//UVUVUV
|
||||
//Each element of destination U is average of 2x2 "original" U elements
|
||||
//Each element of destination V is average of 2x2 "original" V elements
|
||||
//
|
||||
//Limitations:
|
||||
//1. image_width must be a multiple of 2.
|
||||
//2. image_height must be a multiple of 2.
|
||||
//3. I and J must be two separate arrays (in place computation is not supported).
|
||||
void Rgb2NV12(const unsigned char I[], int step,
|
||||
const int image_width,
|
||||
const int image_height,
|
||||
unsigned char J[])
|
||||
{
|
||||
//In NV12 format, UV plane starts below Y plane.
|
||||
// unsigned char *UV = &J[image_width*image_height];
|
||||
unsigned char *UV = J;
|
||||
|
||||
//I0 and I1 points two sequential source rows.
|
||||
const unsigned char *I0; //I0 -> rgbrgbrgbrgbrgbrgb...
|
||||
const unsigned char *I1; //I1 -> rgbrgbrgbrgbrgbrgb...
|
||||
|
||||
//Y0 and Y1 points two sequential destination rows of Y plane.
|
||||
unsigned char *Y0; //Y0 -> yyyyyy
|
||||
unsigned char *Y1; //Y1 -> yyyyyy
|
||||
|
||||
//UV0 points destination rows of interleaved UV plane.
|
||||
unsigned char *UV0; //UV0 -> uvuvuv
|
||||
|
||||
int y; //Row index
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
|
||||
width = image_width > vinfo.xres ? vinfo.xres : image_width;
|
||||
height = image_height > vinfo.yres ? vinfo.yres : image_height;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
//In each iteration: process two rows of Y plane, and one row of interleaved UV plane.
|
||||
for (y = 0; y < height; y += 2)
|
||||
{
|
||||
I0 = &I[y*image_width*step]; //Input row width is image_width*3 bytes (each pixel is R,G,B).
|
||||
I1 = &I[(y+1)*image_width*step];
|
||||
|
||||
Y0 = &J[(y+y_offset)*vinfo.xres+x_offset]; //Output Y row width is image_width bytes (one Y element per pixel).
|
||||
Y1 = &J[(y+1+y_offset)*vinfo.xres+x_offset];
|
||||
|
||||
UV0 = &UV[vinfo.xres*vinfo.yres+((y+y_offset)/2*vinfo.xres/2+x_offset/2)*2]; //Output UV row - width is same as Y row width.
|
||||
|
||||
//Process two source rows into: Two Y destination row, and one destination interleaved U,V row.
|
||||
Rgb2NV12TwoRows(I0,
|
||||
I1,
|
||||
step,
|
||||
width,
|
||||
Y0,
|
||||
Y1,
|
||||
UV0);
|
||||
}
|
||||
}
|
||||
|
||||
int convert_rgb565_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
int y, u, v, r, g, b; /* yuv rgb 相关分量 */
|
||||
unsigned char *YUVdata, *RGBdata; /* YUV和RGB数据指针 */
|
||||
int Ypos, Upos, Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned int start_timems;
|
||||
unsigned int end_timems;
|
||||
struct timespec ts_start, ts_end;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_start);
|
||||
|
||||
|
||||
Rgb2NV12(inBuf, 2, imgWidth, imgHeight, tmp);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_end);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_nsec/1000000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_nsec/1000000;
|
||||
// printf("%s: convert use %dms\n", __func__, end_timems - start_timems);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_start);
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_end);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_nsec/1000000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_nsec/1000000;
|
||||
// printf("%s: use %dms\n", __func__, end_timems - start_timems);
|
||||
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_yuyv_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
int y, u, v, r, g, b; /* yuv rgb 相关分量 */
|
||||
unsigned char *YUVdata, *RGBdata; /* YUV和RGB数据指针 */
|
||||
int Ypos, Upos, Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned int start_timems;
|
||||
unsigned int end_timems;
|
||||
struct timespec ts_start, ts_end;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_start);
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
YUVdata = inBuf;
|
||||
RGBdata = tmp;
|
||||
|
||||
/* 每个像素两个字节 */
|
||||
for(rows = 0; rows < height; rows++)
|
||||
{
|
||||
// vinfo.xres, vinfo.yres vinfo.bits_per_pixel
|
||||
RGBdata = tmp + ((rows + y_offset) * vinfo.xres + x_offset) * vinfo.bits_per_pixel / 8;
|
||||
|
||||
Ypos = rows * imgWidth * 2;
|
||||
Upos = Ypos + 1;
|
||||
Vpos = Upos + 2;
|
||||
i = 0;
|
||||
|
||||
for(cols = 0; cols < width; cols++)
|
||||
{
|
||||
/* 矩阵推到,百度 */
|
||||
y = YUVdata[Ypos];
|
||||
u = YUVdata[Upos] - 128;
|
||||
v = YUVdata[Vpos] - 128;
|
||||
|
||||
r = y + v + ((v * 103) >> 8);
|
||||
g = y - ((u * 88) >> 8) - ((v * 183) >> 8);
|
||||
b = y + u + ((u * 198) >> 8);
|
||||
|
||||
r = r > 255 ? 255 : (r < 0 ? 0 : r);
|
||||
g = g > 255 ? 255 : (g < 0 ? 0 : g);
|
||||
b = b > 255 ? 255 : (b < 0 ? 0 : b);
|
||||
|
||||
/* 从低到高r g b */
|
||||
if (vinfo.bits_per_pixel == 16) { // RGB565
|
||||
*(RGBdata ++) = (((g & 0x1c) << 3) | (b >> 3)); /* g低5位,b高5位 */
|
||||
*(RGBdata ++) = ((r & 0xf8) | (g >> 5)); /* r高5位,g高3位 */
|
||||
} else if (vinfo.bits_per_pixel == 24) { // RGB888
|
||||
*(RGBdata ++) = b;
|
||||
*(RGBdata ++) = g;
|
||||
*(RGBdata ++) = r;
|
||||
} else { // RGB8888
|
||||
*(RGBdata ++) = b;
|
||||
*(RGBdata ++) = g;
|
||||
*(RGBdata ++) = r;
|
||||
*(RGBdata ++) = 0xFF;
|
||||
}
|
||||
/* 两个字节数据中包含一个Y */
|
||||
Ypos += 2;
|
||||
//Ypos++;
|
||||
i++;
|
||||
/* 每两个Y更新一次UV */
|
||||
if(!(i & 0x01))
|
||||
{
|
||||
Upos = Ypos + 1;
|
||||
Vpos = Upos + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_end);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_nsec/1000000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_nsec/1000000;
|
||||
// printf("%s: convert use %dms\n", __func__, end_timems - start_timems);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_start);
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts_end);
|
||||
start_timems = ts_start.tv_sec * 1000 + ts_start.tv_nsec/1000000;
|
||||
end_timems = ts_end.tv_sec * 1000 + ts_end.tv_nsec/1000000;
|
||||
// printf("%s: use %dms\n", __func__, end_timems - start_timems);
|
||||
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_yuv444_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
int y, u, v, r, g, b; /* yuv rgb 相关分量 */
|
||||
unsigned char *YUVdata, *RGBdata; /* YUV和RGB数据指针 */
|
||||
int Ypos, Upos, Vpos; /* Y U V在数据缓存中的偏移 */
|
||||
unsigned int i = 0;
|
||||
unsigned short bar = 0;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
|
||||
YUVdata = inBuf;
|
||||
RGBdata = tmp;
|
||||
/* YUV */
|
||||
Ypos = 0;
|
||||
|
||||
for(rows = 0; rows < imgHeight; rows++)
|
||||
{
|
||||
for(cols = 0; cols < imgWidth; cols++)
|
||||
{
|
||||
y = YUVdata[Ypos];
|
||||
u = YUVdata[Ypos + 1] - 128;
|
||||
v = YUVdata[Ypos + 2] - 128;
|
||||
|
||||
r = y + v + ((v * 103) >> 8);
|
||||
g = y - ((u * 88) >> 8) - ((v * 183) >> 8);
|
||||
b = y + u + ((u * 198) >> 8);
|
||||
|
||||
r = r > 255 ? 255 : (r < 0 ? 0 : r);
|
||||
g = g > 255 ? 255 : (g < 0 ? 0 : g);
|
||||
b = b > 255 ? 255 : (b < 0 ? 0 : b);
|
||||
|
||||
/* 从低到高r g b */
|
||||
if (vinfo.bits_per_pixel == 16) { // RGB565
|
||||
*(RGBdata ++) = (((g & 0x1c) << 3) | (b >> 3)); /* g低5位,b高5位 */
|
||||
*(RGBdata ++) = ((r & 0xf8) | (g >> 5)); /* r高5位,g高3位 */
|
||||
} else if (vinfo.bits_per_pixel == 24) { // RGB888
|
||||
*(RGBdata ++) = b;
|
||||
*(RGBdata ++) = g;
|
||||
*(RGBdata ++) = r;
|
||||
} else { // RGB8888
|
||||
*(RGBdata ++) = b;
|
||||
*(RGBdata ++) = g;
|
||||
*(RGBdata ++) = r;
|
||||
*(RGBdata ++) = 0xFF;
|
||||
}
|
||||
Ypos += 3;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_rgb565_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
unsigned char *RGB565data, *RGBdata; /* YUV和RGB数据指针 */
|
||||
int RGBpos;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
RGB565data = inBuf;
|
||||
RGBdata = tmp;
|
||||
|
||||
if (imgWidth == vinfo.xres) {
|
||||
RGBpos = (y_offset * vinfo.xres + x_offset) * 2;
|
||||
memcpy(&tmp[RGBpos], inBuf, imgWidth * height * 2);
|
||||
memcpy(&outBuf[RGBpos], &tmp[RGBpos], imgWidth * height * 2);
|
||||
// memcpy(&outBuf[RGBpos], inBuf, imgWidth * height * 2);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RGBpos = 0;
|
||||
for(rows = 0; rows < imgHeight; rows++)
|
||||
{
|
||||
RGBdata = tmp + ((rows + y_offset) * vinfo.xres + x_offset) * vinfo.bits_per_pixel / 8;
|
||||
RGBpos = rows * imgWidth * 2;
|
||||
if (vinfo.bits_per_pixel == 16) { // RGB565
|
||||
memcpy(RGBdata, &RGB565data[RGBpos], imgWidth * 2);
|
||||
} else {
|
||||
for(cols = 0; cols < imgWidth; cols++)
|
||||
{
|
||||
*(RGBdata ++) = RGB565data[RGBpos] & 0x1F;
|
||||
*(RGBdata ++) = (RGB565data[RGBpos + 1] & 0x7) << 3 | RGB565data[RGBpos] >> 5;
|
||||
*(RGBdata ++) = RGB565data[RGBpos + 1] >> 3;
|
||||
if (vinfo.bits_per_pixel == 32) { // RGB888
|
||||
*(RGBdata ++) = 0xFF;
|
||||
}
|
||||
RGBpos += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convert_rgb888_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod)
|
||||
{
|
||||
int rows ,cols; /* 行列标志 */
|
||||
unsigned char *RGB888data, *RGBdata; /* YUV和RGB数据指针 */
|
||||
int RGBpos;
|
||||
int width, height;
|
||||
int x_offset, y_offset;
|
||||
unsigned char *tmp = malloc(screensize);
|
||||
unsigned char r, g, b;
|
||||
|
||||
width = imgWidth > vinfo.xres ? vinfo.xres : imgWidth;
|
||||
height = imgHeight > vinfo.yres ? vinfo.yres : imgHeight;
|
||||
x_offset = (vinfo.xres - width) / 2;
|
||||
y_offset = (vinfo.yres - height) / 2;
|
||||
|
||||
RGB888data = inBuf;
|
||||
RGBdata = tmp;
|
||||
|
||||
RGBpos = 0;
|
||||
for(rows = 0; rows < imgHeight; rows++)
|
||||
{
|
||||
RGBdata = tmp + ((rows + y_offset) * vinfo.xres + x_offset) * vinfo.bits_per_pixel / 8;
|
||||
RGBpos = rows * imgWidth * 3;
|
||||
if (vinfo.bits_per_pixel == 24) { // RGB888
|
||||
memcpy(RGBdata, &RGB888data[RGBpos], imgWidth * 3);
|
||||
} else {
|
||||
for(cols = 0; cols < imgWidth; cols++)
|
||||
{
|
||||
if (vinfo.bits_per_pixel == 16) { // RGB565
|
||||
b = RGB888data[RGBpos];
|
||||
g = RGB888data[RGBpos + 1];
|
||||
r = RGB888data[RGBpos + 2];
|
||||
*(RGBdata ++) = (((g & 0x1c) << 3) | (b >> 3)); /* g低5位,b高5位 */
|
||||
*(RGBdata ++) = ((r & 0xf8) | (g >> 5)); /* r高5位,g高3位 */
|
||||
} else { // RGB8888
|
||||
*(RGBdata ++) = RGB888data[RGBpos];
|
||||
*(RGBdata ++) = RGB888data[RGBpos + 1];
|
||||
*(RGBdata ++) = RGB888data[RGBpos + 2];
|
||||
*(RGBdata ++) = 0xFF;
|
||||
}
|
||||
RGBpos += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(outBuf, tmp, screensize);
|
||||
free(tmp);
|
||||
return 0;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
#ifndef _CONVERT_H_
|
||||
#define _CONVERT_H_
|
||||
|
||||
extern int yuyv_resize(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight);
|
||||
|
||||
extern int convert_yuyv_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_yuyv);
|
||||
extern int convert_nv21_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21);
|
||||
extern int convert_nv21_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21);
|
||||
extern int convert_rgb565_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21);
|
||||
extern int convert_yuyv_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod);
|
||||
extern int convert_yuv444_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod);
|
||||
extern int convert_rgb565_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod);
|
||||
extern int convert_rgb888_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod);
|
||||
|
||||
#endif // _CONVERT_H_
|
||||
Executable
+279
@@ -0,0 +1,279 @@
|
||||
#!/bin/sh
|
||||
|
||||
USAGE="Usage: media-ctl-pipeline interface_type sensor_type {start|stop}"
|
||||
|
||||
echo "Pipeline $1 $2 $3"
|
||||
|
||||
case $1 in
|
||||
dvp)
|
||||
case $3 in
|
||||
start)
|
||||
# media-ctl -vl "'sc2235 1-0030':0 -> 'stf_dvp0':0 [1]"
|
||||
# media-ctl -vl "'ov5640 1-003c':0 -> 'stf_dvp0':0 [1]"
|
||||
case $2 in
|
||||
VIN)
|
||||
echo "DVP vin 使能pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_vin0_wr':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_wr':1 -> 'stf_vin0_wr_video0':0 [1]"
|
||||
;;
|
||||
ISP0)
|
||||
echo "DVP ISP0 使能pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp0':0 [1]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [1]"
|
||||
;;
|
||||
ISP0RAW)
|
||||
echo "DVP ISP0RAW 使能pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp0':0 [1]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0_raw':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [1]"
|
||||
;;
|
||||
ISP1)
|
||||
echo "DVP ISP1 使能pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp1':0 [1]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [1]"
|
||||
;;
|
||||
ISP1RAW)
|
||||
echo "DVP ISP1RAW 使能pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp1':0 [1]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1_raw':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [1]"
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
# media-ctl -vl "'sc2235 1-0030':0 -> 'stf_dvp0':0 [0]"
|
||||
# media-ctl -vl "'ov5640 1-003c':0 -> 'stf_dvp0':0 [0]"
|
||||
case $2 in
|
||||
VIN)
|
||||
echo "DVP vin 关闭pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_vin0_wr':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_wr':1 -> 'stf_vin0_wr_video0':0 [0]"
|
||||
;;
|
||||
ISP0)
|
||||
echo "DVP ISP0 关闭pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp0':0 [0]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [0]"
|
||||
;;
|
||||
ISP0RAW)
|
||||
echo "DVP ISP0RAW 关闭pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp0':0 [0]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0_raw':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [0]"
|
||||
;;
|
||||
ISP1)
|
||||
echo "DVP ISP1 关闭pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp1':0 [0]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [0]"
|
||||
;;
|
||||
ISP1RAW)
|
||||
echo "DVP ISP1RAW 关闭pipeline:"
|
||||
media-ctl -vl "'stf_dvp0':1 -> 'stf_isp1':0 [0]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1_raw':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [0]"
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
csiphy0)
|
||||
case $3 in
|
||||
start)
|
||||
# media-ctl -vl "'ov4689 0-0036':0 -> 'stf_csiphy0':0 [1]"
|
||||
case $2 in
|
||||
VIN)
|
||||
echo "csiphy0 CSIRX0 vin 使能pipeline:"
|
||||
;;
|
||||
ISP0)
|
||||
echo "csiphy0 CSIRX0 ISP0 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [1]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp0':0 [1]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [1]"
|
||||
;;
|
||||
ISP0RAW)
|
||||
echo "csiphy0 CSIRX0 ISP0RAW 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [1]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp0':0 [1]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0_raw':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [1]"
|
||||
;;
|
||||
ISP1)
|
||||
echo "csiphy0 CSIRX0 ISP1 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [1]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp1':0 [1]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [1]"
|
||||
;;
|
||||
ISP1RAW)
|
||||
echo "csiphy0 CSIRX0 ISP1RAW 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [1]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp1':0 [1]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1_raw':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [1]"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
# media-ctl -vl "'ov4689 0-0036':0 -> 'stf_csiphy0':0 [0]"
|
||||
case $2 in
|
||||
VIN)
|
||||
echo "csiphy0 CSIRX0 vin 关闭pipeline:"
|
||||
;;
|
||||
ISP0)
|
||||
echo "csiphy0 CSIRX0 ISP0 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [0]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp0':0 [0]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [0]"
|
||||
;;
|
||||
ISP0RAW)
|
||||
echo "csiphy0 CSIRX0 ISP0RAW 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [0]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp0':0 [0]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0_raw':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [0]"
|
||||
;;
|
||||
ISP1)
|
||||
echo "csiphy0 CSIRX0 ISP1 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [0]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp1':0 [0]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [0]"
|
||||
;;
|
||||
ISP1RAW)
|
||||
echo "csiphy0 CSIRX0 ISP1RAW 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy0':1 -> 'stf_csi0':0 [0]"
|
||||
media-ctl -vl "'stf_csi0':1 -> 'stf_isp1':0 [0]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1_raw':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [0]"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
csiphy1)
|
||||
case $3 in
|
||||
start)
|
||||
# media-ctl -vl "'ov4689 2-0036':0 -> 'stf_csiphy1':0 [1]"
|
||||
case $2 in
|
||||
VIN)
|
||||
echo "csiphy1 CSIRX0 vin 使能pipeline:"
|
||||
;;
|
||||
ISP0)
|
||||
echo "csiphy1 CSIRX1 ISP0 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [1]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp0':0 [1]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [1]"
|
||||
;;
|
||||
ISP0RAW)
|
||||
echo "csiphy1 CSIRX1 ISP0RAW 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [1]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp0':0 [1]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0_raw':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [1]"
|
||||
;;
|
||||
ISP1)
|
||||
echo "csiphy1 CSIRX1 ISP1 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [1]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp1':0 [1]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [1]"
|
||||
;;
|
||||
ISP1RAW)
|
||||
echo "csiphy1 CSIRX1 ISP1RAW 使能pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [1]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp1':0 [1]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1_raw':0 [1]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [1]"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
# media-ctl -vl "'ov4689 0-0036':0 -> 'stf_csiphy0':0 [0]"
|
||||
case $2 in
|
||||
VIN)
|
||||
echo "csiphy1 CSIRX0 vin 关闭pipeline:"
|
||||
;;
|
||||
ISP0)
|
||||
echo "csiphy1 CSIRX1 ISP0 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [0]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp0':0 [0]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [0]"
|
||||
;;
|
||||
ISP0RAW)
|
||||
echo "csiphy1 CSIRX1 ISP0RAW 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [0]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp0':0 [0]"
|
||||
media-ctl -vl "'stf_isp0':1 -> 'stf_vin0_isp0_raw':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp0':1 -> 'stf_vin0_isp0_video1':0 [0]"
|
||||
;;
|
||||
ISP1)
|
||||
echo "csiphy1 CSIRX1 ISP1 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [0]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp1':0 [0]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [0]"
|
||||
;;
|
||||
ISP1RAW)
|
||||
echo "csiphy1 CSIRX1 ISP1RAW 关闭pipeline:"
|
||||
media-ctl -vl "'stf_csiphy1':1 -> 'stf_csi1':0 [0]"
|
||||
media-ctl -vl "'stf_csi1':1 -> 'stf_isp1':0 [0]"
|
||||
media-ctl -vl "'stf_isp1':1 -> 'stf_vin0_isp1_raw':0 [0]"
|
||||
# media-ctl -vl "'stf_vin0_isp1':1 -> 'stf_vin0_isp1_video2':0 [0]"
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo $USAGE
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0;
|
||||
Executable
+172
@@ -0,0 +1,172 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* arch/riscv/lib/string.c
|
||||
*
|
||||
* Copyright (C) 2021 Matteo Croce
|
||||
*
|
||||
* string functions optimized for 64 bit hardware which doesn't
|
||||
* handle unaligned memory accesses efficiently.
|
||||
*
|
||||
* May be freely distributed as part of Linux.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#define BITS_PER_LONG 64
|
||||
|
||||
typedef unsigned long uintptr_t;
|
||||
|
||||
typedef __u64 u64;
|
||||
typedef __s64 s64;
|
||||
|
||||
typedef __u32 u32;
|
||||
typedef __s32 s32;
|
||||
|
||||
typedef __u16 u16;
|
||||
typedef __s16 s16;
|
||||
|
||||
typedef __u8 u8;
|
||||
typedef __s8 s8;
|
||||
|
||||
union types {
|
||||
u8 *u8;
|
||||
u16 *u16;
|
||||
u32 *u32;
|
||||
u64 *u64;
|
||||
unsigned long *ulong;
|
||||
uintptr_t ptr;
|
||||
};
|
||||
|
||||
union ctypes {
|
||||
const u8 *u8;
|
||||
const u16 *u16;
|
||||
const u32 *u32;
|
||||
const u64 *u64;
|
||||
unsigned long *ulong;
|
||||
uintptr_t ptr;
|
||||
};
|
||||
|
||||
/**
|
||||
* memcpy - Copy one area of memory to another
|
||||
* @dest: Where to copy to
|
||||
* @src: Where to copy from
|
||||
* @count: The size of the area.
|
||||
*
|
||||
* You should not use this function to access IO space, use memcpy_toio()
|
||||
* or memcpy_fromio() instead.
|
||||
*/
|
||||
void *memcpy(void *dest, const void *src, size_t count)
|
||||
{
|
||||
static const void *labels[] = {
|
||||
&&u64, &&u8, &&u16, &&u8,
|
||||
&&u32, &&u8, &&u16, &&u8,
|
||||
};
|
||||
union types d = { .u8 = dest };
|
||||
union ctypes s = { .u8 = src };
|
||||
#ifdef HAVE_EFFICIENT_UNALIGNED_ACCESS
|
||||
int distance = 0;
|
||||
#else
|
||||
const int mask = BITS_PER_LONG / 8 - 1;
|
||||
int distance = (src - dest) & 7;
|
||||
|
||||
for (; count && d.ptr & s.ptr & mask; count--)
|
||||
*d.u8++ = *s.u8++;
|
||||
#endif
|
||||
|
||||
goto *labels[distance];
|
||||
|
||||
u64:
|
||||
#if BITS_PER_LONG == 64
|
||||
for (; count >= 8; count -= 8)
|
||||
*d.u64++ = *s.u64++;
|
||||
#endif
|
||||
|
||||
u32:
|
||||
for (; count >= 4; count -= 4)
|
||||
*d.u32++ = *s.u32++;
|
||||
|
||||
u16:
|
||||
for (; count >= 2; count -= 2)
|
||||
*d.u16++ = *s.u16++;
|
||||
|
||||
u8:
|
||||
while (count--)
|
||||
*d.u8++ = *s.u8++;
|
||||
|
||||
return dest;
|
||||
}
|
||||
EXPORT_SYMBOL(memcpy);
|
||||
|
||||
void *__memcpy(void *dest, const void *src, size_t count)
|
||||
{
|
||||
return memcpy(dest, src, count);
|
||||
}
|
||||
EXPORT_SYMBOL(__memcpy);
|
||||
|
||||
/**
|
||||
* memmove - Copy one area of memory to another
|
||||
* @dest: Where to copy to
|
||||
* @src: Where to copy from
|
||||
* @count: The size of the area.
|
||||
*
|
||||
* Unlike memcpy(), memmove() copes with overlapping areas.
|
||||
*/
|
||||
void *memmove(void *dest, const void *src, size_t count)
|
||||
{
|
||||
if (dest < src || src + count <= dest)
|
||||
return memcpy(dest, src, count);
|
||||
|
||||
if (dest > src) {
|
||||
const char *s = src + count;
|
||||
char *tmp = dest + count;
|
||||
|
||||
while (count--)
|
||||
*--tmp = *--s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
EXPORT_SYMBOL(memmove);
|
||||
|
||||
void *__memmove(void *dest, const void *src, size_t count)
|
||||
{
|
||||
return memmove(dest, src, count);
|
||||
}
|
||||
EXPORT_SYMBOL(__memmove);
|
||||
|
||||
/**
|
||||
* memset - Fill a region of memory with the given value
|
||||
* @s: Pointer to the start of the area.
|
||||
* @c: The byte to fill the area with
|
||||
* @count: The size of the area.
|
||||
*
|
||||
* Do not use memset() to access IO space, use memset_io() instead.
|
||||
*/
|
||||
void *memset(void *s, int c, size_t count)
|
||||
{
|
||||
const int bytes_long = BITS_PER_LONG / 8;
|
||||
u8 cc[] = { [0 ... bytes_long-1] = c };
|
||||
union ctypes src = { .u8 = cc };
|
||||
union types dest = { .u8 = s };
|
||||
|
||||
#ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS
|
||||
for (; count && dest.ptr % bytes_long; count--)
|
||||
*dest.u8++ = c;
|
||||
#endif
|
||||
|
||||
for (; count >= bytes_long; count -= bytes_long)
|
||||
*dest.ulong++ = *src.ulong;
|
||||
|
||||
while (count--)
|
||||
*dest.u8++ = c;
|
||||
|
||||
return s;
|
||||
}
|
||||
EXPORT_SYMBOL(memset);
|
||||
|
||||
void *__memset(void *s, int c, size_t count)
|
||||
{
|
||||
return memset(s, c, count);
|
||||
}
|
||||
EXPORT_SYMBOL(__memset);
|
||||
Executable
+1711
File diff suppressed because it is too large
Load Diff
Executable
+29
@@ -0,0 +1,29 @@
|
||||
################################################################################
|
||||
#
|
||||
# v4l2test
|
||||
#
|
||||
################################################################################
|
||||
|
||||
V4L2_TEST_LICENSE = GPL-2.0+
|
||||
|
||||
define V4L2_TEST_BUILD_CMDS
|
||||
cp package/v4l2_test/v4l2_test.c $(@D)/
|
||||
cp package/v4l2_test/yuv.c $(@D)/
|
||||
cp package/v4l2_test/yuv.h $(@D)/
|
||||
cp package/v4l2_test/convert.c $(@D)/
|
||||
cp package/v4l2_test/convert.h $(@D)/
|
||||
cp package/v4l2_test/config.h $(@D)/
|
||||
cp package/v4l2_test/string.c $(@D)/
|
||||
cp package/v4l2_test/pipeline_setting.sh $(@D)/
|
||||
(cd $(@D); $(TARGET_CC) -Wall -O2 v4l2_test.c yuv.c convert.c string.c -l v4l2 -l jpeg -o v4l2test)
|
||||
#(cd $(@D); $(TARGET_CC) -Wall -O2 v4l2_test.c -o v4l2test)
|
||||
endef
|
||||
|
||||
define V4L2_TEST_INSTALL_TARGET_CMDS
|
||||
install -m 0755 -D $(@D)/v4l2test $(TARGET_DIR)/usr/bin/v4l2test
|
||||
install -m 0755 -D $(@D)/pipeline_setting.sh $(TARGET_DIR)/usr/bin/pipeline_setting.sh
|
||||
endef
|
||||
|
||||
V4L2_TEST_DEPENDENCIES = jpeg libv4l
|
||||
$(eval $(generic-package))
|
||||
|
||||
Executable
+126
@@ -0,0 +1,126 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2012 by Tobias Müller *
|
||||
* Tobias_Mueller@twam.info *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
Convert from YUV420 format to YUV444.
|
||||
|
||||
\param width width of image
|
||||
\param height height of image
|
||||
\param src source
|
||||
\param dst destination
|
||||
*/
|
||||
|
||||
void YUV420toYUV444(int width, int height, unsigned char* src, unsigned char* dst) {
|
||||
int line, column;
|
||||
unsigned char *py, *pu, *pv;
|
||||
unsigned char *tmp = dst;
|
||||
|
||||
// In this format each four bytes is two pixels. Each four bytes is two Y's, a Cb and a Cr.
|
||||
// Each Y goes to one of the pixels, and the Cb and Cr belong to both pixels.
|
||||
unsigned char *base_py = src;
|
||||
unsigned char *base_pu = src+(height*width);
|
||||
unsigned char *base_pv = src+(height*width)+(height*width)/4;
|
||||
|
||||
for (line = 0; line < height; ++line) {
|
||||
for (column = 0; column < width; ++column) {
|
||||
py = base_py+(line*width)+column;
|
||||
pu = base_pu+(line/2*width/2)+column/2;
|
||||
pv = base_pv+(line/2*width/2)+column/2;
|
||||
|
||||
*tmp++ = *py;
|
||||
*tmp++ = *pu;
|
||||
*tmp++ = *pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void YUV420NV21toYUV444(int width, int height, unsigned char* src, unsigned char* dst) {
|
||||
int line, column;
|
||||
unsigned char *py, *pu, *pv;
|
||||
unsigned char *tmp = dst;
|
||||
|
||||
// In this format each four bytes is two pixels. Each four bytes is two Y's, a Cb and a Cr.
|
||||
// Each Y goes to one of the pixels, and the Cb and Cr belong to both pixels.
|
||||
unsigned char *base_py = src;
|
||||
unsigned char *base_pu = src+(height*width);
|
||||
unsigned char *base_pv = src+(height*width);
|
||||
|
||||
for (line = 0; line < height; ++line) {
|
||||
for (column = 0; column < width; ++column) {
|
||||
py = base_py+(line*width)+column;
|
||||
pu = base_pu+((line/2*width/2)+column/2)*2+1;
|
||||
pv = base_pv+((line/2*width/2)+column/2)*2;
|
||||
|
||||
*tmp++ = *py;
|
||||
*tmp++ = *pu;
|
||||
*tmp++ = *pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void YUV422toYUV444(int width, int height, unsigned char* src, unsigned char* dst) {
|
||||
int line, column;
|
||||
unsigned char *py, *pu, *pv;
|
||||
unsigned char *tmp = dst;
|
||||
|
||||
// In this format each four bytes is two pixels. Each four bytes is two Y's, a Cb and a Cr.
|
||||
// Each Y goes to one of the pixels, and the Cb and Cr belong to both pixels.
|
||||
unsigned char *base_py = src;
|
||||
unsigned char *base_pu = src+(height*width);
|
||||
unsigned char *base_pv = src+(height*width)+(height*width)/2;
|
||||
|
||||
for (line = 0; line < height; ++line) {
|
||||
for (column = 0; column < width; ++column) {
|
||||
py = base_py+((line*width)+column)*2;
|
||||
pu = base_py+((line*width)+column)*2 + 1;
|
||||
pv = base_py+((line*width)+column)*2 + 1;
|
||||
|
||||
*tmp++ = *py;
|
||||
*tmp++ = *pu;
|
||||
*tmp++ = *pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RGB565toRGB888(int width, int height, unsigned char* src, unsigned char* dst)
|
||||
{
|
||||
unsigned short *pix = (unsigned short *)src;
|
||||
unsigned int i;
|
||||
for (i = 0 ; i < width * height; i++)
|
||||
{
|
||||
*dst++ = (*(pix+i) & 0b1111100000000000) >> 8;
|
||||
*dst++ = (*(pix+i) & 0b11111100000) >> 3 ;
|
||||
*dst++ = (*(pix+i) & 0b11111) << 3;
|
||||
}
|
||||
}
|
||||
|
||||
void RAW12toRAW16(int width, int height, unsigned char* src, unsigned char* dst)
|
||||
{
|
||||
unsigned char *p_src = src;
|
||||
unsigned short *p_dst = (unsigned short *)dst;
|
||||
unsigned int i, j;
|
||||
for (i = 0 ; i < height; i++) {
|
||||
p_src = src + (((width * 12 / 8 + 8 * 16 - 1) / (8 * 16)) * 128) * i;
|
||||
for (j = 0 ; j < width * 12 / 8; j += 3) {
|
||||
*p_dst++ = ((*(p_src + j)) | ((*(p_src + j + 1) & 0xF) << 8)) << 4;
|
||||
*p_dst++ = ((*(p_src + j + 2) << 4) | ((*(p_src + j + 1)) >> 4)) << 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#ifndef _YUV_H_
|
||||
#define _YUV_H_
|
||||
|
||||
void YUV420toYUV444(int width, int height, unsigned char* src, unsigned char* dst);
|
||||
void YUV422toYUV444(int width, int height, unsigned char* src, unsigned char* dst);
|
||||
void RGB565toRGB888(int width, int height, unsigned char* src, unsigned char* dst);
|
||||
void RAW12toRAW16(int width, int height, unsigned char* src, unsigned char* dst);
|
||||
void YUV420NV21toYUV444(int width, int height, unsigned char* src, unsigned char* dst);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user