2 * Fast C2P (Chunky-to-Planar) Conversion
4 * Copyright (C) 2003 Geert Uytterhoeven
7 * - This code was inspired by Scout's C2P tutorial
8 * - It assumes to run on a big endian system
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive
15 #include <linux/module.h>
16 #include <linux/string.h>
21 * Basic transpose step
24 #define _transp(d, i1, i2, shift, mask) \
26 u32 t = (d[i1] ^ (d[i2] >> shift)) & mask; \
28 d[i2] ^= t << shift; \
31 static inline u32
get_mask(int n
)
57 #define transp_nx1(d, n) \
59 u32 mask = get_mask(n); \
61 _transp(d, 0, 1, n, mask); \
63 _transp(d, 2, 3, n, mask); \
65 _transp(d, 4, 5, n, mask); \
67 _transp(d, 6, 7, n, mask); \
70 #define transp_nx2(d, n) \
72 u32 mask = get_mask(n); \
74 _transp(d, 0, 2, n, mask); \
75 _transp(d, 1, 3, n, mask); \
77 _transp(d, 4, 6, n, mask); \
78 _transp(d, 5, 7, n, mask); \
81 #define transp_nx4(d, n) \
83 u32 mask = get_mask(n); \
84 _transp(d, 0, 4, n, mask); \
85 _transp(d, 1, 5, n, mask); \
86 _transp(d, 2, 6, n, mask); \
87 _transp(d, 3, 7, n, mask); \
90 #define transp(d, n, m) transp_nx ## m(d, n)
94 * Perform a full C2P step on 32 8-bit pixels, stored in 8 32-bit words
96 * - 32 8-bit chunky pixels on input
97 * - permuted planar data on output
100 static void c2p_8bpp(u32 d
[8])
111 * Array containing the permution indices of the planar data after c2p
114 static const int perm_c2p_8bpp
[8] = { 7, 5, 3, 1, 6, 4, 2, 0 };
118 * Compose two values, using a bitmask as decision value
119 * This is equivalent to (a & mask) | (b & ~mask)
122 static inline unsigned long comp(unsigned long a
, unsigned long b
,
125 return ((a
^ b
) & mask
) ^ b
;
130 * Store a full block of planar data after c2p conversion
133 static inline void store_planar(char *dst
, u32 dst_inc
, u32 bpp
, u32 d
[8])
137 for (i
= 0; i
< bpp
; i
++, dst
+= dst_inc
)
138 *(u32
*)dst
= d
[perm_c2p_8bpp
[i
]];
143 * Store a partial block of planar data after c2p conversion
146 static inline void store_planar_masked(char *dst
, u32 dst_inc
, u32 bpp
,
151 for (i
= 0; i
< bpp
; i
++, dst
+= dst_inc
)
152 *(u32
*)dst
= comp(d
[perm_c2p_8bpp
[i
]], *(u32
*)dst
, mask
);
157 * c2p - Copy 8-bit chunky image data to a planar frame buffer
158 * @dst: Starting address of the planar frame buffer
159 * @dx: Horizontal destination offset (in pixels)
160 * @dy: Vertical destination offset (in pixels)
161 * @width: Image width (in pixels)
162 * @height: Image height (in pixels)
163 * @dst_nextline: Frame buffer offset to the next line (in bytes)
164 * @dst_nextplane: Frame buffer offset to the next plane (in bytes)
165 * @src_nextline: Image offset to the next line (in bytes)
166 * @bpp: Bits per pixel of the planar frame buffer (1-8)
169 void c2p(u8
*dst
, const u8
*src
, u32 dx
, u32 dy
, u32 width
, u32 height
,
170 u32 dst_nextline
, u32 dst_nextplane
, u32 src_nextline
, u32 bpp
)
173 u32 d
[8], first
, last
, w
;
177 dst
+= dy
*dst_nextline
+(dx
& ~31);
179 first
= ~0UL >> dst_idx
;
180 last
= ~(~0UL >> ((dst_idx
+width
) % 32));
185 if (dst_idx
+width
<= 32) {
186 /* Single destination word */
188 memset(d
, 0, sizeof(d
));
189 memcpy((u8
*)d
+dst_idx
, c
, width
);
192 store_planar_masked(p
, dst_nextplane
, bpp
, d
, first
);
195 /* Multiple destination words */
200 memset(d
, 0, dst_idx
);
201 memcpy((u8
*)d
+dst_idx
, c
, w
);
204 store_planar_masked(p
, dst_nextplane
, bpp
, d
, first
);
213 store_planar(p
, dst_nextplane
, bpp
, d
);
221 memset((u8
*)d
+w
, 0, 32-w
);
223 store_planar_masked(p
, dst_nextplane
, bpp
, d
, last
);
230 EXPORT_SYMBOL_GPL(c2p
);
232 MODULE_LICENSE("GPL");
This page took 0.035419 seconds and 5 git commands to generate.