Shop OBEX P1 Docs P2 Docs Learn Events
mcufont working with FlexSpin C - Page 2 — Parallax Forums

mcufont working with FlexSpin C

2»

Comments

  • RaymanRayman Posts: 14,754

    Thinking looks better without the gamma... Maybe McuFont somehow included it already?

        uint32_t BackColor24 = BrightGreen; // NavyBlue;// p[BackColor];
        uint32_t ForeColor24 = WildStrawberry; // Yellow;// p[ForeColor];
    
            if (USE_GAMMA)
            {
                r = ((forer * forer * a) + (backr * backr * (255 - a)));
                b = ((foreb * foreb * a) + (backb * backb * (255 - a)));
                g = ((foreg * foreg * a) + (backg * backg * (255 - a)));
                r = __builtin_sqrt((int)(r)) >> 4;
                b = __builtin_sqrt((int)(b)) >> 4;
                g = __builtin_sqrt((int)(g)) >> 4;
            }
            else
            {
                r = (int) ((forer * a / 255.) + (backr * (255. - a) / 255.)) &0xFF;
                g = (int)((foreg * a / 255.) + (backg * (255. - a) / 255.)) &0xFF;
                b = (int)((foreb * a / 255.) + (backb * (255. - a) / 255.)) &0xFF;
            }
    
    640 x 480 - 5K
    640 x 480 - 5K
  • That is working correctly. You could see it better if you draw a large gradient to the screen - interpolating between two bright colors should not have darker colors in the middle.

    If you want to fix the font appearing too thin, you want to to apply non-linearity to the mixing factor instead.

  • RaymanRayman Posts: 14,754

    got the encoder compiled in Ubuntu. Just had to do "sudo apt-get install cxxtest" for whatever that is...

  • RaymanRayman Posts: 14,754

    Was contemplating moving fonts to PSRAM, but figured out that even the largest size one is only ~15 kB. So, not worth it.

  • RaymanRayman Posts: 14,754

    doing some more work to get a handle on this code, it's a bit complex...

    Am seeing that for VGA with buffer in HUB Ram, one has to be careful about how many fonts you have as they add up and the VGA buffer takes up a lot of space:

    //List of included fonts
    
    #include "DejaVuSans12.c"  // 7,636 bytes
    #include "DejaVuSans12bw.c" // 5,132 bytes
    #include "DejaVuSerif16.c" // 10,092 bytes
    #include "DejaVuSerif32.c" // 18,567 bytes
    #include "fixed_5x8.c" // 2,536 bytes
    #include "fixed_7x14.c"  // 5,156 bytes
    #include "fixed_10x20.c" // 5,700 bytes
    #include "DejaVuSans32.c" // 16,780 bytes
    #include "DejaVuSans12bw_bwfont.c" // 4,916 bytes
    
    //Showfonts.c compiles to 376544 bytes with no fonts, most is bitmap buffer at 302 kB, so code is ~68 kB
    // ..  compiles to 437928 bytes with all the above fonts
    
  • RaymanRayman Posts: 14,754
    edited 2024-11-04 18:00

    Here's example code that shows all the fonts listed in previous post on VGA monitor.
    Also, an example screenshot.

    Think should work on any board with eval equivalent VGA adapter on basepin 8.
    Basepin can be changed in Platform.h

    Main file is ShowFonts.c

    Made the zip using FlexProp GUI...

    640 x 480 - 31K
  • RaymanRayman Posts: 14,754

    Learned a new preprocessor trick from this code...
    It automatically creates a pointer list of available fonts like this:

    This is in the main header:

    /* This will be made into a list of included fonts using macro magic. */
    #define MF_INCLUDED_FONTS 0
    

    Then, each font's code file has this:

    #ifdef MF_INCLUDED_FONTS
    /* List entry for searching fonts by name. */
    static const struct mf_font_list_s mf_rlefont_DejaVuSans12_listentry = {
        MF_INCLUDED_FONTS,
        (struct mf_font_s*)&mf_rlefont_DejaVuSans12
    };
    #undef MF_INCLUDED_FONTS
    #define MF_INCLUDED_FONTS (&mf_rlefont_DejaVuSans12_listentry)
    #endif
    

    I'll have to remember this approach, seems useful for GUI applications too...

Sign In or Register to comment.