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.

59 lines
1.2 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. public:
  11. Image(int w,int h,void* data)
  12. {
  13. if (w == 0 || h == 0 || data== 0)
  14. {
  15. _width = 0;
  16. _height = 0;
  17. _pixel = 0;
  18. }
  19. else
  20. {
  21. _width = w;
  22. _height = h;
  23. _pixel = new uint[w * h];
  24. memcpy(_pixel,data,w * h * sizeof(uint));
  25. }
  26. }
  27. ~Image()
  28. {
  29. delete []_pixel;
  30. }
  31. int width() const
  32. {
  33. return _width;
  34. }
  35. int height() const
  36. {
  37. return _height;
  38. }
  39. Rgba pixelAt(int x,int y) const
  40. {
  41. return Rgba(_pixel[y * _width + x]);
  42. }
  43. Rgba pixelUV(float u,float v)
  44. {
  45. float x = u * _width;
  46. float y = v * _height;
  47. return pixelAt(x,y);
  48. }
  49. public:
  50. static Image* loadFromFile(const char*);
  51. };
  52. }