Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_colormap.cpp - QA for colormap 00004 * 00005 * Created: Tue Apr 01 10:04:27 2008 00006 * Copyright 2007-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 /// @cond QA 00025 00026 #include <fvutils/colormap/yuvcm.h> 00027 #include <fvutils/colormap/cmfile.h> 00028 #include <fvutils/color/colorspaces.h> 00029 00030 #include <fvwidgets/image_display.h> 00031 #include <core/exception.h> 00032 00033 #include <cstdlib> 00034 #include <cstdio> 00035 00036 using namespace fawkes; 00037 using namespace firevision; 00038 00039 #define BIGDEPTH 8 00040 00041 int 00042 main(int argc, char **argv) 00043 { 00044 00045 const char *filename = "qatest.colormap"; 00046 if ( argc > 1 ) { 00047 filename = argv[1]; 00048 } 00049 00050 printf("Creating simple one-plane colormap\n"); 00051 YuvColormap *cm = new YuvColormap(); 00052 00053 for (unsigned int u = 100; u < 150; ++u) { 00054 for (unsigned int v = 100; v < 150; ++v) { 00055 cm->set(128, u, v, C_ORANGE); 00056 } 00057 } 00058 00059 unsigned char *imgb = malloc_buffer(YUV422_PLANAR, cm->width() * 2, cm->height() * 2); 00060 cm->to_image(imgb); 00061 00062 ImageDisplay *imgd = new ImageDisplay(cm->width() * 2, cm->height() * 2); 00063 imgd->show(imgb); 00064 00065 imgd->loop_until_quit(); 00066 00067 delete cm; 00068 00069 printf("Trying to create colormap with illegal depth, should throw an exception.."); 00070 try { 00071 cm = new YuvColormap(3); 00072 printf(" Test failed, colormap was created\n"); 00073 delete cm; 00074 } catch (Exception &e) { 00075 printf(" Test succeeded, caught exception\n"); 00076 } 00077 00078 printf("Trying colormap with depth of %u\n", BIGDEPTH); 00079 cm = new YuvColormap(BIGDEPTH); 00080 00081 for (unsigned int d = 0; d < cm->depth(); ++d) { 00082 unsigned int y = 256 / cm->depth() * d; 00083 printf("d=%u y=%u u=[%u,%u] v=[%u,%u]\n", d, y, 00084 cm->depth() * d, cm->depth() * (d+1), cm->depth() * d, cm->depth() * (d+1)); 00085 00086 for (unsigned int u = cm->deepness() / cm->depth() * d; u < cm->deepness() / cm->depth() * (d+1); ++u) { 00087 for (unsigned int v = cm->deepness() / cm->depth() * d; v < cm->deepness() / cm->depth() * (d+1); ++v) { 00088 cm->set(y, u, v, C_ORANGE); 00089 } 00090 } 00091 00092 cm->to_image(imgb, d); 00093 imgd->show(imgb); 00094 imgd->loop_until_quit(); 00095 } 00096 00097 printf("Saving colormap to a file\n"); 00098 ColormapFile cmf; 00099 cmf.add_colormap(cm); 00100 cmf.write(filename); 00101 00102 ColormapFile::ColormapBlockVector *blocks = cmf.colormap_blocks(); 00103 printf("Written, created %zu blocks\n", blocks->size()); 00104 delete blocks; 00105 delete cm; 00106 00107 cmf.clear(); 00108 00109 printf("Reading colormap from file\n"); 00110 cmf.read(filename); 00111 00112 Colormap *tcm = cmf.get_colormap(); 00113 if ( (cm = dynamic_cast<YuvColormap *>(tcm)) == 0 ) { 00114 printf("Error, did not get valid yuv colormap\n"); 00115 } else { 00116 printf("Showing all %u colormap levels\n", cm->depth()); 00117 for (unsigned int d = 0; d < cm->depth(); ++d) { 00118 cm->to_image(imgb, d); 00119 imgd->show(imgb); 00120 imgd->loop_until_quit(); 00121 } 00122 } 00123 00124 delete cm; 00125 00126 unsigned int depth = 4, width = 128, height = 128; 00127 printf("Trying colormap with low resolution, choosing %dx%dx%d\n", depth, width, height); 00128 cm = new YuvColormap(depth, width, height); 00129 printf("YuvColormap dimensions: %dx%dx%d\n", cm->depth(), cm->width(), cm->height()); 00130 ColormapFile cmfr(depth, width, height); 00131 delete cm; 00132 cmfr.write(filename); 00133 cmfr.clear(); 00134 cmfr.read(filename); 00135 cm = dynamic_cast<YuvColormap *>(cmfr.get_colormap()); 00136 printf("Read back colormap dimensions %dx%dx%d\n", 00137 cm->depth(), cm->width(), cm->height()); 00138 delete cm; 00139 00140 //delete imgd; 00141 //free(imgb); 00142 return 0; 00143 } 00144 00145 /// @endcond