Created
April 30, 2020 03:30
-
-
Save AllanChen/cd5ddd45cab663d9d30d691788474641 to your computer and use it in GitHub Desktop.
数据转换
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//int ArmSkySegPreprocessor::resize_cpp(const VN_Image *__input, const VN_Image *__out) { | |
// const uint8_t *src = (uint8_t *) __input->data; | |
// uint8_t *dst = (uint8_t *) __out->data; | |
// uint64_t src_h = (uint64_t) __input->height; | |
// uint64_t src_w = (uint64_t) __input->width; | |
// uint64_t dst_h = (uint64_t) __out->height; | |
// uint64_t dst_w = (uint64_t) __out->width; | |
// | |
// float scale_y = static_cast<float>(src_h) / static_cast<float>(dst_h); | |
// float scale_x = static_cast<float>(src_w) / static_cast<float>(dst_w); | |
// | |
// for (int h = 0; h < dst_h; h++) { | |
// const int y = (int) MIN(static_cast<uint64_t>(h * scale_y), src_h - 1); | |
// for (int w = 0; w < dst_w; w++) { | |
// const int x = (int) MIN(static_cast<uint64_t>(w * scale_x), src_w - 1); | |
// const uint8_t *input = &src[4 * (y * src_w + x)]; | |
// uint8_t *output = &dst[4 * (h * dst_w + w)]; | |
// for (int k = 0; k < 4; k++) { | |
// *output++ = *input++; | |
// } | |
// } | |
// } | |
// return 0; | |
//} | |
//int ArmSkySegPreprocessor::yuv2bgra_nv12_cpp(const VN_Image *__input, VN_Image *__out) { | |
// | |
// int iWidth = __input->width; | |
// int iHeight = __input->height; | |
// | |
// uint8_t *src = (uint8_t *) __input->data; | |
// | |
// uint8_t *y_data = new uint8_t[iWidth * iHeight]; | |
// uint8_t *cbcr_data = new uint8_t[iWidth * iHeight / 2]; | |
// | |
// memcpy(y_data, src, iWidth * iHeight); | |
// memcpy(cbcr_data, src + iWidth * iHeight, iWidth * iHeight / 2); | |
// | |
// uint8_t *outBuffer = (uint8_t *) malloc(iWidth * iHeight * 4); | |
// | |
// for (int h = 0; h < iHeight; h++) { | |
// | |
// uint8_t *y_data_line = &y_data[h + iWidth]; | |
// uint8_t *uv_data_line = &cbcr_data[(h >> 1) + iWidth]; | |
// uint8_t *bgraBufferRow = &outBuffer[h + iWidth]; | |
// | |
// for (int w = 0; w < iWidth; w++) { | |
// uint16_t y_d = y_data_line[w]; | |
// uint16_t cb = uv_data_line[w & -1] - 128; | |
// uint16_t cr = uv_data_line[w | 1] - 128; | |
// | |
// uint8_t *bgraOutput = &bgraBufferRow[w * 4]; | |
// | |
// int16_t r = (int16_t) roundf(y_d + cr * 1.4); | |
// int16_t g = (int16_t) roundf(y_d + cb * -0.343 + cr * -0.711); | |
// int16_t b = (int16_t) roundf(y_d + cb * 1.765); | |
// | |
// bgraOutput[0] = b > 0 ? (b < 255 ? b : 255) : 0; | |
// bgraOutput[1] = g > 0 ? (g < 255 ? g : 255) : 0; | |
// bgraOutput[2] = r > 0 ? (r < 255 ? r : 255) : 0; | |
// bgraOutput[3] = 0xff; | |
// } | |
// } | |
// __out->data = outBuffer; | |
// __out->pix_fmt = VN_PIX_FMT_BGRA8888; | |
// return 0; | |
//} | |
//int ArmSkySegPreprocessor::bgra2rgb(const VN_Image *__input, VN_Image *__out) { | |
// int iWidth = __input->width; | |
// int iHeight = __input->height; | |
// | |
// uint8_t *bgraBuffer = (uint8_t *) __input->data; | |
// uint8_t *rgbBuffer = (uint8_t *) malloc(iWidth * iHeight * 3); | |
// | |
// for (int h = 0; h < iHeight; h++) { | |
// uint8_t *rgbBufferLine = &rgbBuffer[h * iWidth * 3]; | |
// uint8_t *in_data_line = &bgraBuffer[h * iWidth * 4]; | |
// for (int w = 0; w < iWidth; w++) { | |
// uint8_t *rgbOutput = &rgbBufferLine[w * 3]; | |
// uint8_t *in_datas = &in_data_line[w * 4]; | |
// int16_t b = (int16_t) in_datas[0]; | |
// int16_t g = (int16_t) in_datas[1]; | |
// int16_t r = (int16_t) in_datas[2]; | |
// | |
// rgbOutput[0] = r; | |
// rgbOutput[1] = g; | |
// rgbOutput[2] = b; | |
// } | |
// } | |
// __out->data = rgbBuffer; | |
// return 0; | |
//} | |
//int ArmSkySegPreprocessor::bgra2rgba(const VN_Image *__input, VN_Image *__out) { | |
// int iWidth = __input->width; | |
// int iHeight = __input->height; | |
// | |
// uint8_t *bgraBuffer = (uint8_t *) __input->data; | |
// uint8_t *rgbaBuffer = (uint8_t *) malloc(iWidth * iHeight * 4); | |
// | |
// for (int h = 0; h < iHeight; h++) { | |
// uint8_t *rgbaBufferLine = &rgbaBuffer[h * iWidth * 4]; | |
// uint8_t *in_data_line = &bgraBuffer[h * iWidth * 4]; | |
// for (int w = 0; w < iWidth; w++) { | |
// uint8_t *rgbaOutput = &rgbaBufferLine[w * 4]; | |
// uint8_t *in_datas = &in_data_line[w * 4]; | |
// int16_t b = (int16_t) in_datas[0]; | |
// int16_t g = (int16_t) in_datas[1]; | |
// int16_t r = (int16_t) in_datas[2]; | |
// int16_t a = (int16_t) in_datas[3]; | |
// | |
// rgbaOutput[0] = r; | |
// rgbaOutput[1] = g; | |
// rgbaOutput[2] = b; | |
// rgbaOutput[3] = a; | |
// } | |
// } | |
// | |
// __out->data = rgbaBuffer; | |
// return 0; | |
//} | |
//int ArmSkySegPreprocessor::nomalize(const VN_Image *__input, | |
// VN_Image *__out, | |
// const float *mean_vals, | |
// const float *nomal_vals) { | |
// int iWidth = __input->width; | |
// int iHeight = __input->height; | |
// int channel = __out->channels; | |
// uint8_t *bgraBuffer = (uint8_t *) __input->data; | |
// float *rgbaBuffer = new float[512 * 512 * 4]; | |
// for (int h = 0; h < iHeight; h++) { | |
// for (int w = 0; w < iWidth; w++) { | |
// for (int c = 0; c < channel; c++) { | |
// int dst_idx = (c * iHeight + h) * iWidth + w; | |
// int src_idx = (h * iWidth + w) * channel + c; | |
// rgbaBuffer[dst_idx] = ((float) bgraBuffer[src_idx] - mean_vals[c]) * nomal_vals[c]; | |
// } | |
// } | |
// } | |
// __out->data = rgbaBuffer; | |
// return 0; | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment