Libav 0.7.1
|
00001 /* 00002 * Header file for hardcoded motionpixels RGB to YUV table 00003 * 00004 * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 static 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 /* CONFIG_HARDCODED_TABLES */ 00090 00091 #endif /* AVCODEC_MOTIONPIXELS_TABLEGEN_H */