00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef AVCODEC_MOTIONPIXELS_TABLEGEN_H
00024 #define AVCODEC_MOTIONPIXELS_TABLEGEN_H
00025 
00026 #include <stdint.h>
00027 
00028 typedef struct YuvPixel {
00029     int8_t y, v, u;
00030 } YuvPixel;
00031 
00032 static int mp_yuv_to_rgb(int y, int v, int u, int clip_rgb) {
00033     const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
00034     int r, g, b;
00035 
00036     r = (1000 * y + 701 * v) / 1000;
00037     g = (1000 * y - 357 * v - 172 * u) / 1000;
00038     b = (1000 * y + 886 * u) / 1000;
00039     if (clip_rgb)
00040         return ((cm[r * 8] & 0xF8) << 7) | ((cm[g * 8] & 0xF8) << 2) | (cm[b * 8] >> 3);
00041     if ((unsigned)r < 32 && (unsigned)g < 32 && (unsigned)b < 32)
00042         return (r << 10) | (g << 5) | b;
00043     return 1 << 15;
00044 }
00045 
00046 #if CONFIG_HARDCODED_TABLES
00047 #define motionpixels_tableinit()
00048 #include "libavcodec/motionpixels_tables.h"
00049 #else
00050 static YuvPixel mp_rgb_yuv_table[1 << 15];
00051 
00052 static void mp_set_zero_yuv(YuvPixel *p)
00053 {
00054     int i, j;
00055 
00056     for (i = 0; i < 31; ++i) {
00057         for (j = 31; j > i; --j)
00058             if (!(p[j].u | p[j].v | p[j].y))
00059                 p[j] = p[j - 1];
00060         for (j = 0; j < 31 - i; ++j)
00061             if (!(p[j].u | p[j].v | p[j].y))
00062                 p[j] = p[j + 1];
00063     }
00064 }
00065 
00066 static void mp_build_rgb_yuv_table(YuvPixel *p)
00067 {
00068     int y, v, u, i;
00069 
00070     for (y = 0; y <= 31; ++y)
00071         for (v = -31; v <= 31; ++v)
00072             for (u = -31; u <= 31; ++u) {
00073                 i = mp_yuv_to_rgb(y, v, u, 0);
00074                 if (i < (1 << 15) && !(p[i].u | p[i].v | p[i].y)) {
00075                     p[i].y = y;
00076                     p[i].v = v;
00077                     p[i].u = u;
00078                 }
00079             }
00080     for (i = 0; i < 1024; ++i)
00081         mp_set_zero_yuv(p + i * 32);
00082 }
00083 
00084 static void motionpixels_tableinit(void)
00085 {
00086     if (!mp_rgb_yuv_table[0].u)
00087         mp_build_rgb_yuv_table(mp_rgb_yuv_table);
00088 }
00089 #endif 
00090 
00091 #endif