Difficulties with Scaling down Y axis GUI Memory Device

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

    • Difficulties with Scaling down Y axis GUI Memory Device

      UPDATE: Upon reading the documentation over and over, I noticed that I had missed this previously:
      "Note that the function currently only works with Memory Devices with 32-bpp color
      depth and a system color depth of 32 bpp."
      Now I feel like an idiot!!!

      The question remains; How do I scale down the Yresolution from 360 to 238!


      In order to print the ticket drawn, currently I declare a memdev handle as such;

      C Source Code

      1. // printer has 101 dpi
      2. m_memhandle = GUI_MEMDEV_CreateFixed(0, 0, 224, 360, 0,
      3. GUI_MEMDEV_APILIST_1,
      4. GUI_COLOR_CONV_1);
      5. GUI_MEMDEV_Select(m_memhandle);
      6. draw_stuff();
      7. buffer = (U8 * )GUI_MEMDEV_GetDataPtr(m_memhandle );
      8. // this works
      9. print_buffer();
      due to some supply issues, I have to change the printer and the new printer is 67dpi, so printing the above buffer results in a stretched image in the Y direction! Using scaling factor of 101dpi/67dpi = 1.5, I came up with new Y resolution to be 238.

      I tried to use the following to fix it, but it's not working.

      Source Code

      1. GUI_MEMDEV_Handle m_memhandle= GUI_MEMDEV_CreateFixed(0, 0, 224, 360, 0, GUI_MEMDEV_APILIST_1, GUI_COLOR_CONV_1);
      2. GUI_MEMDEV_Handle m_memhandleDst = GUI_MEMDEV_CreateFixed(0, 0, 224, 238, 0, GUI_MEMDEV_APILIST_1, GUI_COLOR_CONV_1);
      3. GUI_MEMDEV_Select(m_memhandle);
      4. draw_stuff();
      5. GUI_MEMDEV_Select(m_memhandleDst);
      6. // x and y = 0
      7. // h0 and h1 = 238 (New Y edge)
      8. // dx = 224 (width didn't change)
      9. // dy = 0
      10. GUI_MEMDEV_DrawPerspectiveX(m_memhandle, 0, 0, 238, 238, 224, 0);
      11. buffer = (U8 * )GUI_MEMDEV_GetDataPtr(m_memhandleDst);
      12. // this prints rubbish
      13. print_buffer();
      Display All
      By the way, I also tried the GUI_MEMDEV_WriteExAt since I can scale the y values, but it has an alpha component and that also didn't work.

      The only thing that worked was writing a down-sampling algorithm that reduced the y pixels, but that added some delay.

      Cheers,
      Simon

      The post was edited 2 times, last by sayo9394: added more info about GUI_MEMDEV_WriteExAt and downsampling ().

    • Hi,

      I gave it a try and was able to scale down the device by using the function GUI_MEMDEV_WriteExAt(). Unfortunately, we have found an issue when using a color depth if 1bpp for the LCD and configured emWin for ARGB mode (#define GUI_USE_ARGB 1 in GUIConf.h). This is fixed now and will be released with the next emWin version (V5.48).
      If you are using 1bpp color depths and the define is set to 1, try to get a precompiled library which was not build with GUI_USE_ARGB set to 1. With a color conversion of 1bpp this define should make no difference.

      This is the code I used for testing:

      C Source Code

      1. /*********************************************************************
      2. *
      3. * MainTask
      4. */
      5. void MainTask(void) {
      6. GUI_MEMDEV_Handle hMem;
      7. GUI_Init();
      8. //
      9. // Create a 32 bpp memory device
      10. //
      11. hMem = GUI_MEMDEV_CreateFixed32(0, 0, 224, 360);
      12. //
      13. // Select it and draw something into
      14. //
      15. GUI_MEMDEV_Select(hMem);
      16. GUI_SetBkColor(GUI_WHITE);
      17. GUI_Clear();
      18. GUI_SetColor(GUI_BLACK);
      19. GUI_DrawLine(0, 0, 224, 360);
      20. GUI_DrawLine(0, 360, 224, 0);
      21. GUI_MEMDEV_Select(0);
      22. //
      23. // Write at a position with a scaling, alpha set to opaque
      24. // || Depending on the configuration this will result in an opaque value
      25. GUI_MEMDEV_WriteExAt(hMem, 0, 0, 1000, (67 * 1000) / 101, GUI_MAKE_TRANS(0x00));
      26. GUI_SetColor(GUI_RED);
      27. GUI_DrawHLine((360 * 67) / 101, 0, 224);
      28. while(1) {
      29. GUI_Delay(2000);
      30. }
      31. }
      Display All
      Regards,
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.