Exemple #1
0
//----------------------------------------------------------------------------
void Renderer::EnableLighting(const ColorRGB& rAmbient)
{
	const GXColor amb = { rAmbient.R()*255, rAmbient.G()*255,
		rAmbient.B()*255, 255 };
	GXSetChanAmbColor(GX_COLOR0A0, amb);

	GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
}
void SaveBmp(const string &aFileName,const Image<ColorRGB> &aImage)
{
    FILE* pFile = fopen(aFileName.c_str(),"wb+");
    
    BitmapFileHeader oFileHeader;
    BitmapInfoHeader oInfoHeader;

    oInfoHeader.biWidth  = aImage.GetWidth();
    oInfoHeader.biHeight = aImage.GetHeight();

    //We compute stride sizes. A stride must be a factor
    //of 4.
    int StrideSize = oInfoHeader.biWidth * 3;
    if((oInfoHeader.biWidth*3)%4)
    {
        StrideSize += 4-((oInfoHeader.biWidth*3)%4);
    }

    //Only 24 bit mot is encoded (1 char per color components)
    //other modes require a palette, which would be a big more
    //complicated here.
    oInfoHeader.biBitCount  = 24;
    oInfoHeader.biSizeImage = StrideSize * oInfoHeader.biHeight;
    
    //Offset & size. (File header = 14 bytes, File info = 40 bytes)
    oFileHeader.bfOffBits = 54;
    oFileHeader.bfSize =    54 + sizeof(char) * 
                            StrideSize * 
                            oInfoHeader.biHeight;

    unsigned char * pBuffer = new unsigned char[StrideSize];

    //Write header information in the bmp file.
    oFileHeader.Write(pFile);
    oInfoHeader.Write(pFile);

    //Write raster data in the bmp file.
    //The y axis is inverted in bmp files, this is why we're
    //copying lines backward.
    for(int i = oInfoHeader.biHeight-1 ;i >=0; --i)
    {
        for(int j = 0; j < oInfoHeader.biWidth; ++j)
        {
            ColorRGB PixelColor = 
                aImage.GetRasterData()[i*oInfoHeader.biWidth + j];
            PixelColor.Clamp();

            pBuffer[j*3]    =    unsigned char(PixelColor.B()*255);
            pBuffer[j*3+1]  =    unsigned char(PixelColor.G()*255);
            pBuffer[j*3+2]  =    unsigned char(PixelColor.R()*255);
        }
        fwrite(pBuffer,StrideSize,1,pFile);
    }

    delete[] pBuffer;

    fclose(pFile);
}
Exemple #3
0
void Image::gammaCorrect(float gamma) {
	ColorRGB temp;
	float power = 1.0 / gamma;
	for (int i = 0; i < nx; i++) {
		for (int j=0; j < ny; j++) {
			temp = image[i][j];
			image[i][j] = ColorRGB(pow(temp.getRed(), power), pow(temp.getGreen(), power), pow(temp.getBlue(), power));
		}
	}
}
Exemple #4
0
    ColorRGB ColorHSL::getRGB()
    {
        //Fix angle being too large or too small - that'll mess up the conversion
        while (h >= 360.f)
            h -= 360.f;
        while (h < 0.f)
            h += 360.f;

        float c = (1.f - fabs((2.f * l) - 1.f)) * s;
        float newH = h / 60.f;
        float x = c * (1.f - fabs(fmodf(newH, 2.f) - 1.f));

        float m = l - (c / 2.f);

        float rgb[3] = {0, 0, 0};

        if (0.f <= h && h < 60.f)
        {
            rgb[0] = c; rgb[1] = x;
        }
        if (60.f <= h  && h < 120.f)
        {
            rgb[0] = x; rgb[1] = c;
        }
        if (120.f <= h && h < 180.f)
        {
            rgb[1] = c; rgb[2] = x;
        }
        if (180.f <= h && h < 240.f)
        {
            rgb[1] = x; rgb[2] = c;
        }
        if (240.f <= h && h < 300.f)
        {
            rgb[0] = x; rgb[2] = c;
        }
        if (300.f <= h && h < 360.f)
        {
            rgb[0] = c; rgb[2] = x;
        }

        rgb[0] = (rgb[0] + m) * 255.f;
        rgb[1] = (rgb[1] + m) * 255.f;
        rgb[2] = (rgb[2] + m) * 255.f;

        ColorRGB color;
        color.setR((int)rgb[0]);
        color.setG((int)rgb[1]);
        color.setB((int)rgb[2]);
        return color;
    }
