fix RGB565 to RBG888

This commit is contained in:
pikastech 2022-07-14 17:49:19 +08:00
parent 18e15559b7
commit 01ed312fdf
4 changed files with 20 additions and 8 deletions

View File

@ -264,9 +264,15 @@ void PikaCV_Converter_toRGB888(PikaObj* self, PikaObj* image) {
if (img->format == PikaCV_ImageFormat_Type_RGB565) {
for (int i = 0; i < img->size; i += 2) {
uint16_t* p565 = (uint16_t*)&data[i];
uint32_t buf888 = 0;
uint32_t* pbuf888 = (uint32_t*)&buf888;
*pbuf888 = ((*p565 & 0xF800) << 8) | ((*p565 & 0x07E0) << 5) |
((*p565 & 0x001F) << 3);
uint32_t* p888 = (uint32_t*)&data_new[i / 2 * 3];
*p888 = ((*p565 & 0xF800) << 8) | ((*p565 & 0x07E0) << 5) |
((*p565 & 0x001F) << 3);
((uint8_t*)p888)[0] = ((uint8_t*)pbuf888)[2];
((uint8_t*)p888)[1] = ((uint8_t*)pbuf888)[1];
((uint8_t*)p888)[2] = ((uint8_t*)pbuf888)[0];
}
goto exit;
}

View File

@ -8,8 +8,8 @@ void PikaCV_Transforms_rotateDown(PikaObj* self, PikaObj* image) {
pika_assert(0);
return;
}
if (img->format == PikaCV_ImageFormat_Type_BGR888 ||
img->format == PikaCV_ImageFormat_Type_RGB888) {
if ((img->format != PikaCV_ImageFormat_Type_BGR888) &&
(img->format != PikaCV_ImageFormat_Type_RGB888)) {
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
__platform_printf("unsupported image format\n");
return;

View File

@ -264,9 +264,15 @@ void PikaCV_Converter_toRGB888(PikaObj* self, PikaObj* image) {
if (img->format == PikaCV_ImageFormat_Type_RGB565) {
for (int i = 0; i < img->size; i += 2) {
uint16_t* p565 = (uint16_t*)&data[i];
uint32_t buf888 = 0;
uint32_t* pbuf888 = (uint32_t*)&buf888;
*pbuf888 = ((*p565 & 0xF800) << 8) | ((*p565 & 0x07E0) << 5) |
((*p565 & 0x001F) << 3);
uint32_t* p888 = (uint32_t*)&data_new[i / 2 * 3];
*p888 = ((*p565 & 0xF800) << 8) | ((*p565 & 0x07E0) << 5) |
((*p565 & 0x001F) << 3);
((uint8_t*)p888)[0] = ((uint8_t*)pbuf888)[2];
((uint8_t*)p888)[1] = ((uint8_t*)pbuf888)[1];
((uint8_t*)p888)[2] = ((uint8_t*)pbuf888)[0];
}
goto exit;
}

View File

@ -8,8 +8,8 @@ void PikaCV_Transforms_rotateDown(PikaObj* self, PikaObj* image) {
pika_assert(0);
return;
}
if (img->format == PikaCV_ImageFormat_Type_BGR888 ||
img->format == PikaCV_ImageFormat_Type_RGB888) {
if ((img->format != PikaCV_ImageFormat_Type_BGR888) &&
(img->format != PikaCV_ImageFormat_Type_RGB888)) {
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
__platform_printf("unsupported image format\n");
return;