mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix rgb565 chanel err
This commit is contained in:
parent
18a6b01f79
commit
18e15559b7
@ -175,13 +175,16 @@ void PikaCV_Converter_toGray(PikaObj* self, PikaObj* image) {
|
||||
uint8_t* data_new = arg_getBytes(arg_data_new);
|
||||
if (img->format == PikaCV_ImageFormat_Type_RGB888) {
|
||||
for (int i = 0; i < size_new; i++) {
|
||||
data_new[i] = (data[i * 3] + data[i * 3 + 1] + data[i * 3 + 2]) / 3;
|
||||
data_new[i] = (uint8_t)((uint16_t)(data[i * 3] + data[i * 3 + 1] +
|
||||
data[i * 3 + 2]) /
|
||||
3);
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
if (img->format == PikaCV_ImageFormat_Type_RGB565) {
|
||||
for (int i = 0; i < size_new; i++) {
|
||||
data_new[i] = (data[i * 2] + data[i * 2 + 1]) / 2;
|
||||
data_new[i] =
|
||||
(uint8_t)((uint16_t)(data[i * 2] + data[i * 2 + 1]) >> 1);
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
@ -217,11 +220,9 @@ void PikaCV_Converter_toRGB565(PikaObj* self, PikaObj* image) {
|
||||
uint8_t* data_new = arg_getBytes(arg_data_new);
|
||||
if (img->format == PikaCV_ImageFormat_Type_RGB888) {
|
||||
for (int i = 0; i < img->size; i += 3) {
|
||||
uint32_t* p888 = (uint32_t*)&data[i];
|
||||
uint16_t* p565 = (uint16_t*)&data_new[i / 3 * 2];
|
||||
|
||||
*p565 = ((*p888 & 0x00F80000) >> 8) | ((*p888 & 0x0000FC00) >> 5) |
|
||||
((*p888 & 0x000000F8) >> 3);
|
||||
*p565 = (uint16_t)(((data[i] >> 3) << 11) |
|
||||
((data[i + 1] >> 2) << 5) | (data[i + 2] >> 3));
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
|
@ -251,28 +251,13 @@ void PikaCV_Image_add(PikaObj *self, PikaObj* image){
|
||||
/* add two images */
|
||||
for (i = 0; i < (src->size)/3; i++) {
|
||||
result=src_data[i * 3] + img_data[i * 3];
|
||||
if(result<MAX(src_data[i * 3],img_data[i * 3])){
|
||||
src_data[i * 3]=255;
|
||||
}
|
||||
else{
|
||||
src_data[i * 3]=result;
|
||||
}
|
||||
src_data[i * 3] = ((result<MAX(src_data[i * 3],img_data[i * 3]))?255:result);
|
||||
|
||||
result=src_data[i * 3 + 1] + img_data[i * 3 + 1];
|
||||
if(result<MAX(src_data[i * 3 + 1],img_data[i * 3 + 1])){
|
||||
src_data[i * 3 + 1]=255;
|
||||
}
|
||||
else{
|
||||
src_data[i * 3 + 1]=result;
|
||||
}
|
||||
src_data[i * 3 + 1] = ((result<MAX(src_data[i * 3 + 1],img_data[i * 3 + 1]))?255:result);
|
||||
|
||||
result=src_data[i * 3 + 2] + img_data[i * 3 + 2];
|
||||
if(result<MAX(src_data[i * 3 + 2],img_data[i * 3 + 2])){
|
||||
src_data[i * 3 + 2]=255;
|
||||
}
|
||||
else{
|
||||
src_data[i * 3 + 2]=result;
|
||||
}
|
||||
src_data[i * 3 + 2] = ((result<MAX(src_data[i * 3 + 2],img_data[i * 3 + 2]))?255:result);
|
||||
|
||||
}
|
||||
|
||||
@ -307,28 +292,13 @@ void PikaCV_Image_minus(PikaObj *self, PikaObj* image){
|
||||
/* minus two images */
|
||||
for (i = 0; i < (src->size)/3; i++) {
|
||||
result=src_data[i * 3] - img_data[i * 3];
|
||||
if(result>MIN(src_data[i * 3],img_data[i * 3])){
|
||||
src_data[i * 3]=0;
|
||||
}
|
||||
else{
|
||||
src_data[i * 3]=result;
|
||||
}
|
||||
src_data[i * 3] = ((result<MIN(src_data[i * 3],img_data[i * 3]))?0:result);
|
||||
|
||||
result=src_data[i * 3 + 1] - img_data[i * 3 + 1];
|
||||
if(result>MIN(src_data[i * 3 + 1],img_data[i * 3 + 1])){
|
||||
src_data[i * 3 + 1]=0;
|
||||
}
|
||||
else{
|
||||
src_data[i * 3 + 1]=result;
|
||||
}
|
||||
src_data[i * 3 + 1] = ((result>MIN(src_data[i * 3 + 1],img_data[i * 3 + 1]))?0:result);
|
||||
|
||||
result=src_data[i * 3 + 2] - img_data[i * 3 + 2];
|
||||
if(result>MIN(src_data[i * 3 + 2],img_data[i * 3 + 2])){
|
||||
src_data[i * 3 + 2]=0;
|
||||
}
|
||||
else{
|
||||
src_data[i * 3 + 2]=result;
|
||||
}
|
||||
src_data[i * 3 + 2] = ((result<MIN(src_data[i * 3 + 2],img_data[i * 3 + 2]))?0:result);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
"--gtest_filter=parser.str_equ"
|
||||
// "--gtest_filter=parser.str_equ"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -175,13 +175,16 @@ void PikaCV_Converter_toGray(PikaObj* self, PikaObj* image) {
|
||||
uint8_t* data_new = arg_getBytes(arg_data_new);
|
||||
if (img->format == PikaCV_ImageFormat_Type_RGB888) {
|
||||
for (int i = 0; i < size_new; i++) {
|
||||
data_new[i] = (uint8_t)((uint16_t)(data[i * 3] + data[i * 3 + 1] + data[i * 3 + 2]) / 3);
|
||||
data_new[i] = (uint8_t)((uint16_t)(data[i * 3] + data[i * 3 + 1] +
|
||||
data[i * 3 + 2]) /
|
||||
3);
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
if (img->format == PikaCV_ImageFormat_Type_RGB565) {
|
||||
for (int i = 0; i < size_new; i++) {
|
||||
data_new[i] = (uint8_t)((uint16_t)(data[i * 2] + data[i * 2 + 1]) >> 1);
|
||||
data_new[i] =
|
||||
(uint8_t)((uint16_t)(data[i * 2] + data[i * 2 + 1]) >> 1);
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
@ -217,11 +220,9 @@ void PikaCV_Converter_toRGB565(PikaObj* self, PikaObj* image) {
|
||||
uint8_t* data_new = arg_getBytes(arg_data_new);
|
||||
if (img->format == PikaCV_ImageFormat_Type_RGB888) {
|
||||
for (int i = 0; i < img->size; i += 3) {
|
||||
uint32_t* p888 = (uint32_t*)&data[i];
|
||||
uint16_t* p565 = (uint16_t*)&data_new[i / 3 * 2];
|
||||
|
||||
*p565 = ((*p888 & 0x00F80000) >> 8) | ((*p888 & 0x0000FC00) >> 5) |
|
||||
((*p888 & 0x000000F8) >> 3);
|
||||
*p565 = (uint16_t)(((data[i] >> 3) << 11) |
|
||||
((data[i + 1] >> 2) << 5) | (data[i + 2] >> 3));
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user