250 lines
6.5 KiB
C++
250 lines
6.5 KiB
C++
#define LOG_NDEBUG 0
|
|
#define LOG_TAG "rgaClip"
|
|
|
|
#include "myrga.h"
|
|
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
#include <math.h>
|
|
#include <fcntl.h>
|
|
#include <signal.h>
|
|
#include <sys/time.h>
|
|
|
|
#include <RockchipRga.h>
|
|
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
|
|
///
|
|
// #include "../drmrga.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
|
#include <linux/stddef.h>
|
|
// #include <RockchipFileOps.h>
|
|
///
|
|
rga_client_t rga_client;
|
|
|
|
// const int SRCFMT = RK_FORMAT_YCrCb_420_SP;
|
|
const int SRCFMT = RK_FORMAT_YCbCr_420_SP;
|
|
const int DSTFMT = RK_FORMAT_RGB_888;
|
|
|
|
// const int DSTWidth = 640;
|
|
// const int DSTHeight = 640;
|
|
|
|
int rga_client_t::convert(unsigned char *src, int sw, int sh, int swstride, int shstride, char *out)
|
|
{
|
|
RockchipRga &rga(RockchipRga::getInstance());
|
|
int ret = 0;
|
|
char *buf = (char *)src;
|
|
// get_buf_from_file(buf, SRCFMT, sw, sh, 1);
|
|
// out should be 1280*720*3
|
|
buf = out;
|
|
// get_buf_from_file(buf, DSTFMT, DSTWidth, DSTHeight, 0);
|
|
|
|
while (1)
|
|
{
|
|
// ********** rga_info_t Init **********
|
|
rga_info_t rgasrc;
|
|
rga_info_t rgadst;
|
|
|
|
memset(&rgasrc, 0, sizeof(rga_info_t));
|
|
rgasrc.fd = -1;
|
|
rgasrc.mmuFlag = 1;
|
|
rgasrc.virAddr = src;
|
|
|
|
memset(&rgadst, 0, sizeof(rga_info_t));
|
|
rgadst.fd = -1;
|
|
rgadst.mmuFlag = 1;
|
|
rgadst.virAddr = out;
|
|
|
|
struct timeval tpend1, tpend2;
|
|
long usec1 = 0;
|
|
|
|
gettimeofday(&tpend1, NULL);
|
|
|
|
rgadst.color = 0xcccccc;
|
|
rga_set_rect(&rgadst.rect, 0, 0, DSTWidth, DSTHeight, DSTWidth, DSTHeight, DSTFMT);
|
|
rga.RkRgaCollorFill(&rgadst);
|
|
|
|
float widthratio = 1.0 * swstride / DSTWidth;
|
|
float heightratio = 1.0 * shstride / DSTHeight;
|
|
|
|
int TMPWIDTH = DSTWidth;
|
|
int TMPHEIGHT = DSTHeight;
|
|
int startwidth = 0;
|
|
int startheight = 0;
|
|
if (widthratio < heightratio)
|
|
{
|
|
TMPWIDTH = int(swstride / heightratio);
|
|
startwidth = int((DSTWidth - TMPWIDTH) / 2);
|
|
}
|
|
else
|
|
{
|
|
TMPHEIGHT = int(shstride / widthratio);
|
|
startheight = int((DSTHeight - TMPHEIGHT) / 2);
|
|
}
|
|
|
|
// ********** set the rect_info **********
|
|
rga_set_rect(&rgasrc.rect, 0, 0, sw, sh,
|
|
// stride
|
|
swstride, shstride, SRCFMT);
|
|
/*
|
|
rga_set_rect(&rgadst.rect, 0, 0, DSTWidth, DSTHeight,
|
|
// stride
|
|
DSTWidth, DSTHeight,
|
|
DSTFMT);
|
|
*/
|
|
rga_set_rect(&rgadst.rect, startwidth, startheight, TMPWIDTH, TMPHEIGHT, DSTWidth, DSTHeight, DSTFMT);
|
|
|
|
// ************ set the rga_mod ,rotation\composition\scale\copy .... **********
|
|
// rgasrc.blend = 0xff0105;
|
|
// rga_set_rect(&rgasrc.rect, 0, 0, sw, sh, swstride, shstride, SRCFMT);
|
|
// rga_set_rect(&rgadst.rect, 0, 0, DSTWidth, DSTHeight, DSTWidth, DSTHeight, DSTFMT);
|
|
|
|
// ********** call rga_Interface **********
|
|
ret = rga.RkRgaBlit(&rgasrc, &rgadst, NULL);
|
|
|
|
gettimeofday(&tpend2, NULL);
|
|
usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000;
|
|
|
|
printf("rga cost_time=%ld ms\n", usec1);
|
|
|
|
if (ret)
|
|
{
|
|
printf("rgaFillColor error : %s\n",
|
|
strerror(errno));
|
|
}
|
|
|
|
{
|
|
// ********** output buf data to file *********
|
|
/*
|
|
char* dstbuf = (char *)dst;
|
|
output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
|
|
*/
|
|
}
|
|
// printf("threadloop\n");
|
|
usleep(5000);
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void initRkRga()
|
|
{
|
|
}
|
|
|
|
void deinitRkRga()
|
|
{
|
|
}
|
|
|
|
// using namespace android;
|
|
|
|
/*
|
|
int main() {
|
|
int ret = 0;
|
|
int srcWidth,srcHeight,srcFormat;
|
|
int dstWidth,dstHeight,dstFormat;
|
|
|
|
void *src = NULL;
|
|
void *dst = NULL;
|
|
|
|
srcWidth = 1280;
|
|
srcHeight = 720;
|
|
// srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
|
|
srcFormat = RK_FORMAT_RGBA_8888;
|
|
|
|
dstWidth = 1280;
|
|
dstHeight = 720;
|
|
//dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
|
|
dstFormat = RK_FORMAT_RGBA_8888;
|
|
|
|
// ********** apply for buffer **********
|
|
src = malloc(srcWidth * srcHeight * 4);
|
|
if (!src)
|
|
return -ENOMEM;
|
|
|
|
//********** apply for buffer **********
|
|
dst = malloc(dstWidth * dstHeight * 4);
|
|
if (!dst) {
|
|
free(src);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
RockchipRga& rkRga(RockchipRga::get());
|
|
|
|
// ********** get data to src_buffer or init buffer**********
|
|
char* buf = (char *)src;
|
|
#if 1
|
|
get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 1);
|
|
#else
|
|
memset(buf,0x55,4*1280*720);
|
|
#endif
|
|
|
|
// ********** get data to dst_buffer or init buffer **********
|
|
buf = (char *)dst;
|
|
#if 1
|
|
get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
|
|
#else
|
|
memset(buf,0x00,4*1280*720);
|
|
#endif
|
|
|
|
while(1) {
|
|
// ********** rga_info_t Init **********
|
|
rga_info_t rgasrc;
|
|
rga_info_t rgadst;
|
|
|
|
memset(&rgasrc, 0, sizeof(rga_info_t));
|
|
rgasrc.fd = -1;
|
|
rgasrc.mmuFlag = 1;
|
|
rgasrc.virAddr = src;
|
|
|
|
memset(&rgadst, 0, sizeof(rga_info_t));
|
|
rgadst.fd = -1;
|
|
rgadst.mmuFlag = 1;
|
|
rgadst.virAddr = dst;
|
|
|
|
// ********** set the rect_info **********
|
|
rga_set_rect(&rgasrc.rect, 0,0,srcWidth,srcHeight,
|
|
// stride
|
|
srcWidth,srcHeight,
|
|
srcFormat);
|
|
rga_set_rect(&rgadst.rect, 0,0,dstWidth,dstHeight,
|
|
// stride
|
|
dstWidth,dstHeight,
|
|
dstFormat);
|
|
|
|
// ************ set the rga_mod ,rotation\composition\scale\copy .... **********
|
|
rgasrc.blend = 0xff0105;
|
|
|
|
// ********** call rga_Interface **********
|
|
struct timeval tpend1, tpend2;
|
|
long usec1 = 0;
|
|
gettimeofday(&tpend1, NULL);
|
|
ret = rkRga.RkRgaBlit(&rgasrc, &rgadst, NULL);
|
|
gettimeofday(&tpend2, NULL);
|
|
usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000;
|
|
printf("cost_time=%ld ms\n", usec1);
|
|
|
|
if (ret) {
|
|
printf("rgaFillColor error : %s\n",
|
|
strerror(errno));
|
|
}
|
|
|
|
{
|
|
// ********** output buf data to file *********
|
|
char* dstbuf = (char *)dst;
|
|
output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
|
|
}
|
|
printf("threadloop\n");
|
|
usleep(500000);
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
*/ |