Exemplo n.º 1
0
MagickPPExport int Magick::operator == (const Magick::Color &left_,
  const Magick::Color &right_)
{
  return((left_.isValid() == right_.isValid()) &&
    (left_.redQuantum() == right_.redQuantum()) &&
    (left_.greenQuantum() == right_.greenQuantum()) &&
    (left_.blueQuantum() == right_.blueQuantum()));
}
Exemplo n.º 2
0
MagickPPExport int Magick::operator < (const Magick::Color &left_,
  const Magick::Color &right_)
{
  if(left_.redQuantum() < right_.redQuantum())
    return(true);
  if(left_.redQuantum() > right_.redQuantum())
    return(false);
  if(left_.greenQuantum() < right_.greenQuantum())
    return(true);
  if(left_.greenQuantum() > right_.greenQuantum())
    return(false);
  if(left_.blueQuantum() < right_.blueQuantum())
    return(true);
  return(false);
}
Exemplo n.º 3
0
		TmpClass(){
			Image tmp;
			GLubyte *texImage = NULL;
			mx = 0;mn = 255;
			tmp.read(greyImage);
			texture.textWidth = tmp.columns();
			texture.textHeight = tmp.rows();
			texture.texImage = new GLubyte[texture.textHeight * texture.textWidth * 3];
			texImage = texture.texImage;
			for(unsigned int i = 0;i < texture.textHeight;++ i){
				for(unsigned int j = 0, index = 3 * i * texture.textWidth;j < texture.textWidth;++ j, index += 3){
					Magick::Color c = tmp.pixelColor(j, texture.textHeight - i);
					texImage[index] = (unsigned char)c.redQuantum();
					texImage[index + 1] = (unsigned char)c.greenQuantum();
					texImage[index + 2] = (unsigned char)c.blueQuantum();
					//texImage[index + 3] = rand() / (float)RAND_MAX;
					if(texImage[index] > mx)
						mx = texImage[index];
					if(texImage[index] < mn)
						mn = texImage[index];
				}
			}
			cout << mx << ' ' << mn << endl;
			tmp.display();
		}
