00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __FIREVISION_UTILS_COLOR_CONVERSIONS_H
00026 #define __FIREVISION_UTILS_COLOR_CONVERSIONS_H
00027
00028 #include <fvutils/color/yuv.h>
00029 #include <fvutils/color/rgb.h>
00030 #include <fvutils/color/yuvrgb.h>
00031 #include <fvutils/color/rgbyuv.h>
00032 #include <fvutils/color/bayer.h>
00033 #include <fvutils/color/colorspaces.h>
00034
00035 #include <core/exception.h>
00036 #include <cstring>
00037
00038 namespace firevision {
00039 #if 0
00040 }
00041 #endif
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 inline void
00056 convert(colorspace_t from, colorspace_t to,
00057 const unsigned char *src, unsigned char *dst,
00058 unsigned int width, unsigned int height)
00059 {
00060 if (from == to) {
00061 if ( src != dst ) {
00062 memcpy(dst, src, colorspace_buffer_size(from, width, height));
00063 }
00064 } else if ( (from == YUV422_PACKED) && (to == YUV422_PLANAR) ) {
00065 yuv422packed_to_yuv422planar(src, dst, width, height);
00066 } else if ( (from == YUY2) && (to == YUV422_PLANAR_QUARTER) ) {
00067 yuy2_to_yuv422planar_quarter(src, dst, width, height);
00068 } else if ( (from == YUY2) && (to == YUV422_PLANAR) ) {
00069 yuy2_to_yuv422planar(src, dst, width, height);
00070 } else if ( (from == YVY2) && (to == YUV422_PLANAR) ) {
00071 yvy2_to_yuv422planar(src, dst, width, height);
00072
00073 #if ( \
00074 defined __i386__ || \
00075 defined __386__ || \
00076 defined __X86__ || \
00077 defined _M_IX86 || \
00078 defined i386 \
00079 )
00080 } else if ( (from == YUV411_PLANAR) && (to == RGB) ) {
00081 yuv411planar_to_rgb_mmx(src, dst, width, height);
00082 #endif
00083 } else if ( (from == BGR) && (to == RGB) ) {
00084 bgr_to_rgb_plainc(src, dst, width, height);
00085 } else if ( (from == RGB) && (to == YUV411_PACKED) ) {
00086 rgb_to_yuv411packed_plainc(src, dst, width, height);
00087 } else if ( (from == RGB) && (to == YUV422_PLANAR) ) {
00088 rgb_to_yuv422planar_plainc(src, dst, width, height);
00089 } else if ( (from == RGB) && (to == YUV422_PACKED) ) {
00090 rgb_to_yuv422packed_plainc(src, dst, width, height);
00091 } else if ( (from == BGR) && (to == YUV422_PLANAR) ) {
00092 bgr_to_yuv422planar_plainc(src, dst, width, height);
00093 } else if ( (from == GRAY8) && (to == YUY2) ) {
00094 gray8_to_yuy2(src, dst, width, height);
00095 } else if ( (from == GRAY8) && (to == YUV422_PLANAR) ) {
00096 gray8_to_yuv422planar_plainc(src, dst, width, height);
00097 } else if ( (from == MONO8) && (to == YUV422_PLANAR) ) {
00098 gray8_to_yuv422planar_plainc(src, dst, width, height);
00099 } else if ( (from == YUV422_PLANAR) && (to == YUV422_PACKED) ) {
00100 yuv422planar_to_yuv422packed(src, dst, width, height);
00101 } else if ( (from == YUV422_PLANAR_QUARTER) && (to == YUV422_PACKED) ) {
00102 yuv422planar_quarter_to_yuv422packed(src, dst, width, height);
00103 } else if ( (from == YUV422_PLANAR_QUARTER) && (to == YUV422_PLANAR) ) {
00104 yuv422planar_quarter_to_yuv422planar(src, dst, width, height);
00105 } else if ( (from == YUV422_PLANAR) && (to == RGB) ) {
00106 yuv422planar_to_rgb_plainc(src, dst, width, height);
00107 } else if ( (from == YUV422_PACKED) && (to == RGB) ) {
00108 yuv422packed_to_rgb_plainc(src, dst, width, height);
00109 } else if ( (from == YUV422_PLANAR) && (to == BGR) ) {
00110 yuv422planar_to_bgr_plainc(src, dst, width, height);
00111 } else if ( (from == YUV422_PLANAR) && (to == RGB_WITH_ALPHA) ) {
00112 yuv422planar_to_rgb_with_alpha_plainc(src, dst, width, height);
00113 } else if ( (from == RGB) && (to == RGB_WITH_ALPHA) ) {
00114 rgb_to_rgb_with_alpha_plainc(src, dst, width, height);
00115 } else if ( (from == RGB) && (to == BGR_WITH_ALPHA) ) {
00116 rgb_to_bgr_with_alpha_plainc(src, dst, width, height);
00117 } else if ( (from == YUV422_PLANAR) && (to == BGR_WITH_ALPHA) ) {
00118 yuv422planar_to_bgr_with_alpha_plainc(src, dst, width, height);
00119 } else if ( (from == YUV422_PACKED) && (to == BGR_WITH_ALPHA) ) {
00120 yuv422packed_to_bgr_with_alpha_plainc(src, dst, width, height);
00121 } else if ( (from == BAYER_MOSAIC_GBRG) && (to == YUV422_PLANAR) ) {
00122 bayerGBRG_to_yuv422planar_bilinear(src, dst, width, height);
00123 } else if ( (from == YUV444_PACKED) && (to == YUV422_PLANAR) ) {
00124 yuv444packed_to_yuv422planar(src, dst, width, height);
00125 } else if ( (from == YUV444_PACKED) && (to == YUV422_PACKED) ) {
00126 yuv444packed_to_yuv422packed(src, dst, width, height);
00127 } else if ( (from == YVU444_PACKED) && (to == YUV422_PLANAR) ) {
00128 yvu444packed_to_yuv422planar(src, dst, width, height);
00129 } else if ( (from == YVU444_PACKED) && (to == YUV422_PACKED) ) {
00130 yvu444packed_to_yuv422packed(src, dst, width, height);
00131 } else {
00132 throw fawkes::Exception("Cannot convert image data from %s to %s",
00133 colorspace_to_string(from),
00134 colorspace_to_string(to));
00135 }
00136 }
00137
00138
00139 inline void
00140 grayscale(colorspace_t cspace,
00141 unsigned char *src, unsigned char *dst,
00142 unsigned int width, unsigned int height)
00143 {
00144 switch (cspace) {
00145 case YUV422_PACKED:
00146 grayscale_yuv422packed(src, dst, width, height);
00147 break;
00148 case YUV422_PLANAR:
00149 grayscale_yuv422planar(src, dst, width, height);
00150 break;
00151 default:
00152 fawkes::Exception e("FirevisionUtils: Cannot grayscale image. "
00153 "Images from colorspace %s are not supported.",
00154 colorspace_to_string(cspace));
00155 throw e;
00156 }
00157 }
00158
00159 }
00160
00161 #endif