fbcon_rotate.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 FNTCHARCNT(fd) (((int *)(fd))[-3])
  13. #define GETVYRES(s,i) ({ \
  14. (s == SCROLL_REDRAW || s == SCROLL_MOVE) ? \
  15. (i)->var.yres : (i)->var.yres_virtual; })
  16. #define GETVXRES(s,i) ({ \
  17. (s == SCROLL_REDRAW || s == SCROLL_MOVE || !(i)->fix.xpanstep) ? \
  18. (i)->var.xres : (i)->var.xres_virtual; })
  19. /*
  20. * The bitmap is always big endian
  21. */
  22. #if defined(__LITTLE_ENDIAN)
  23. #define FBCON_BIT(b) (7 - (b))
  24. #else
  25. #define FBCON_BIT(b) (b)
  26. #endif
  27. static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pat)
  28. {
  29. u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8;
  30. pat +=index;
  31. return (test_bit(FBCON_BIT(bit), (void *)pat));
  32. }
  33. static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat)
  34. {
  35. u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8;
  36. pat += index;
  37. set_bit(FBCON_BIT(bit), (void *)pat);
  38. }
  39. static inline void rotate_ud(const char *in, char *out, u32 width, u32 height)
  40. {
  41. int i, j;
  42. int shift = width % 8;
  43. width = (width + 7) & ~7;
  44. for (i = 0; i < height; i++) {
  45. for (j = 0; j < width; j++) {
  46. if (pattern_test_bit(j, i, width, in))
  47. pattern_set_bit(width - (1 + j + shift),
  48. height - (1 + i),
  49. width, out);
  50. }
  51. }
  52. }
  53. static inline void rotate_cw(const char *in, char *out, u32 width, u32 height)
  54. {
  55. int i, j, h = height, w = width;
  56. int shift = (8 - (height % 8)) & 7;
  57. width = (width + 7) & ~7;
  58. height = (height + 7) & ~7;
  59. for (i = 0; i < h; i++) {
  60. for (j = 0; j < w; j++) {
  61. if (pattern_test_bit(j, i, width, in))
  62. pattern_set_bit(height - 1 - i - shift, j,
  63. height, out);
  64. }
  65. }
  66. }
  67. static inline void rotate_ccw(const char *in, char *out, u32 width, u32 height)
  68. {
  69. int i, j, h = height, w = width;
  70. int shift = width % 8;
  71. width = (width + 7) & ~7;
  72. height = (height + 7) & ~7;
  73. for (i = 0; i < h; i++) {
  74. for (j = 0; j < w; j++) {
  75. if (pattern_test_bit(j, i, width, in))
  76. pattern_set_bit(i, width - 1 - j - shift,
  77. height, out);
  78. }
  79. }
  80. }
  81. extern void fbcon_rotate_cw(struct fbcon_ops *ops);
  82. #endif