Ejemplo n.º 1
0
void FloatImage::write_pgm(char *filename, float mini, float maxi)
{
  int i,j;
  int count = xsize * ysize;

  /* maybe find minimum and maximum values */

  float min = mini;
  float max = maxi;

  if (min == 0 && max == 0) {

    get_extrema (min, max);

    if (max == min)
      min = max - 1;
  }

  unsigned char *image_data;
  image_data = new unsigned char [count];

  for (j = 0; j < ysize; j++)
    for (i = 0; i < xsize; i++) {

      int val = (int) (255 * (pixel(i,j) - min) / (max - min));

      /* clamp values */
      if (val < 0) val = 0;
      if (val > 255) val = 255;
      image_data[i+j*xsize] = val;
    }

  int fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0666);
  if (fd < 0) {
    fprintf(stderr, "Unable to open %s: %s\n", filename, strerror(errno));
    exit(-1);
  }

  char str[80];
  sprintf (str, "P5\n%d %d\n255\n", xsize, ysize);
  int cc = write(fd, str, strlen(str));
  if (cc == -1) {
    fprintf (stderr, "Can't write to file.\n");
    exit (-1);
  }

  cc = write(fd, image_data, sizeof(unsigned char) * xsize * ysize);

  if (cc != sizeof(unsigned char) * xsize * ysize) {
    fprintf(stderr, "Write returned short: %s\n", strerror(errno));
    close(fd);
    exit(-1);
  }

  close(fd);
}
Ejemplo n.º 2
0
void Bitmap::premultiplyAlpha()
{
  if(!premultiplied)
  {
    for(uint32_t x=0; x<width; ++x)
    {
      for(uint32_t y=0; y<height; ++y)
      {
        common::Color c = pixel(x,y);
        float a = c.fv[3];
        c.fv[0] = c.fv[0]*a;
        c.fv[1] = c.fv[1]*a;
        c.fv[2] = c.fv[2]*a;
        pixel(x,y,c);
      }
    }
    premultiplied = true;
  }
}
Ejemplo n.º 3
0
void Bitmap::draw(uint32_t x, uint32_t y, lost::shared_ptr<Bitmap> target)
{
  for(uint32_t cy=0; cy<height; ++cy)
  {
    for(uint32_t cx=0; cx<width; ++cx)
    {
      target->pixel(x+cx, y+cy, pixel(cx, cy));
    }
  }
}
Ejemplo n.º 4
0
void ShowSubdiv(HWND hw)
{
	HDC	dc = GetDC	(hw);

	u32 CB = RGB(255,0,0);
	for (int z=0; z<dimZ; z++)
	{
		for (int x=0; x<dimX; x++)
		{
			Texel&	T	= texels[z*dimX+x];
			if (T.N)	{
				pixel	(dc,x,z,RGB(127,127,127));
				vertex&	N = *T.N;

				int		_x=x*3,_y=z*3;
				if		(isBorder(N,0))	{		// left
					SetPixel(dc,_x,_y+0,CB);
					SetPixel(dc,_x,_y+1,CB);
					SetPixel(dc,_x,_y+2,CB);
				}
				if		(isBorder(N,1))	{		// fwd
					SetPixel(dc,_x+0,_y,CB);
					SetPixel(dc,_x+1,_y,CB);
					SetPixel(dc,_x+2,_y,CB);
				}
				if		(isBorder(N,2))	{		// right
					SetPixel(dc,_x+2,_y+0,CB);
					SetPixel(dc,_x+2,_y+1,CB);
					SetPixel(dc,_x+2,_y+2,CB);
				}
				if		(isBorder(N,3))	{		// back
					SetPixel(dc,_x+0,_y+2,CB);
					SetPixel(dc,_x+1,_y+2,CB);
					SetPixel(dc,_x+2,_y+2,CB);
				}
			} else {
				pixel	(dc,x,z,RGB(0,127,0));
			}
		}
	}

	ReleaseDC		(hw, dc);
}
Ejemplo n.º 5
0
int clear(int sx, int sy, int ex, int ey)
{
	for(int j=sy; j<ey; j++)
	{
		for(int i=sx; i<ex; i++)
		{
			pixel(i, j, 0, 0, 0);
		}
	}
}
Ejemplo n.º 6
0
Array<Vector<T,3>,2> Image<T>::median(const vector<Array<const Vector<T,3>,2> >& images) {
  GEODE_ASSERT(images.size());
  int n = (int)images.size();
  for (int k=1;k<n;k++)
    GEODE_ASSERT(images[0].sizes()==images[k].sizes());

  Array<T,2> pixel(3,n);
  Array<Vector<T,3>,2> result(images[0].sizes());
  for(int t=0; t<result.flat.size(); t++){
    for (int k=0;k<n;k++)
      images[k].flat[t].get(pixel(0,k),pixel(1,k),pixel(2,k));
    for (int a=0;a<3;a++) {
      RawArray<T> samples = pixel[a];
      nth_element(&samples[0],&samples[n/2],&samples[n-1]);
      result.flat[t][a] = samples[n/2];
    }
  }
  return result;
}
void Utility::Yuv422FileSaver::savePacked() {
	for(std::size_t k=0; k<video_->getNumberOfFrames()&&isRunning_; k++) {
		auto frame=video_->getFrame(k);
		for(int i=0; i<width_*height_; i+=2) {
			int y1=i/width_;
			int x1=i%width_;
			int y2=(i+1)/width_;
			int x2=(i+1)%width_;

			if(!frame->valid(x1,y1)||!frame->valid(x2,y2)) {
				qDebug()<<"Wrong pixel coordinates";
				continue;
			}

			auto vec=Rgb888ToYuv422(frame->pixel(x1,y1),frame->pixel(x2,y2));
			dataStream_<<vec.getU()<<vec.getY1()<<vec.getV()<<vec.getY2();
		}
	}
}
Ejemplo n.º 8
0
 void copyToLedsArray(uint8_t (*state)[WIDTH][HEIGHT]) {
     for (int x = 0; x < WIDTH; x++) {
         for (int y = 0; y < HEIGHT; y++) {
             uint8_t hugh = (*state)[x][y];
             if (hugh > 0) {
                 pixel(x, y) = CHSV(hugh, 255, 255);
             }
         }
     }      
 }
