extractedLnx/linux-2.6.38/drivers/staging/easycap/easycap_main.c_redaub.c
int
redaub(struct easycap *peasycap, void *pad, void *pex, int much, int more, \
__u8 mask, __u8 margin, bool isuy)
{
static __s32 ay[256], bu[256], rv[256], gu[256], gv[256];
__u8 *pcache;
__u8 r, g, b, y, u, v, c, *p2, *p3, *pz, *pr;
int bytesperpixel;
bool byteswaporder, decimatepixel, last;
int j, rump;
__s32 s32;
if (much % 2) {
SAM("MISTAKE: much is odd\n");
return -EFAULT;
}
bytesperpixel = peasycap->bytesperpixel;
byteswaporder = peasycap->byteswaporder;
decimatepixel = peasycap->decimatepixel;
/*---------------------------------------------------------------------------*/
if (!bu[255]) {
for (j = 0; j < 112; j++) {
s32 = (0xFF00 & (453 * j)) >> 8;
bu[j + 128] = s32; bu[127 - j] = -s32;
s32 = (0xFF00 & (359 * j)) >> 8;
rv[j + 128] = s32; rv[127 - j] = -s32;
s32 = (0xFF00 & (88 * j)) >> 8;
gu[j + 128] = s32; gu[127 - j] = -s32;
s32 = (0xFF00 & (183 * j)) >> 8;
gv[j + 128] = s32; gv[127 - j] = -s32;
}
for (j = 0; j < 16; j++) {
bu[j] = bu[16]; rv[j] = rv[16];
gu[j] = gu[16]; gv[j] = gv[16];
}
for (j = 240; j < 256; j++) {
bu[j] = bu[239]; rv[j] = rv[239];
gu[j] = gu[239]; gv[j] = gv[239];
}
for (j = 16; j < 236; j++)
ay[j] = j;
for (j = 0; j < 16; j++)
ay[j] = ay[16];
for (j = 236; j < 256; j++)
ay[j] = ay[235];
JOM(8, "lookup tables are prepared\n");
}
pcache = peasycap->pcache;
if (NULL == pcache)
pcache = &peasycap->cache[0];
/*---------------------------------------------------------------------------*/
/*
* TRANSFER CONTENTS OF CACHE TO THE FRAME BUFFER
*/
/*---------------------------------------------------------------------------*/
if (!pcache) {
SAM("MISTAKE: pcache is NULL\n");
return -EFAULT;
}
if (pcache != &peasycap->cache[0])
JOM(16, "cache has %i bytes\n", (int)(pcache - &peasycap->cache[0]));
p2 = &peasycap->cache[0];
p3 = (__u8 *)pad - (int)(pcache - &peasycap->cache[0]);
while (p2 < pcache) {
*p3++ = *p2; p2++;
}
pcache = &peasycap->cache[0];
if (p3 != pad) {
SAM("MISTAKE: pointer misalignment\n");
return -EFAULT;
}
/*---------------------------------------------------------------------------*/
rump = (int)(0x03 & mask);
u = 0; v = 0;
p2 = (__u8 *)pex; pz = p2 + much; pr = p3 + more; last = false;
p2++;
if (true == isuy)
u = *(p2 - 1);
else
v = *(p2 - 1);
if (rump)
JOM(16, "%4i=much %4i=more %i=rump\n", much, more, rump);
/*---------------------------------------------------------------------------*/
switch (bytesperpixel) {
case 2: {
if (false == decimatepixel) {
memcpy(pad, pex, (size_t)much);
if (false == byteswaporder)
/*---------------------------------------------------*/
/*
** UYVY
*/
/*---------------------------------------------------*/
return 0;
else {
/*---------------------------------------------------*/
/*
** YUYV
*/
/*---------------------------------------------------*/
p3 = (__u8 *)pad; pz = p3 + much;
while (pz > p3) {
c = *p3;
*p3 = *(p3 + 1);
*(p3 + 1) = c;
p3 += 2;
}
return 0;
}
} else {
if (false == byteswaporder) {
/*---------------------------------------------------*/
/*
** UYVY DECIMATED
*/
/*---------------------------------------------------*/
p2 = (__u8 *)pex; p3 = (__u8 *)pad; pz = p2 + much;
while (pz > p2) {
*p3 = *p2;
*(p3 + 1) = *(p2 + 1);
*(p3 + 2) = *(p2 + 2);
*(p3 + 3) = *(p2 + 3);
p3 += 4; p2 += 8;
}
return 0;
} else {
/*---------------------------------------------------*/
/*
** YUYV DECIMATED
**/
/*---------------------------------------------------*/
p2 = (__u8 *)pex; p3 = (__u8 *)pad; pz = p2 + much;
while (pz > p2) {
*p3 = *(p2 + 1);
*(p3 + 1) = *p2;
*(p3 + 2) = *(p2 + 3);
*(p3 + 3) = *(p2 + 2);
p3 += 4; p2 += 8;
}
return 0;
}
}
break;
}
case 3:
{
if (false == decimatepixel) {
if (false == byteswaporder) {
/*---------------------------------------------------*/
/*
** RGB
**/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = r;
*pcache++ = g;
*pcache++ = b;
break;
}
case 2: {
*p3 = r;
*(p3 + 1) = g;
*pcache++ = b;
break;
}
default: {
SAM("MISTAKE: %i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = r;
*(p3 + 1) = g;
*(p3 + 2) = b;
}
p2 += 2;
if (true == isuy)
isuy = false;
else
isuy = true;
p3 += bytesperpixel;
}
return 0;
} else {
/*---------------------------------------------------*/
/*
** BGR
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
}
else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = b;
*pcache++ = g;
*pcache++ = r;
break;
}
case 2: {
*p3 = b;
*(p3 + 1) = g;
*pcache++ = r;
break;
}
default: {
SAM("MISTAKE: %i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = b;
*(p3 + 1) = g;
*(p3 + 2) = r;
}
p2 += 2;
if (true == isuy)
isuy = false;
else
isuy = true;
p3 += bytesperpixel;
}
}
return 0;
} else {
if (false == byteswaporder) {
/*---------------------------------------------------*/
/*
** RGB DECIMATED
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
if (true == isuy) {
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - \
gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = r;
*pcache++ = g;
*pcache++ = b;
break;
}
case 2: {
*p3 = r;
*(p3 + 1) = g;
*pcache++ = b;
break;
}
default: {
SAM("MISTAKE: " \
"%i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = r;
*(p3 + 1) = g;
*(p3 + 2) = b;
}
isuy = false;
p3 += bytesperpixel;
} else {
isuy = true;
}
p2 += 2;
}
return 0;
} else {
/*---------------------------------------------------*/
/*
* BGR DECIMATED
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
if (true == isuy) {
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - \
gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = b;
*pcache++ = g;
*pcache++ = r;
break;
}
case 2: {
*p3 = b;
*(p3 + 1) = g;
*pcache++ = r;
break;
}
default: {
SAM("MISTAKE: " \
"%i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = b;
*(p3 + 1) = g;
*(p3 + 2) = r;
}
isuy = false;
p3 += bytesperpixel;
}
else
isuy = true;
p2 += 2;
}
return 0;
}
}
break;
}
case 4:
{
if (false == decimatepixel) {
if (false == byteswaporder) {
/*---------------------------------------------------*/
/*
** RGBA
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = r;
*pcache++ = g;
*pcache++ = b;
*pcache++ = 0;
break;
}
case 2: {
*p3 = r;
*(p3 + 1) = g;
*pcache++ = b;
*pcache++ = 0;
break;
}
case 3: {
*p3 = r;
*(p3 + 1) = g;
*(p3 + 2) = b;
*pcache++ = 0;
break;
}
default: {
SAM("MISTAKE: %i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = r;
*(p3 + 1) = g;
*(p3 + 2) = b;
*(p3 + 3) = 0;
}
p2 += 2;
if (true == isuy)
isuy = false;
else
isuy = true;
p3 += bytesperpixel;
}
return 0;
} else {
/*---------------------------------------------------*/
/*
** BGRA
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = b;
*pcache++ = g;
*pcache++ = r;
*pcache++ = 0;
break;
}
case 2: {
*p3 = b;
*(p3 + 1) = g;
*pcache++ = r;
*pcache++ = 0;
break;
}
case 3: {
*p3 = b;
*(p3 + 1) = g;
*(p3 + 2) = r;
*pcache++ = 0;
break;
}
default: {
SAM("MISTAKE: %i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = b;
*(p3 + 1) = g;
*(p3 + 2) = r;
*(p3 + 3) = 0;
}
p2 += 2;
if (true == isuy)
isuy = false;
else
isuy = true;
p3 += bytesperpixel;
}
}
return 0;
} else {
if (false == byteswaporder) {
/*---------------------------------------------------*/
/*
** RGBA DECIMATED
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
if (true == isuy) {
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - \
gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = r;
*pcache++ = g;
*pcache++ = b;
*pcache++ = 0;
break;
}
case 2: {
*p3 = r;
*(p3 + 1) = g;
*pcache++ = b;
*pcache++ = 0;
break;
}
case 3: {
*p3 = r;
*(p3 + 1) = g;
*(p3 + 2) = b;
*pcache++ = 0;
break;
}
default: {
SAM("MISTAKE: " \
"%i=rump\n", \
bytesperpixel - \
rump);
return -EFAULT;
}
}
} else {
*p3 = r;
*(p3 + 1) = g;
*(p3 + 2) = b;
*(p3 + 3) = 0;
}
isuy = false;
p3 += bytesperpixel;
} else
isuy = true;
p2 += 2;
}
return 0;
} else {
/*---------------------------------------------------*/
/*
** BGRA DECIMATED
*/
/*---------------------------------------------------*/
while (pz > p2) {
if (pr <= (p3 + bytesperpixel))
last = true;
else
last = false;
y = *p2;
if ((true == last) && (0x0C & mask)) {
if (0x04 & mask) {
if (true == isuy)
v = margin;
else
u = margin;
} else
if (0x08 & mask)
;
} else {
if (true == isuy)
v = *(p2 + 1);
else
u = *(p2 + 1);
}
if (true == isuy) {
s32 = ay[(int)y] + rv[(int)v];
r = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] - gu[(int)u] - \
gv[(int)v];
g = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
s32 = ay[(int)y] + bu[(int)u];
b = (255 < s32) ? 255 : ((0 > s32) ? \
0 : (__u8)s32);
if ((true == last) && rump) {
pcache = &peasycap->cache[0];
switch (bytesperpixel - rump) {
case 1: {
*p3 = b;
*pcache++ = g;
*pcache++ = r;
*pcache++ = 0;
break;
}
case 2: {
*p3 = b;
*(p3 + 1) = g;
*pcache++ = r;
*pcache++ = 0;
break;
}
case 3: {
*p3 = b;
*(p3 + 1) = g;
*(p3 + 2) = r;
*pcache++ = 0;
break;
}
default: {
SAM("MISTAKE: " \
"%i=rump\n", \
bytesperpixel - rump);
return -EFAULT;
}
}
} else {
*p3 = b;
*(p3 + 1) = g;
*(p3 + 2) = r;
*(p3 + 3) = 0;
}
isuy = false;
p3 += bytesperpixel;
} else
isuy = true;
p2 += 2;
}
return 0;
}
}
break;
}
default: {
SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel);
return -EFAULT;
}
}
return 0;
}
Generated by GNU enscript 1.6.4.