Esempio n. 1
0
void intersectRP(vec4 is, float ax, float ay, float az, float bx, float by, float bz, RGB *ci, RGB ca, RGB cb, float ix){

  float my, qy, mz, qz, iy, iz;
  int rda, rdb, gra, grb, bla, blb, ird, igr, ibl, mrd, mgr, mbl, qrd, qgr, qbl;

  getRGB(ca, &rda, &gra, &bla);
  getRGB(cb, &rdb, &grb, &blb);
  if (ax==bx) {
    return;
  }
  else {
    my = (by - ay)/(bx - ax);
    qy = ay - (my*ax);
    mz = (bz - az)/(bx - ax);
    qz = az - (mz*ax);
    mrd = (int) ((rdb - rda)/(bx - ax)); 
    qrd = (int) (rdb - (mrd*ax));
    mgr = (int) ((grb - gra)/(bx - ax));
    qgr = (int) (grb - (mgr*ax));
    mbl = (int) ((blb - bla)/(bx - ax));
    qbl = (int) (blb - (mbl*ax));
    iy = my*ix + qy;
    iz = mz*ix + qz;
    ird = (int) (mrd*ix + qrd);
    igr = (int) (mgr*ix + qgr);
    ibl = (int) (mbl*ix + qbl);
    setRGB(ci, ird, igr, ibl);
    initVec4Norm(ix, iy, iz, is);
  }
}
void JointBilateralFilter::visualize(float* depth_host){

	cudaMemcpy(Filtered_Host, Filtered_Device, sizeof(float)*Width*Height, cudaMemcpyDeviceToHost);
	for(int y = 0; y < Height; y++){
		for(int x = 0; x < Width; x++){
			cv::Vec3b color;
			if(depth_host[y * Width + x] > 50.0f){
				getRGB(depth_host[y * Width + x]/ 5000.0f, color);
				InputDepth.at<cv::Vec3b>(y, x) = color;
			}
			else
				InputDepth.at<cv::Vec3b>(y, x) = cv::Vec3b(0, 0, 0);
			
			}
		}
	for(int y = 0; y < Height; y++){
		for(int x = 0; x < Width; x++){
			cv::Vec3b color2;
			if(Filtered_Host[y * Width + x] > 50.0f){
				getRGB(Filtered_Host[y * Width + x]/ 5000.0f, color2);
				OutputDepth.at<cv::Vec3b>(y, x) = color2;
			}
			else
				OutputDepth.at<cv::Vec3b>(y, x) = cv::Vec3b(0, 0, 0);
			}
		}
	cv::imshow("depth_input", InputDepth);
	cv::imshow("depth_filtered", OutputDepth);
	cv::waitKey(1);
}
Esempio n. 3
0
void SVGReader::readPath(void)
{
    Q_ASSERT(mXml.isStartElement() && mXml.name() == "path");
    QColor color;
    int pos;
    bool ok = false;
    // <path style="fill-opacity:0.230442;fill:rgb(14,9,206)" d="M 0.845225 0.845225 L 0.431106 0.585496 L 0.0788198 0.4925 L 0.0861273 0.692974 Z" />
    const QString& style = mXml.attributes().value("style").toString();
    color = getRGB(QRegExp("fill\\s*:\\s*rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)"), style, mXml, &ok);
    if (!color.isValid()) { // fallback to v0.4 format
        const QString& fill = mXml.attributes().value("fill").toString();
        color = getRGB(QRegExp("(\\d+),\\s*(\\d+),\\s*(\\d+)"), fill, mXml, &ok);
    }
    if (!ok) {
        mXml.raiseError(QObject::tr("fill not found or invalid"));
        return;
    }
    QRegExp fo_re("fill-opacity\\s*:\\s*([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)");
    pos = fo_re.indexIn(style);
    qreal alpha = (-1 != pos)? fo_re.capturedTexts().at(1).toDouble(&ok) : color.alphaF();
    if (!ok) {
        mXml.raiseError(QObject::tr("fill-opacity (%1): not found or invalid").arg(fo_re.capturedTexts().at(1)));
        return;
    }
    color.setAlphaF(alpha);
    QPolygonF polygon;
    // ... 0.0788198 0.4925 ... 3.687e-4 -0.91112 ...
    QRegExp coords_re("([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)\\s+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)");
    QString d = mXml.attributes().value("d").toString();
    while ((pos = coords_re.indexIn(d)) != -1) {
        const QStringList& xy = coords_re.capturedTexts();
        const qreal x = xy.at(1).toDouble(&ok);
        if (!ok) {
            mXml.raiseError(QObject::tr("invalid x coordinate in \"%1\"").arg(xy.at(0)));
            return;
        }
        const qreal y = xy.at(3).toDouble(&ok);
        if (!ok) {
            mXml.raiseError(QObject::tr("invalid y coordinate in \"%1\"").arg(xy.at(0)));
            return;
        }
        polygon << QPointF(x, y);
        d = d.right(d.size() - pos - xy.at(0).size() + 1);
    }
    mDNA.append(Gene(polygon, color));
    while (mXml.readNextStartElement()) {
        if (mXml.name() == "path")
            readPath();
        else
            mXml.skipCurrentElement();
    }
}
Esempio n. 4
0
void Terrain::
smoothPNG()
{
	 image<rgb_pixel> smooth(width, height);
	float* rgb = new float[3];
	
	float* mid_middle = new float[3];
	float* mid_top = new float[3];
	float* mid_bottom = new float[3];
	
	float* left_middle = new float[3];
	float* left_top = new float[3];
	float* left_bottom = new float[3];
	
	float* right_middle = new float[3];
	float* right_top = new float[3];
	float* right_bottom = new float[3];
	
	
	
	for(int z = 1; z < height - 1; z++)
	{
		for (int x = 1; x < width - 1; x++)
		{

			mid_top = getRGB(x, z-1);//2
			mid_middle = getRGB(x, z);//4
			mid_bottom = getRGB(x, z+1);//2
			
			left_top = getRGB(x-1, z-1);//1
			left_middle = getRGB(x-1, z);//2
			left_bottom = getRGB(x-1, z+1);//1
			
			right_top = getRGB(x+1, z-1);//1
			right_middle = getRGB(x+1, z);//2
			right_bottom = getRGB(x+1, z+1);//1
			
			rgb[0] = (4.0f * mid_middle[0] + 2.0f * mid_top[0] + 2.0f * mid_bottom[0] + 2.0f * left_middle[0] + 2.0f * right_middle[0] + 1.0f * left_top[0] + 1.0f * right_top[0] + 1.0f * left_bottom[0] + 1.0f * right_bottom[0]) / 16.0f;
			rgb[1] = (4.0f * mid_middle[1] + 2.0f * mid_top[1] + 2.0f * mid_bottom[1] + 2.0f * left_middle[1] + 2.0f * right_middle[1] + 1.0f * left_top[1] + 1.0f * right_top[1] + 1.0f * left_bottom[1] + 1.0f * right_bottom[1]) / 16.0f;
			rgb[2] = (4.0f * mid_middle[2] + 2.0f * mid_top[2] + 2.0f * mid_bottom[2] + 2.0f * left_middle[2] + 2.0f * right_middle[2] + 1.0f * left_top[2] + 1.0f * right_top[2] + 1.0f * left_bottom[2] + 1.0f * right_bottom[2]) / 16.0f;

			float r = (float)heightMap.get_pixel(x, z).red;
			float g = (float)heightMap.get_pixel(x, z).green;
			float b = (float)heightMap.get_pixel(x, z).blue;
			
			
			
			//cout << "(" << (float)heightMap.get_pixel(x, z).red << "," << (float)heightMap.get_pixel(x, z).green << "," << (float)heightMap.get_pixel(x, z).blue << ")";
			smooth[x][z] = rgb_pixel(rgb[0], rgb[0], rgb[0]);
		}
	}
	
	 //smooth.write("heightmaps/GoodHeightmap1Smoothing.png");
	 //image<rgb_pixel > image("heightmaps/GoodHeightmap1Smoothing.png");
	heightMap = smooth;
}
Esempio n. 5
0
void draw_voltage(int x0, int x1, double lastVoltage, double voltage) {
    rectangle r1 = {x0, x1, 0, 0};
    if(lastVoltage > voltage) {
        r1.bottom = get_height() * (lastVoltage / 3.3);
        r1.top = get_height() * (voltage / 3.3);
        fill_rectangle(r1, BLACK);
        r1.top = 0;
        r1.bottom = get_height() * (voltage / 3.3);
        fill_rectangle(r1, getRGB(255 * (voltage / 3.3), 255 * (1 - (voltage / 3.3)), 0));
    } else if(lastVoltage < voltage) {
        r1.top = 0;
        r1.bottom = get_height() * (voltage / 3.3);
        fill_rectangle(r1, getRGB(255 * (voltage / 3.3), 255 * (1 - (voltage / 3.3)), 0));
    }
}
Esempio n. 6
0
void OOFImage3D::threshold(double T) {
  vtkImageData *rgb = getRGB();
  vtkImageData *alpha = getAlpha();
  vtkImageData *gray;
  vtkImageLuminance *luminance;
  vtkImageThreshold *thold1, *thold2; 

  luminance = vtkImageLuminance::New();

  luminance->SetInputConnection(rgb->GetProducerPort());
  gray = luminance->GetOutput();
	
  thold1 = vtkImageThreshold::New();
  thold1->ThresholdByUpper(T*255);
  thold1->SetOutValue(0);
  thold1->SetInputConnection(gray->GetProducerPort());
	
  thold2 = vtkImageThreshold::New();
  thold2->ThresholdByLower(T*255);
  thold2->SetOutValue(255);
  thold2->SetInputConnection(thold1->GetOutputPort());

  gray = thold2->GetOutput();
  gray->Update();

  combineChannels(gray,alpha);
  imageChanged();

}
Esempio n. 7
0
void CameraFeed::getRGB(int x,int y,int &R, int &G, int &B) {
	if (x>_width || y>_height) return;
	DWORD Pix = getPos(x,y);
	int Y,U,V;
	getYUV(&data[Pix],Y,U,V);
	getRGB(Y,U,V,R,G,B);
}
Esempio n. 8
0
void printText( const float& x, const float& y, const string& cad, const Color color )
{
	char c[256];
	strcpy_s( c, cad.c_str() );
	RGB rgb = getRGB( color );
	glutPrint(x, y, c , rgb.r, rgb.g, rgb.b, 255);
	changeColorRGB(actualColor);
}
Esempio n. 9
0
 void JColor::setPixel(int _pixel) {
   if (hnd == _pixel) return;
   XColor color;
   color.pixel = _pixel;
   XQueryColor(JUNIX::theDisplay, JUNIX::theColormap, &color);
   value = JColor(color.red >> 8, color.green >> 8, 
     color.blue >> 8).getRGB();
   Release();
 }
