PolyImage.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * PolyImage.h
  3. * TAU
  4. *
  5. * Created by Ivan Safrin on 3/13/08.
  6. * Copyright 2008 Ivan Safrin. All rights reserved.
  7. *
  8. */
  9. // @package BasicTypes
  10. #pragma once
  11. #include "PolyGlobals.h"
  12. #include "png.h"
  13. #include "PolyColor.h"
  14. #include "PolyPerlin.h"
  15. #include <string>
  16. #include <math.h>
  17. #include "OSBasics.h"
  18. using std::string;
  19. namespace Polycode {
  20. class _PolyExport Image {
  21. public:
  22. Image(string fileName);
  23. Image(int width, int height, int type = IMAGE_RGBA);
  24. Image(char *data, int width, int height, int type = IMAGE_RGBA);
  25. Image(Image *copyImage);
  26. Image();
  27. ~Image();
  28. bool loadImage(string fileName);
  29. bool loadPNG(string fileName);
  30. void createEmpty(unsigned int width, unsigned int height);
  31. void fill(float r, float g, float b, float a);
  32. // drawing
  33. void setPixel(int x, int y, float r, float g, float b, float a);
  34. void setPixel(int x, int y, Color col);
  35. Color getPixel(int x, int y);
  36. void setAAPixel(int x, int y, Color col);
  37. void swap(int *v1, int *v2);
  38. void line(int x0, int y0, int x1, int y1, Color col);
  39. void moveTo(int x, int y);
  40. void move(int x, int y);
  41. void lineTo(int x, int y, Color col);
  42. void drawRect(int x, int y, int w, int h, Color col);
  43. // effex
  44. void perlinNoise(int seed, bool alpha);
  45. void fastBlur(int blurSize);
  46. void fastBlurVert(int blurSize);
  47. void fastBlurHor(int blurSize);
  48. void darken(float amt, bool color, bool alpha);
  49. void lighten(float amt, bool color, bool alpha);
  50. void multiply(float amt, bool color, bool alpha);
  51. int getBrushX();
  52. int getBrushY();
  53. bool isLoaded();
  54. int getType() { return imageType; }
  55. void writeBMP(string fileName);
  56. unsigned int getWidth();
  57. unsigned int getHeight();
  58. char *getPixels();
  59. static const int IMAGE_RGB = 0;
  60. static const int IMAGE_RGBA = 1;
  61. protected:
  62. void setPixelType(int type);
  63. int imageType;
  64. int pixelSize;
  65. bool loaded;
  66. Color strokeColor;
  67. int brushPosX;
  68. int brushPosY;
  69. char *imageData;
  70. unsigned int width;
  71. unsigned int height;
  72. };
  73. }