Exemple #5
0
int
  main (int argc, char** argv)
{
  sensor_msgs::PointCloud2 cloud_blob;
  pcl::PointCloud<PointT> cloud;

  if (pcl::io::loadPCDFile (argv[1], cloud_blob) == -1)
  {
    ROS_ERROR ("Couldn't read file test_pcd.pcd");
    return (-1);
  }
  ROS_INFO ("Loaded %d data points from test_pcd.pcd with the following fields: %s", (int)(cloud_blob.width * cloud_blob.height), pcl::getFieldsList (cloud_blob).c_str ());

  // Convert to the templated message type
  pcl::fromROSMsg (cloud_blob, cloud);
  pcl::PointCloud<PointT>::Ptr  cloud_ptr (new pcl::PointCloud<PointT> (cloud));


  pcl::PassThrough<PointT> pass;
  pass.setInputCloud (cloud_ptr);
  pass.filter (cloud);

  ROS_INFO ("Size after removing NANs : %d", (int)cloud.points.size());

  ColorRGB color;
  vector<pcl::PointPLY> points (cloud.points.size());
  for(size_t i = 0; i < cloud.points.size(); i++)
  {
      color.assignColor(cloud.points.at(i).rgb);
      points.at(i).x = cloud.points.at(i).x;
      points.at(i).y = cloud.points.at(i).y;
      points.at(i).z = cloud.points.at(i).z;
      points.at(i).r = color.getR();
      points.at(i).g = color.getG();
      points.at(i).b = color.getB();

  }

  std::string fn (argv[1]);
  fn = fn.substr(0,fn.find('.'));
  fn = fn+ ".ply";
 // pcl::io::savePCDFileASCII (fn, cloud);
  writePLY(fn,points);
  ROS_INFO ("Saved %d data points to ply file.", (int)cloud.points.size ());

  return (0);
}
Exemple #6
0
void Scene3D::render(const Camera& camera, const int imgSize, std::ostream& os)
{
	
	os << "P3 " << imgSize << " " << imgSize << " " << 255 << "\n";
	
	for (int y = 0; y < imgSize; y++)
	{
		for (int x = 0; x < imgSize; x++)
		{
			ColorRGB pixelColor = traceRay(camera.getRayForPixel(x, y, imgSize));
			pixelColor*=255;
			pixelColor.clamp_output(0,255, std::cout);
			os << "\n";
		}
	}
	
}
Exemple #7
0
//MAIN!
int main(int argc, char **argv) {
  InitializeMagick(*argv);
  Image image = magickRead("test_wallpaper.jpg");
  int a=0;
  for(a=0;a<20;a++)
    cout << "ahaha" << endl;
  ColorRGB c = image.pixelColor(0,0);
  cout << (double)(c.red()) << endl;
  cout << image.baseRows() << endl;
  cout << image.baseColumns() << endl;
  int* k = (int*) malloc(sizeof(int)*6);
  int i=0;
  for(i=0;i<6;i++)
    *(k+i) = i*2;
  getClusters(&image,k,3,1.0);
  image.write("test_output.png" );
  return 0;
}
Exemple #8
0
//inherited from BaseFeature
void ImageFeature::load(const ::std::string& filename, bool forceGray){
  //temporary pixel data
  ColorGray grayPixel;
  ColorRGB rgbPixel;
  
  if(filename.find("gray") < filename.size()) {
    forceGray=true;
  }
  
  //temporary image data
  Image loaded;
  // try {
    loaded.read(filename);
    //  } catch( Exception &error_ ) {
    // ERR << "Exception loading image: " << error_.what() << endl;
    // return;
    // }
  
  xsize_=loaded.columns();
  ysize_=loaded.rows();
  if(loaded.colorSpace()==RGBColorspace && !forceGray) {
    zsize_=3;
    DBG(30) << "found image in RGB" << endl;
  } else if ( loaded.colorSpace()==GRAYColorspace || forceGray) {
    DBG(30) << "found image in gray" << endl;
    zsize_=1;
  } else {
    ERR << "Unknown color space" << loaded.colorSpace() << endl;
  }
  
  data_.resize(zsize_);
  for(uint c=0;c<zsize_;++c) data_[c].resize(xsize_*ysize_);
  
  switch(zsize_) {
  case 1: //gray image
    DBG(30) << "Loading gray image" << endl;
    for(uint y=0;y<ysize_;++y) {
      for(uint x=0;x<xsize_;++x) {
        rgbPixel=loaded.pixelColor(x,y);
        data_[0][y*xsize_+x]=(rgbPixel.red()+rgbPixel.green()+rgbPixel.blue())/3;
      }
    }
    break;
  case 3: //rgb image
    DBG(30) << "Loading rgb image" << endl;
    for(uint y=0;y<ysize_;++y) {
      for(uint x=0;x<xsize_;++x) {
        rgbPixel=loaded.pixelColor(x,y);
        data_[0][y*xsize_+x]=rgbPixel.red();
        data_[1][y*xsize_+x]=rgbPixel.green();
        data_[2][y*xsize_+x]=rgbPixel.blue();
      }
    }
    break;
  default:
    ERR << "Unknown image format, depth=" << zsize_ << endl;
    break;
  }
}
Exemple #9
0
void Svg::addLine(const Vector2d &p1, const Vector2d &p2, const int width, const ColorRGB &color)
{
	std::stringstream ss;
	ss << SvgHelper::elemStart("line") << SvgHelper::attribute("x1", p1.x)
		<< SvgHelper::attribute("y1", p1.y)
		<< SvgHelper::attribute("x2", p2.x)
		<< SvgHelper::attribute("y2", p2.y)
		<< SvgHelper::attribute("stroke-width", width) << SvgHelper::attribute("stroke", color.toString()) << SvgHelper::emptyElemEnd();

	body += ss.str();
}
Exemple #10
0
void Svg::addText(const std::string &text, float x, const float y, const ColorRGB &color)
{
	std::stringstream ss;
	ss << "<text "
		<< SvgHelper::attribute("x", x)
		<< SvgHelper::attribute("y", y)
		<< SvgHelper::attribute("fill", color.toString())
		<< ">"
		<< text.c_str()
		<< "</text>";

	body += ss.str();
}
Exemple #11
0
double getColorDistance(ColorRGB color1, ColorRGB color2) {
  cout << "getting color distance" << endl;
  double distance = pow(color1.red()-color2.red(),2);
  distance += pow(color1.blue()-color2.blue(),2);
  distance += pow(color1.green()-color2.green(),2);
  cout << "distance is " << distance << endl;
  return distance;
}
Exemple #12
0
 /** Construct from an RGB color and an alpha component. */
 ColorRGBA(ColorRGB const & rgb_, Real a_ = 1) { c[0] = rgb_.r(); c[1] = rgb_.g(); c[2] = rgb_.b(); c[3] = a_; }
