qa_colormap.cpp
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
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
00038 #define BIGDEPTH 8
00039
00040 int
00041 main(int argc, char **argv)
00042 {
00043
00044 const char *filename = "qatest.colormap";
00045 if ( argc > 1 ) {
00046 filename = argv[1];
00047 }
00048
00049 printf("Creating simple one-plane colormap\n");
00050 YuvColormap *cm = new YuvColormap();
00051
00052 for (unsigned int u = 100; u < 150; ++u) {
00053 for (unsigned int v = 100; v < 150; ++v) {
00054 cm->set(128, u, v, C_ORANGE);
00055 }
00056 }
00057
00058 unsigned char *imgb = malloc_buffer(YUV422_PLANAR, cm->width() * 2, cm->height() * 2);
00059 cm->to_image(imgb);
00060
00061 ImageDisplay *imgd = new ImageDisplay(cm->width() * 2, cm->height() * 2);
00062 imgd->show(imgb);
00063
00064 imgd->loop_until_quit();
00065
00066 delete cm;
00067
00068 printf("Trying to create colormap with illegal depth, should throw an exception..");
00069 try {
00070 cm = new YuvColormap(3);
00071 printf(" Test failed, colormap was created\n");
00072 delete cm;
00073 } catch (Exception &e) {
00074 printf(" Test succeeded, caught exception\n");
00075 }
00076
00077 printf("Trying colormap with depth of %u\n", BIGDEPTH);
00078 cm = new YuvColormap(BIGDEPTH);
00079
00080 for (unsigned int d = 0; d < cm->depth(); ++d) {
00081 unsigned int y = 256 / cm->depth() * d;
00082 printf("d=%u y=%u u=[%u,%u] v=[%u,%u]\n", d, y,
00083 cm->depth() * d, cm->depth() * (d+1), cm->depth() * d, cm->depth() * (d+1));
00084
00085 for (unsigned int u = cm->deepness() / cm->depth() * d; u < cm->deepness() / cm->depth() * (d+1); ++u) {
00086 for (unsigned int v = cm->deepness() / cm->depth() * d; v < cm->deepness() / cm->depth() * (d+1); ++v) {
00087 cm->set(y, u, v, C_ORANGE);
00088 }
00089 }
00090
00091 cm->to_image(imgb, d);
00092 imgd->show(imgb);
00093 imgd->loop_until_quit();
00094 }
00095
00096 printf("Saving colormap to a file\n");
00097 ColormapFile cmf;
00098 cmf.add_colormap(cm);
00099 cmf.write(filename);
00100
00101 ColormapFile::ColormapBlockVector *blocks = cmf.colormap_blocks();
00102 printf("Written, created %zu blocks\n", blocks->size());
00103 delete blocks;
00104 delete cm;
00105
00106 cmf.clear();
00107
00108 printf("Reading colormap from file\n");
00109 cmf.read(filename);
00110
00111 Colormap *tcm = cmf.get_colormap();
00112 if ( (cm = dynamic_cast<YuvColormap *>(tcm)) == 0 ) {
00113 printf("Error, did not get valid yuv colormap\n");
00114 } else {
00115 printf("Showing all %u colormap levels\n", cm->depth());
00116 for (unsigned int d = 0; d < cm->depth(); ++d) {
00117 cm->to_image(imgb, d);
00118 imgd->show(imgb);
00119 imgd->loop_until_quit();
00120 }
00121 }
00122
00123 delete cm;
00124
00125 unsigned int depth = 4, width = 128, height = 128;
00126 printf("Trying colormap with low resolution, choosing %dx%dx%d\n", depth, width, height);
00127 cm = new YuvColormap(depth, width, height);
00128 printf("YuvColormap dimensions: %dx%dx%d\n", cm->depth(), cm->width(), cm->height());
00129 ColormapFile cmfr(depth, width, height);
00130 delete cm;
00131 cmfr.write(filename);
00132 cmfr.clear();
00133 cmfr.read(filename);
00134 cm = dynamic_cast<YuvColormap *>(cmfr.get_colormap());
00135 printf("Read back colormap dimensions %dx%dx%d\n",
00136 cm->depth(), cm->width(), cm->height());
00137 delete cm;
00138
00139
00140
00141 return 0;
00142 }
00143
00144