From 153672b8d3bc73655bf083961cb2c73e27ef444b Mon Sep 17 00:00:00 2001 From: xulei2020 <“xulei83@huawei.com”> Date: Fri, 11 Sep 2020 17:28:11 +0800 Subject: [PATCH] add code --- .../kernels/image/lite_cv/image_process.cc | 22 +++++++++++++++++++ .../dataset/kernels/image/lite_cv/lite_mat.h | 1 + 2 files changed, 23 insertions(+) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc index c6c31bc428..fd15e13059 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc @@ -250,6 +250,26 @@ static bool ConvertRGBAToBGR(const unsigned char *data, LDataType data_type, int return true; } +static bool ConvertRGBAToRGB(const unsigned char *data, LDataType data_type, int w, int h, LiteMat &mat) { + if (data_type == LDataType::UINT8) { + mat.Init(w, h, 3, LDataType::UINT8); + unsigned char *ptr = mat; + const unsigned char *data_ptr = data; + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + ptr[0] = data_ptr[0]; + ptr[1] = data_ptr[1]; + ptr[2] = data_ptr[2]; + ptr += 3; + data_ptr += 4; + } + } + } else { + return false; + } + return true; +} + static bool ConvertRGBAToGRAY(const unsigned char *data, LDataType data_type, int w, int h, LiteMat &mat) { if (data_type == LDataType::UINT8) { mat.Init(w, h, 1, LDataType::UINT8); @@ -279,6 +299,8 @@ bool InitFromPixel(const unsigned char *data, LPixelType pixel_type, LDataType d return ConvertRGBAToBGR(data, data_type, w, h, m); } else if (pixel_type == LPixelType::RGBA2GRAY) { return ConvertRGBAToGRAY(data, data_type, w, h, m); + } else if (pixel_type == LPixelType::RGBA2RGB) { + return ConvertRGBAToRGB(data, data_type, w, h, m); } else { return false; } diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h index 48250d9948..697b3a1935 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h @@ -91,6 +91,7 @@ enum LPixelType { RGBA = 2, RGBA2GRAY = 3, RGBA2BGR = 4, + RGBA2RGB = 5, }; class LDataType {