Scanline.hh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef SCANLINE_HH
  2. #define SCANLINE_HH
  3. #include "PixelOperations.hh"
  4. #include <cstdint>
  5. namespace openmsx {
  6. /**
  7. * Helper class to perform 'pixel x scalar' calculations.
  8. */
  9. template<typename Pixel> class Multiply;
  10. template<> class Multiply<uint16_t>
  11. {
  12. public:
  13. explicit Multiply(const PixelOperations<uint16_t>& pixelOps);
  14. void setFactor(unsigned f);
  15. inline uint16_t multiply(uint16_t p, unsigned factor) const;
  16. inline uint16_t multiply(uint16_t p) const;
  17. inline const uint16_t* getTable() const;
  18. private:
  19. const PixelOperations<uint16_t>& pixelOps;
  20. unsigned factor;
  21. uint16_t tab[0x10000];
  22. };
  23. template<> class Multiply<uint32_t>
  24. {
  25. public:
  26. explicit Multiply(const PixelOperations<uint32_t>& pixelOps);
  27. void setFactor(unsigned f);
  28. inline uint32_t multiply(uint32_t p, unsigned factor) const;
  29. inline uint32_t multiply(uint32_t p) const;
  30. const uint32_t* getTable() const;
  31. private:
  32. unsigned factor;
  33. };
  34. /**
  35. * Helper class to draw scalines
  36. */
  37. template <class Pixel> class Scanline
  38. {
  39. public:
  40. explicit Scanline(const PixelOperations<Pixel>& pixelOps);
  41. /** Draws a scanline. The scanline will be the average of the two
  42. * input lines and darkened by a certain factor.
  43. * @param src1 First input line.
  44. * @param src2 Second input line.
  45. * @param dst Output line.
  46. * @param factor Darkness factor, 0 means completely black,
  47. * 255 means no darkening.
  48. * @param width Line width in pixels.
  49. */
  50. void draw(const Pixel* src1, const Pixel* src2, Pixel* dst,
  51. unsigned factor, size_t width);
  52. /** Darken one pixel. Typically used to implement drawBlank().
  53. */
  54. Pixel darken(Pixel p, unsigned factor);
  55. /** Darken and blend two pixels.
  56. */
  57. Pixel darken(Pixel p1, Pixel p2, unsigned factor);
  58. private:
  59. Multiply<Pixel> darkener;
  60. PixelOperations<Pixel> pixelOps;
  61. };
  62. } // namespace openmsx
  63. #endif