Exemplo n.º 4
0
//  This helper function exists because when an image includes color
//
//  0x112233
//
//  ImageMagick will represent it with high-res quanta multiplied by **257**,
//
//  0x111122223333
//
//  which will not be the same as the quantum we get programmatically from
//
//  Color("#112233")
//
//  which will be the 256x,
//
//  0x110022003300
//
//  hence not the same as the value from the file.  We can use the provided
//  macros for scaling quanta to do away with this whole mess, and so I'll
//  use my own Vector3i to represent a color.
//
//  (Why: multiplying by 257 fills up the dynamic range completely.)
//
static Vector3i sConvertColor(const Magick::Color & inColor)
{
    Vector3i outColor;
    
    outColor[0] = MagickCore::ScaleQuantumToChar(inColor.redQuantum());
    outColor[1] = MagickCore::ScaleQuantumToChar(inColor.blueQuantum());
    outColor[2] = MagickCore::ScaleQuantumToChar(inColor.greenQuantum());

/*
#if (MagickLibVersion == 0x618)
    outColor[0] = ScaleQuantumToChar(inColor.redQuantum());
    outColor[1] = ScaleQuantumToChar(inColor.blueQuantum());
    outColor[2] = ScaleQuantumToChar(inColor.greenQuantum());
#elif (MagickLibVersion == 0x628)
    outColor[0] = MagickLib::ScaleQuantumToChar(inColor.redQuantum());
    outColor[1] = MagickLib::ScaleQuantumToChar(inColor.blueQuantum());
    outColor[2] = MagickLib::ScaleQuantumToChar(inColor.greenQuantum());
#else
    outColor[0] = MagickCore::ScaleQuantumToChar(inColor.redQuantum());
    outColor[1] = MagickCore::ScaleQuantumToChar(inColor.blueQuantum());
    outColor[2] = MagickCore::ScaleQuantumToChar(inColor.greenQuantum());
#endif
*/
    return outColor;
}
Exemplo n.º 5
0
void SimWorld::renderWorld()
{
	//Create an image of the specified world size
	Magick::Image blankWorld(Magick::Geometry(worldSizeX, worldSizeY), "white");

	//Publish the world image
	sensor_msgs::Image rosImg;
	rosImg.height = worldSizeY;
	rosImg.width = worldSizeX;
	rosImg.encoding = "rgba8";
	rosImg.step = 4 * worldSizeX; //R, G, B, A = 4, at 8 bits per channel, times width

	//Copy the ImageMagick image into the message
	//TODO There may be a faster way to do this...
	for(int ii = 0; ii < worldSizeX; ii++)
	{
		for(int jj = 0; jj < worldSizeY; jj++)
		{
			Magick::Color pColor = blankWorld.pixelColor(ii, jj);
			rosImg.data.push_back(pColor.redQuantum());
			rosImg.data.push_back(pColor.greenQuantum());
			rosImg.data.push_back(pColor.blueQuantum());
			rosImg.data.push_back(pColor.alphaQuantum());
		}
	}

	//Tell the world!
	worldState.publish(rosImg);
}
Exemplo n.º 6
0
void init(const char *fileName){
	GLfloat light_position[]={ 0.0, 0.0, 10.0, 1.0 };
        GLfloat light_color[]   ={ 1.0, 1.0, 1.0, 1.0 };
        GLfloat ambient_color[] ={ 0.9, 0.3, 0.3, 1.0 };
        GLfloat mat_specular[]  ={ 1.0, 1.0, 1.0, 1.0 };
	int i = 1;

	glClearColor(0.1, 0.1, 0.1, 0);
	glEnable(GL_DEPTH);
	glShadeModel(GL_SMOOTH);
	glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE, &i ); // two-sided lighting
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular );
        glLightfv(GL_LIGHT0, GL_POSITION, light_position );
        glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color );
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_color );
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color );
	makeRamp();
	/*glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage1D(GL_TEXTURE_1D, 0, 3, width, 0, GL_RGB, GL_FLOAT, ramp[0]);
	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_1D);*/
	tmpFunc = funcs[current].func;
	normFunc = funcs[current].normFunc;
	{
		Image tmp;
		GLubyte *texImage = NULL;
		tmp.read(fileName);
		texture.textWidth = tmp.columns();
		texture.textHeight = tmp.rows();
		texture.texImage = new GLubyte[texture.textHeight * texture.textWidth * 3];
		texImage = texture.texImage;
		for(unsigned int i = 0;i < texture.textHeight;++ i){
			for(unsigned int j = 0, index = 3 * i * texture.textWidth;j < texture.textWidth;++ j, index += 3){
				Magick::Color c = tmp.pixelColor(j, texture.textHeight - i);
				texImage[index] = (unsigned char)c.redQuantum();
				texImage[index + 1] = (unsigned char)c.greenQuantum();
				texImage[index + 2] = (unsigned char)c.blueQuantum();
				//texImage[index + 3] = rand() / (float)RAND_MAX;
			}
		}
	}
        glEnable(GL_TEXTURE_2D); // allow 2D texture maps
	glEnable(GL_LIGHTING);   // so lighting models are used
        glEnable(GL_LIGHT0);     // we'll use LIGHT0
}
Exemplo n.º 7
0
int main(int argc,char **argv)
{
    try {
        yarp::sig::ImageOf<yarp::sig::PixelRgb> yimg1, yimg2;

        yimg1.resize(255,127);
        for (int i=0; i<yimg1.width(); i++) {
            for (int j=0; j<yimg1.height(); j++) {
                yarp::sig::PixelRgb& pix = yimg1.pixel(i,j);
                pix.r = ((i+j)/2)%256;
                pix.g = i%256;
                pix.b = j%256;
            }
        }

        printf("Creating a YARP image, and showing the value of one pixel\n");

        yarp::sig::PixelRgb& pixel1 = yimg1.pixel(10,20);
        printf("rgb %d %d %d\n", pixel1.r, pixel1.g, pixel1.b);

        Magick::Image mimg;
        copyImage(yimg1,mimg);

        printf("Copying image to Magick, and tracking the value of the same pixel\n");

        Magick::Color c = mimg.pixelColor(10, 20);
        printf("rgb %d %d %d\n", c.redQuantum(),c.greenQuantum(),c.blueQuantum());

        printf("Saving image as test.gif\n");
        mimg.write("test.gif");

        copyImage(mimg,yimg2);

        printf("Copying image back to YARP, and tracking the value of the same pixel\n");

        yarp::sig::PixelRgb& pixel2 = yimg2.pixel(10,20);
        printf("rgb %d %d %d\n", pixel2.r, pixel2.g, pixel2.b);
    }
    catch( Magick::Exception &error_ )
        {
            cout << "Caught exception: " << error_.what() << endl;
            return 1;
        }
    return 0;
}