/** * Modifications for 4:2:0 to RGB by Billy Biggs * * These are from lavtools in mjpegtools: * colorspace.c: Routines to perform colorspace conversions. * Copyright (C) 2001 Matthew J. Marjanovic * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ static inline __attribute__ ((always_inline,const)) uint8_t clip255( int x ) { if( x > 255 ) { return 255; } else if( x < 0 ) { return 0; } else { return x; } } #define FP_BITS 18 /* precomputed tables */ static int RGB_Y[256]; static int R_Cr[256]; static int G_Cb[256]; static int G_Cr[256]; static int B_Cb[256]; static int conv_YR_inited = 0; static int myround(double n) { if (n >= 0) return (int)(n + 0.5); else return (int)(n - 0.5); } static void init_YCbCr_to_RGB_tables(void) { int i; /* * Q_Z[i] = (coefficient * i * * (Q-excursion) / (Z-excursion) * fixed-point-factor) * * to one of each, add the following: * + (fixed-point-factor / 2) --- for rounding later * + (Q-offset * fixed-point-factor) --- to add the offset * */ /* clip Y values under 16 */ for (i = 0; i < 16; i++) { RGB_Y[i] = myround((1.0 * (double)(16) * 255.0 / 219.0 * (double)(1<> 1); int cur_cr = cr + ((y & ~1) * width/2) + (x >> 1); output[ 0 ] = clip255( (RGB_Y[ cur_l ] + R_Cr[ cur_cr ]) >> FP_BITS ); output[ 1 ] = clip255( (RGB_Y[ cur_l ] + G_Cb[ cur_cb ] + G_Cr[ cur_cr ]) >> FP_BITS ); output[ 2 ] = clip255( (RGB_Y[ cur_l ] + B_Cb[ cur_cb ]) >> FP_BITS ); output += 3; } } }