Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
  3.  * Copyright 2010 Michael Drake <tlsa@netsurf-browser.org>
  4.  *
  5.  * This file is part of libnsfb, http://www.netsurf-browser.org/
  6.  * Licenced under the MIT License,
  7.  *                http://www.opensource.org/licenses/mit-license.php
  8.  */
  9.  
  10. #include <stdbool.h>
  11. #include <endian.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "libnsfb.h"
  16. #include "libnsfb_plot.h"
  17. #include "libnsfb_plot_util.h"
  18.  
  19. #include "nsfb.h"
  20. #include "palette.h"
  21. #include "plot.h"
  22.  
  23. static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
  24. {
  25.         return (uint8_t *)(nsfb->ptr + (y * nsfb->linelen) + (x));
  26. }
  27.  
  28.  
  29. static inline nsfb_colour_t pixel_to_colour(nsfb_t *nsfb, uint8_t pixel)
  30. {
  31.         if (nsfb->palette == NULL)
  32.                 return 0;
  33.  
  34.         return nsfb->palette->data[pixel];
  35. }
  36.  
  37. static uint8_t colour_to_pixel(nsfb_t *nsfb, nsfb_colour_t c)
  38. {
  39.         if (nsfb->palette == NULL)
  40.                 return 0;
  41.  
  42.         return nsfb_palette_best_match_dither(nsfb->palette, c);
  43. }
  44.  
  45. #define PLOT_TYPE uint8_t
  46. #define PLOT_LINELEN(ll) (ll)
  47.  
  48. #include "common.c"
  49.  
  50. static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
  51. {
  52.         int y;
  53.         uint8_t ent;
  54.         uint8_t *pvideo;
  55.  
  56.         if (!nsfb_plot_clip_ctx(nsfb, rect))
  57.                 return true; /* fill lies outside current clipping region */
  58.  
  59.         pvideo = get_xy_loc(nsfb, rect->x0, rect->y0);
  60.  
  61.         ent = colour_to_pixel(nsfb, c);
  62.  
  63.         for (y = rect->y0; y < rect->y1; y++) {
  64.                 memset(pvideo, ent, rect->x1 - rect->x0);
  65.                 pvideo += nsfb->linelen;
  66.         }
  67.  
  68.         return true;
  69. }
  70.  
  71. const nsfb_plotter_fns_t _nsfb_8bpp_plotters = {
  72.         .line = line,
  73.         .fill = fill,
  74.         .point = point,
  75.         .bitmap = bitmap,
  76.         .glyph8 = glyph8,
  77.         .glyph1 = glyph1,
  78.         .readrect = readrect,
  79. };
  80.  
  81.  
  82. /*
  83.  * Local Variables:
  84.  * c-basic-offset:8
  85.  * End:
  86.  */
  87.