Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Fast C2P (Chunky-to-Planar) Conversion | |
3 | * | |
1f034456 | 4 | * Copyright (C) 2003-2008 Geert Uytterhoeven |
1da177e4 | 5 | * |
1da177e4 LT |
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 | ||
8b54b613 | 11 | #include <linux/module.h> |
1da177e4 | 12 | #include <linux/string.h> |
1f034456 GU |
13 | |
14 | #include <asm/unaligned.h> | |
15 | ||
1da177e4 | 16 | #include "c2p.h" |
2cd1de0a | 17 | #include "c2p_core.h" |
1da177e4 LT |
18 | |
19 | ||
20 | /* | |
21 | * Perform a full C2P step on 32 8-bit pixels, stored in 8 32-bit words | |
22 | * containing | |
23 | * - 32 8-bit chunky pixels on input | |
1f034456 | 24 | * - permutated planar data (1 plane per 32-bit word) on output |
1da177e4 LT |
25 | */ |
26 | ||
1f034456 | 27 | static void c2p_32x8(u32 d[8]) |
1da177e4 | 28 | { |
1f034456 GU |
29 | transp8(d, 16, 4); |
30 | transp8(d, 8, 2); | |
31 | transp8(d, 4, 1); | |
32 | transp8(d, 2, 4); | |
33 | transp8(d, 1, 2); | |
1da177e4 LT |
34 | } |
35 | ||
36 | ||
37 | /* | |
1f034456 | 38 | * Array containing the permutation indices of the planar data after c2p |
1da177e4 LT |
39 | */ |
40 | ||
1f034456 | 41 | static const int perm_c2p_32x8[8] = { 7, 5, 3, 1, 6, 4, 2, 0 }; |
1da177e4 LT |
42 | |
43 | ||
1da177e4 LT |
44 | /* |
45 | * Store a full block of planar data after c2p conversion | |
46 | */ | |
47 | ||
1f034456 | 48 | static inline void store_planar(void *dst, u32 dst_inc, u32 bpp, u32 d[8]) |
1da177e4 | 49 | { |
8280eb8a | 50 | int i; |
1da177e4 | 51 | |
8280eb8a | 52 | for (i = 0; i < bpp; i++, dst += dst_inc) |
1f034456 | 53 | put_unaligned_be32(d[perm_c2p_32x8[i]], dst); |
1da177e4 LT |
54 | } |
55 | ||
56 | ||
57 | /* | |
58 | * Store a partial block of planar data after c2p conversion | |
59 | */ | |
60 | ||
1f034456 | 61 | static inline void store_planar_masked(void *dst, u32 dst_inc, u32 bpp, |
1da177e4 LT |
62 | u32 d[8], u32 mask) |
63 | { | |
8280eb8a | 64 | int i; |
1da177e4 | 65 | |
8280eb8a | 66 | for (i = 0; i < bpp; i++, dst += dst_inc) |
1f034456 GU |
67 | put_unaligned_be32(comp(d[perm_c2p_32x8[i]], |
68 | get_unaligned_be32(dst), mask), | |
69 | dst); | |
1da177e4 LT |
70 | } |
71 | ||
72 | ||
73 | /* | |
74 | * c2p - Copy 8-bit chunky image data to a planar frame buffer | |
75 | * @dst: Starting address of the planar frame buffer | |
76 | * @dx: Horizontal destination offset (in pixels) | |
77 | * @dy: Vertical destination offset (in pixels) | |
78 | * @width: Image width (in pixels) | |
79 | * @height: Image height (in pixels) | |
80 | * @dst_nextline: Frame buffer offset to the next line (in bytes) | |
81 | * @dst_nextplane: Frame buffer offset to the next plane (in bytes) | |
82 | * @src_nextline: Image offset to the next line (in bytes) | |
83 | * @bpp: Bits per pixel of the planar frame buffer (1-8) | |
84 | */ | |
85 | ||
1f034456 | 86 | void c2p(void *dst, const void *src, u32 dx, u32 dy, u32 width, u32 height, |
1da177e4 LT |
87 | u32 dst_nextline, u32 dst_nextplane, u32 src_nextline, u32 bpp) |
88 | { | |
1f034456 GU |
89 | union { |
90 | u8 pixels[32]; | |
91 | u32 words[8]; | |
92 | } d; | |
93 | u32 dst_idx, first, last, w; | |
8280eb8a | 94 | const u8 *c; |
1f034456 | 95 | void *p; |
8280eb8a GU |
96 | |
97 | dst += dy*dst_nextline+(dx & ~31); | |
98 | dst_idx = dx % 32; | |
1f034456 GU |
99 | first = 0xffffffffU >> dst_idx; |
100 | last = ~(0xffffffffU >> ((dst_idx+width) % 32)); | |
8280eb8a GU |
101 | while (height--) { |
102 | c = src; | |
103 | p = dst; | |
104 | w = width; | |
105 | if (dst_idx+width <= 32) { | |
106 | /* Single destination word */ | |
107 | first &= last; | |
1f034456 GU |
108 | memset(d.pixels, 0, sizeof(d)); |
109 | memcpy(d.pixels+dst_idx, c, width); | |
8280eb8a | 110 | c += width; |
1f034456 GU |
111 | c2p_32x8(d.words); |
112 | store_planar_masked(p, dst_nextplane, bpp, d.words, | |
113 | first); | |
8280eb8a GU |
114 | p += 4; |
115 | } else { | |
116 | /* Multiple destination words */ | |
117 | w = width; | |
118 | /* Leading bits */ | |
119 | if (dst_idx) { | |
120 | w = 32 - dst_idx; | |
1f034456 GU |
121 | memset(d.pixels, 0, dst_idx); |
122 | memcpy(d.pixels+dst_idx, c, w); | |
8280eb8a | 123 | c += w; |
1f034456 GU |
124 | c2p_32x8(d.words); |
125 | store_planar_masked(p, dst_nextplane, bpp, | |
126 | d.words, first); | |
8280eb8a GU |
127 | p += 4; |
128 | w = width-w; | |
129 | } | |
130 | /* Main chunk */ | |
131 | while (w >= 32) { | |
1f034456 | 132 | memcpy(d.pixels, c, 32); |
8280eb8a | 133 | c += 32; |
1f034456 GU |
134 | c2p_32x8(d.words); |
135 | store_planar(p, dst_nextplane, bpp, d.words); | |
8280eb8a GU |
136 | p += 4; |
137 | w -= 32; | |
138 | } | |
139 | /* Trailing bits */ | |
140 | w %= 32; | |
141 | if (w > 0) { | |
1f034456 GU |
142 | memcpy(d.pixels, c, w); |
143 | memset(d.pixels+w, 0, 32-w); | |
144 | c2p_32x8(d.words); | |
145 | store_planar_masked(p, dst_nextplane, bpp, | |
146 | d.words, last); | |
8280eb8a GU |
147 | } |
148 | } | |
149 | src += src_nextline; | |
150 | dst += dst_nextline; | |
1da177e4 | 151 | } |
1da177e4 | 152 | } |
880e5e21 | 153 | EXPORT_SYMBOL_GPL(c2p); |
1da177e4 | 154 | |
8b54b613 | 155 | MODULE_LICENSE("GPL"); |