コード例 #1
0
//set the brightness
static void setBright(int *R, int *G, int *B, int A, int bValue)
{
    int intR = *R;
    int intG = *G;
    int intB = *B;
    if (bValue > 0)
    {
        intR = (intR + (255 - intR) * bValue / 255) * A / 255;
        intG = (intG + (255 - intG) * bValue / 255) * A / 255;
        intB = (intB + (255 - intB) * bValue / 255) * A / 255;
    }
    else if (bValue < 0)
    {
        intR = intR + intR * bValue / 255;
        intG = intG + intG * bValue / 255;
        intB = intB + intB * bValue / 255;
    }
    checkRGB(&intR);
    checkRGB(&intG);
    checkRGB(&intB);
    assignRGB(R, G, B, intR, intG, intB);
}
コード例 #2
0
ファイル: volumeinformation.cpp プロジェクト: mdoube/drishti
bool
VolumeInformation::volInfo(QString volfile,
			   VolumeInformation& pvlInfo)
{  
  if (!xmlHeaderFile(volfile))
    {
      QMessageBox::information(0, "Error",
	QString("%1 is not a valid preprocessed volume file").arg(volfile));
      return false;
    }
      
  bool rgba = checkRGB(volfile) || checkRGBA(volfile);

  pvlInfo.pvlFile = volfile;


  std::vector<float> pvlmap;
  std::vector<float> rawmap;

  QDomDocument document;
  QFile f(volfile.toAscii().data());
  if (f.open(QIODevice::ReadOnly))
    {
      document.setContent(&f);
      f.close();
    }
  
  QDomElement main = document.documentElement();
  QDomNodeList dlist = main.childNodes();
  for(int i=0; i<dlist.count(); i++)
    {
      if (dlist.at(i).nodeName() == "rawfile")
	{
	  pvlInfo.rawFile = dlist.at(i).toElement().text();
	}
      else if (dlist.at(i).nodeName() == "description")
	{
	  pvlInfo.description = dlist.at(i).toElement().text();
	}
      else if (dlist.at(i).nodeName() == "voxeltype")
	{
	  QString pvalue = dlist.at(i).toElement().text();
	  if (pvalue == "unsigned char")
	    pvlInfo.voxelType = VolumeInformation::_UChar;
	  else if (pvalue == "char")
	    pvlInfo.voxelType = VolumeInformation::_Char;
	  else if (pvalue == "unsigned short")
	    pvlInfo.voxelType = VolumeInformation::_UShort;
	  else if (pvalue == "short")
	    pvlInfo.voxelType = VolumeInformation::_Short;
	  else if (pvalue == "int")
	    pvlInfo.voxelType = VolumeInformation::_Int;
	  else if (pvalue == "float")
	    pvlInfo.voxelType = VolumeInformation::_Float;
	}
      else if (dlist.at(i).nodeName() == "voxelunit")
	{
	  QString pvalue = dlist.at(i).toElement().text();
	  pvlInfo.voxelUnit = VolumeInformation::Nounit;
	  if (pvalue == "angstrom")
	    pvlInfo.voxelUnit = VolumeInformation::Angstrom;
	  else if (pvalue == "nanometer")
	    pvlInfo.voxelUnit = VolumeInformation::Nanometer;
	  else if (pvalue == "micron")
	    pvlInfo.voxelUnit = VolumeInformation::Micron;
	  else if (pvalue == "millimeter")
	    pvlInfo.voxelUnit = VolumeInformation::Millimeter;
	  else if (pvalue == "centimeter")
	    pvlInfo.voxelUnit = VolumeInformation::Centimeter;
	  else if (pvalue == "meter")
	    pvlInfo.voxelUnit = VolumeInformation::Meter;
	  else if (pvalue == "kilometer")
	    pvlInfo.voxelUnit = VolumeInformation::Kilometer;
	  else if (pvalue == "parsec")
	    pvlInfo.voxelUnit = VolumeInformation::Parsec;
	  else if (pvalue == "kiloparsec")
	    pvlInfo.voxelUnit = VolumeInformation::Kiloparsec;
	}
      else if (dlist.at(i).nodeName() == "voxelsize")
	{
	  QStringList str = (dlist.at(i).toElement().text()).split(" ", QString::SkipEmptyParts);
	  float vx = str[0].toFloat();
	  float vy = str[1].toFloat();
	  float vz = str[2].toFloat();
	  pvlInfo.voxelSize = Vec(vx, vy, vz);
	}
      else if (dlist.at(i).nodeName() == "gridsize")
	{
	  QStringList str = (dlist.at(i).toElement().text()).split(" ", QString::SkipEmptyParts);
	  int d = str[0].toInt();
	  int w = str[1].toInt();
	  int h = str[2].toInt();
	  pvlInfo.dimensions = Vec(d,w,h);
	}
      else if (dlist.at(i).nodeName() == "slabsize")
	{
	  pvlInfo.slabSize = (dlist.at(i).toElement().text()).toInt();
	}
      else if (dlist.at(i).nodeName() == "rawmap")
	{
	  QStringList str = (dlist.at(i).toElement().text()).split(" ", QString::SkipEmptyParts);
	  for(int im=0; im<str.count(); im++)
	    rawmap.push_back(str[im].toFloat());
	}
      else if (dlist.at(i).nodeName() == "pvlmap")
	{
	  QStringList str = (dlist.at(i).toElement().text()).split(" ", QString::SkipEmptyParts);
	  for(int im=0; im<str.count(); im++)
	    pvlmap.push_back(str[im].toInt());
	}
    }

  for(int i=0; i<(int)qMin(rawmap.size(), pvlmap.size()); i++)
    pvlInfo.mapping << QPointF(rawmap[i], pvlmap[i]);
  
  rawmap.clear();
  pvlmap.clear();

  return true;
}
コード例 #3
0
/*!
 * @brief Set parameters
 * @param cmd Command to change parameters
 * @return 0 if no error
 */
