Alpha images rendered correctly only to dark background

  • I have many alpha images. For example:

    Every pixel is descripted as a single byte that represents the "quantity" of the image respect the background. Of course, the content of those images is only the shape.

    I draw alpha images with GUI_SetColor(), that selects the color of the shape, and GUI_DrawBitmap() that really draws the bitmap on the screen. It works very well during the simulation at the PC, and it seems working well on the embedded target when the background is dark (black) or blue (GUI_BLUE). When the background is light (GUI_RED or GUI_GREEN) the alpha blending doesn't work well. The shape isn't smooth. I don't know if it is correct, I think the real color used are calculated if the background was always black.

    My driver is GUIDRV_FLEXCOLOR_F66709. Here it is the initialization.

    So I don't use cache (and I can't use cache for RAM restrictions). So I think emWin is forced to read back the color of pixels during drawing of an alpha image. One cause of my problem could be a wrong read back. For example, the behaviour I observed can be explined if the driver reads back always zero (black colors). So the alpha drawing works (or appears good) when the background is black or dark.


    How could I check if this is correct? I know ILI9341 supports read back.

  • Hi,

    I use the ILI9341 as well and had similar problems with the read function. I use the EDIT widget with the blinking cursor functionality. Therefore emWin reads back the color for the blinking functionality.
    It is important that you use the correct parameters for the read function GUIDRV_FlexColor_SetReadFunc66709_B16(). There are several different parameters. For me I have to pass GUIDRV_FLEXCOLOR_READ_FUNC_III as second parameter. (s. manual)

    It is also important to call the GUIDRV_FlexColor_SetReadFunc66709_B16() function befor calling the GUIDRV_FlexColor_SetFunc() function.

    here is my code:

  • I didn't call GUIDRV_FlexColor_SetReadFunc66709_B16(), so I think the driver was using GUIDRV_FLEXCOLOR_READ_FUNC_I (the default function).

    When I tried to set GUIDRV_FLEXCOLOR_READ_FUNC_III, the program crashes with a HardFault. The call stack says that _ReadRect_16bpp_B16_III() calls guimem() that failed.
    Do you know why?

    Could you share the source code of LCD_X_ReadM1_16 and LCD_X_Read1_16?

  • Good morning,

    here we go:

    I am on a STM32F2 and use the FMSC peripheral for the communication with the display. Have you reserved enough memory for emWin in GUIConf.c (Function GUI_ALLOC_AssignMemory();)?

  • I found the problem that caused the crash. I forgot to set PortAPI.pfRead16_A1 for GUIDRV_FlexColor_SetFunc(). Now it works.

    Anyway I didin't understand. We configured ILI9341 to use the 16-bits interface in 16-bits per pixel (5-6-5). When the driver wants to set a pixel color, it issues a write command with a single 16-bits word where the color is packed in 5-6-5 format.
    Why the ILI9341 responds with 2-bytes (18-bits 6-6-6 format) during read commands? Is it possible to configure the driver to responds in 5-6-5 format, avoiding one read command for every pixel? In this case we could use GUIDRV_FLEXCOLOR_READ_FUNC_III.

  • Hello,

    to be honest, I tested the 3 different read function variants and the read function III was the only one which was working in my application. For the test I used a function where I can dump the screen content on a USB MSD with the aid of GUI_BMP_Serialize(). I took a lot of time in this issue, but I aborted the investigations after I got the correct behavior. Nevertheless this was a long time ago (2 years?) but today I took a deeper look into the ILI9341/emWin manuals and found the following:

    If I take a look into the ILI9341 manual to the section "8080-II Series Parallel Interface" there are 2 data packets in the drawing for the read cycle.

    emWin Manual:
    Commands supported by LCD_SetDevFunc()
    Further information about the LCD layer routines can be found under LCD layer routines
    on page 1277.
    Important note on reading back pixel data from the controller
    Because of the plurality of the supported display controllers and their operation
    modes the driver has not been tested with each interface of each supported controller.
    The behavior of the controller when reading back pixel data often depends on
    custom configuration and hardware details. Because of that it could happen, that the
    driver has no appropriate reading function(s) available. In that case the above
    explained function LCD_SetDevFunc() can be used to set application defined functions
    for reading back pixel data.
    The main problem for the driver here is not getting data from the driver. Getting the
    color bits in the right order is the problem here. The custom defined functions need
    to supply pixel index values. This index format needs to comply to the index format
    determined by the color conversion routines configured for the driver device.
    Because the data supplied by the hardware interface functions of the driver in most
    cases does not have the right index format, the reading routines need to convert that
    raw data into the required pixel index format determined by the driver device configuration.
    For details about the hardware interface functions please also refer to
    GUIDRV_FlexColor_SetFunc() and its parameter pHW_API.
    For details about the pixel index format please also refer to
    GUI_DEVICE_CreateAndLink() and its parameter pColorConvAPI and the chapter
    Colors.
    A sample configuration which shows how custom reading functions can be achieved is
    available in the configuration file sample folder shipped with the driver.

    Maybe you must define your own read back function in order to achieve single byte reads. But that is only an assumption...

    regards Thomas

  • Maybe you must define your own read back function in order to achieve single byte reads. But that is only an assumption...

    I don't think so. The controller (ILI9341) replies with one dummy plus two data bytes. Both bytes have colors, so one-byte read can't work.

    I was searching a command to configure the controller to reply with only one byte (encoded as 5-6-5), but it seems impossible. This behaviour can't be changed only by rewriting a new read back funtion on the host controller.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!