Exemple #13
0
void Svg::addPoint(const Vector2d &point, const int radius, const ColorRGB &color)
{
	std::stringstream ss;

	ss << SvgHelper::elemStart("circle");
	ss << SvgHelper::attribute("cx", point.x) << SvgHelper::attribute("cy", point.y) << SvgHelper::attribute("r", radius) << SvgHelper::attribute("fill", color.toString()) << SvgHelper::emptyElemEnd();

	body += ss.str();
}
Exemple #14
0
//----------------------------------------------------------------------------
Texture2D* Sample5::CreateTexture()
{
	if (mspTexture)
	{
		return mspTexture;
	}

	// define the properties of the image to be used as a texture
	const UInt width = 256;
	const UInt height = 256;
	const Image2D::FormatMode format = Image2D::FM_RGB888;
	const UInt bpp = Image2D::GetBytesPerPixel(format);
	ColorRGB* const pColorDst = WIRE_NEW ColorRGB[width*height];

	// create points with random x,y position and color
	TArray<Cell> cells;
	Random random;
	for (UInt i = 0; i < 10; i++)
	{
		Cell cell;
		cell.point.X() = random.GetFloat() * width;
		cell.point.Y() = random.GetFloat() * height;
		cell.color.R() = random.GetFloat();
		cell.color.G() = random.GetFloat();
		cell.color.B() = random.GetFloat();

		Float max = 0.0F;
		max = max < cell.color.R() ? cell.color.R() : max;
		max = max < cell.color.G() ? cell.color.G() : max;
		max = max < cell.color.B() ? cell.color.B() : max;
		max = 1.0F / max;
		cell.color *= max;
		cells.Append(cell);
	}

	// iterate over all texels and use the distance to the 2 closest random
	// points to calculate the texel's color
	Float max = 0;
	for (UInt y = 0; y < height; y++)
	{
		for (UInt x = 0; x < width; x++)
		{
			Float minDist = MathF::MAX_REAL;
			Float min2Dist = MathF::MAX_REAL;
			UInt minIndex = 0;

			for (UInt i = 0; i < cells.GetQuantity(); i++)
			{
				Vector2F pos(static_cast<Float>(x), static_cast<Float>(y));

				// Handle tiling
				Vector2F vec = cells[i].point - pos;
				vec.X() = MathF::FAbs(vec.X());
				vec.Y() = MathF::FAbs(vec.Y());
				vec.X() = vec.X() > width/2 ? width-vec.X() : vec.X();
				vec.Y() = vec.Y() > height/2 ? height-vec.Y() : vec.Y();

				Float distance = vec.Length();

				if (minDist > distance)
				{
					min2Dist = minDist;
					minDist = distance;
					minIndex = i;
				}
				else if (min2Dist > distance)
				{
					min2Dist = distance;
				}
			}

			Float factor = (min2Dist - minDist) + 3;
			ColorRGB color = cells[minIndex].color * factor;
			pColorDst[y*width+x] = color;

			max = max < color.R() ? color.R() : max;
			max = max < color.G() ? color.G() : max;
			max = max < color.B() ? color.B() : max;
		}
	}

	// convert and normalize the ColorRGBA float array to an 8-bit per
	// channel texture
	max = 255.0F / max;
	UChar* const pDst = WIRE_NEW UChar[width * height * bpp];
	for (UInt i = 0; i < width*height; i++)
	{
		ColorRGB color = pColorDst[i];
		pDst[i*bpp] = static_cast<UChar>(color.R() * max);
		pDst[i*bpp+1] = static_cast<UChar>(color.G() * max);
		pDst[i*bpp+2] = static_cast<UChar>(color.B() * max);
	}

	Image2D* pImage = WIRE_NEW Image2D(format, width, height, pDst);
	Texture2D* pTexture = WIRE_NEW Texture2D(pImage);
	// The texture tiles are supposed to be seamless, therefore
	// we need the UV set to be repeating.
	pTexture->SetWrapType(0, Texture2D::WT_REPEAT);
	pTexture->SetWrapType(1, Texture2D::WT_REPEAT);

	// save the texture for later reference
	mspTexture = pTexture;

	return pTexture;
}