PolyImage.h 2.1 KB

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