Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* libnsfb plotter test program */
  2.  
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10.  
  11. #include "libnsfb.h"
  12. #include "libnsfb_plot.h"
  13. #include "libnsfb_event.h"
  14.  
  15. #define UNUSED(x) ((x) = (x))
  16.  
  17. const struct {
  18.         unsigned int w;
  19.         unsigned int h;
  20.         unsigned char data[16];
  21. } Mglyph1 = {
  22.         8, 16,
  23.         {
  24.                 0x00, /* 00000000 */
  25.                 0x00, /* 00000000 */
  26.                 0xc6, /* 11000110 */
  27.                 0xee, /* 11101110 */
  28.                 0xfe, /* 11111110 */
  29.                 0xfe, /* 11111110 */
  30.                 0xd6, /* 11010110 */
  31.                 0xc6, /* 11000110 */
  32.                 0xc6, /* 11000110 */
  33.                 0xc6, /* 11000110 */
  34.                 0xc6, /* 11000110 */
  35.                 0xc6, /* 11000110 */
  36.                 0x00, /* 00000000 */
  37.                 0x00, /* 00000000 */
  38.                 0x00, /* 00000000 */
  39.                 0x00, /* 00000000 */
  40.         }
  41. };
  42.  
  43. int main(int argc, char **argv)
  44. {
  45.         const char *fename;
  46.         enum nsfb_type_e fetype;
  47.         nsfb_t *nsfb;
  48.  
  49.         nsfb_bbox_t box;
  50.         nsfb_bbox_t box3;
  51.         uint8_t *fbptr;
  52.         int fbstride;
  53.         int i;
  54.         unsigned int x, y;
  55.  
  56.         if (argc < 2) {
  57.                 fename="sdl";
  58.         } else {
  59.                 fename = argv[1];
  60.         }
  61.  
  62.         fetype = nsfb_type_from_name(fename);
  63.         if (fetype == NSFB_SURFACE_NONE) {
  64.                 printf("Unable to convert \"%s\" to nsfb surface type\n",
  65.                                 fename);
  66.                 return EXIT_FAILURE;
  67.         }
  68.  
  69.         nsfb = nsfb_new(fetype);
  70.         if (nsfb == NULL) {
  71.                 printf("Unable to allocate \"%s\" nsfb surface\n", fename);
  72.                 return EXIT_FAILURE;
  73.         }
  74.  
  75.         if (nsfb_init(nsfb) == -1) {
  76.                 printf("Unable to initialise nsfb surface\n");
  77.                 nsfb_free(nsfb);
  78.                 return EXIT_FAILURE;
  79.         }
  80.  
  81.         /* get the geometry of the whole screen */
  82.         box.x0 = box.y0 = 0;
  83.         nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);
  84.  
  85.         nsfb_get_buffer(nsfb, &fbptr, &fbstride);
  86.         nsfb_claim(nsfb, &box);
  87.  
  88.         /* Clear to white */
  89.         nsfb_plot_clg(nsfb, 0xffffffff);
  90.         nsfb_update(nsfb, &box);
  91.  
  92.         /* test glyph plotting */
  93.         for (i = 0; i < 1000; i++) {
  94.                 for (y = 0; y < box.y1 - Mglyph1.h; y += Mglyph1.h) {
  95.                         for (x = 0; x < box.x1 - Mglyph1.w; x += Mglyph1.w) {
  96.                                 box3.x0 = x;
  97.                                 box3.y0 = y;
  98.                                 box3.x1 = box3.x0 + Mglyph1.w;
  99.                                 box3.y1 = box3.y0 + Mglyph1.h;
  100.  
  101.                                 nsfb_plot_glyph1(nsfb, &box3,  Mglyph1.data,
  102.                                                 Mglyph1.w, 0xff000000);
  103.                         }
  104.                 }
  105.                 nsfb_update(nsfb, &box);
  106.         }
  107.  
  108.         nsfb_update(nsfb, &box);
  109.         nsfb_free(nsfb);
  110.  
  111.         return 0;
  112. }
  113.