thresholds.cpp

00001
00002 /***************************************************************************
00003  *  thresholds.cpp - Implementation of a thresholds color model
00004  *
00005  *  Generated: Wed May 18 13:59:18 2005
00006  *  Copyright  2005  Tim Niemueller  [www.niemueller.de]
00007  *                   Matrin Heracles <martin.heracles@rwth-aachen.de>
00008  *
00009  ****************************************************************************/
00010
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version. A runtime exception applies to
00015  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU Library General Public License for more details.
00021  *
00022  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00023  */
00024
00025 #include <iostream>
00026
00027 #include "models/color/thresholds.h"
00028
00029 using namespace std;
00030 
00031 /** @class ColorModelThresholds <models/color/thresholds.h>
00032  * Really simple thresholds-based model with some hard-coded thresholds. Was
00033  * just for initial development of color models.
00034  */
00035
00036 color_t
00037 ColorModelThresholds::determine(unsigned int y,
00038                                 unsigned int u,
00039                                 unsigned int v) const
00040 {
00041   if ( y >= THRESHOLD_WHITE_Y_LOW) {
00042     return C_WHITE;
00043   }
00044   if ( u <= THRESHOLD_GREEN_U_HIGH &&
00045        v <= THRESHOLD_GREEN_V_HIGH) {
00046     return C_GREEN;
00047   }
00048   else if (/*THRESHOLD_ORANGE_U_LOW <= u &&*/
00049            u <= THRESHOLD_ORANGE_U_HIGH &&
00050            v >= THRESHOLD_ORANGE_V_LOW) {
00051     return C_ORANGE;
00052   }
00053   else if (u >= THRESHOLD_BLUE_U_LOW &&
00054            v <= THRESHOLD_BLUE_V_HIGH) {
00055     return C_BLUE;
00056   }
00057   else if (u <= THRESHOLD_YELLOW_U_HIGH &&
00058            v >= THRESHOLD_YELLOW_V_LOW) {
00059     return C_YELLOW;
00060   }
00061   else if (u >= THRESHOLD_MAGENTA_U_LOW &&
00062            v >= THRESHOLD_MAGENTA_V_LOW) {
00063     return C_MAGENTA;
00064   }
00065   else if (THRESHOLD_CYAN_U_LOW <= u &&
00066            u <= THRESHOLD_CYAN_U_HIGH &&
00067            v <= THRESHOLD_CYAN_V_HIGH) {
00068     return C_CYAN;
00069   }
00070   else {
00071     return C_OTHER;
00072   }
00073 }
00074
00075 const char *
00076 ColorModelThresholds::get_name()
00077 {
00078   return "ColorModelThresholds";
00079 }
00080
00081 
00082 /** Print the thresholds to stdout.
00083  */
00084 void
00085 ColorModelThresholds::print_thresholds()
00086 {
00087   cout << "ColorModelThresholds" << endl
00088        << "==========================================================" << endl
00089        << "Orange:  u_low=" << THRESHOLD_ORANGE_U_LOW
00090        << "  u_high=" << THRESHOLD_ORANGE_U_HIGH
00091        << " v_low=" << THRESHOLD_ORANGE_V_LOW
00092        << endl
00093        << "Yellow:  u_high=" << THRESHOLD_YELLOW_U_HIGH
00094        << " v_low=" << THRESHOLD_YELLOW_V_LOW
00095        << endl;
00096 }