You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.8 KiB

5 years ago
  1. #pragma once
  2. namespace CELL
  3. {
  4. class Image
  5. {
  6. protected:
  7. int _width;
  8. int _height;
  9. uint* _pixel;
  10. int _wrapType;
  11. public:
  12. Image(int w,int h,void* data)
  13. {
  14. _wrapType = 0;
  15. if (w == 0 || h == 0 || data== 0)
  16. {
  17. _width = 0;
  18. _height = 0;
  19. _pixel = 0;
  20. }
  21. else
  22. {
  23. _width = w;
  24. _height = h;
  25. _pixel = new uint[w * h];
  26. memcpy(_pixel,data,w * h * sizeof(uint));
  27. }
  28. }
  29. ~Image()
  30. {
  31. delete []_pixel;
  32. }
  33. void setWrapType(int type)
  34. {
  35. _wrapType = type;
  36. }
  37. int width() const
  38. {
  39. return _width;
  40. }
  41. int height() const
  42. {
  43. return _height;
  44. }
  45. Rgba pixelAt(int x,int y) const
  46. {
  47. return Rgba(_pixel[y * _width + x]);
  48. }
  49. Rgba pixelUV(float u,float v)
  50. {
  51. float x = u * _width;
  52. float y = v * _height;
  53. if (_wrapType == 0)
  54. {
  55. return pixelAt((unsigned)(x)%_width,(unsigned)(y)%_height);
  56. }
  57. else
  58. {
  59. if (x >= _width)
  60. {
  61. x = _width - 1;
  62. }
  63. if (y >= _height)
  64. {
  65. y = _height - 1;
  66. }
  67. return pixelAt(x,y);
  68. }
  69. }
  70. public:
  71. static Image* loadFromFile(const char*);
  72. };
  73. }