Ejemplo n.º 9
0
/// Allow access to these pixels.
void asf::parameter_float_image::pixel_setsize(const pixel_rectangle &pixel_meta,int zoom_meta)
{
	super::pixel_setsize(pixel_meta,zoom_meta);
	int new_dx=bands(), new_dy=bands()*pixel().size_x();
	if ((data!=0) && (new_dx==xd) && (new_dy==yd))
		{ /* then re-use existing buffer--it's still OK. */ }
	else { /* Have to allocate a new buffer */
		data_alloc(src_alloc,0,new_dx,new_dy);
	}
}
void mycircle(int a,int b,int r,int c)
{
    int p=1-r,x=0,y=r;
    pixel(a,b,x,y,c);
    while(x<y)
    {
      if(p<0)
      {
      x++;
      p=p+(2*x)+1;
      }
      else
      {
      x++;
      y--;
      p=p+(2*x)-(2*y)+1;
      }
      pixel(a,b,x,y,c);
  }
}
Ejemplo n.º 11
0
void spinHue(void) {
  static float angle = 0.0f;
  angle += 0.001;
  if (angle > PI * 2) angle -= PI * 2;
  
  pixel(
      64.0f * (sin(angle + circleThird(0)) + 1.0f),
      64.0f * (sin(angle + circleThird(1)) + 1.0f),
      64.0f * (sin(angle + circleThird(2)) + 1.0f)
    );
}
Ejemplo n.º 12
0
	Rect CoordConverter::screenToWindow(const Window& window, const URect& rect)
	{
		Vector2 base(getBaseValue(window));
		Rect pixel(rect.asAbsolute(System::getSingleton().getRenderer()->getSize()));

		// negate base position
		base.d_x = -base.d_x;
		base.d_y = -base.d_y;

		return pixel.offset(base);
	}