Esempio n. 10
0
/*
=============
getData

Gets the image data for the specified bit depth.
=============
*/
char *getData (FILE *s, int sz, int iBits)
{
    if (iBits == 32)
        return getRGBA (s, sz);
    else if (iBits == 24)
        return getRGB (s, sz);	
    else if (iBits == 8)
        return getGray (s, sz);
}
Esempio n. 11
0
// For now, save just writes the slices as pnms.  We
// might want to implement different formats later, but for now, this
// is a sensible default since it's something we can read in easily.
void OOFImage3D::save(const std::string &filepattern) {
  vtkPNMWriter *writer;
  writer = vtkPNMWriter::New();

  padImage(-1);
  vtkImageData *rgb = getRGB();

  writer->SetFilePattern(filepattern.c_str());
  writer->SetInputConnection(rgb->GetProducerPort());
  writer->Update();
  writer->Write();

}
Esempio n. 12
0
char *getData (FILE *s, int sz, int imageWidth, int imageHeight, int iBits, int picmip)
{
	char *data;

	if (iBits == 32)
		return (char *)getRGBA (s, sz, picmip);
	else if (iBits == 24)
	{
		data = (char *)getRGB (s, sz, imageWidth, imageHeight, picmip);
		return data;
	}

	return NULL;
}
Esempio n. 13
0
void OOFImage3D::gray() {
  vtkImageData *rgb = getRGB();
  vtkImageData *alpha = getAlpha();
  vtkImageData *gray;
  vtkImageLuminance *luminance;

  luminance = vtkImageLuminance::New();

  luminance->SetInputConnection(rgb->GetProducerPort());
  gray = luminance->GetOutput();
  gray->Update();

  combineChannels(gray,alpha);
  imageChanged();

}
Esempio n. 14
0
void OOFImage3D::dim(double factor) {
  vtkImageData *rgb = getRGB();
  vtkImageData *alpha = getAlpha();
  vtkImageMathematics *dimmer;

  dimmer = vtkImageMathematics::New();
  dimmer->SetOperationToMultiplyByK();
  dimmer->SetConstantK(factor);
  dimmer->SetInputConnection(rgb->GetProducerPort());
  rgb = dimmer->GetOutput();
  rgb->SetScalarTypeToUnsignedChar();
  rgb->Update();
	
  combineChannels(rgb,alpha);
  imageChanged();

}
Esempio n. 15
0
void OOFImage3D::medianFilter(int radius) {
  padImage(-1);
  vtkImageData *rgb = getRGB();
  vtkImageData *alpha = getAlpha();
  vtkImageMedian3D *median;
	
  median = vtkImageMedian3D::New();
  median->SetKernelSize(radius*2, radius*2, radius*2);
  median->SetInputConnection(rgb->GetProducerPort());
	
  rgb = median->GetOutput();
  rgb->Update();
	
  combineChannels(rgb,alpha);
  padImage(1);
  imageChanged();
}
Esempio n. 16
0
void imageUtils::invert_color_image(ofImage* im, float color, ofTexture* t) {
    int bytes_per_pixel = im->bpp / 8;
    
    
    /*if (im->type != OF_IMAGE_COLOR_ALPHA || bytes_per_pixel != 4)
     // This function only works on RGB images.
     cout << "i guess this is the problem " << bytes_per_pixel << " " << im->type << " " << OF_IMAGE_COLOR_ALPHA << endl;
     return NULL;
     */
    int w = im->width;
    int h = im->height;
    // (t) will hold the result of the processing that we do on (im).
    //ofTexture* t = new ofTexture();
    //t->allocate(w, h, GL_RGBA);
    //cout << "what " << bytes_per_pixel << endl;
    unsigned char* im_pixels = im->getPixels(); // These are the pixel data of im,
    unsigned char* p = new unsigned char[w*h*bytes_per_pixel]; // and here's where we keep our processed pixel data.
    for (int i = 0; i < w*h; i++) {
        int base = i * bytes_per_pixel;
        
        // Assuming the pixels come in RGB order, here we grab the intensity
        // (a value in the range [0,255]) of each color channel of the image.
        unsigned char r = im_pixels[base + 0];
        unsigned char g = im_pixels[base + 1];
        unsigned char b = im_pixels[base + 2];
        unsigned char a = im_pixels[base + 3];
        
        unsigned char* rgb = getRGB(color, 255, 255);
        //unsigned char* rgb;
        
        p[base + 0] = rgb[0]; // Invert R.
        p[base + 1] = rgb[1]; // Invert G.
        p[base + 2] = rgb[2]; // Invert B.
        p[base + 3] = a; // keep alpha.
    }
    t->loadData(p, w, h, GL_RGBA); // This copies our processed pixel data into a texture that can be displayed.
    
    delete [] p; // Because loadData performed a copy, we no longer need to store the processed pixel data.
    
    return;
}  
int main(void)
{
    InicializarLEDS();
    InicializarBotones();

    //gets:
    int verde = getVerde();
    int rojo = getRojo();
    int amarillo = getAmarillo();
    int rgb = getRGB();
    int rgb_blanco = getRGBBlanco();
    int rgb_cian = getRGBCian();
    int rgb_magenta = getRGBMagenta();
    int rgb_amarillo = getRGBAmarillo();

    do {

        int tecla = EscanearTeclas();

        switch (tecla) {
        case 1:
            ParpadearLED(rgb, rgb_magenta);
            break;
        case 2:
            ParpadearLED(rojo, 0);
            break;
        case 3:
            ParpadearLED(amarillo, 0);
            break;
        case 4:
            ParpadearLED(verde, 0);
            break;
        default:
            break;
        }

    } while(1);

    return 0;
}
Esempio n. 18
0
void OOFImage3D::negate(double dummy) {
  vtkImageData *rgb = getRGB();
  vtkImageData *alpha = getAlpha();
  vtkImageMathematics *negator, *corrector;

  negator = vtkImageMathematics::New();
  negator->SetOperationToMultiplyByK();
  negator->SetConstantK(-1.0);
  negator->SetInputConnection(rgb->GetProducerPort());

  corrector = vtkImageMathematics::New();
  corrector->SetOperationToAddConstant();
  corrector->SetConstantC(255);
  corrector->SetInputConnection(negator->GetOutputPort());

  rgb = corrector->GetOutput();
  rgb->SetScalarTypeToUnsignedChar();
  rgb->Update();
	
  combineChannels(rgb,alpha);
  imageChanged();

}
Esempio n. 19
0
void OOFImage3D::fade(double factor) {
  vtkImageData *rgb = getRGB();
  vtkImageData *alpha = getAlpha();
  vtkImageMathematics *fade1, *fade2;

  fade1 = vtkImageMathematics::New();
  fade1->SetOperationToMultiplyByK();
  fade1->SetConstantK(1.0-factor);
  fade1->SetInputConnection(rgb->GetProducerPort());
	
  fade2 = vtkImageMathematics::New();
  fade2->SetOperationToAddConstant();
  fade2->SetConstantC(255*factor);
  fade2->SetInputConnection(fade1->GetOutputPort());
	
  rgb = fade2->GetOutput();
  rgb->SetScalarTypeToUnsignedChar();
  rgb->Update();
	
  combineChannels(rgb,alpha);
  imageChanged();

}
Esempio n. 20
0
void parseSVG(char* inputFile){

  Data data;  
  std::ifstream inFile(inputFile, std::ios::in);
  std::string line;
  int check=0;
  while(std::getline(inFile,line)){
    check=checkLine(line);
    if(check>0){
      
      data.rgb=getRGB(line);
      if(check==1)
	data.points=getPoints(line);
      else
	data.points=getRect(line);

      data.value=getValue(line);
      DataVect.push_back(data);
      //if(check==2)
      //data.print();
    }
  }
}
task raising()
{
	while(true)
	{
		int red=0;
		int blue=0;
		int green=0;

		getRGB(failSafe, red, green, blue);
		nxtDisplayTextLine(3, "Red:    %d",  red);
		nxtDisplayTextLine(4, "Green:  %d",  green);
		nxtDisplayTextLine(5, "Blue:   %d",  blue);

		if(joy1Btn(5))
		{
			motor[pulley]=75;
		}
		else if(joy1Btn(7))
		{
			//if(green<40||green>200)
			motor[pulley]=-10;
		}
		else if(joy2Btn(6))
		{
			motor[pulley]=75;
		}
		else if(joy2Btn(8))
		{
			motor[pulley]=-10;
		}
		else
		{
			motor[pulley]=10;
		}
		abortTimeslice();
	}
}
Esempio n. 22
0
void dumpimage(char *filename, int in_grid_array[], int in_pixels_across, int in_pixels_down,
	       int in_max_pixel_value, char input_string[], int num_colors, color_t colors[])
{
    FILE *ifp;
    int i, j, k;
#ifdef USE_PPM
    int r, g, b;
#endif

    printf("%s\nwidth: %d\nheight: %d\ncolors: %d\nstr: %s\n",
	filename, in_pixels_across, in_pixels_down, num_colors, input_string);
    fflush(stdout);

    if ( (ifp=fopen(filename, "w")) == NULL)
    {
	printf("Error, could not open output file\n");
	MPI_Abort(MPI_COMM_WORLD, -1);
	exit(-1);
    }

#ifdef USE_PPM
    fprintf(ifp, "P3\n");  /* specifies type of file, in this case ppm */
    fprintf(ifp, "# %s\n", input_string);  /* an arbitrary file identifier */
    /* now give the file size in pixels by pixels */
    fprintf(ifp, "%d %d\n", in_pixels_across, in_pixels_down);
    /* give the max r,g,b level */
    fprintf(ifp, "255\n");

    k=0; /* counter for the linear array of the final image */
    /* assumes first point is upper left corner (element 0 of array) */

    if (in_max_pixel_value < 1)
    {
	for (j=0; j<in_pixels_down; ++j) /* start at the top row and work down */
	{
	    for (i=0; i<in_pixels_across; ++i) /* go along the row */
	    {
		fprintf(ifp, "0 0 0 ");
	    }
	    fprintf(ifp, "\n"); /* done writing one row, begin next line */
	}
    }
    else
    {
	for (j=0; j<in_pixels_down; ++j) /* start at the top row and work down */
	{
	    for (i=0; i<in_pixels_across; ++i) /* go along the row */
	    {
		getRGB(colors[(in_grid_array[k] * num_colors) / in_max_pixel_value], &r, &g, &b);
		fprintf(ifp, "%d %d %d ", r, g, b); /* +1 since 0 = first color */
		++k;
	    }
	    fprintf(ifp, "\n"); /* done writing one row, begin next line */
	}
    }
#else
    fprintf(ifp, "P2\n");  /* specifies type of file, in this case pgm */
    fprintf(ifp, "# %s\n", input_string);  /* an arbitrary file identifier */
    /* now give the file size in pixels by pixels */
    fprintf(ifp, "%d %d\n", in_pixels_across, in_pixels_down);
    /* gives max number of grayscale levels */
    fprintf(ifp, "%d\n", in_max_pixel_value+1); /* plus 1 because 0=first color */

    k=0; /* counter for the linear array of the final image */
    /* assumes first point is upper left corner (element 0 of array) */

    for (j=0;j<in_pixels_down;++j) /* start at the top row and work down */
    {
	for (i=0;i<in_pixels_across;++i) /* go along the row */
	{
	    fprintf(ifp, "%d ", in_grid_array[k]+1); /* +1 since 0 = first color */
	    ++k;
	}
	fprintf(ifp, "\n"); /* done writing one row, begin next line */
    }
#endif

    fclose(ifp);
}
Esempio n. 23
0
void gDC::exec(const gOpcode *o)
{
	switch (o->opcode)
	{
	case gOpcode::setBackgroundColor:
		m_background_color = o->parm.setColor->color;
		m_background_color_rgb = getRGB(m_background_color);
		delete o->parm.setColor;
		break;
	case gOpcode::setForegroundColor:
		m_foreground_color = o->parm.setColor->color;
		m_foreground_color_rgb = getRGB(m_foreground_color);
		delete o->parm.setColor;
		break;
	case gOpcode::setBackgroundColorRGB:
		if (m_pixmap->needClut())
			m_background_color = m_pixmap->surface->clut.findColor(o->parm.setColorRGB->color);
		m_background_color_rgb = o->parm.setColorRGB->color;
		delete o->parm.setColorRGB;
		break;
	case gOpcode::setForegroundColorRGB:
		if (m_pixmap->needClut())
			m_foreground_color = m_pixmap->surface->clut.findColor(o->parm.setColorRGB->color);
		m_foreground_color_rgb = o->parm.setColorRGB->color;
		delete o->parm.setColorRGB;
		break;
	case gOpcode::setFont:
		m_current_font = o->parm.setFont->font;
		o->parm.setFont->font->Release();
		delete o->parm.setFont;
		break;
	case gOpcode::renderText:
	{
		ePtr<eTextPara> para = new eTextPara(o->parm.renderText->area);
		int flags = o->parm.renderText->flags;
		ASSERT(m_current_font);
		para->setFont(m_current_font);
		para->renderString(o->parm.renderText->text, (flags & gPainter::RT_WRAP) ? RS_WRAP : 0, o->parm.renderText->border);
		if (o->parm.renderText->text)
			free(o->parm.renderText->text);
		if (flags & gPainter::RT_HALIGN_LEFT)
			para->realign(eTextPara::dirLeft);
		else if (flags & gPainter::RT_HALIGN_RIGHT)
			para->realign(eTextPara::dirRight);
		else if (flags & gPainter::RT_HALIGN_CENTER)
			para->realign((flags & gPainter::RT_WRAP) ? eTextPara::dirCenter : eTextPara::dirCenterIfFits);
		else if (flags & gPainter::RT_HALIGN_BLOCK)
			para->realign(eTextPara::dirBlock);
		else
			para->realign(eTextPara::dirBidi);

		ePoint offset = m_current_offset;

		if (o->parm.renderText->flags & gPainter::RT_VALIGN_CENTER)
		{
			eRect bbox = para->getBoundBox();
			int vcentered_top = o->parm.renderText->area.top() + ((o->parm.renderText->area.height() - bbox.height()) / 2);
			int correction = vcentered_top - bbox.top();
			// Only center if it fits, don't push text out the top
			if (correction > 0)
			{
				offset += ePoint(0, correction);
			}
		}
		else if (o->parm.renderText->flags & gPainter::RT_VALIGN_BOTTOM)
		{
			eRect bbox = para->getBoundBox();
			int correction = o->parm.renderText->area.height() - bbox.height() - 2;
			offset += ePoint(0, correction);
		}
		if (o->parm.renderText->border)
		{
			para->blit(*this, offset, m_background_color_rgb, o->parm.renderText->bordercolor, true);
			para->blit(*this, offset, o->parm.renderText->bordercolor, m_foreground_color_rgb);
		}
		else
		{
			para->blit(*this, offset, m_background_color_rgb, m_foreground_color_rgb);
		}
		delete o->parm.renderText;
		break;
	}
	case gOpcode::renderPara:
	{
		o->parm.renderPara->textpara->blit(*this, o->parm.renderPara->offset + m_current_offset, m_background_color_rgb, m_foreground_color_rgb);
		o->parm.renderPara->textpara->Release();
		delete o->parm.renderPara;
		break;
	}
	case gOpcode::fill:
	{
		eRect area = o->parm.fill->area;
		area.moveBy(m_current_offset);
		gRegion clip = m_current_clip & area;
		if (m_pixmap->needClut())
			m_pixmap->fill(clip, m_foreground_color);
		else
			m_pixmap->fill(clip, m_foreground_color_rgb);
		delete o->parm.fill;
		break;
	}
	case gOpcode::fillRegion:
	{
		o->parm.fillRegion->region.moveBy(m_current_offset);
		gRegion clip = m_current_clip & o->parm.fillRegion->region;
		if (m_pixmap->needClut())
			m_pixmap->fill(clip, m_foreground_color);
		else
			m_pixmap->fill(clip, m_foreground_color_rgb);
		delete o->parm.fillRegion;
		break;
	}
	case gOpcode::clear:
		if (m_pixmap->needClut())
			m_pixmap->fill(m_current_clip, m_background_color);
		else
			m_pixmap->fill(m_current_clip, m_background_color_rgb);
		delete o->parm.fill;
		break;
	case gOpcode::blit:
	{
		gRegion clip;
				// this code should be checked again but i'm too tired now

		o->parm.blit->position.moveBy(m_current_offset);

		if (o->parm.blit->clip.valid())
		{
			o->parm.blit->clip.moveBy(m_current_offset);
			clip.intersect(gRegion(o->parm.blit->clip), m_current_clip);
		} else
			clip = m_current_clip;

		m_pixmap->blit(*o->parm.blit->pixmap, o->parm.blit->position, clip, o->parm.blit->flags);
		o->parm.blit->pixmap->Release();
		delete o->parm.blit;
		break;
	}
	case gOpcode::setPalette:
		if (o->parm.setPalette->palette->start > m_pixmap->surface->clut.colors)
			o->parm.setPalette->palette->start = m_pixmap->surface->clut.colors;
		if (o->parm.setPalette->palette->colors > (m_pixmap->surface->clut.colors-o->parm.setPalette->palette->start))
			o->parm.setPalette->palette->colors = m_pixmap->surface->clut.colors-o->parm.setPalette->palette->start;
		if (o->parm.setPalette->palette->colors)
			memcpy(m_pixmap->surface->clut.data+o->parm.setPalette->palette->start, o->parm.setPalette->palette->data, o->parm.setPalette->palette->colors*sizeof(gRGB));

		delete[] o->parm.setPalette->palette->data;
		delete o->parm.setPalette->palette;
		delete o->parm.setPalette;
		break;
	case gOpcode::mergePalette:
		m_pixmap->mergePalette(*o->parm.mergePalette->target);
		o->parm.mergePalette->target->Release();
		delete o->parm.mergePalette;
		break;
	case gOpcode::line:
	{
		ePoint start = o->parm.line->start + m_current_offset, end = o->parm.line->end + m_current_offset;
		if (m_pixmap->needClut())
			m_pixmap->line(m_current_clip, start, end, m_foreground_color);
		else
			m_pixmap->line(m_current_clip, start, end, m_foreground_color_rgb);
		delete o->parm.line;
		break;
	}
	case gOpcode::addClip:
		m_clip_stack.push(m_current_clip);
		o->parm.clip->region.moveBy(m_current_offset);
		m_current_clip &= o->parm.clip->region;
		delete o->parm.clip;
		break;
	case gOpcode::setClip:
		o->parm.clip->region.moveBy(m_current_offset);
		m_current_clip = o->parm.clip->region & eRect(ePoint(0, 0), m_pixmap->size());
		delete o->parm.clip;
		break;
	case gOpcode::popClip:
		if (!m_clip_stack.empty())
		{
			m_current_clip = m_clip_stack.top();
			m_clip_stack.pop();
		}
		break;
	case gOpcode::setOffset:
		if (o->parm.setOffset->rel)
			m_current_offset += o->parm.setOffset->value;
		else
			m_current_offset  = o->parm.setOffset->value;
		delete o->parm.setOffset;
		break;
	case gOpcode::waitVSync:
		break;
	case gOpcode::flip:
		break;
	case gOpcode::flush:
		break;
	case gOpcode::sendShow:
		break;
	case gOpcode::sendHide:
		break;
#ifdef USE_LIBVUGLES2
	case gOpcode::setView:
		break;
#endif
	case gOpcode::enableSpinner:
		enableSpinner();
		break;
	case gOpcode::disableSpinner:
		disableSpinner();
		break;
	case gOpcode::incrementSpinner:
		incrementSpinner();
		break;
	default:
		eFatal("illegal opcode %d. expect memory leak!", o->opcode);
	}
}
Esempio n. 24
0
void UnsharpMasking::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
    float* lumMap = new float[info.width*info.height];
	int width = mipMapSize[info.level].width();
	if (type == 0) //classic unsharp masking
	{
        float* uvMap = new float[info.width*info.height*2];
		LightMemoized lVec(info.light.X(), info.light.Y());
        
		#pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
            int offsetBuf = (y-info.offy)*info.width<<2;
			int offset = y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				float r = redPtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(redPtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
                float g = greenPtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(greenPtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
                float b = bluePtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(bluePtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
				getYUV(r, g, b, lumMap[offset2], uvMap[offset2*2], uvMap[offset2*2 + 1]);
				offset++;
				offset2++;
			}
		}
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset2 =(y - info.offy)*info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lumMap[offset2] * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset2 =(y - info.offy)*info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float r, g, b;
					getRGB(lumMap[offset2], uvMap[offset2*2], uvMap[offset2*2 +1], r, g, b);
					buffer[offsetBuf] = tobyte(r*255);
					buffer[offsetBuf + 1] = tobyte(g*255);
					buffer[offsetBuf + 2] = tobyte(b*255);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		delete[] uvMap;
	}
	else //luminance unsharp masking
	{
        #pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
			int offset= y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				lumMap[offset2] = getLum(normalsPtr[offset], info.light);
				offset++;
				offset2++;
			}
		}
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
		LightMemoized lVec(info.light.X(), info.light.Y());
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset = y * width + info.offx;
				int offset2 = (y - info.offy)*info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float lum = lumMap[offset2];
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lum / 2.0 * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset++;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset = y * width + info.offx;
				int offset2 = (y - info.offy)*info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float lum = lumMap[offset2];
					buffer[offsetBuf] = tobyte(redPtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(redPtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 1] = tobyte(greenPtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(greenPtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 2] = tobyte(bluePtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(bluePtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset++;
					offset2++;
				}
			}
		}
	}
	delete[] lumMap;
}
void SpecificWorker::getImage(ColorSeq& color, DepthSeq& depth, PointSeq& points, RoboCompJointMotor::MotorStateMap &hState, RoboCompDifferentialRobot::TBaseState& bState)
{
	getDepth(depth,hState,bState);
	getRGB(color,hState,bState);
	getXYZ(points,hState,bState);
}
Esempio n. 26
0
    void putEmergencyFont(K_Surface *screen, int xpos, int ypos, int scrw, int scrh, uint16 color, const char *buf)
    {
        const byte *buffer = (const byte *)buf;
        
        int clipw = 0;
        
        int px = xpos;
        int py = ypos;
        if ( SDL_MUSTLOCK(screen) ) {
            if ( SDL_LockSurface(screen) < 0 ) {
                //printf("putEmergencyFont(): Lock 실패\n");
                warning("putEmergencyFont(): Lock 실패\n");
                return;
            }
        }
        uint16 *dst;
        
        int c;
        
        int w = 8;
        int h = _engFontHeight;
        
        int engMargin = 0;
        
        do {
            c = *buffer++;
            if (c == 0) {
                break;
            }
            if (c == 0x0B)
                continue;
            if (c == '\\') {
                if ( *buffer == 'n' || *buffer == 'N' ) {
                    buffer++;
                    px = xpos;
                    py += h + 2;
                    dst = (uint16 *)screen->pixels + py * screen->pitch / 2 + px;
                } else if (*buffer == 'c' || *buffer == 'C' )	{
                    uint8 d = *buffer++;
                    if (color)	// 검은색(0,0,0)이 아니라면
                        color = getRGB(screen, _kPalette[d].r, _kPalette[d].g, _kPalette[d].b);
                }
                continue;
            } else if ( c == 13 ) {
                if ( *buffer == 10 ) {
                    px = xpos;
                    py += h + 2;
                }
                continue;
            }
            if (c & 0x80) {
                c += (*buffer++) * 256;	//LE
                w = _korFontWidth;
                h = _korFontHeight;
                engMargin = 0;
            } else {
                w = getEngWidth(c);
                h = _engFontHeight;
                engMargin = getTopMargin(c);
            }
            
            if(px < 0 || px + w > (scrw + (1 - clipw))) {	// 가로로 화면 밖
				px = xpos;
				py += h + 2;
            }
            dst = (uint16 *)screen->pixels + (py + engMargin) * screen->pitch / 2 + px;
            
            int offsetX[9] = { -1,  0, 1, 1, 1, 0, -1, -1, 0 };
            int offsetY[9] = {  -1, -1, -1, 0, 1, 1, 1, 0, 0 };
            int cTable[9] =  {  0,  0, 0, 0, 0, 0, 0, 0, color };
            int i = 0;
            
            int showShadow = 1;
            
            if (!showShadow)
                i = 8;
            
            for (; i < 9; i++) {
                dst = (uint16 *)screen->pixels + (py + engMargin + offsetY[i]) * screen->pitch / 2 + (px + offsetX[i]);
                putEmergencyChar(dst, (screen->pitch / 2), cTable[i], c);
            }
            dst += w;
            px += w;
        } while (1);
        
        if(SDL_MUSTLOCK(screen))
            SDL_UnlockSurface(screen);
    }
Esempio n. 27
0
Color CameraFeed::getColor(int Y,int U,int V) {
	int R,G,B;
	getRGB(Y,U,V,R,G,B);
	return Color(R,G,B);
}
Esempio n. 28
0
Color CameraFeed::getColor(BYTE *data) {
	int R,G,B;
	getRGB(data,R,G,B);
	return Color(R,G,B);
}
Esempio n. 29
0
void CameraFeed::getRGB(BYTE *data,int &R,int &G,int &B) {
	int Y,U,V;
	getYUV(data,Y,U,V);
	getRGB(Y,U,V,R,G,B);
}
Esempio n. 30
0
Color CameraFeed::getColor(int x,int y) {
	int R,G,B;
	getRGB(x,y,R,G,B);
	return Color(R,G,B);
}