fbcon_rotate.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * linux/drivers/video/console/fbcon_rotate.h -- Software Display Rotation
  3. *
  4. * Copyright (C) 2005 Antonino Daplas <adaplas@pol.net>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #ifndef _FBCON_ROTATE_H
  11. #define _FBCON_ROTATE_H
  12. #define GETVYRES(s,i) ({ \
  13. (s == SCROLL_REDRAW || s == SCROLL_MOVE) ? \
  14. (i)->var.yres : (i)->var.yres_virtual; })
  15. #define GETVXRES(s,i) ({ \
  16. (s == SCROLL_REDRAW || s == SCROLL_MOVE || !(i)->fix.xpanstep) ? \
  17. (i)->var.xres : (i)->var.xres_virtual; })
  18. static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pat)
  19. {
  20. u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8;
  21. pat +=index;
  22. return (*pat) & (0x80 >> bit);
  23. }
  24. static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat)
  25. {
  26. u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8;
  27. pat += index;
  28. (*pat) |= 0x80 >> bit;
  29. }
  30. static inline void rotate_ud(const char *in, char *out, u32 width, u32 height)
  31. {
  32. int i, j;
  33. int shift = (8 - (width % 8)) & 7;
  34. width = (width + 7) & ~7;
  35. for (i = 0; i < height; i++) {
  36. for (j = 0; j < width - shift; j++) {
  37. if (pattern_test_bit(j, i, width, in))
  38. pattern_set_bit(width - (1 + j + shift),
  39. height - (1 + i),
  40. width, out);
  41. }
  42. }
  43. }
  44. static inline void rotate_cw(const char *in, char *out, u32 width, u32 height)
  45. {
  46. int i, j, h = height, w = width;
  47. int shift = (8 - (height % 8)) & 7;
  48. width = (width + 7) & ~7;
  49. height = (height + 7) & ~7;
  50. for (i = 0; i < h; i++) {
  51. for (j = 0; j < w; j++) {
  52. if (pattern_test_bit(j, i, width, in))
  53. pattern_set_bit(height - 1 - i - shift, j,
  54. height, out);
  55. }
  56. }
  57. }
  58. static inline void rotate_ccw(const char *in, char *out, u32 width, u32 height)
  59. {
  60. int i, j, h = height, w = width;
  61. int shift = (8 - (width % 8)) & 7;
  62. width = (width + 7) & ~7;
  63. height = (height + 7) & ~7;
  64. for (i = 0; i < h; i++) {
  65. for (j = 0; j < w; j++) {
  66. if (pattern_test_bit(j, i, width, in))
  67. pattern_set_bit(i, width - 1 - j - shift,
  68. height, out);
  69. }
  70. }
  71. }
  72. extern void fbcon_rotate_cw(struct fbcon_ops *ops);
  73. extern void fbcon_rotate_ud(struct fbcon_ops *ops);
  74. extern void fbcon_rotate_ccw(struct fbcon_ops *ops);
  75. #endif