Fawkes API  Fawkes Development Version
rgb.h
00001 
00002 /***************************************************************************
00003  *  rgb.h - RGB specific methods, macros and constants
00004  *
00005  *  Created: Sat Aug 12 14:58:02 2006
00006  *  based on colorspaces.h from Tue Feb 23 13:49:38 2005
00007  *  Copyright  2005-2006  Tim Niemueller [www.niemueller.de]
00008  *
00009  ****************************************************************************/
00010 
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version. A runtime exception applies to
00015  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU Library General Public License for more details.
00021  *
00022  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00023  */
00024 
00025 #ifndef __FIREVISION_UTILS_COLOR_RGB_H
00026 #define __FIREVISION_UTILS_COLOR_RGB_H
00027 
00028 namespace firevision {
00029 #if 0 /* just to make Emacs auto-indent happy */
00030 }
00031 #endif
00032 
00033 #define RGB_PIXEL_SIZE 3
00034 #define RGB_PIXEL_AT(RGB, width, x, y)    ((RGB_t *)(RGB + ((y) * (width) * RGB_PIXEL_SIZE) + (x) * RGB_PIXEL_SIZE))
00035 #define RGB_CLEAR_PIXEL(RGB, width, x, y) memset(RGB + ((y) * (width) * RGB_PIXEL_SIZE) + (x) * RGB_PIXEL_SIZE, 0, RGB_PIXEL_SIZE);
00036 #define RGB_RED_AT(RGB, width, x, y)      (RGB_PIXEL_AT(RGB, (width), (x), (y))->R)
00037 #define RGB_GREEN_AT(RGB, width, x, y)    (RGB_PIXEL_AT(RGB, (width), (x), (y))->G)
00038 #define RGB_BLUE_AT(RGB, width, x, y)     (RGB_PIXEL_AT(RGB, (width), (x), (y))->B)
00039 #define RGB_SET_RED(RGB, width, x, y)     {RGB_t *p=RGB_PIXEL_AT(RGB, (width), (x), (y)); p->R=255; p->G=0;   p->B=0; }
00040 #define RGB_SET_GREEN(RGB, width, x, y)   {RGB_t *p=RGB_PIXEL_AT(RGB, (width), (x), (y)); p->R=0;   p->G=255; p->B=0; }
00041 #define RGB_SET_BLUE(RGB, width, x, y)    {RGB_t *p=RGB_PIXEL_AT(RGB, (width), (x), (y)); p->R=0;   p->G=0;   p->B=255; }
00042 
00043 /** Structure defining an RGB pixel (in R-G-B byte ordering). */
00044 typedef struct {
00045   unsigned char R;      /**< R value */
00046   unsigned char G;      /**< G value */
00047   unsigned char B;      /**< B value */
00048 } RGB_t;
00049 
00050 /** Structure defining an RGB pixel (in B-G-R byte ordering). */
00051 typedef struct {
00052   unsigned char B;      /**< B value */
00053   unsigned char G;      /**< G value */
00054   unsigned char R;      /**< R value */
00055 } BGR_t;
00056 
00057 void rgb_to_rgb_with_alpha_plainc(const unsigned char *rgb, unsigned char *rgb_alpha,
00058                                   unsigned int width, unsigned int height);
00059 
00060 void rgb_to_bgr_with_alpha_plainc(const unsigned char *rgb, unsigned char *bgr_alpha,
00061                                   unsigned int width, unsigned int height);
00062 
00063 void bgr_to_rgb_plainc(const unsigned char *BGR, unsigned char *RGB,
00064                        unsigned int width, unsigned int height);
00065 
00066 void convert_line_bgr_rgb(const unsigned char *BGR, unsigned char *RGB,
00067                            unsigned int width, unsigned int height);
00068 
00069 } // end namespace firevision
00070 
00071 #endif