Ejemplo n.º 13
0
Archivo: svg.c Proyecto: Chuongv/uTox
static void drawcircle(uint8_t *data, int width) {
    int x, y;
    double hw = (double)width / 2.0 - 0.5;
    for(y = 0; y != width; y++) {
        for(x = 0; x != width; x++) {
            double dx = (x - hw), dy = (y - hw);
            double d = sqrt(dx * dx  + dy * dy) - hw + 0.5;
            *data++ = pixel(d);
        }
    }
}
Ejemplo n.º 14
0
void vga_fill(int w, int h, int x, int y, int c)
{
    int tx,ty;
    
    for(ty = y; ty < y+h; ty++){
        for(tx = x; tx < x+w; tx++){
            pixel(tx,ty,c);
        }
    }

}
Ejemplo n.º 15
0
int noise(void)
{
	for(int j=96; j<yres; j++)
	{
		for(int i=0; i<xres; i++)
		{
			char r=rand()>>23-1;
			pixel(i, j, r, r, r);
		}
	}
}
Ejemplo n.º 16
0
Archivo: color.hpp Proyecto: 8l/x11
      void free_color()
	{
	  unsigned long pixels[2];
	  pixels[0] = pixel();

	  XFreeColors ( m_display,
			m_map,
			pixels,
			1,
			0 );
	}
Ejemplo n.º 17
0
void vga_fill_grad(int w, int h, int x, int y)
{
    int tx,ty;
    
    for(ty = y; ty < y+h; ty++){
        for(tx = x; tx < x+w; tx++){
            pixel(tx,ty,128 + ty/4);
        }
    }

}
Ejemplo n.º 18
0
void Picasso::circle (unsigned int x, unsigned int y, unsigned int r) {
  float rads = 0;
  
  for(float da = 1; da <= 360; da++) {
    rads = da / 180 * 3.14;
    
    pixel(
      x + (unsigned int)(cos(rads) * r),
      y + (unsigned int)(sin(rads) * r)
    );
  }
};
Ejemplo n.º 19
0
Archivo: svg.c Proyecto: Chuongv/uTox
static void drawcross(uint8_t *data, int width) {
    int x, y;
    double hw = 0.5 * (double)(width - 1);
    double w = 0.0625 * (double)width;
    for(y = 0; y != width; y++) {
        for(x = 0; x != width; x++) {
            double dx = fabs(x - hw), dy = fabs(y - hw);
            double d = fmin(dx, dy) - w;
            *data++ = pixel(d);
        }
    }
}
Ejemplo n.º 20
0
lost::shared_ptr<Bitmap> Bitmap::rotCW()
{
  shared_ptr<Bitmap> result(new Bitmap(height, width, COMPONENTS_RGBA));
  for(uint32_t y=0; y<height; ++y)
  {
    for(uint32_t x=0; x<width; ++x)
    {
      result->pixel(y, x, pixel((width-1)-x,y));
    }
  }
  return result;
}
Ejemplo n.º 21
0
void Bitmap::filledRect(const common::Color& col, uint32_t posx, uint32_t posy, uint32_t sizew, uint32_t sizeh)
{
  uint32_t maxx = posx+sizew;
  uint32_t maxy = posy+sizeh;
  for(uint32_t x=posx; x<maxx; ++x)
  {
    for(uint32_t y=posy; y<maxy; ++y)
    {
      pixel(x,y,col);
    }
  }
}
Ejemplo n.º 22
0
//----------------------------------------------------------------------------//
Rectf CoordConverter::screenToWindow(const Window& window, const URect& rect)
{
    Vector2f base(getBaseValue(window));
    Rectf pixel(asAbsolute(rect, window.getRootContainerSize()));

    // negate base position
    base.d_x = -base.d_x;
    base.d_y = -base.d_y;

    pixel.offset(base);
    return pixel;
}
Ejemplo n.º 23
0
	void eHealthDisplayClass::initValuesScreen()
	{
		bodyPosition = 0;
		oxygen = 0;

		eHealth.initPositionSensor();	delay(50);
		eHealth.initPulsioximeter();	delay(50);
		clearLCD();		delay(50);

		coordinates(99, 60);	writeLCD("Pose");			delay(100);
		coordinates(1,60);	writeLCD("CURRENT DATA");		delay(100);
		coordinates(1, 47);	writeLCD("Pulse (bpm)");		delay(100);
		coordinates(1, 35);	writeLCD("Conductance");		delay(100);
		coordinates(1, 22);	writeLCD("Oxygen");			delay(100);
		coordinates(90, 22);	writeLCD("%");				delay(100);
		coordinates(1, 9);	writeLCD("Temperature");		delay(100);
		coordinates(105, 9);	writeLCD("C");				delay(100);

		pixel (103,9,1);	pixel (104,9,1);
		pixel (103,8,1);	pixel (104,8,1);
	}
