diff --git a/package/PikaCV/PikaCV_Converter.c b/package/PikaCV/PikaCV_Converter.c index 54598786b..9602dd89b 100644 --- a/package/PikaCV/PikaCV_Converter.c +++ b/package/PikaCV/PikaCV_Converter.c @@ -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; } diff --git a/package/PikaCV/PikaCV_Transforms.c b/package/PikaCV/PikaCV_Transforms.c index 57285abd4..693c9577f 100644 --- a/package/PikaCV/PikaCV_Transforms.c +++ b/package/PikaCV/PikaCV_Transforms.c @@ -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; diff --git a/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Converter.c b/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Converter.c index 54598786b..9602dd89b 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Converter.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Converter.c @@ -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; } diff --git a/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Transforms.c b/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Transforms.c index 57285abd4..693c9577f 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Transforms.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaCV/PikaCV_Transforms.c @@ -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;