title.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef __TITLE_H__
  2. #define __TITLE_H__
  3. #include <stdint.h>
  4. typedef struct {
  5. int enable;
  6. int type; /* 0 = bar (solid, reserves space), 1 = overlay (translucent) */
  7. int height; /* bar height, rounded down to even */
  8. char text[256];
  9. char logo[256];
  10. char font[256];
  11. int font_size;
  12. unsigned color; /* RGB, e.g. 0xFFFFFF = white */
  13. int logo_pad;
  14. int opacity; /* logo/text global opacity 0-255, 255 = opaque */
  15. } TitleCfg;
  16. /* Render the title bar (logo + text) into the top of an NV12 buffer.
  17. * map must point to out_w*out_h*3/2 bytes. Returns 0 on success, -1 on error. */
  18. int title_render(uint8_t *map, int out_w, int out_h, const TitleCfg *cfg);
  19. /* Return the first available default font path (WQY microhei, else zenhei). */
  20. const char *title_default_font(void);
  21. /* Render a translucent title strip over existing frame content (overlay mode):
  22. * darkens the top cfg->height rows, then draws logo + text on top. The video
  23. * below/under it is left intact. Returns 0 on success, -1 on error. */
  24. int title_render_overlay(uint8_t *map, int out_w, int out_h, const TitleCfg *cfg);
  25. /* Render one text line centered on (center_x, center_y) into the NV12 buffer.
  26. * center_x <= 0 centers over the whole width; center_y <= 0 uses out_h/2.
  27. * Font falls back to the WQY micro hei path if empty. Returns 0 on success. */
  28. int title_render_text(uint8_t *map, int out_w, int out_h,
  29. const char *font, const char *text, int size,
  30. unsigned color, int center_x, int center_y);
  31. /* Advance width (px) of a UTF-8 text line, or -1 on error.
  32. * Empty font falls back to the WQY default. Used for right-aligned text. */
  33. long title_measure_text(const char *font, const char *text, int size);
  34. /* Draw a small translucent PLC connection status badge in the top-right
  35. * corner of an NV12 buffer: colored dot (green = connected, red = offline)
  36. * plus a label. Returns 0 on success, -1 on error. */
  37. int title_render_plc_status(uint8_t *map, int out_w, int out_h,
  38. const char *font, int connected);
  39. /* Draw a translucent pill in the bottom-left corner showing the given text
  40. * (used for the board's IP address(es)) so the operator can read it on screen.
  41. * Returns 0 on success, -1 on error. */
  42. int title_render_ip(uint8_t *map, int out_w, int out_h,
  43. const char *font, const char *text);
  44. #endif