Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 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 | |
| 11 | #ifndef _FBCON_ROTATE_H |
| 12 | #define _FBCON_ROTATE_H |
| 13 | |
| 14 | #define FNTCHARCNT(fd) (((int *)(fd))[-3]) |
| 15 | |
| 16 | #define GETVYRES(s,i) ({ \ |
| 17 | (s == SCROLL_REDRAW || s == SCROLL_MOVE) ? \ |
| 18 | (i)->var.yres : (i)->var.yres_virtual; }) |
| 19 | |
| 20 | #define GETVXRES(s,i) ({ \ |
| 21 | (s == SCROLL_REDRAW || s == SCROLL_MOVE || !(i)->fix.xpanstep) ? \ |
| 22 | (i)->var.xres : (i)->var.xres_virtual; }) |
| 23 | |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 24 | |
| 25 | static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pat) |
| 26 | { |
| 27 | u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8; |
| 28 | |
| 29 | pat +=index; |
Benjamin Herrenschmidt | 1a9c3f7 | 2005-11-28 13:43:52 -0800 | [diff] [blame^] | 30 | return (*pat) & (0x80 >> bit); |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 31 | } |
| 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 | |
| 37 | pat += index; |
Benjamin Herrenschmidt | 1a9c3f7 | 2005-11-28 13:43:52 -0800 | [diff] [blame^] | 38 | |
| 39 | (*pat) |= 0x80 >> bit; |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static inline void rotate_ud(const char *in, char *out, u32 width, u32 height) |
| 43 | { |
| 44 | int i, j; |
Antonino A. Daplas | b4627de | 2005-11-21 21:32:25 -0800 | [diff] [blame] | 45 | int shift = (8 - (width % 8)) & 7; |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 46 | |
| 47 | width = (width + 7) & ~7; |
| 48 | |
| 49 | for (i = 0; i < height; i++) { |
| 50 | for (j = 0; j < width; j++) { |
| 51 | if (pattern_test_bit(j, i, width, in)) |
| 52 | pattern_set_bit(width - (1 + j + shift), |
| 53 | height - (1 + i), |
| 54 | width, out); |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | static inline void rotate_cw(const char *in, char *out, u32 width, u32 height) |
| 61 | { |
| 62 | int i, j, h = height, w = width; |
| 63 | int shift = (8 - (height % 8)) & 7; |
| 64 | |
| 65 | width = (width + 7) & ~7; |
| 66 | height = (height + 7) & ~7; |
| 67 | |
| 68 | for (i = 0; i < h; i++) { |
| 69 | for (j = 0; j < w; j++) { |
| 70 | if (pattern_test_bit(j, i, width, in)) |
| 71 | pattern_set_bit(height - 1 - i - shift, j, |
| 72 | height, out); |
| 73 | |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | static inline void rotate_ccw(const char *in, char *out, u32 width, u32 height) |
| 79 | { |
| 80 | int i, j, h = height, w = width; |
Antonino A. Daplas | b4627de | 2005-11-21 21:32:25 -0800 | [diff] [blame] | 81 | int shift = (8 - (width % 8)) & 7; |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 82 | |
| 83 | width = (width + 7) & ~7; |
| 84 | height = (height + 7) & ~7; |
| 85 | |
| 86 | for (i = 0; i < h; i++) { |
| 87 | for (j = 0; j < w; j++) { |
| 88 | if (pattern_test_bit(j, i, width, in)) |
| 89 | pattern_set_bit(i, width - 1 - j - shift, |
| 90 | height, out); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 95 | extern void fbcon_rotate_cw(struct fbcon_ops *ops); |
Antonino A. Daplas | 33ee829 | 2005-11-08 21:39:13 -0800 | [diff] [blame] | 96 | extern void fbcon_rotate_ud(struct fbcon_ops *ops); |
Antonino A. Daplas | ed8c0e9 | 2005-11-08 21:39:14 -0800 | [diff] [blame] | 97 | extern void fbcon_rotate_ccw(struct fbcon_ops *ops); |
Antonino A. Daplas | 6cc50e1 | 2005-11-08 21:39:11 -0800 | [diff] [blame] | 98 | #endif |