1 /*****************************************************************************
2 * Common pixel/chroma manipulation routines.
3 *****************************************************************************
4 * Copyright (C) 2003, 2004 VideoLAN
5 * $Id: pixmap.h,v 1.6 2004/01/31 23:33:02 rocky Exp $
7 * Author: Rocky Bernstein
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
27 /** Color and transparency of a pixel or a palette (CLUT) entry
39 /** An undefined or invalid colormap index. */
40 #define INVALID_CMAP_ENTRY -1
42 /** Type of a palette/colormap index*/
43 typedef int16_t cmap_t;
45 /** Number of entries in RGB palette/colormap*/
46 #define CMAP_RGB2_SIZE 256
49 Force v in the range 0..255. In video_chroma/i420_rgb.c, this
50 is macro is called CLIP. FIXME: Combine with that.
52 #define clip_8_bit(v) \
53 ((v < 0) ? 0 : (v > 255) ? 255 : v)
57 http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html#RTFToC30
58 http://people.ee.ethz.ch/~buc/brechbuehler/mirror/color/ColorFAQ.html
60 Thanks to Billy Biggs <vektor@dumbterm.net> for the pointer and
61 the following conversion.
63 R' = [ 1.1644 0 1.5960 ] ([ Y' ] [ 16 ])
64 G' = [ 1.1644 -0.3918 -0.8130 ] * ([ Cb ] - [ 128 ])
65 B' = [ 1.1644 2.0172 0 ] ([ Cr ] [ 128 ])
67 See also vlc/modules/video_chroma/i420_rgb.h and
68 vlc/modules/video_chroma/i420_rgb_c.h for a way to do this in a way
69 more optimized for integer arithmetic. Would be nice to merge the
75 Convert a YUV pixel into an RGB pixel.
78 yuv2rgb(const ogt_yuvt_t *p_yuv, uint8_t *p_rgb_out )
81 int i_Y = p_yuv->s.y - 16;
82 int i_Cb = p_yuv->s.v - 128;
83 int i_Cr = p_yuv->s.u - 128;
85 int i_red = (1.1644 * i_Y) + (1.5960 * i_Cr);
86 int i_green = (1.1644 * i_Y) - (0.3918 * i_Cb) - (0.8130 * i_Cr);
87 int i_blue = (1.1644 * i_Y) + (2.0172 * i_Cb);
89 i_red = clip_8_bit( i_red );
90 i_green = clip_8_bit( i_green );
91 i_blue = clip_8_bit( i_blue );
93 #ifdef WORDS_BIGENDIAN
95 *p_rgb_out++ = i_green;
96 *p_rgb_out++ = i_blue;
98 *p_rgb_out++ = i_blue;
99 *p_rgb_out++ = i_green;
100 *p_rgb_out++ = i_red;
105 /* The byte storage of an RGB pixel. */
108 #define GREEN_PIXEL 1
109 #ifdef WORDS_BIGENDIAN
118 Store an RGB pixel into the location of p_pixel, taking into
119 account the "Endian"-ness of the underlying machine.
121 (N.B. Not sure if I've got this right or this is the right thing
125 put_rgb24_pixel(const uint8_t *rgb, /*out*/ uint8_t *p_pixel)
127 #ifdef WORDS_BIGENDIAN
130 *p_pixel++ = rgb[RED_PIXEL];
131 *p_pixel++ = rgb[GREEN_PIXEL];
132 *p_pixel++ = rgb[BLUE_PIXEL];
136 Find the nearest colormap entry in p_vout (assumed to have RGB2
137 chroma, i.e. 256 RGB 8bpp entries) that is closest in color to p_rgb. Set
138 out_rgb to the color found and return the colormap index.
139 INVALID_CMAP_ENTRY is returned if there is some error.
142 find_cmap_rgb8_nearest(const vout_thread_t *p_vout, const uint8_t *p_rgb,
143 /*out*/ uint8_t *out_rgb);
146 Get the the rgb value for a given colormap entry for p_vout (which is'
147 assumed to have RGB2 chroma).
149 VLC_FALSE is returned if there was some error.
152 query_color(const vout_thread_t *p_vout, cmap_t i_cmap,
153 /*out*/ uint8_t *rgb);
155 #endif /* PIXMAP_H */
160 * c-file-style: "gnu"
162 * indent-tabs-mode: nil