summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoi Cohen <roico@roico-desktop.(none)>2007-05-24 00:28:40 +0300
committerRoi Cohen <roico@roico-desktop.(none)>2007-05-24 00:28:40 +0300
commit5f9bad4d6640cc58f99a0ece6e16cb68ecca5744 (patch)
tree9139bb9b8089853babb14955fe4f9b89c5f6251d
parent4f0c5227736fe6285416dee1b96f7b3a7753accb (diff)
downloadscreencasting-5f9bad4d6640cc58f99a0ece6e16cb68ecca5744.tar.gz
screencasting-5f9bad4d6640cc58f99a0ece6e16cb68ecca5744.tar.bz2
integer math for rgb -> yuv.
-rw-r--r--plugin/rsc2raw.c66
-rw-r--r--rsc2raw/rsc2raw.c80
2 files changed, 78 insertions, 68 deletions
diff --git a/plugin/rsc2raw.c b/plugin/rsc2raw.c
index 3dae84f..0b022a5 100644
--- a/plugin/rsc2raw.c
+++ b/plugin/rsc2raw.c
@@ -42,47 +42,53 @@ void writeOutputFrame(FILE *output, u_int8_t *data, u_int32_t width, u_int32_t h
for (y = 0; y < height; y++) // Don't forget, our data are bottom-to-top
for(x = 0; x < width; x++)
- { // Magic conversion factors - Wikipedia knows what they mean.
- Ys[(y*width)+x] = (0.257 * data[(y*width*3) + (x*3) + 0]) + // R
- (0.504 * data[(y*width*3) + (x*3) + 1]) + // G
- (0.098 * data[(y*width*3) + (x*3) + 2]) + 16; // B
-
-
+ {
+ int pixel1 = (y*width*3) + (x*3);
+
+ // Magic conversion factors - Wikipedia knows what they mean.
+ Ys[(y*width)+x] = ((66 * data[pixel1 + 0] + // R
+ 129 * data[pixel1 + 1] + // G
+ 25 * data[pixel1 + 2] + 128) >> 8) + 16; // B
if (y % 2 == 0 && x % 2 == 0)
{
- Us[z]=((-(0.148 * data[(y*width*3) + (x*3) + 0]) - // R
- (0.291 * data[(y*width*3) + (x*3) + 1]) + // G
- (0.439 * data[(y*width*3) + (x*3) + 2]) + 128) + // B
+ int pixel2 = (y*width*3) + ((x+1)*3);
+ int pixel3 = ((y+1)*width*3) + (x*3);
+ int pixel4 = ((y+1)*width*3) + ((x+1)*3);
+
+ Us[z] = ((-38 * data[pixel1 + 0] + // R
+ -74 * data[pixel1 + 1] + // G
+ 112 * data[pixel1 + 2] + 128 + // B
+
+ -38 * data[pixel2 + 0] + // R
+ -74 * data[pixel2 + 1] + // G
+ 112 * data[pixel2 + 2] + 128 + // B
- (-(0.148 * data[(y*width*3) + ((x+1)*3) + 0]) - // R
- (0.291 * data[(y*width*3) + ((x+1)*3) + 1]) + // G
- (0.439 * data[(y*width*3) + ((x+1)*3) + 2]) + 128) + // B
+ -38 * data[pixel3 + 0] + // R
+ -74 * data[pixel3 + 1] + // G
+ 112 * data[pixel3 + 2] + 128 + // B
- (-(0.148 * data[((y+1)*width*3) + (x*3) + 0]) - // R
- (0.291 * data[((y+1)*width*3) + (x*3) + 1]) + // G
- (0.439 * data[((y+1)*width*3) + (x*3) + 2]) + 128) + // B
+ -38 * data[pixel4 + 0] + // R
+ -74 * data[pixel4 + 1] + // G
+ 112 * data[pixel4 + 2] + 128) >> 8) / 4 + 128; // B
- (-(0.148 * data[((y+1)*width*3) + ((x+1)*3) + 0]) - // R
- (0.291 * data[((y+1)*width*3) + ((x+1)*3) + 1]) + // G
- (0.439 * data[((y+1)*width*3) + ((x+1)*3) + 2]) + 128)) / 4; // B
+ Us[z] = ((112 * data[pixel1 + 0] + // R
+ -94 * data[pixel1 + 1] + // G
+ -18 * data[pixel1 + 2] + 128 + // B
- Vs[z]=(((0.439 * data[(y*width*3) + (x*3) + 0]) - // R
- (0.368 * data[(y*width*3) + (x*3) + 1]) - // G
- (0.071 * data[(y*width*3) + (x*3) + 2]) + 128) + // B
+ 112 * data[pixel2 + 0] + // R
+ -94 * data[pixel2 + 1] + // G
+ -18 * data[pixel2 + 2] + 128 + // B
- ((0.439 * data[(y*width*3) + ((x+1)*3) + 0]) - // R
- (0.368 * data[(y*width*3) + ((x+1)*3) + 1]) - // G
- (0.071 * data[(y*width*3) + ((x+1)*3) + 2]) + 128) + // B
+ 112 * data[pixel3 + 0] + // R
+ -94 * data[pixel3 + 1] + // G
+ -18 * data[pixel3 + 2] + 128 + // B
- ((0.439 * data[((y+1)*width*3) + (x*3) + 0]) - // R
- (0.368 * data[((y+1)*width*3) + (x*3) + 1]) - // G
- (0.071 * data[((y+1)*width*3) + (x*3) + 2]) + 128) + // B
+ 112 * data[pixel4 + 0] + // R
+ -94 * data[pixel4 + 1] + // G
+ -18 * data[pixel4 + 2] + 128) >> 8) / 4 + 128; // B
- ((0.439 * data[((y+1)*width*3) + ((x+1)*3) + 0]) - // R
- (0.368 * data[((y+1)*width*3) + ((x+1)*3) + 1]) - // G
- (0.071 * data[((y+1)*width*3) + ((x+1)*3) + 2]) + 128)) / 4; // B
z++;
}
}
diff --git a/rsc2raw/rsc2raw.c b/rsc2raw/rsc2raw.c
index 82a52ea..c65ba4e 100644
--- a/rsc2raw/rsc2raw.c
+++ b/rsc2raw/rsc2raw.c
@@ -80,47 +80,51 @@ int writeOutputFrame(FILE *output, u_int8_t *data, u_int32_t width, u_int32_t he
for (y = 0; y < height; y++) // Don't forget, our data are bottom-to-top
for(x = 0; x < width; x++)
- { // Magic conversion factors - Wikipedia knows what they mean.
- Ys[(y*width)+x] = (0.257 * data[(y*width*3) + (x*3) + 0]) + // R
- (0.504 * data[(y*width*3) + (x*3) + 1]) + // G
- (0.098 * data[(y*width*3) + (x*3) + 2]) + 16; // B
-
-
+ { int pixel1 = (y*width*3) + (x*3);
+
+ // Magic conversion factors - Wikipedia knows what they mean.
+ Ys[(y*width)+x] = ((66 * data[pixel1 + 0] + // R
+ 129 * data[pixel1 + 1] + // G
+ 25 * data[pixel1 + 2] + 128) >> 8) + 16; // B
if (y % 2 == 0 && x % 2 == 0)
{
- Us[z]=((-(0.148 * data[(y*width*3) + (x*3) + 0]) - // R
- (0.291 * data[(y*width*3) + (x*3) + 1]) + // G
- (0.439 * data[(y*width*3) + (x*3) + 2]) + 128) + // B
-
- (-(0.148 * data[(y*width*3) + ((x+1)*3) + 0]) - // R
- (0.291 * data[(y*width*3) + ((x+1)*3) + 1]) + // G
- (0.439 * data[(y*width*3) + ((x+1)*3) + 2]) + 128) + // B
-
- (-(0.148 * data[((y+1)*width*3) + (x*3) + 0]) - // R
- (0.291 * data[((y+1)*width*3) + (x*3) + 1]) + // G
- (0.439 * data[((y+1)*width*3) + (x*3) + 2]) + 128) + // B
-
- (-(0.148 * data[((y+1)*width*3) + ((x+1)*3) + 0]) - // R
- (0.291 * data[((y+1)*width*3) + ((x+1)*3) + 1]) + // G
- (0.439 * data[((y+1)*width*3) + ((x+1)*3) + 2]) + 128)) / 4; // B
-
-
- Vs[z]=(((0.439 * data[(y*width*3) + (x*3) + 0]) - // R
- (0.368 * data[(y*width*3) + (x*3) + 1]) - // G
- (0.071 * data[(y*width*3) + (x*3) + 2]) + 128) + // B
-
- ((0.439 * data[(y*width*3) + ((x+1)*3) + 0]) - // R
- (0.368 * data[(y*width*3) + ((x+1)*3) + 1]) - // G
- (0.071 * data[(y*width*3) + ((x+1)*3) + 2]) + 128) + // B
-
- ((0.439 * data[((y+1)*width*3) + (x*3) + 0]) - // R
- (0.368 * data[((y+1)*width*3) + (x*3) + 1]) - // G
- (0.071 * data[((y+1)*width*3) + (x*3) + 2]) + 128) + // B
-
- ((0.439 * data[((y+1)*width*3) + ((x+1)*3) + 0]) - // R
- (0.368 * data[((y+1)*width*3) + ((x+1)*3) + 1]) - // G
- (0.071 * data[((y+1)*width*3) + ((x+1)*3) + 2]) + 128)) / 4; // B
+ int pixel2 = (y*width*3) + ((x+1)*3);
+ int pixel3 = ((y+1)*width*3) + (x*3);
+ int pixel4 = ((y+1)*width*3) + ((x+1)*3);
+
+ Us[z] = ((-38 * data[pixel1 + 0] + // R
+ -74 * data[pixel1 + 1] + // G
+ 112 * data[pixel1 + 2] + 128 + // B
+
+ -38 * data[pixel2 + 0] + // R
+ -74 * data[pixel2 + 1] + // G
+ 112 * data[pixel2 + 2] + 128 + // B
+
+ -38 * data[pixel3 + 0] + // R
+ -74 * data[pixel3 + 1] + // G
+ 112 * data[pixel3 + 2] + 128 + // B
+
+ -38 * data[pixel4 + 0] + // R
+ -74 * data[pixel4 + 1] + // G
+ 112 * data[pixel4 + 2] + 128) >> 8) / 4 + 128; // B
+
+
+ Vs[z] = ((112 * data[pixel1 + 0] + // R
+ -94 * data[pixel1 + 1] + // G
+ -18 * data[pixel1 + 2] + 128 + // B
+
+ 112 * data[pixel2 + 0] + // R
+ -94 * data[pixel2 + 1] + // G
+ -18 * data[pixel2 + 2] + 128 + // B
+
+ 112 * data[pixel3 + 0] + // R
+ -94 * data[pixel3 + 1] + // G
+ -18 * data[pixel3 + 2] + 128 + // B
+
+ 112 * data[pixel4 + 0] + // R
+ -94 * data[pixel4 + 1] + // G
+ -18 * data[pixel4 + 2] + 128) >> 8) / 4 + 128; // B
z++;
}
}