00001
00002
00003
00004
00005
00006
00007
00008 #include "ColorTable32K.h"
00009 #include "Platform/GTAssert.h"
00010
00011 void ColorTable32K::unpack(unsigned char* unpackedCube, const unsigned char* packedCube){
00012 int lpos1, lpos2, pos;
00013 unsigned char mask1, mask2;
00014 for (int y=0; y<8; y++)
00015 for (int u=0; u<64; u++)
00016 for (int v=0; v<64; v++){
00017 lpos1 = ((2*y)<<12)|(u<<6)|v;
00018 lpos2 = ((2*y+1)<<12)|(u<<6)|v;
00019 pos = (y<<12)|(u<<6)|v;
00020 mask1 = 0x0f&packedCube[pos];
00021 mask2 = 0x0f&(packedCube[pos]>>4);
00022 unpackedCube[lpos1] = mask1;
00023 unpackedCube[lpos2] = mask2;
00024 }
00025 }
00026
00027 colorClass ColorTable32K::getColorClass(const unsigned char y,
00028 const unsigned char u,
00029 const unsigned char v) const
00030 {
00031 return getColorClassFast(y, u, v);
00032 }
00033
00034 void ColorTable32K::generateColorClassImage(const Image& image,
00035 ColorClassImage& colorClassImage) const
00036 {
00037 colorClassImage.width = image.cameraInfo.resolutionWidth;
00038 colorClassImage.height = image.cameraInfo.resolutionHeight;
00039
00040 for (register int y = 0; y < image.cameraInfo.resolutionHeight; y++) {
00041 for (register int x = 0; x < image.cameraInfo.resolutionWidth; x++) {
00042 colorClassImage.image[y][x]
00043 = getColorClassFast(image.image[y][0][x], image.image[y][1][x], image.image[y][2][x]);
00044 }
00045 }
00046 }
00047
00048 void ColorTable32K::generateColorClassImage(const Image& image,
00049 ColorClassImage& colorClassImage,
00050 colorClass colorClass
00051 ) const
00052 {
00053 colorClassImage.width = image.cameraInfo.resolutionWidth;
00054 colorClassImage.height = image.cameraInfo.resolutionHeight;
00055
00056 for (register int y = 0; y < image.cameraInfo.resolutionHeight; y++) {
00057 for (register int x = 0; x < image.cameraInfo.resolutionWidth; x++) {
00058 if(getColorClassFast(image.image[y][0][x], image.image[y][1][x], image.image[y][2][x]) == colorClass)
00059 {
00060 colorClassImage.image[y][x] = colorClass;
00061 }
00062 else
00063 {
00064 colorClassImage.image[y][x] = noColor;
00065 }
00066 }
00067 }
00068 }
00069
00070 void ColorTable32K::generateHighResColorClassImage(const Image& image,
00071 ColorClassImage& colorClassImage
00072 ) const
00073 {
00074 colorClassImage.width = image.cameraInfo.resolutionWidth * 2;
00075 colorClassImage.height = image.cameraInfo.resolutionHeight * 2;
00076
00077 for (register int y = 0; y < image.cameraInfo.resolutionHeight * 2; y++) {
00078 for (register int x = 0; x < image.cameraInfo.resolutionWidth * 2; x++) {
00079 colorClassImage.image[y][x] =
00080 getColorClassFast(image.getHighResY(x, y),
00081 image.image[y / 2][1][x / 2],
00082 image.image[y / 2][2][x / 2]);
00083 }
00084 }
00085 }
00086
00087 void ColorTable32K::generateHighResColorClassImage(const Image& image,
00088 ColorClassImage& colorClassImage,
00089 colorClass colorClass
00090 ) const
00091 {
00092 colorClassImage.width = image.cameraInfo.resolutionWidth * 2;
00093 colorClassImage.height = image.cameraInfo.resolutionHeight * 2;
00094
00095 for (register int y = 0; y < image.cameraInfo.resolutionHeight * 2; y++) {
00096 for (register int x = 0; x < image.cameraInfo.resolutionWidth * 2; x++) {
00097 if(getColorClassFast(image.getHighResY(x, y),
00098 image.image[y / 2][1][x / 2],
00099 image.image[y / 2][2][x / 2])
00100 == colorClass)
00101 {
00102 colorClassImage.image[y][x] = colorClass;
00103 }
00104 else
00105 {
00106 colorClassImage.image[y][x] = noColor;
00107 }
00108 }
00109 }
00110 }
00111
00112 void ColorTable32K::getBoxAroundColorClass(colorClass color,
00113 Vector3<int>& pNear, Vector3<int>& pFar)
00114 {
00115 pNear = Vector3<int>(0,0,0);
00116 pFar = Vector3<int>(255,255,255);
00117 unsigned char y(0),u(0),v(0);
00118 while(y<16)
00119 {
00120 u = 0;
00121 while(u<64)
00122 {
00123 v = 0;
00124 while(v<64)
00125 {
00126 if(colorClassesUnpacked[(y<<12)|(v<<6)|u] == color)
00127 {
00128 Vector3<int> first(4*y,u,v);
00129 pNear = first;
00130 pFar = first;
00131 v++;
00132 goto expandBox;
00133 }
00134 v++;
00135 }
00136 u++;
00137 }
00138 y++;
00139 }
00140 return;
00141 expandBox:
00142 while(y<16)
00143 {
00144 u = 0;
00145 while(u<64)
00146 {
00147 v = 0;
00148 while(v<64)
00149 {
00150 if(colorClassesUnpacked[(y<<12)|(v<<6)|u] == color)
00151 {
00152 Vector3<int> expand(4*y,u,v);
00153 if(expand.x < pNear.x)
00154 {
00155 pNear.x = expand.x;
00156 }
00157 else if(expand.x > pFar.x)
00158 {
00159 pFar.x = expand.x;
00160 }
00161 if(expand.y < pNear.y)
00162 {
00163 pNear.y = expand.y;
00164 }
00165 else if(expand.y > pFar.y)
00166 {
00167 pFar.y = expand.y;
00168 }
00169 if(expand.z < pNear.z)
00170 {
00171 pNear.z = expand.z;
00172 }
00173 else if(expand.z > pFar.z)
00174 {
00175 pFar.y = expand.y;
00176 }
00177 }
00178 v++;
00179 }
00180 u++;
00181 }
00182 y++;
00183 }
00184 pNear *= 4;
00185 pFar *= 4;
00186 }
00187
00188 ColorTable32K::~ColorTable32K()
00189 {
00190 }
00191
00192 ColorTable32K::ColorTable32K()
00193 {
00194 clear();
00195 }
00196
00197
00198
00199
00200
00201 void ColorTable32K::addColorClass
00202 (
00203 colorClass colorClass,
00204 unsigned char y,
00205 unsigned char u,
00206 unsigned char v
00207 )
00208 {
00209
00210 }
00211
00212
00213
00214
00215
00216 void ColorTable32K::addColorClass
00217 (
00218 colorClass colorClass,
00219 unsigned char y,
00220 unsigned char u,
00221 unsigned char v,
00222 unsigned char range
00223 )
00224 {
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 }
00251
00252
00253
00254
00255
00256 void ColorTable32K::addCuboidToColorClass
00257 (
00258 colorClass colorClass,
00259 unsigned char yMin,
00260 unsigned char uMin,
00261 unsigned char vMin,
00262 unsigned char yMax,
00263 unsigned char uMax,
00264 unsigned char vMax
00265 )
00266 {
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 }
00284
00285
00286
00287
00288
00289 void ColorTable32K::removeColorClass
00290 (
00291 unsigned char y,
00292 unsigned char u,
00293 unsigned char v,
00294 unsigned char range
00295 )
00296 {
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 }
00320
00321
00322
00323
00324
00325
00326 void ColorTable32K::clearChannel(colorClass colorClass)
00327 {
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 }
00339
00340 void ColorTable32K::clear()
00341 {
00342 for (int i = 0; i < 8*64*64; i++)
00343 {
00344 colorClasses[i] = noColor;
00345 }
00346 }
00347
00348 Out& operator << (Out& stream, const ColorTable32K& colorTable32K)
00349 {
00350
00351
00352
00353
00354
00355
00356
00357 unsigned char currentColorClass = (unsigned char)(colorTable32K.colorClasses[0]);
00358
00359
00360 unsigned char nextColorClass;
00361
00362
00363 const unsigned char* colorTable = (const unsigned char*)&colorTable32K.colorClasses;
00364
00365
00366 int currentLength = 1;
00367
00368 for (unsigned int i=1;i<sizeof(colorTable32K.colorClasses);i++)
00369 {
00370 nextColorClass = colorTable[i];
00371
00372 if (nextColorClass != currentColorClass)
00373 {
00374 stream << currentLength << currentColorClass;
00375 currentColorClass = nextColorClass;
00376 currentLength = 1;
00377 }
00378 else
00379 {
00380 currentLength++;
00381 }
00382 }
00383 stream << currentLength << currentColorClass;
00384
00385
00386 stream << (int)0;
00387
00388 return stream;
00389 }
00390
00391 In& operator>>(In& stream,ColorTable32K& colorTable32K)
00392 {
00393
00394
00395
00396
00397
00398
00399 unsigned char* colorTable = (unsigned char*)&colorTable32K.colorClasses;
00400
00401
00402 unsigned char currentColorClass;
00403
00404
00405 unsigned int currentLength;
00406
00407
00408 unsigned int pos=0;
00409
00410 while(pos < sizeof(colorTable32K.colorClasses))
00411 {
00412 stream >> currentLength;
00413 if (currentLength == 0)
00414 if(!pos)
00415 stream >> currentLength >> currentLength;
00416 else
00417 break;
00418 stream >> currentColorClass;
00419
00420 for (unsigned int i=0;i<=currentLength && i + pos < sizeof(colorTable32K.colorClasses);i++)
00421 {
00422 colorTable[i+pos] = currentColorClass;
00423 if (i+pos > sizeof(colorTable32K.colorClasses) - 1)
00424 break;
00425 }
00426
00427 pos += currentLength;
00428 }
00429
00430 unsigned char* colorTableUnpacked = (unsigned char*)&colorTable32K.colorClassesUnpacked;
00431 colorTable32K.unpack(colorTableUnpacked, colorTable);
00432
00433 return stream;
00434 }