Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/main.c b/src/main.c
- index 32a0f47..72ebd3b 100644
- --- a/src/main.c
- +++ b/src/main.c
- @@ -55,12 +55,12 @@ int main(int argc, char *argv[])
- finish = clock();
- printf("rgb2yuv_tables64: %.3f sec\n", (float) (finish - start) / CLOCKS_PER_SEC);
- -#ifdef PRINT_PIXELS
- - for (i = 0; i < 4 * PIXELS_COUNT; i++)
- +
- + for (i = 0; i < 27; i++)
- {
- printf("%d: %d %d %d %d\n", i, pixels_wiki[i], pixels_novel_ch[i], pixels_tables[i], pixels_tables64[i]);
- }
- -#endif
- +
- return 0;
- }
- diff --git a/src/rgb2yuv_tables64.c b/src/rgb2yuv_tables64.c
- index f30be2d..c49d641 100644
- --- a/src/rgb2yuv_tables64.c
- +++ b/src/rgb2yuv_tables64.c
- @@ -6,15 +6,15 @@
- */
- #include "rgb2yuv.h"
- -
- +#include <stdio.h>
- static int64_t t_r3[256], t_g3[256], t_b3[256];
- void rgb2yuv_tables64_init(void)
- {
- int i, j;
- - int k_r[] = { 66, -38, 112 };
- - int k_g[] = { 129, -74, -94 };
- - int k_b[] = { 25, 112, -18 };
- + int k_r[] = { 47, -26, 112 };
- + int k_g[] = { 157, -87, -102 };
- + int k_b[] = { 16, 112, -10 };
- for (i = 0; i <= 255; i++)
- @@ -36,9 +36,7 @@ void rgb2yuv_tables64(uint8_t *pixels, int count)
- {
- int t;
- uint8_t r, g, b;
- - int64_t c1 = (128LL << 32) + (128 << 16) + 128 +
- - (16LL << 40) + (128LL << 24) + (128 << 8);
- -
- + int64_t c1 = ((uint64_t) 4096 << 32) + (32768 << 16) + (32768);
- for (t = 0; t < count * 4; t += 4)
- {
- r = pixels[t + 1];
- @@ -51,4 +49,4 @@ void rgb2yuv_tables64(uint8_t *pixels, int count)
- pixels[t + 2] = x3 >> 24;
- pixels[t + 3] = x3 >> 8;
- }
- -}
- +}
- diff --git a/src/rgb2yuv_wiki.c b/src/rgb2yuv_wiki.c
- index d1d82f2..b5c406f 100644
- --- a/src/rgb2yuv_wiki.c
- +++ b/src/rgb2yuv_wiki.c
- @@ -6,24 +6,28 @@
- #include "rgb2yuv.h"
- -#define RGB2Y(R, G, B) (0.299 * R + 0.587 * G + 0.114 * B)
- -#define RGB2U(R, G, B) (-0.14713 * R - 0.28886 * G + 0.436 * B + 128)
- -#define RGB2V(R, G, B) (0.615 * R - 0.51499 * G - 0.10001 * B + 128)
- -
- +#define RGB2Y(R, G, B) ( 47 * (R) + 157 * (G) + 16 * (B) + 4096) >> 8
- +#define RGB2U(R, G, B) ( -26 * (R) + -87 * (G) + 112 * (B) + 32768) >> 8
- +#define RGB2V(R, G, B) ( 112 * (R) + -102 * (G) + -10 * (B) + 32768) >> 8
- void rgb2yuv_wiki(uint8_t *pixels, int count)
- {
- - int t;
- - int r, g, b;
- -
- - for (t = 0; t < count * 4; t += 4)
- - {
- - r = pixels[t + 1];
- - g = pixels[t + 2];
- - b = pixels[t + 3];
- - pixels[t + 1] = RGB2Y(r,g,b);
- - pixels[t + 2] = RGB2U(r,g,b);
- - pixels[t + 3] = RGB2V(r,g,b);
- - }
- + int i, t;
- + int y, u, v;
- + int r, g, b;
- + uint8_t *p = pixels;
- + for (i = 0; i < count; i++)
- + {
- + t = i * 4;
- + y = t + 1;
- + u = t + 2;
- + v = t + 3;
- + r = p[y];
- + g = p[u];
- + b = p[v];
- + p[y] = RGB2Y(r,g,b);
- + p[u] = RGB2U(r,g,b);
- + p[v] = RGB2V(r,g,b);
- + }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement