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 static inline int pattern_test_bit(u32 x, u32 y, u32 pitch, const char *pat) 15 { 16 u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8; 17 18 pat +=index; 19 return (*pat) & (0x80 >> bit); 20 } 21 22 static inline void pattern_set_bit(u32 x, u32 y, u32 pitch, char *pat) 23 { 24 u32 tmp = (y * pitch) + x, index = tmp / 8, bit = tmp % 8; 25 26 pat += index; 27 28 (*pat) |= 0x80 >> bit; 29 } 30 31 static inline void rotate_ud(const char *in, char *out, u32 width, u32 height) 32 { 33 int i, j; 34 int shift = (8 - (width % 8)) & 7; 35 36 width = (width + 7) & ~7; 37 38 for (i = 0; i < height; i++) { 39 for (j = 0; j < width - shift; j++) { 40 if (pattern_test_bit(j, i, width, in)) 41 pattern_set_bit(width - (1 + j + shift), 42 height - (1 + i), 43 width, out); 44 } 45 46 } 47 } 48 49 static inline void rotate_cw(const char *in, char *out, u32 width, u32 height) 50 { 51 int i, j, h = height, w = width; 52 int shift = (8 - (height % 8)) & 7; 53 54 width = (width + 7) & ~7; 55 height = (height + 7) & ~7; 56 57 for (i = 0; i < h; i++) { 58 for (j = 0; j < w; j++) { 59 if (pattern_test_bit(j, i, width, in)) 60 pattern_set_bit(height - 1 - i - shift, j, 61 height, out); 62 63 } 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 = (8 - (width % 8)) & 7; 71 72 width = (width + 7) & ~7; 73 height = (height + 7) & ~7; 74 75 for (i = 0; i < h; i++) { 76 for (j = 0; j < w; j++) { 77 if (pattern_test_bit(j, i, width, in)) 78 pattern_set_bit(i, width - 1 - j - shift, 79 height, out); 80 } 81 } 82 } 83 84 extern void fbcon_rotate_cw(struct fbcon_ops *ops); 85 extern void fbcon_rotate_ud(struct fbcon_ops *ops); 86 extern void fbcon_rotate_ccw(struct fbcon_ops *ops); 87 #endif 88