image.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 Merge_non_crop(Image* background, const int x, const int y);
  46. void Crop(const int x, const int y, const int w, const int h);
  47. void Tile(const int w, const int h);
  48. void Center(const int w, const int h, const char *hex);
  49. void Plain(const int w, const int h, const char *hex);
  50. void computeShift(unsigned long mask, unsigned char &left_shift,
  51. unsigned char &right_shift);
  52. Pixmap createPixmap(Display *dpy, int scr, Window win);
  53. private:
  54. int width, height, area;
  55. unsigned char *rgb_data;
  56. unsigned char *png_alpha;
  57. int quality_;
  58. int readJpeg(const char *filename, int *width, int *height,
  59. unsigned char **rgb);
  60. int readPng(const char *filename, int *width, int *height,
  61. unsigned char **rgb, unsigned char **alpha);
  62. };
  63. #endif /* _IMAGE_H_ */