00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ColorClassImage.h"
00010 #include <string.h>
00011
00012
00013 ColorClassImage::ColorClassImage() : height(144), width(176)
00014 {
00015 memset(image,0,sizeof(image));
00016 }
00017
00018 void ColorClassImage::convertToImage(Image& image)
00019 {
00020 image.cameraInfo.resolutionHeight = height;
00021 image.cameraInfo.resolutionWidth = width;
00022
00023 colorClass color;
00024 for (register int y = 0; y < height; y++)
00025 {
00026 for (register int x = 0; x < width; x++)
00027 {
00028 color = (colorClass)this->image[y][x];
00029
00030 image.image[y][3][x] = 128;
00031 image.image[y][4][x] = 128;
00032 image.image[y][5][x] = 128;
00033 switch (color)
00034 {
00035 case white:
00036 image.image[y][0][x] = 255;
00037 image.image[y][1][x] = 127;
00038 image.image[y][2][x] = 127;
00039 break;
00040 case green:
00041 image.image[y][0][x] = 180;
00042 image.image[y][1][x] = 0;
00043 image.image[y][2][x] = 0;
00044 break;
00045 case gray:
00046 image.image[y][0][x] = 127;
00047 image.image[y][1][x] = 127;
00048 image.image[y][2][x] = 127;
00049 break;
00050 case red:
00051 image.image[y][0][x] = 0;
00052 image.image[y][1][x] = 255;
00053 image.image[y][2][x] = 0;
00054 break;
00055 case orange:
00056 image.image[y][0][x] = 100;
00057 image.image[y][1][x] = 255;
00058 image.image[y][2][x] = 0;
00059 break;
00060 case yellow:
00061 image.image[y][0][x] = 255;
00062 image.image[y][1][x] = 255;
00063 image.image[y][2][x] = 0;
00064 break;
00065 case yellowOrange:
00066 image.image[y][0][x] = 170;
00067 image.image[y][1][x] = 255;
00068 image.image[y][2][x] = 0;
00069 break;
00070 case pink:
00071 image.image[y][0][x] = 255;
00072 image.image[y][1][x] = 255;
00073 image.image[y][2][x] = 255;
00074 break;
00075 case skyblue:
00076 image.image[y][0][x] = 180;
00077 image.image[y][1][x] = 0;
00078 image.image[y][2][x] = 255;
00079 break;
00080 case blue:
00081 image.image[y][0][x] = 60;
00082 image.image[y][1][x] = 80;
00083 image.image[y][2][x] = 255;
00084 break;
00085 case black:
00086 image.image[y][0][x] = 0;
00087 image.image[y][1][x] = 127;
00088 image.image[y][2][x] = 127;
00089 break;
00090 default:
00091 image.image[y][0][x] = 70;
00092 image.image[y][1][x] = 127;
00093 image.image[y][2][x] = 127;
00094 break;
00095 }
00096 }
00097 }
00098 }
00099
00100 Out& operator << (Out& stream, const ColorClassImage& colorClassImage)
00101 {
00102 stream << colorClassImage.height << colorClassImage.width;
00103
00104
00105 unsigned char currentColorClass = (unsigned char)colorClassImage.image[0][0];
00106
00107
00108 int currentLength = 0;
00109
00110 for(int y = 0; y < colorClassImage.height; ++y)
00111 for(int x = 0; x < colorClassImage.width; ++x)
00112 {
00113 unsigned char nextColorClass = (unsigned char) colorClassImage.image[y][x];
00114
00115 if (nextColorClass != currentColorClass)
00116 {
00117 stream << currentLength << currentColorClass;
00118 currentColorClass = nextColorClass;
00119 currentLength = 1;
00120 }
00121 else
00122 ++currentLength;
00123 }
00124 return stream << currentLength << currentColorClass;
00125 }
00126
00127 In& operator>>(In& stream,ColorClassImage& colorClassImage)
00128 {
00129
00130 unsigned char currentColorClass;
00131
00132
00133 unsigned int currentLength = 0;
00134
00135 stream >> colorClassImage.height >> colorClassImage.width;
00136
00137 for(int y = 0; y < colorClassImage.height; ++y)
00138 for(int x = 0; x < colorClassImage.width; ++x)
00139 {
00140 if(!currentLength)
00141 stream >> currentLength >> currentColorClass;
00142 colorClassImage.image[y][x] = currentColorClass;
00143 --currentLength;
00144 }
00145 return stream;
00146 }