Problem with COLOR_CONVERSION Table

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Problem with COLOR_CONVERSION Table

    Hello to all,

    I have a general problem regarding the color definintion in emWin 5.22.

    In gui.h the standard colors are defined.

    for example:

    #define GUI_RED 0x000000FF

    However, everywhere else in the world Red and Blue is swapped that means plain Red should be:
    #define RED 0x00FF0000
    Here a link to common color definitions: en.wikipedia.org/wiki/Web_colo…erting_RGB_to_hexadecimal

    Why is emWin 5.22 doing it the other way round?

    However I solved the problem in using the GUICC_565 color conversion table and I don´t use the emWin color definitions.
    This workes fine everywhere in my project regarding the output to the LCD!

    But when I use the GUI_BMP_Serialize() Function the Red and Blue colors are again swapped in the resulting file.
    So this output obviously doesn´t take care of the color conversion table setting in LCDConf.c

    I would be happy about any ideas to detour this issue!

    Andy
  • Hello Adrian,

    I know the different color conversion tables GUICC_565 and GUICC_M565.

    I explain my problem again:

    When I work with built in colors from emWin like GUI_RED a have to work with GUICC_M565 to have the color shown as red.
    So far so good.

    But I after a while I got external colors supplied from a designer.
    These colors are from common color schemes available elsewhere in the world.

    When I implemented these colors I realized that Red and Blue was swapped in the LCD.
    Therefore I changed color conversion table from GUICC_M565 to GUICC_565.
    Everything workes now fine with my colors.

    And now the questions:
    a) Regardless of color conversion tables for example red is defined as a STANDARD:
    #define RED 0x00FF0000
    This can be verified with this link: http://en.wikipedia.org/wiki/Web_colors#…_to_hexadecimal

    WHY DOES EMWIN DEFINE RED AS:
    #define GUI_RED 0x000000FF ????

    RED and BLUE are swapped here!

    b) despite of the obvious color swapping in emWin I corrected it using another color conversion table
    it works fine with the LCD.
    BUT: GETTING A BITMAP USING GUI_BMP_Serialize() SHOWES THE COLORS AGAIN SWAPPED IN THE BITMAP-FILE!!
    How can it be that in any circumstances the bitmap picture shows other colors than the LCD??

    I would highly appreciate an answer to these conflicts

    Thanks a lot for your help

    Andy
  • Hello Andy,

    This is based on hardware. Display controllers are designed to use both color arrangements, so we had to make a decision.

    I did a test using GUICC_565 and GUICC_M565 when running our sample application 2DGL_BMPExport.c. It looks fine in every case. Could you please tell me what you did different from the sample? If there is a problem, I would like to reproduce it.

    Best regards,
    Adrian
  • Hello Adrian,

    thanks for your reply.

    I think the case is very simple. The GUI_BMP_Serialize() does NOT take care of color conversion table setting!
    It seemes to fixed to GUICC_M565.

    I have emWin 5.22

    I provoke the fault like this:

    With setting COLOR_CONVERSION GUICC_M565 both LCD and BMP-Output have the same colors.
    (I just swapped my colors manually to work correct with this)

    Then I change the setting to COLOR_CONVERSION GUICC_565: the LCD has blue and red swapped but the BMP-Output is still the same!!

    Below you have my lcdconf.c

    best regards
    Andy

    /*********************************************************************
    * SEGGER Microcontroller GmbH & Co. KG *
    * Solutions for real time microcontroller applications *
    **********************************************************************
    * *
    * (c) 1996 - 2013 SEGGER Microcontroller GmbH & Co. KG *
    * *
    * Internet: segger.com Support: support@segger.com *
    * *
    **********************************************************************

    ** emWin V5.22 - Graphical user interface for embedded applications **
    All Intellectual Property rights in the Software belongs to SEGGER.
    emWin is protected by international copyright laws. Knowledge of the
    source code may not be used to write a similar product. This file may
    only be used in accordance with the following terms:

    The software has been licensed to ARM LIMITED whose registered office
    is situated at 110 Fulbourn Road, Cambridge CB1 9NJ, England solely
    for the purposes of creating libraries for ARM7, ARM9, Cortex-M
    series, and Cortex-R4 processor-based devices, sublicensed and
    distributed as part of the MDK-ARM Professional under the terms and
    conditions of the End User License supplied with the MDK-ARM
    Professional.
    Full source code is available at: segger.com

    We appreciate your understanding and fairness.
    */

    /**
    ****************************************************************************
    * @file LCDConf.c
    * @brief Display controller configuration
    * Display: Ampire AM320240L2TMQW
    * Controller: SSD1963
    * Display driver: GUIDRV_FlexColor
    ****************************************************************************/

    #include "stm32f2xx.h" /* STM32F2xx Definitions */
    #include "GUIDRV_FlexColor.h"
    #include "SSD1963.h"

    /*********************************************************************
    *
    * Layer configuration
    *
    **********************************************************************
    */

    //
    // Physical display size
    //
    #define XSIZE_PHYS 320
    #define YSIZE_PHYS 240

    //
    // Color conversion
    //
    #define COLOR_CONVERSION GUICC_M565

    //
    // Display driver
    //
    #define DISPLAY_DRIVER GUIDRV_FLEXCOLOR

    //
    // Buffers / VScreens
    //
    #define NUM_BUFFERS 1
    #define NUM_VSCREENS 1

    //
    // Display orientation
    //
    #define DISPLAY_ORIENTATION 0
    //#define DISPLAY_ORIENTATION (GUI_MIRROR_X | GUI_MIRROR_Y)
    //#define DISPLAY_ORIENTATION (GUI_SWAP_XY | GUI_MIRROR_Y)
    //#define DISPLAY_ORIENTATION (GUI_SWAP_XY | GUI_MIRROR_X)

    //
    // Touch screen
    //

    #define USE_TOUCH 0

    //
    // Touch screen calibration
    #define TOUCH_X_MIN 0x00E0
    #define TOUCH_X_MAX 0x0F40
    #define TOUCH_Y_MIN 0x00C0
    #define TOUCH_Y_MAX 0x0F60

    /*********************************************************************
    *
    * Configuration checking
    *
    **********************************************************************
    */
    #ifndef XSIZE_PHYS
    #error Physical X size of display is not defined!
    #endif
    #ifndef YSIZE_PHYS
    #error Physical Y size of display is not defined!
    #endif
    #ifndef COLOR_CONVERSION
    #error Color conversion not defined!
    #endif
    #ifndef DISPLAY_DRIVER
    #error No display driver defined!
    #endif
    #ifndef NUM_VSCREENS
    #define NUM_VSCREENS 1
    #else
    #if (NUM_VSCREENS <= 0)
    #error At least one screeen needs to be defined!
    #endif
    #endif
    #if (NUM_VSCREENS > 1) && (NUM_BUFFERS > 1)
    #error Virtual screens and multiple buffers are not allowed!
    #endif
    #ifndef DISPLAY_ORIENTATION
    #define DISPLAY_ORIENTATION 0
    #endif

    #if ((DISPLAY_ORIENTATION & GUI_SWAP_XY) != 0)
    #define LANDSCAPE 1
    #else
    #define LANDSCAPE 0
    #endif

    #if (LANDSCAPE == 1)
    #define WIDTH YSIZE_PHYS /* Screen Width (in pixels) */
    #define HEIGHT XSIZE_PHYS /* Screen Hight (in pixels) */
    #else
    #define WIDTH XSIZE_PHYS /* Screen Width (in pixels) */
    #define HEIGHT YSIZE_PHYS /* Screen Hight (in pixels) */
    #endif

    #if ((DISPLAY_ORIENTATION & GUI_SWAP_XY) != 0)
    #if ((DISPLAY_ORIENTATION & GUI_MIRROR_X) != 0)
    #define TOUCH_TOP TOUCH_X_MAX
    #define TOUCH_BOTTOM TOUCH_X_MIN
    #else
    #define TOUCH_TOP TOUCH_X_MIN
    #define TOUCH_BOTTOM TOUCH_X_MAX
    #endif
    #if ((DISPLAY_ORIENTATION & GUI_MIRROR_Y) != 0)
    #define TOUCH_LEFT TOUCH_Y_MAX
    #define TOUCH_RIGHT TOUCH_Y_MIN
    #else
    #define TOUCH_LEFT TOUCH_Y_MIN
    #define TOUCH_RIGHT TOUCH_Y_MAX
    #endif
    #else
    #if ((DISPLAY_ORIENTATION & GUI_MIRROR_X) != 0)
    #define TOUCH_LEFT TOUCH_X_MAX
    #define TOUCH_RIGHT TOUCH_X_MIN
    #else
    #define TOUCH_LEFT TOUCH_X_MIN
    #define TOUCH_RIGHT TOUCH_X_MAX
    #endif
    #if ((DISPLAY_ORIENTATION & GUI_MIRROR_Y) != 0)
    #define TOUCH_TOP TOUCH_Y_MAX
    #define TOUCH_BOTTOM TOUCH_Y_MIN
    #else
    #define TOUCH_TOP TOUCH_Y_MIN
    #define TOUCH_BOTTOM TOUCH_Y_MAX
    #endif
    #endif



    /*********************************************************************
    *
    * _InitController
    *
    * Purpose:
    * Initializes the display controller
    */
    static void _InitController(void) {
    SSD1963_Init(); //Den SSD1963 auf Registerebene initialisieren, seine PLL wurde schon bei FSMC-Init initialisiert!!
    }

    /*********************************************************************
    *
    * Public code
    *
    **********************************************************************
    */
    /*********************************************************************
    *
    * LCD_X_Config
    *
    * Purpose:
    * Called during the initialization process in order to set up the
    * display driver configuration.
    *
    */
    void LCD_X_Config(void) {
    GUI_DEVICE * pDevice;
    GUI_PORT_API PortAPI = {0};
    CONFIG_FLEXCOLOR Config = {0};

    #if (NUM_BUFFERS > 1)
    GUI_MULTIBUF_Config(NUM_BUFFERS);
    #endif
    //
    // Set display driver and color conversion for 1st layer
    //
    pDevice = GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER, COLOR_CONVERSION, 0, 0);
    //
    // Common display driver configuration
    //
    if (LCD_GetSwapXY()) {
    LCD_SetSizeEx (0, YSIZE_PHYS, XSIZE_PHYS);
    LCD_SetVSizeEx(0, YSIZE_PHYS * NUM_VSCREENS, XSIZE_PHYS);
    } else {
    LCD_SetSizeEx (0, XSIZE_PHYS, YSIZE_PHYS);
    LCD_SetVSizeEx(0, XSIZE_PHYS, YSIZE_PHYS * NUM_VSCREENS);
    }
    //
    // Configuration of GUIDRV_FLEX_COLOR
    //

    // Set controller type SSD1963
    //
    PortAPI.pfWrite16_A0 = LCD_X_WR_CTRL;
    PortAPI.pfWrite16_A1 = LCD_X_WR_DAT;
    PortAPI.pfWriteM16_A1 = LCD_X_WriteM01_16;
    PortAPI.pfReadM16_A1 = LCD_X_ReadM01_16;
    GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66720, GUIDRV_FLEXCOLOR_M16C0B16);

    //Select Readback Interface
    //GUIDRV_FLEXCOLOR_READ_FUNC_II liest 2 mal, das erste ein Dummybyte. Dieser Interfacetyp ist für den SSD1963 NICHT zutreffend!!
    //da es jedoch keinen anderen gibt musste die Leseroutine LCD_X_ReadM01_16 entsprechend modifiziert werden, damit der DummyRead
    //übersprungen wird und nicht auf den SSD1963 durchgelassen wird!!
    GUIDRV_FlexColor_SetReadFunc66720_B16(pDevice, GUIDRV_FLEXCOLOR_READ_FUNC_II);

    // Orientation and offset of SEG/COM lines
    //
    Config.Orientation = DISPLAY_ORIENTATION;
    Config.RegEntryMode = 0;
    GUIDRV_FlexColor_Config(pDevice, &Config);

    #if (USE_TOUCH == 1)
    //
    // Set orientation of touch screen
    //
    GUI_TOUCH_SetOrientation(DISPLAY_ORIENTATION);
    //
    // Calibrate touch screen
    //
    GUI_TOUCH_Calibrate(GUI_COORD_X, 0, WIDTH - 1, TOUCH_LEFT, TOUCH_RIGHT);
    GUI_TOUCH_Calibrate(GUI_COORD_Y, 0, HEIGHT - 1, TOUCH_TOP, TOUCH_BOTTOM);
    #endif
    }

    /*********************************************************************
    *
    * LCD_X_DisplayDriver
    *
    * Purpose:
    * This function is called by the display driver for several purposes.
    * To support the according task the routine needs to be adapted to
    * the display controller. Please note that the commands marked with
    * 'optional' are not cogently required and should only be adapted if
    * the display controller supports these features.
    *
    * Parameter:
    * LayerIndex - Index of layer to be configured
    * Cmd - Please refer to the details in the switch statement below
    * pData - Pointer to a LCD_X_DATA structure
    *
    * Return Value:
    * < -1 - Error
    * -1 - Command not handled
    * 0 - Ok
    */
    int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
    int r;

    switch (Cmd) {
    //
    // Required
    //
    case LCD_X_INITCONTROLLER: {
    //
    // Called during the initialization process in order to set up the
    // display controller and put it into operation. If the display
    // controller is not initialized by any external routine this needs
    // to be adapted by the customer...
    //
    _InitController();
    return 0;
    }
    default:
    r = -1;
    }
    return r;
    }

    /*************************** End of file ****************************/