File Index
Files and directories
Sign in
FILE

c2p_iplan2.c

File preview with syntax highlighting.

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