Ejemplo n.º 24
0
// 横向
static void display(int x, int y, unsigned char* lattice, int width, int height)
{
    char tmp = 0;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            //tmp = lattice[i * width + j];
            tmp = *lattice++;
            if (tmp & 0x01)
                pixel(x + j, y + i, 0);
            else
                pixel(x + j, y + i, 0xffffff);
            //Sleep(10);
            //myrefresh();
        }
        //Sleep(1000);
        //myrefresh();
    }
    myrefresh();
}
Ejemplo n.º 25
0
 void tick(unsigned long t) {
   for(int col = 0; col < width; col++) {
     for( int row = 0; row < height; row++) {
       uint8_t s = sin8(col * 3 + t);
       uint8_t c = cos8(row * 2 + t);
       
       pixel(col, row) = qadd8(s, c);
     }
   }
     
   rotate(rotation+2);    
 }
Ejemplo n.º 26
0
void Texture::copyTo(Texture* destination, unsigned int destinationX, unsigned int destinationY, unsigned int sourceX, unsigned int sourceY, unsigned int sourceWidth, unsigned int sourceHeight)
{
    if (sourceWidth == 0) sourceWidth = width();
    if (sourceHeight == 0) sourceHeight = height();

    for (unsigned int y = 0; y != sourceHeight; y++)
    {
        for(unsigned int x = 0; x != sourceWidth; x++)
        {
            destination->setPixel(destinationX + x, destinationY + y, pixel(sourceX + x, sourceY + y));
        }
    }
}
Ejemplo n.º 27
0
/* an improved Bresenham line drawing alogrithm
   from http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html */
void Facade::line(int x1, int y1, int x2, int y2)
{
    int dy = y2 - y1;
    int dx = x2 - x1;
    int stepx, stepy;

    if(dy < 0) {
        dy = -dy;
        stepy = -1;
    }
    else {
        stepy = 1;
    }
    if(dx < 0) {
        dx = -dx;
        stepx = -1;
    }
    else {
        stepx = 1;
    }
    dy <<= 1;                                                  // dy is now 2*dy
    dx <<= 1;                                                  // dx is now 2*dx

    pixel(x1, y1);
    if(dx > dy)
    {
        int fraction = dy - (dx >> 1);                         // same as 2*dy - dx
        while(x1 != x2)
        {
            if(fraction >= 0)
            {
                y1 += stepy;
                fraction -= dx;                                // same as fraction -= 2*dx
            }
            x1 += stepx;
            fraction += dy;                                    // same as fraction -= 2*dy
            pixel(x1, y1);
        }
    }
Ejemplo n.º 28
0
	void Image<T>::fillRectangle(ushort x,ushort y,ushort w,ushort h,T degre)
	{
	    /**
	    @brief : on parcours l'image et on l'a remplie
	    **/
	       for(ushort j = y ; j < y + h  ; j++)
            {
               for(ushort i = x ; i < x + w  ; i++)
                {
                    pixel(i,j) = degre;
                }
            }
	}
Ejemplo n.º 29
0
void Screen::draw(Drawable *drawable,float scale){
	vector<Pixel> explosion_coordinate=drawable->getPixels();
	vector<Pixel>::iterator it;
	vector<Pixel> result;
	int x_center=0,ycenter=0;
	int numb_of_pixels=0;
	for(it=explosion_coordinate.begin();it!=explosion_coordinate.end();it++){
		Point point((int)(scale*(it->getPosition().x)),(int)(scale*(it->getPosition().y)));
		Pixel pixel(point,it->getColor());		
		result.push_back(pixel);
	}
	for(it=result.begin();it!=result.end();it++) drawPixel(*it); 
}
cinder::Surface ColorAlgoGen::crossOver(const cinder::Surface& s1, const cinder::Surface& s2) const
{
    cinder::Surface crossOver = s1.clone();

    auto s1Iter = crossOver.getIter();
    auto s2Iter = s2.getIter();

    while (s1Iter.line() && s2Iter.line())
    {
        while (s1Iter.pixel() && s2Iter.pixel())
        {
            if(RANDOMIZER.nextBool())
            {
                s1Iter.r() = s2Iter.r();
                s1Iter.g() = s2Iter.g();
                s1Iter.b() = s2Iter.b();
            }
        }
    }

    return crossOver;
}