Advertisement
Guest User

8bpp.c

a guest
Oct 1st, 2013
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  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.  
  24. static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
  25. {
  26.         return (uint8_t *)(nsfb->ptr + (y * nsfb->linelen) + (x));
  27. }
  28.  
  29.  
  30. static inline nsfb_colour_t pixel_to_colour(nsfb_t *nsfb, uint8_t pixel)
  31. {
  32.         if (nsfb->palette == NULL)
  33.                 return 0;
  34.  
  35.         return nsfb->palette->data[pixel];
  36. }
  37.  
  38. static uint8_t colour_to_pixel(nsfb_t *nsfb, nsfb_colour_t c)
  39. {
  40.         if (nsfb->palette == NULL)
  41.                 return 0;
  42.  
  43.            
  44.         return nsfb_palette_best_match_dither(nsfb->palette,c);
  45. }
  46.  
  47. #define PLOT_TYPE uint8_t
  48. #define PLOT_LINELEN(ll) (ll)
  49.  
  50. #include "common.c"
  51.  
  52. static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
  53. {
  54.         int y;
  55.         uint8_t ent;
  56.         uint8_t *pvideo;
  57.  
  58.         if (!nsfb_plot_clip_ctx(nsfb, rect))
  59.                 return true; /* fill lies outside current clipping region */
  60.  
  61.         pvideo = get_xy_loc(nsfb, rect->x0, rect->y0);
  62.  
  63.         ent = colour_to_pixel(nsfb, c);
  64.  
  65.         for (y = rect->y0; y < rect->y1; y++) {
  66.                 memset(pvideo, ent, rect->x1 - rect->x0);
  67.                 pvideo += nsfb->linelen;
  68.         }
  69.  
  70.         return true;
  71. }
  72.  
  73. const nsfb_plotter_fns_t _nsfb_8bpp_plotters = {
  74.         .line = line,
  75.         .fill = fill,
  76.         .point = point,
  77.         .bitmap = bitmap,
  78.         .glyph8 = glyph8,
  79.         .glyph1 = glyph1,
  80.         .readrect = readrect,
  81. };
  82.  
  83.  
  84. /*
  85.  * Local Variables:
  86.  * c-basic-offset:8
  87.  * End:
  88.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement