Using weighted averaging for subsampling 2x2 -> 1x1

git-svn-id: svn://code.dyne.org/veejay/trunk@6 eb8d1916-c9e9-0310-b8de-cf0c9472ead5
This commit is contained in:
Niels Elburg
2004-07-31 11:37:30 +00:00
parent c25c06558b
commit ba5793d378

View File

@@ -95,26 +95,58 @@ static void ss_444_to_420jpeg(uint8_t *buffer, int width, int height)
} }
} }
*/ */
/*
using weighted averaging for subsampling 2x2 -> 1x1
here, 4 pixels are filled in each inner loop, (weighting
16 source pixels)
*/
static void ss_444_to_420jpeg(uint8_t *buffer, int width, int height) static void ss_444_to_420jpeg(uint8_t *buffer, int width, int height)
{ {
uint8_t *in0, *in1, *out; const uint8_t *in0, *in1;
int x, y; uint8_t *out;
int x, y = height;
in0 = buffer; in0 = buffer;
in1 = buffer + width; in1 = buffer + width;
out = buffer; out = buffer;
for (y = 0; y < height; y += 2) {
for (x = 0; x < width; x += 2) {
*out = (in0[0] + 3 * (in0[1] + in1[0]) + (9 * in1[1]) + 8) >> 4;
in0 += 2;
in1 += 2;
out++;
}
in0 += width;
in1 += width;
}
}
// for (y = 0; y < height; y += 2) {
// for (x = 0; x < width; x += 2) {
// *out = (in0[0] + 3 * (in0[1] + in1[0]) + (9 * in1[1]) + 8) >> 4;
// in0 += 2;
// in1 += 2;
// out++;
// }
// in0 += width;
// in1 += width;
// }
for(; y > 0; y -- )
{
in0 = buffer;
in1 = buffer + width;
out = buffer;
for( x = width; x >= 4; x -= 4 )
{
out[0] = ( in0[0] + 3 * ( in0[1] + in1[0] ) + (9 * in1[1]) + 8) >> 4;
out[1] = ( in0[2] + 3 * ( in0[3] + in1[2] ) + (9 * in1[3]) + 8) >> 4;
out[2] = ( in0[4] + 3 * ( in0[5] + in1[4] ) + (9 * in1[5]) + 8) >> 4;
out[3] = ( in0[6] + 3 * ( in0[7] + in1[6] ) + (9 * in1[7]) + 8) >> 4;
in0 += 8;
in1 += 8;
out += 4;
}
for(; x > 0; x -- )
{
out[0] = ( in0[0] + 3 * ( in0[1] + in1[0] ) + (9 * in1[1] ) + 8) >> 4;
in0 += 2;
in1 += 2;
out ++;
}
buffer += (width << 1);
out += width;
}
}
/* vertical/horizontal interstitial siting /* vertical/horizontal interstitial siting