int CommentGenerator::setParams(std::string &cmd){
	std::string::size_type loc = 0;

	int res;

	//flags
	bool delimiter_required = false;
	bool font_set = false;
	bool scale_set = false;
	bool color_set = false;
	bool thick_set = false;

	while((loc!=std::string::npos)&&(loc<cmd.size())){ //if not empty, read command
		//std::cout << loc << '/' << cmd.size() << std::endl;
		// ------------- Ignore spaces -----------------------------
		if(cmd[loc] == ' '){
			loc++;
			continue;
		}
		// ------------ End ignore spaces --------------------------

		// --------------- Check delimiter -------------------------
		if(delimiter_required){
			if(cmd[loc] == ','){
				loc++;
				delimiter_required = false;
				continue;
			}else{
				std::cerr << "Error in CommentGenerator::setParams(): invalid command - expected \',\'" << std::endl;
				return -1;
			}
		}
		// ------------ End check delimiter ------------------------
		
		// --------------- Check command ---------------------------
		res = checkKey(cmd, loc); //Check if the command is one of the keys
		if(res==0){ //if not keys
			res = checkRGB(cmd, loc); //Check if the command is an RGB command
			if(res==0){ //if not RGB command
				res = checkSIZE(cmd, loc); //Check if the command is a number
			}
		}

		//Check result
		if(res>0){
			delimiter_required = true;
			if(res==SET_FONT){
				if(font_set){
					std::cerr << "Warning in CommentGenerator::setParams(): multiple font paramters in command" << std::endl;
				}
				font_set = true;
			}else if(res==SET_SCALE){
				if(scale_set){
					std::cerr << "Warning in CommentGenerator::setParams(): multiple scale paramters in command" << std::endl;
				}
				scale_set = true;
			}else if(res==SET_COLOR){
				if(color_set){
					std::cerr << "Warning in CommentGenerator::setParams(): multiple color paramters in command" << std::endl;
				}
				color_set = true;
			}else if(res==SET_THICKNESS){
				if(thick_set){
					std::cerr << "Warning in CommentGenerator::setParams(): multiple thickness paramters in command" << std::endl;
				}
				thick_set = true;
			}else if(res==SET_SCALE_AND_THICKNESS){
				if(scale_set){
					std::cerr << "Warning in CommentGenerator::setParams(): multiple scale paramters in command" << std::endl;
				}
				if(thick_set){
					std::cerr << "Warning in CommentGenerator::setParams(): multiple thickness paramters in command" << std::endl;
				}
				scale_set = true;
				thick_set = true;
			}
		}else if(res<0){ //error in command
			return -1;
		}else{ //cannot find any commands
			std::cerr << "Error in CommentGenerator::setParams(): invalid command - command undefined" << std::endl;
			return -1;
		}
		// --------------- End check command -----------------------
	} //end while((loc!=std::string::npos)&&(loc<cmd.size()))

	return 0;
}
コード例 #4
0
//set the hue and saturation
static void setHueAndSaturation(int *R, int *G, int *B, int hValue, int sValue)
{
    int intR = *R;
    int intG = *G;
    int intB = *B;
	
    if (intR < intG)
        swapRGB(&intR, &intG);
    if (intR < intB)
        swapRGB(&intR, &intB);
    if (intB > intG)
        swapRGB(&intB, &intG);
	
    int delta = intR - intB;
    if (!delta) return;
	
    int entire = intR + intB;
    int H, S, L = entire >> 1;  
    if (L < 128)
        S = delta * 255 / entire;
    else
        S = delta * 255 / (510 - entire);
    
    if (hValue)
    {
        if (intR == *R)
            H = (*G - *B) * 60 / delta;
        else if (intR == *G)
            H = (*B - *R) * 60 / delta + 120;
        else
            H = (*R - *G) * 60 / delta + 240;
        H += hValue;
        if (H < 0) H += 360;
        else if (H > 360) H -= 360;
        int index = H / 60;
        int extra = H % 60;
        if (index & 1) extra = 60 - extra;
        extra = (extra * 255 + 30) / 60;
        intG = extra - (extra - 128) * (255 - S) / 255;
        int Lum = L - 128;
        if (Lum > 0)
            intG += (((255 - intG) * Lum + 64) / 128);
        else if (Lum < 0)
            intG += (intG * Lum / 128);
        checkRGB(&intG);
        switch (index)
        {
            case 1:
                swapRGB(&intR, &intG);
                break;
            case 2:
                swapRGB(&intR, &intB);
                swapRGB(&intG, &intB);
                break;
            case 3:
                swapRGB(&intR, &intB);
                break;
            case 4:
                swapRGB(&intR, &intG);
                swapRGB(&intG, &intB);
                break;
            case 5:
                swapRGB(&intG, &intB);
                break;
        }
    }
    else
    {
        intR = *R;
        intG = *G;
        intB = *B;
    }
    if (sValue)
    {
        if (sValue > 0)
        {
            sValue = sValue + S >= 255? S: 255 - sValue;
            sValue = 65025 / sValue - 255;
        }
        intR += ((intR - L) * sValue / 255);
        intG += ((intG - L) * sValue / 255);
        intB += ((intB - L) * sValue / 255);
        checkRGB(&intR);
        checkRGB(&intG);
        checkRGB(&intB);
    }
    assignRGB(R, G, B, intR, intG, intB);
}