Hi, I'm usign MEMDEVICES to make a image to rotate in screen. I create 3 MEM_DEV: image_background, image_source, image_destination. Image_background is a LCD copy made before the screen initialization. Image_source is a MEM_DEV created from a SDRAM copy of a image created by BitmapConverter (dta type). Image_destination is the image generated by MEMDEV_ROTATE with angle and magnifier parameters.
The sequence of my code is something like 2 functions. LoadIcon to read the source image and create background and RotateIcon to rotate the image and draw it to screen:
void LoadIcon(ICON_ROTATION* icon, GUI_BITMAP *bmp)
{
hMemSource[icon->icon_id] = GUI_MEMDEV_CreateFixed(icon->x,icon->y,icon->w,icon->h,GUI_MEMDEV_HASTRANS,GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
hMemDest[icon->icon_id] = GUI_MEMDEV_CreateFixed(icon->x,icon->y,icon->w,icon->h,GUI_MEMDEV_HASTRANS,GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
hMemBk[icon->icon_id] = GUI_MEMDEV_CreateFixed(icon->x,icon->y,icon->w,icon->h,GUI_MEMDEV_NOTRANS,GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_888);
GUI_MEMDEV_Select(hMemBk[icon->icon_id]);
GUI_MEMDEV_CopyFromLCD(hMemBk[icon->icon_id]);
statusimg=4;
GUI_MEMDEV_Select(hMemSource[icon->icon_id]);
GUI_SetBkColor(GUI_TRANSPARENT);
GUI_Clear();
GUI_DrawBitmap(&icones[icon->icon_id],(icon->x+(icon->w/2)-(sprite->XSize/2)),(icon->y+(icon->h/2)-(sprite->YSize/2))); //EMV 0302
GUI_MEMDEV_Select(0); //retorna para p/ LCD
}
void RotateIcon(U8 icon_id, U16 angle, ICON_ROTATION* icon)
{
GUI_MEMDEV_Select(hMemDest[icon_id]);
GUI_MEMDEV_WriteAt(hMemBk[icon_id],icon->x,icon->y);
GUI_MEMDEV_Rotate(hMemSource[icon_id], hMemDest[icon_id], icon->icon_rotation_center_x, icon->icon_rotation_center_y, (-1000*(angle>initial_rotation_angle)), 1000);
GUI_MEMDEV_Select(0);
GUI_MEMDEV_WriteAt(hMemDest[icon_id],icon->x,icon->y);
}
The problem is sometimes (very frequently) when GUI_MEMDEV_WriteAt(hMemBk) is executed, a Hard Fault is reached in by code.
I already verify MemoryUsage by emWin, tested SDRAM timing, and tried another MEMDEV in this project. The only problem is with this feature of rotate a image.
I believe the issue is because different types of depth color. My LCD is a TFT16bit and the image generated by BitmapConverter is a 8 bit pallete image. I'm right?
Thanks.
The sequence of my code is something like 2 functions. LoadIcon to read the source image and create background and RotateIcon to rotate the image and draw it to screen:
void LoadIcon(ICON_ROTATION* icon, GUI_BITMAP *bmp)
{
hMemSource[icon->icon_id] = GUI_MEMDEV_CreateFixed(icon->x,icon->y,icon->w,icon->h,GUI_MEMDEV_HASTRANS,GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
hMemDest[icon->icon_id] = GUI_MEMDEV_CreateFixed(icon->x,icon->y,icon->w,icon->h,GUI_MEMDEV_HASTRANS,GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
hMemBk[icon->icon_id] = GUI_MEMDEV_CreateFixed(icon->x,icon->y,icon->w,icon->h,GUI_MEMDEV_NOTRANS,GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_888);
GUI_MEMDEV_Select(hMemBk[icon->icon_id]);
GUI_MEMDEV_CopyFromLCD(hMemBk[icon->icon_id]);
statusimg=4;
GUI_MEMDEV_Select(hMemSource[icon->icon_id]);
GUI_SetBkColor(GUI_TRANSPARENT);
GUI_Clear();
GUI_DrawBitmap(&icones[icon->icon_id],(icon->x+(icon->w/2)-(sprite->XSize/2)),(icon->y+(icon->h/2)-(sprite->YSize/2))); //EMV 0302
GUI_MEMDEV_Select(0); //retorna para p/ LCD
}
void RotateIcon(U8 icon_id, U16 angle, ICON_ROTATION* icon)
{
GUI_MEMDEV_Select(hMemDest[icon_id]);
GUI_MEMDEV_WriteAt(hMemBk[icon_id],icon->x,icon->y);
GUI_MEMDEV_Rotate(hMemSource[icon_id], hMemDest[icon_id], icon->icon_rotation_center_x, icon->icon_rotation_center_y, (-1000*(angle>initial_rotation_angle)), 1000);
GUI_MEMDEV_Select(0);
GUI_MEMDEV_WriteAt(hMemDest[icon_id],icon->x,icon->y);
}
The problem is sometimes (very frequently) when GUI_MEMDEV_WriteAt(hMemBk) is executed, a Hard Fault is reached in by code.
I already verify MemoryUsage by emWin, tested SDRAM timing, and tried another MEMDEV in this project. The only problem is with this feature of rotate a image.
I believe the issue is because different types of depth color. My LCD is a TFT16bit and the image generated by BitmapConverter is a 8 bit pallete image. I'm right?
Thanks.