Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. diff --git a/src/main.c b/src/main.c
  2. index 32a0f47..72ebd3b 100644
  3. --- a/src/main.c
  4. +++ b/src/main.c
  5. @@ -55,12 +55,12 @@ int main(int argc, char *argv[])
  6.     finish = clock();
  7.     printf("rgb2yuv_tables64: %.3f sec\n", (float) (finish - start) / CLOCKS_PER_SEC);
  8.  
  9. -#ifdef PRINT_PIXELS
  10. -   for (i = 0; i < 4 * PIXELS_COUNT; i++)
  11. +
  12. +   for (i = 0; i < 27; i++)
  13.     {
  14.         printf("%d: %d %d %d %d\n", i, pixels_wiki[i], pixels_novel_ch[i], pixels_tables[i], pixels_tables64[i]);
  15.     }
  16. -#endif
  17. +
  18.  
  19.     return 0;
  20.  }
  21. diff --git a/src/rgb2yuv_tables64.c b/src/rgb2yuv_tables64.c
  22. index f30be2d..c49d641 100644
  23. --- a/src/rgb2yuv_tables64.c
  24. +++ b/src/rgb2yuv_tables64.c
  25. @@ -6,15 +6,15 @@
  26.   */
  27.  
  28.  #include "rgb2yuv.h"
  29. -
  30. +#include <stdio.h>
  31.  static int64_t t_r3[256], t_g3[256], t_b3[256];
  32.  
  33.  void rgb2yuv_tables64_init(void)
  34.  {
  35.     int i, j;
  36. -   int k_r[] = {  66, -38, 112 };
  37. -   int k_g[] = { 129, -74, -94 };
  38. -   int k_b[] = {  25, 112, -18 };
  39. +   int k_r[] = {  47, -26, 112 };
  40. +   int k_g[] = { 157, -87, -102 };
  41. +   int k_b[] = {  16, 112, -10 };
  42.  
  43.  
  44.     for (i = 0; i <= 255; i++)
  45. @@ -36,9 +36,7 @@ void rgb2yuv_tables64(uint8_t *pixels, int count)
  46.  {
  47.     int t;
  48.     uint8_t r, g, b;
  49. -   int64_t c1 = (128LL << 32) + (128 << 16) + 128 +
  50. -           (16LL << 40) + (128LL << 24) + (128 << 8);
  51. -
  52. +   int64_t c1 = ((uint64_t) 4096 << 32) + (32768 << 16) + (32768);
  53.     for (t = 0; t < count * 4; t += 4)
  54.     {
  55.         r = pixels[t + 1];
  56. @@ -51,4 +49,4 @@ void rgb2yuv_tables64(uint8_t *pixels, int count)
  57.         pixels[t + 2] = x3 >> 24;
  58.         pixels[t + 3] = x3 >> 8;
  59.     }
  60. -}
  61. +}
  62. diff --git a/src/rgb2yuv_wiki.c b/src/rgb2yuv_wiki.c
  63. index d1d82f2..b5c406f 100644
  64. --- a/src/rgb2yuv_wiki.c
  65. +++ b/src/rgb2yuv_wiki.c
  66. @@ -6,24 +6,28 @@
  67.  
  68.  #include "rgb2yuv.h"
  69.  
  70. -#define RGB2Y(R, G, B) (0.299 * R + 0.587 * G + 0.114 * B)
  71. -#define RGB2U(R, G, B) (-0.14713 * R - 0.28886 * G + 0.436 * B + 128)
  72. -#define RGB2V(R, G, B) (0.615 * R - 0.51499 * G - 0.10001 * B + 128)
  73. -
  74. +#define RGB2Y(R, G, B) (  47 * (R) + 157 * (G) +  16 * (B) + 4096) >> 8
  75. +#define RGB2U(R, G, B) ( -26 * (R) +  -87 * (G) + 112 * (B) + 32768) >> 8
  76. +#define RGB2V(R, G, B) ( 112 * (R) +  -102 * (G) +  -10 * (B) + 32768) >> 8
  77.  void rgb2yuv_wiki(uint8_t *pixels, int count)
  78.  {
  79. -   int t;
  80. -   int r, g, b;
  81. -
  82. -   for (t = 0; t < count * 4; t += 4)
  83. -   {
  84. -       r = pixels[t + 1];
  85. -       g = pixels[t + 2];
  86. -       b = pixels[t + 3];
  87. -       pixels[t + 1] = RGB2Y(r,g,b);
  88. -       pixels[t + 2] = RGB2U(r,g,b);
  89. -       pixels[t + 3] = RGB2V(r,g,b);
  90. -   }
  91. +        int i, t;
  92. +        int y, u, v;
  93. +        int r, g, b;
  94. +        uint8_t *p = pixels;
  95.  
  96. +        for (i = 0; i < count; i++)
  97. +        {
  98. +                t = i * 4;
  99. +                y = t + 1;
  100. +                u = t + 2;
  101. +                v = t + 3;
  102. +                r = p[y];
  103. +                g = p[u];
  104. +                b = p[v];
  105. +                p[y] = RGB2Y(r,g,b);
  106. +                p[u] = RGB2U(r,g,b);
  107. +                p[v] = RGB2V(r,g,b);
  108. +        }
  109.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement