Skip to content

Commit

Permalink
v4l2test: add YUYV/NV12 format display the black background
Browse files Browse the repository at this point in the history
Signed-off-by: Arvin Zhu <arvin.zhu@starfivetech.com>
  • Loading branch information
Arv1nZhu authored and andyhu-stf committed Jan 20, 2022
1 parent 04245ff commit 889bb48
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions package/starfive/v4l2_test/convert.c 100644 → 100755
Expand Up @@ -28,13 +28,33 @@ int yuyv_resize(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeig
int YUVinpos; /* Y U V offset */
int width, height;
int x_offset, y_offset;
uint8_t *tmp = malloc(g_screen_size);
uint32_t start_timems;
uint32_t end_timems;
struct timeval ts_start, ts_end;
static uint8_t *tmp = NULL;

if (!tmp)
return -1;
{
tmp = malloc(g_screen_size);
if (tmp)
{
// for YUYV buffer, set it to black
for ( rows = 0; rows < g_screen_size; rows++)
{
if (rows == 0 || rows % 2 == 0)
{
//even is Y
tmp[rows] = 0;
}
else
{
//odd is U or V
tmp[rows] = 128;
}
}
}
}
assert(tmp);

gettimeofday(&ts_start, NULL);

Expand All @@ -55,7 +75,7 @@ int yuyv_resize(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeig
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);
//free(tmp);
return 0;
}

Expand Down Expand Up @@ -83,7 +103,7 @@ int yuyv_resize(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, int imgHeig
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);
//free(tmp);
return 0;

}
Expand All @@ -97,13 +117,22 @@ int convert_yuyv_to_nv12(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, in
int fb_Ypos, fb_Upos, fb_Vpos;
int width, height;
int x_offset, y_offset;
uint8_t *tmp = malloc(g_screen_size);
uint32_t start_timems;
uint32_t end_timems;
struct timeval ts_start, ts_end;
static uint8_t *tmp = NULL;

if (!tmp)
return -1;
{
tmp = malloc(g_screen_size);
if (tmp)
{
// for NV12 buffer, set it to black
memset(tmp, 0, g_screen_size / 3 * 2);
memset(tmp + g_screen_size / 3 * 2, 128, g_screen_size / 3);
}
}
assert(tmp);

gettimeofday(&ts_start, NULL);

Expand Down Expand Up @@ -148,7 +177,7 @@ int convert_yuyv_to_nv12(const uint8_t *inBuf, uint8_t *outBuf, int imgWidth, in
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);
//free(tmp);
return 0;
}

Expand All @@ -162,12 +191,23 @@ int convert_nv21_to_nv12(const uint8_t *inBuf, uint8_t *outBuf,
int fb_Ypos, fb_Upos, fb_Vpos;
int width, height;
int x_offset, y_offset;
uint8_t *tmp = malloc(g_screen_size);
static uint8_t *tmp = NULL;
uint32_t start_timems;
uint32_t end_timems;
struct timeval ts_start, ts_end;

if (!tmp)
{
tmp = malloc(g_screen_size);
if (tmp)
{
// for NV12 buffer, set it to black
memset(tmp, 0, g_screen_size / 3 * 2);
memset(tmp + g_screen_size / 3 * 2, 128, g_screen_size / 3);
}
}
assert(tmp);

gettimeofday(&ts_start, NULL);

width = imgWidth > g_screen_width ? g_screen_width : imgWidth;
Expand Down Expand Up @@ -198,7 +238,7 @@ int convert_nv21_to_nv12(const uint8_t *inBuf, uint8_t *outBuf,
memcpy(&outBuf[fb_Ypos], inBuf, imgWidth * height);
memcpy(&outBuf[fb_Upos], &inBuf[Upos], imgWidth * height / 2);
}
free(tmp);
//free(tmp);
return 0;
}

Expand Down Expand Up @@ -241,7 +281,7 @@ int convert_nv21_to_nv12(const uint8_t *inBuf, uint8_t *outBuf,
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);
//free(tmp);
return 0;
}

Expand Down

0 comments on commit 889bb48

Please sign in to comment.