image.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SLiM - Simple Login Manager
  2. Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
  3. Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
  4. Copyright (C) 2012 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. The following code has been adapted and extended from
  10. xplanet 1.0.1, Copyright (C) 2002-04 Hari Nair <hari@alumni.caltech.edu>
  11. */
  12. #ifndef _IMAGE_H_
  13. #define _IMAGE_H_
  14. #include <X11/Xlib.h>
  15. #include <X11/Xmu/WinUtil.h>
  16. #include "log.h"
  17. class Image {
  18. public:
  19. Image();
  20. Image(const int w, const int h, const unsigned char *rgb,
  21. const unsigned char *alpha);
  22. ~Image();
  23. const unsigned char * getPNGAlpha() const {
  24. return(png_alpha);
  25. };
  26. const unsigned char * getRGBData() const {
  27. return(rgb_data);
  28. };
  29. void getPixel(double px, double py, unsigned char *pixel);
  30. void getPixel(double px, double py, unsigned char *pixel,
  31. unsigned char *alpha);
  32. int Width() const {
  33. return(width);
  34. };
  35. int Height() const {
  36. return(height);
  37. };
  38. void Quality(const int q) {
  39. quality_ = q;
  40. };
  41. bool Read(const char *filename);
  42. void Reduce(const int factor);
  43. void Resize(const int w, const int h);
  44. void Merge(Image* background, const int x, const int y);
  45. void Crop(const int x, const int y, const int w, const int h);
  46. void Tile(const int w, const int h);
  47. void Center(const int w, const int h, const char *hex);
  48. void Plain(const int w, const int h, const char *hex);
  49. void computeShift(unsigned long mask, unsigned char &left_shift,
  50. unsigned char &right_shift);
  51. Pixmap createPixmap(Display* dpy, int scr, Window win);
  52. private:
  53. int width, height, area;
  54. unsigned char *rgb_data;
  55. unsigned char *png_alpha;
  56. int quality_;
  57. int readJpeg(const char *filename, int *width, int *height,
  58. unsigned char **rgb);
  59. int readPng(const char *filename, int *width, int *height,
  60. unsigned char **rgb, unsigned char **alpha);
  61. };
  62. #endif /* _IMAGE_H_ */