void drawLine(SDL_Surface* dest,int x0,int y0,int x1,int y1)
 {
         int tmp;
         bool step;
        
         step=abs(y1-y0)>abs(x1-x0);
         if(step)
         {
                 swapValue(x0,y0);
                 swapValue(x1,y1);
         }
        
         if(x0>x1)
         {
                 swapValue(x1,x0);
                 swapValue(y1,y0);
         }
         float error=0.0;
         float y=y0;
         float roundError=(float)abs(y1-y0)/(x1-x0);
         int ystep=(y1>y0 ? 1 : -1);
         for(int i=x0;i<x1;i++)
         {
                 if(step)
                         putPixel(dest,y,i,255,255,255);
                 else
                         putPixel(dest,i,y,255,255,255);
                 error+=roundError;
                 if(error>=0.5)
                 {
                         y+=ystep;
                         error-=1;
                 }
         }
 }
void ACgraph::drawLine(SDL_Surface*dest, int x0, int y0, int x1, int y1){
	bool step = abs(x1 - x0) < abs(y1 - y0);

	if(step){
		swapValue(x0,y0);
		swapValue(x1,y1);
	}
	if(x1<x0){
		swapValue(x0,x1);
		swapValue(y0,y1);
	}
	float error = 0.0;
	float roundError = (float)abs(y1-y0)/(x1-x0); // approximations
	int y = y0;
	int ystep = (y1>y0? 1: -1);
	for(int i = x0; i<x1; i++){
		if(step){
			putPixel(dest,y,i,255,255,255);
		}
		else{
			putPixel(dest,i,y,255,255,255);
		}
		error+=roundError;
		if(error>=0.5){
			y+=ystep;
			error -= 1.0;
		}
	}
}
Exemple #3
0
/**
 * Sierra's Bresenham line drawing.
 * WARNING: Do not replace this with Graphics::drawLine(), as this causes issues
 * with flood fill, due to small difference in the Bresenham logic.
 */
void GfxScreen::drawLine(Common::Point startPoint, Common::Point endPoint, byte color, byte priority, byte control) {
    int16 maxWidth = _width - 1;
    int16 maxHeight = _height - 1;
    // we need to clip values here, lsl3 room 620 background picture draws a line from 0, 199 t 320, 199
    //  otherwise we would get heap corruption.
	int16 left = CLIP<int16>(startPoint.x, 0, maxWidth);
	int16 top = CLIP<int16>(startPoint.y, 0, maxHeight);
	int16 right = CLIP<int16>(endPoint.x, 0, maxWidth);
	int16 bottom = CLIP<int16>(endPoint.y, 0, maxHeight);

	//set_drawing_flag
	byte drawMask = getDrawingMask(color, priority, control);

	// horizontal line
	if (top == bottom) {
		if (right < left)
			SWAP(right, left);
		for (int i = left; i <= right; i++)
			putPixel(i, top, drawMask, color, priority, control);
		return;
	}
	// vertical line
	if (left == right) {
		if (top > bottom)
			SWAP(top, bottom);
		for (int i = top; i <= bottom; i++)
			putPixel(left, i, drawMask, color, priority, control);
		return;
	}
	// sloped line - draw with Bresenham algorithm
	int dy = bottom - top;
	int dx = right - left;
	int stepy = dy < 0 ? -1 : 1;
	int stepx = dx < 0 ? -1 : 1;
	dy = ABS(dy) << 1;
	dx = ABS(dx) << 1;

	// setting the 1st and last pixel
	putPixel(left, top, drawMask, color, priority, control);
	putPixel(right, bottom, drawMask, color, priority, control);
	// drawing the line
	if (dx > dy) { // going horizontal
		int fraction = dy - (dx >> 1);
		while (left != right) {
			if (fraction >= 0) {
				top += stepy;
				fraction -= dx;
			}
			left += stepx;
			fraction += dy;
			putPixel(left, top, drawMask, color, priority, control);
		}
	} else { // going vertical
Exemple #4
0
		void Pixmap::checkers(const rgba8& color) {
			//const int D = min(height(), width()) / 16;
			int mask;
			rgba8 colorMasked = rgba8(color.x ^ 255, color.y ^ 255, color.z ^ 255, color.w);
			for (int x = 0; x < width(); x++) {
				for (int y = 0; y < height(); y++) {
					mask = ((x & 16) == 0) ^ ((y & 16) == 0);
					if(mask)
						putPixel(x, y, colorMasked);
					else
						putPixel(x, y, color);
				}
			}
		}
Exemple #5
0
/**
 * Sierra's Bresenham line drawing.
 * WARNING: Do not replace this with Graphics::drawLine(), as this causes issues
 * with flood fill, due to small difference in the Bresenham logic.
 */
void GfxScreen::drawLine(Common::Point startPoint, Common::Point endPoint, byte color, byte priority, byte control) {
	int16 left = startPoint.x;
	int16 top = startPoint.y;
	int16 right = endPoint.x;
	int16 bottom = endPoint.y;

	//set_drawing_flag
	byte drawMask = getDrawingMask(color, priority, control);

	// horizontal line
	if (top == bottom) {
		if (right < left)
			SWAP(right, left);
		for (int i = left; i <= right; i++)
			putPixel(i, top, drawMask, color, priority, control);
		return;
	}
	// vertical line
	if (left == right) {
		if (top > bottom)
			SWAP(top, bottom);
		for (int i = top; i <= bottom; i++)
			putPixel(left, i, drawMask, color, priority, control);
		return;
	}
	// sloped line - draw with Bresenham algorithm
	int dy = bottom - top;
	int dx = right - left;
	int stepy = dy < 0 ? -1 : 1;
	int stepx = dx < 0 ? -1 : 1;
	dy = ABS(dy) << 1;
	dx = ABS(dx) << 1;

	// setting the 1st and last pixel
	putPixel(left, top, drawMask, color, priority, control);
	putPixel(right, bottom, drawMask, color, priority, control);
	// drawing the line
	if (dx > dy) { // going horizontal
		int fraction = dy - (dx >> 1);
		while (left != right) {
			if (fraction >= 0) {
				top += stepy;
				fraction -= dx;
			}
			left += stepx;
			fraction += dy;
			putPixel(left, top, drawMask, color, priority, control);
		}
	} else { // going vertical
Exemple #6
0
void Costix::DrawImage()
{
	unsigned char *p = raw;

	for( int y = 0; y < 205; y++ )
	{
		for( int x = 0; x < 192; x++ )
		{
			unsigned int color = 0;
			
			color+=(*p<<16);
			p++;

			color+=(*p<<8);
			p++;

			color+=(*p);
			p++;

			p += 3;
			
			/*if ( color == 0x00FF00 )
			{
				color = CPCPalette[ImgPalette[4]];
			}*/

			putPixel(x, y, color);
		}
	}
}
Exemple #7
0
void
Canvas::drawPoint(const Vector &position, const Color &color) {
    if (position.x >= 0 && position.y >= 0 &&
        position.x < _width && position.y < _height) {
        putPixel(position.x, position.y, position.z, color);
    }
}
Exemple #8
0
void displaySplash(char *fileName, signed char transparentColor)
{
    FILE *fp;
    unsigned short int garbage;
    unsigned int w, h;
    const SPLASH_WIDTH = 320;
    const SPLASH_HEIGHT = 200;
    unsigned int colorByte;
    
    if ((fp = fopen(fileName,"rb")) != NULL)
    {
        fscanf(fp,"%d", &garbage);
        fscanf(fp,"%d", &garbage);
        
        for (h = 0; h < SPLASH_HEIGHT; h++)
            for (w = 0; w < SPLASH_WIDTH; w++)
            {
                fscanf(fp, "%d", &colorByte);
                
                if(colorByte != transparentColor)
                    putPixel(w ,h ,colorByte);
            }
        fclose(fp);
    }
    else
        errorHandler("Could not open splash file.");
}
Exemple #9
0
static void 
writeTgaRaster(struct pam *          const pamP,
               tuple **              const tuples, 
               tuplehash             const cht,
               enum TGAbaseImageType const imgType,
               bool                  const withAlpha,
               bool                  const rle,
               unsigned char         const orgBit) {

    int* runlength;  /* malloc'ed */
    int row;

    if (rle)
        MALLOCARRAY(runlength, pamP->width);

    for (row = 0; row < pamP->height; ++row) {
        int realrow;
        realrow = (orgBit != 0) ? row : pamP->height - row - 1;
        if (rle) {
            int col;
            computeRunlengths(pamP, tuples[realrow], runlength);
            for (col = 0; col < pamP->width; ) {
                if (runlength[col] > 0) {
                    putchar(0x80 + runlength[col] - 1);
                    putPixel(pamP, tuples[realrow][col], imgType, withAlpha,
                             cht);
                    col += runlength[col];
                } else if (runlength[col] < 0) {
                    int i;
                    putchar(-runlength[col] - 1);
                    for (i = 0; i < -runlength[col]; ++i)
                        putPixel(pamP, tuples[realrow][col+i], 
                                 imgType, withAlpha, cht);
                    col += -runlength[col];
                } else
                    pm_error("Internal error: zero run length");
            }
        } else {
            int col;
            for (col = 0; col < pamP->width; ++col)
                putPixel(pamP, tuples[realrow][col], imgType, withAlpha, cht);
        }
    }
    if (rle)
        free(runlength);
}
Exemple #10
0
void drawSlowShadedTriangle(
	SDL_Surface * screen,
	int ax, int ay, int aR, int aG, int aB,
	int bx, int by, int bR, int bG, int bB,
	int cx, int cy, int cR, int cG, int cB)
{
	// number of "vertical" lines to draw
	int abmax = max(abs(bx-ax),abs(by-ay));
	int acmax = max(abs(cx-ax),abs(cy-ay));
	int imax = max( abmax, acmax );

//	printf("Trianglize (%d,%d)-(%d,%d)-(%d,%d) imax=%d\n", ax, ay, bx, by, cx, cy, imax);

	// index toward above
	int i;
	for (i = 0; i <= imax; i++)
	{
		// ab-line current position - top
		int abx = ax + ((bx - ax) * i) / imax;
		int aby = ay + ((by - ay) * i) / imax;
		int abR = aR + ((bR - aR) * i) / imax;
		int abG = aG + ((bG - aG) * i) / imax;
		int abB = aB + ((bB - aB) * i) / imax;

		// ac-line current position - bottom
		int acx = ax + ((cx - ax) * i) / imax;
		int acy = ay + ((cy - ay) * i) / imax;
		int acR = aR + ((cR - aR) * i) / imax;
		int acG = aG + ((cG - aG) * i) / imax;
		int acB = aB + ((cB - aB) * i) / imax;

//		printf("element %d (%d,%d)-(%d,%d) \n", i, abx, aby, acx, acy);
		// number of line elements to draw
		int jmax = max(abs(acx-abx), abs(acy-aby));

//		printf("(%d/%d) ", i, jmax);

		// index toward above
		int j;

		if ( jmax > 0)
		for (j = 0; j <= jmax; j++)
			putPixel(
				screen,
				abx + ((acx - abx) * j) / jmax,
				aby + ((acy - aby) * j) / jmax,
				SDL_MapRGB(screen->format,
					abR + ((acR - abR) * j) / jmax,
					abG + ((acG - abG) * j) / jmax,
					abB + ((acB - abB) * j) / jmax
				)
			);
	}

//	printf("Trianglize done\n");
}
Exemple #11
0
void BitmapRawConverter::bitmapToPixels() {
    pixels = (int *) malloc(width * height * sizeof(int));  //new int[width * height];

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            RGBApixel pxl = bitmap.GetPixel(i,j);
            putPixel(i, j, pxl);
        }
    }
}
  void MyImage::Test ()
  {
    color c;

    c.a = 1;
    for (int i = 0; i < height; i++)
    {
      c.r = c.g = c.b = float(i) / height;
      for (int j = 0; i < width; j++)
        putPixel (j, i, &c);
    }
  }
void			GlCanvas::_fillRect(ft::Rect<int> const &rect, ft::Color::t color)
{
    int const	left = std::max(rect.left, _clip.left);
    int const	top = std::max(rect.top, _clip.top);
    int const	width = std::min(rect.right, _clip.right) - left;
    int			y;

    y = std::min(rect.bottom, _clip.bottom);
    if (width > 0)
        while (--y >= top)
            putPixel(left, y, color, width);
}
Exemple #14
0
void FireWorks::DrawFXDot(float x, float y, unsigned int color)
{
	int startX = (int)x;
	int startY = (int)y;

	for ( int iY = 0; iY < BLOCK_HEIGHT; iY++ )
	{
		for ( int iX = 0; iX < BLOCK_WIDTH; iX++ )
		{
			putPixel(startX+iX, startY+iY, color);
		}
	}
}
Exemple #15
0
void TgraphPage::shiftLeft(void)
{
    shift++;
    memmove(graphBits, graphBits + 1, stride * gy - 1);
    if (shift == 30) {
        lineY(gx - 1, 0, gy - 1, 1);
        shift = 0;
    } else {
        lineY(gx - 1, 0, gy - 1, 0);
    }
    for (int y = 0; y < gy; y += 30) {
        putPixel(gx - 1, y, 1);
    }
}
void MyBrush::drawBrush( ) {
    // apply the current brush mask to image location (x,y)
    // the mouse location is in mouseDrag

    const int radius = brushUI->getRadius();
    const float pixelFlow = brushUI->getFlow();
    const Color colBrush = brushUI->getColor();
	std::cout<<"imageHeight"<<imageHeight;
	//image location
	ScreenPoint startPt = mouseDrag + ScreenVector(-radius,-radius);
	ScreenPoint endPt = mouseDrag + ScreenVector(radius,radius);

	// boundary check
	int XoFF=0;
	int YoFF=0;
	int ymin = startPt[1] ,ymax = endPt[1], xmin = startPt[0],xmax = endPt[0];
	if (ymin < 0) {
		YoFF = -ymin;
		ymin=0;
	}	
	if (ymax > imageHeight){
		ymax = imageHeight;
	}
	if (xmin < 0 ){
		XoFF = -xmin;
		xmin = 0;
	}
	if (xmax > imageWidth){
		xmax = imageWidth;
	}

	for(int i=XoFF , x  = xmin; x < xmax; x++,i++){
		
		for(int y = ymin, j= YoFF; y < ymax; y++,j++){
			const Color colImage = getPixel(x,y);
			float d = sqrt((float) (mouseDrag[0]-x)*(mouseDrag[0]-x) + (mouseDrag[1]-y)*(mouseDrag[1]-y));
			if ( d <= radius){
				putPixel(x,y, colBrush*mask[i][j]*pixelFlow + colImage*(1.0f - mask[i][j]*pixelFlow));
			}
			
			
		}

	//	j=YoFF; // reseting the mask
		
		
	}

}
Exemple #17
0
void displayHFGFile(char *fileName, unsigned char x, 
                    unsigned char y, signed char transparentByte)
{
    /* File Pointer */
    FILE *fp;
    
    /* Width; Height & Color Information */
    unsigned short int width;
    unsigned short int height;
    unsigned int w, h;
    unsigned int colorByte;

    /* The error buffer to store compound strings. */
    char errorBuffer[80];

    /* Try to open the HFG file. */
    if ((fp = fopen(fileName, "rb")) != NULL)
    {
        /* Try to read a valid image size; if not goto error handler */
        if ( (fscanf(fp, "%d", &width) + fscanf(fp, "%d", &height)) != 2)
            errorHandler("Unable to Read HFG File Width & Height.");

        /* Iterate through the image data. */
        for (h = 0; h < height; h++) 
            for (w = 0; w < width; w++)
                if ( fscanf(fp, "%d", &colorByte) != 1)
                    /* We did not read valid value. */
                    errorHandler("Invalid HFG File format."); 
                else
                    if (colorByte != transparentByte)
                        /* Move to proper location, put colorByte @ x+w, y+h */
                        putPixel((x + w), (y + h), colorByte);

        /* Make 100% sure we close the file, I ran into a bug here because In
         * displaying several pictures one after another I would be unable to
         * open another file. */
        if (fclose(fp) == EOF)
            errorHandler("Unable to close an open HFG file!");
    }
    else
    {
        /* Display */
        sprintf(errorBuffer, "Unable to open a file named: %s", fileName);
        errorHandler(errorBuffer);
    }
}
void MyBrush::filterRegion( ) {
    // apply the filter indicated by filterType to the square
    // defined by the two corner points mouseDown and mouseDrag
    // these corners are not guarenteed to be in any order
    // The filter width is given by the brush radius
	FilterType fType = brushUI->getFilterType();
	int p1x = mouseDown[0];
	int p1y = mouseDown[1];
	int p2x = mouseDrag[0];
	int p2y = mouseDrag[1];
	int xStart = min( p1x, p2x );
	int yStart = min( p1y, p2y );
	int xEnd = max( p1x, p2x );
	int yEnd = max( p1y, p2y );
	int r = p2x - p1x;
	int iSrc;
	int jSrc;
	Color origColor;
	Color **outColor;
	Color colSum;

	/*switch (fType){
	case FILTER_BLUR:*/
		
	for ( int x = xStart; x <= xEnd; x++ ){
		for ( int y = yStart; y <= yEnd; y++ ){
			colSum = Color(0,0,0);
			for ( int i = -r/2; i <= r/2; i++ ){
				iSrc = x + i;
				if ( iSrc < 0 ) iSrc = 0;
				if ( iSrc >= imageWidth ) iSrc = imageWidth - 1;
				for ( int j = -r/2; j <= r/2; j++ ){
					jSrc = y + j;
					if ( jSrc < 0 ) jSrc = 0;
					if ( jSrc >= imageHeight ) jSrc = imageHeight - 1;
					colSum += getPixel( iSrc, jSrc );
				}
				//outColor[x][y] = colSum;
			 putPixel(x,y,colSum);
			}
		}
	}
}
Exemple #19
0
int main(int argc, char *argv[]) 
{
	int width;
	int height;
	BMPfile bmpfile;	/* bmpfile is a variable of type BMPfile */
	pixel p;			/* p is a variable of type pixel */

	/* Check for the correct number of arguments. The first argument
	 * (i.e. argv[0]) is always the program name (i.e. sample), so we
	 * require argc to be at least 2.
	 */
  	if (argc < 2) 
	{
		/* Print error message and quit program */
	 	fprintf(stderr, "Usage: %s filename\n", argv[0]);
	 	exit(-1);
  	}
  
	/* Open the image file */
  	bmpfile = openBMPfile(argv[1]);

	/* Find image's dimensions */
	width = getWidth(bmpfile);
	height = getHeight(bmpfile);
	printf("This image is of size %d x %d pixels.\n", width, height);

	/* Tint the entire image blue */
	for (int y = 0 ; y < height ; y++) 
	{
		for (int x = 0 ; x < width ; x++) 
		{
			p = getPixel(bmpfile, x, y);		/* read pixel */
			p.blue = 255;						/* access and set the blue component */
			putPixel(bmpfile, p, x, y);			/* write modified pixel */
	 	}
	}

  	printf("\n");

	/* Close open image file */
  	closeBMPfile(bmpfile);
}
Exemple #20
0
void score_Score(MATCH scoredMatch){
	int xCoord, yCoord;	// Remove to new func.
	int xAccum = 0, yAccum = 0;
	int x, y;
	
	switch( scoredMatch.matchType )
	{
		case MATCH_TYPE_THREE:

			intermediateScore += SCORE_THREE_MATCH_VALUE;
			
			// What I should be doing is finding the center of three points.
			// should check some textbooks for this one perhaps.
			// {
			xAccum += scoredMatch.match.three_match.p1.x;
			yAccum += scoredMatch.match.three_match.p1.y;
			
			xAccum += scoredMatch.match.three_match.p2.x;
			yAccum += scoredMatch.match.three_match.p2.y;
			
			xAccum += scoredMatch.match.three_match.p3.x;
			yAccum += scoredMatch.match.three_match.p3.y;
			
			xCoord = (xAccum / 3) * TILE_WIDTH + BOARD_BORDER_OFFSET + 13;
			yCoord = (yAccum / 3) * TILE_WIDTH + BOARD_BORDER_OFFSET + 10;
			// }
			
			// Render the number.
			for (x = 0; x < 11; x++)
				for (y = 0; y < 8; y++)
					if (SCORE_FIFTY_PTS_TEXTURE[y][x] != 0x00)
						putPixel(x + xCoord,
								 y + yCoord, SCORE_FIFTY_PTS_TEXTURE[y][x]);
					
			
		break;
		
	}
	
	return;
}
Exemple #21
0
void TgraphPage::shiftGraph(Tframe &frame)
{
    shiftLeft();
    unsigned char color;
    switch (frame.frametype) {
        case FRAME_TYPE::I:
            color = 4;
            break;
        case FRAME_TYPE::B:
            color = 5;
            break;
        default:
        case FRAME_TYPE::P:
            color = 3;
            break;
    }
    if (frame.size) {
        lineY(gx - 1, 2, (gy - 4)*frame.size / oldmaxframesize, color);
    }
    if (isIn(frame.quant, (unsigned int)parent->qmin, (unsigned int)parent->qmax)) {
        putPixel(gx - 1, (gy - 5) * (frame.quant - parent->qmin) / (parent->qmax - parent->qmin + 1) + 2, 2);
    }
}
void			GlCanvas::_putAlphaBitmap(ft::Vec2<int> pos, uint8_t const *bitmap,
        ft::Rect<int> const &rect, int pitch, ft::Color::t color)
{
    int const		max_x = std::min(rect.right, _clip.right - pos.x);
    int const		max_y = std::min(rect.bottom, _clip.bottom - pos.y);
    int				x;
    int				y;

    y = std::max(rect.top, _clip.top - pos.y);
    while (y < max_y)
    {
        x = std::max(rect.left, _clip.left - pos.x);
        while (x < max_x)
        {
            if (bitmap[x] > 0)
                putPixel(x + pos.x, y + pos.y,
                         ft::Color::alpha(color, bitmap[x]));
            x++;
        }
        y++;
        bitmap += pitch;
    }
}
Exemple #23
0
void Costix::FilterBlocks()
{
	int minDataX = 4324;

	unsigned int colorReplace = getPixel(96, 0);
	
	for ( int y = 0; y < 205; y += 5 )
	{
		for ( int x = 0; x < 192; x += 2 )
		{
			bool isBlockOn = false;

			for ( int blockY = 0; blockY < 5; blockY++ )
			{
				for ( int blockX = 0; blockX < 2; blockX++ )
				{
					if ( m_costixMask[ (y+blockY) * 192 + x+blockX ] != 0 )
					{
						isBlockOn = true;
					}
				}
			}

			if ( !isBlockOn )
			{
				for ( int blockY = 0; blockY < 5; blockY++ )
				{
					for ( int blockX = 0; blockX < 2; blockX++ )
					{
						putPixel(x+blockX, y+blockY, colorReplace);
						//putPixel(x+blockX+1, y+blockY, colorReplace);
					}
				}
			}
		}
	}
}
Exemple #24
0
void Surface::putPixel(int x, int y, RGBAColor color) {
	putPixel(x,y, SDL_MapRGBA( raw->format , color.r , color.g , color.b, color.a ));
}
void MyBrush::drawCircle() {
  //   draw a thick circle at mouseDown with radius r
  //   the width of the circle is given by the current brush radius
	 int width = brushUI->getRadius();
	 for(int i  = 0; i<=width; i++){
	 const Color colBrush = brushUI->getColor();

	
	 int x0 = mouseDown[0];
	 int y0 = mouseDown[1];
	 int radius =  mouseDown[0] + abs( mouseDrag[0]);
	 radius += width; 
	 int x;
	 x = 0;
	
	
	 // top canvas
	 if((mouseDown[1]+radius) > imageHeight){
		radius =  imageHeight - mouseDown[1] - 1;
	 }
	 // bot canvas
	 if((mouseDown[1]-radius) < 0){
		radius = mouseDown[1] - 1;
	 }
	 //left canvas
	 if((mouseDown[0]-radius) < 0){
		radius =  mouseDown[0] - 1;
	 }
	 // right canvas
	 if((mouseDown[0]+radius) > imageWidth){
		radius = imageWidth - mouseDown[0] -1;
	 }
	 int y =  radius;

	 
	 float decision = 1 - radius ;
	 
	  putPixel(x0 + x,y0 + y,colBrush);
	  putPixel(x0 + x,y0 - y,colBrush);
	  putPixel(x0 - x,y0 + y,colBrush);
	  putPixel(x0 - x,y0 - y,colBrush);
	  putPixel(x0 + y,y0 + x,colBrush);
	  putPixel(x0 - y,y0 + x,colBrush);
	  putPixel(x0 + y,y0 - x,colBrush);
	  putPixel(x0 - y,y0 - x,colBrush);
	 while ( y >= x ) {
		 x++; 
		 if (decision < 0) { // Move East
			decision += 2 * x + 3;
			//decision += deltaE;
			//deltaE += 2; 
			//deltaSE += 2; // Update delta
		 } 
		 else { // Move SouthEast
			y--;
		
			decision += 2 * (x - y) + 5;
		
		}
		
		  putPixel(x0 + x,y0 + y,colBrush);
		  putPixel(x0 + x,y0 - y,colBrush);
		  putPixel(x0 - x,y0 + y,colBrush);
		  putPixel(x0 - x,y0 - y,colBrush);
		  putPixel(x0 + y,y0 + x,colBrush);
		  putPixel(x0 - y,y0 + x,colBrush);
		  putPixel(x0 + y,y0 - x,colBrush);
		  putPixel(x0 - y,y0 - x,colBrush);
	 }
	 }
}
void MyBrush::drawLine( ) {
    // draw a thick line from mouseDown to mouseDrag
    // the width of the line is given by the current brush radius
    const int radius = brushUI->getRadius();
    const Color colBrush = brushUI->getColor();
	int x1 = mouseDrag[0];
	int x0 = mouseDown[0];
	int y1 = mouseDrag[1];
	int y0 = mouseDown[1];
		
	if (mouseDrag[1] > imageHeight) {
		y1 = imageHeight;
	}	
	if (y1 < 0){
		y1 = 0;
	}
	if (x1 < 0 ){
		x1 = 0;
	}
	if (mouseDrag[0] > imageWidth){
		x1 = imageWidth;
	}
	int dx = x1 - x0;
	int dy = y1 - y0;
	int x = x0; 
	int	y = y0;
	putPixel(x, y,colBrush);
	
	//special cases

	//vertical line
	if( abs(dy) > 0  && dx == 0){
	
		
		if(dy>0){
			while (y < y1) {

					putPixel(x,y,colBrush);	
					y++;
			}
		}
		else{
			while (y > y1) {

					putPixel(x,y,colBrush);	
					y--;
			}
		}

	}

	

	//octant 1
	else if(dy >= 0 && dy <= dx && dx > 0){
	
		int d = 2 * dy - dx;
 		int incrE = 2 * dy;
		int incrNE = 2 * (dy - dx);
		//ScreenVector line1 = ScreenPoint(x1,y1) - ScreenPoint(x,y);
		//ScreenVector perpline = (ScreenPoint(y,x1) - ScreenPoint(y1,y));
		//ScreenVector normperpline = perpline* (1/perpline.length());
		////new points
		//ScreenPoint pt3 =  ScreenPoint(x,y) + normperpline*(radius/2);
		//ScreenPoint pt4 =  ScreenPoint(x,y) - normperpline*(radius/2);
		//ScreenPoint pt5 =  ScreenPoint(x1,y1) + normperpline*(radius/2);
		//ScreenPoint pt6 =  ScreenPoint(x1,y1) - normperpline*(radius/2);
		//
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // East Case
				else { d = d + incrNE; ++y;/*pt3[1]++;*/ } // Northeast Case
				++x;
				//pt3[0]++;
				putPixel(x,y,colBrush);	
				//putPixel(pt3[0],pt3[1],colBrush);
		}
	}
	//octant 2
	else if(dy >= dx && dx >  0  ){
		std::swap(x,y);
		std::swap(x1,y1);
		dx = x1 - x;
		dy = abs(y1 - y);

		int d = 2 * dy - dx;
 		int incrE = 2 * dy;
		int incrNE = 2 * (dy - dx);
		
	
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // East Case
				else { d = d + incrNE; ++y; } // Northeast Case
				++x;
				putPixel(y,x,colBrush);	
	
		}
	}
	
	////octant 3
	else if((dy >= abs(dx)) && dx <= 0 && dy >0){
		
		

		//std::swap(x,x1);
		std::swap(x,y);
		std::swap(x1,y1);
		std::swap(y,y1);
		std::swap(x1,x);
		

		dx = x1 - x;
		dy = abs(y1 - y);

		int d = 2 * (dy) - dx;
 		int incrE = 2 * (dy);
		int incrNE = 2 * (dy - dx);
		
		std::cout<<"x: "<<x<<std::endl;
		std::cout<<"x1: "<<x1<<std::endl;
		std::cout<<"start: "<<mouseDown[0]<<"\n";
		std::cout<<"end: "<<mouseDrag[0]<<"\n";
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // west Case
				else { d = d + incrNE; ++y; } // Northwest Case
				++x;
				putPixel(y,x,colBrush);	
	
		}
	
	
	}
	//octant 4
	else if((dy <= abs(dx)  && dx <= 0 && dy >= 0)){
		
		std::swap(x,x1);
		dx = x1 - x;
		dy = y1 - y;

		int d = 2 * (dy) - dx;
 		int incrE = 2 * (dy);
		int incrNE = 2 * (dy - dx);
		
		std::cout<<"x: "<<x<<std::endl;
		std::cout<<"x1: "<<x1<<std::endl;
		std::cout<<"start: "<<mouseDown[0]<<"\n";
		std::cout<<"end: "<<mouseDrag[0]<<"\n";
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // 
				else { d = d + incrNE; ++y; } //
				++x;
				putPixel(-x,y,colBrush);	
	
		}
		
	}
	//octant 5
	else if(dy < 0 && dx < 0 && abs(dy) <= abs(dx)  ){
		
		std::swap(x1,x);
		std::swap(y1,y);
		dx = x1 - x;
		dy = y1 - y;
		int d = 2 * dy - dx;
 		int incrE = 2 * dy;
		int incrNE = 2 * (dy - dx);
		
	
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // East Case
				else { d = d + incrNE; ++y; } // Northeast Case
				++x;
				putPixel(x,y,colBrush);	
	
		}
	
	}
	// octant 6 
	else if(dy < 0 && dx < 0 && abs(dy) >= abs(dx)){
		std::swap(x,y);
		std::swap(x1,y1);
		std::swap(x,x1);
		std::swap(y,y1);
		dx = x1 - x;
		dy = y1 - y;

		int d = 2 * dy - dx;
 		int incrE = 2 * dy;
		int incrNE = 2 * (dy - dx);
		
	
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // East Case
				else { d = d + incrNE; ++y; } // Northeast Case
				++x;
				putPixel(y,x,colBrush);	
	
		}
	}
	//octant 7 
	else if(dy<0 && dx>0 && abs(dy) >= abs(dx)){
		std::swap(x,x1);
		std::swap(x,y);
		std::swap(x1,y1);

		dx = x1 - x;
		dy = y1 - y;

		int d = 2 * dy - dx;
 		int incre = 2 * dy;
		int incrne = 2 * (dy - dx);
	
	
		while (x > x1) {
			
				if (d <= 0) d = d + incre; // east case
				else { d = d + incrne; ++y; } // southeast case
				++x;
				putPixel(-y,x,colBrush);	
	
		}
	
	}
	//octant 8 
	else if(dy <= 0 && dx > 0 && dx > abs(dy)){
		
		std::swap(x,x1);
		std::swap(y1,y);
		std::swap(x1,x);
	
		dx = x1 - x;
		dy = y1 - y;

		int d = 2 * (dy) - dx;
 		int incrE = 2 * (dy);
		int incrNE = 2 * (dy - dx);
		
	
		while (x < x1) {
			
				if (d <= 0) d = d + incrE; // west Case
				else { d = d + incrNE; ++y; } // Northwest Case
				++x;
				putPixel(-x,y,colBrush);	
	
		}
	}
	//octant 8
	/*if(dy < 0 ){
			y = -y;
			y1 = -y1;
	}
	else{
		x = x;
		y = y;
	}*/
	
	//vertical line
	/*if(dx = 0 && dy > 0){
		while(x < x1){
			putPixel(x,y,colBrush);
			y++;
		}
	}*/
//	else{
	
//	}	

}
void drawLine(raster *r, colorRGB c, pointXY *line, int numElems) {
    int i;
    for (i = 0; i < numElems; i++) putPixel(r, c, line[i]);
}
Exemple #28
0
		void Pixmap::fill(const rgba8& color)
		{
			for (int x=0; x<width(); x++)
				for (int y=0; y<height(); y++)
					putPixel(x, y, color);
		}
Exemple #29
0
SDL_Surface *textureSynthesis(SDL_Surface *inputTexture, int w, int h)
{
	debug("Making output texture\n");						//I_s
	SDL_Surface *outputTexture = createSurface(w, h);

	debug("Generating noise on output texture\n");
	noisify(outputTexture);

	debug("Making output texture Gaussian Pyramid\n");				//G_s
	gauss_pyramid *outPyramid = new gauss_pyramid(outputTexture, -1, false);

	debug("Making input texture Gaussian Pyramid\n");				//G_a
	gauss_pyramid *inPyramid = new gauss_pyramid(inputTexture, outPyramid->getLevels());
	hood_pyramid *inHoodPyramid = new hood_pyramid(inPyramid);

	debug("Beginning texture synthesis...\n");
	int l = 0;
	double totTime = 0;
#ifdef TEX_SYN_USE_MULTIRESOLUTION
	for(l = outPyramid->getLevels() - 1; l >= 0; l--)
	{
#endif
		SDL_Surface *curLevel = outPyramid->getLevel(l);
		int lvlW = curLevel->w, lvlH = curLevel->h;
		debug("\tBeginning work on %d x %d level %d of the output pyramid..\n", lvlW, lvlH, l);

		//do this in scanline order
		for(int y = 0; y < lvlH; y++)
		{
            //for timing the operation
            clock_t start = clock();
			for(int x = 0; x < lvlW; x++)
			{
				verboseDebug("\t\tCalculating color for level %d at (%d, %d)\n", l, x, y);

				//update the display
				dispSurface(curLevel);

				//calculate the color to put here
				Uint32 color = findBestMatch(inHoodPyramid, inPyramid, outPyramid, l, x, y);

				//put that color on the pyramid level
				putPixel(curLevel, x, y, color);
			}
			totTime += ((double)clock() - start) / CLOCKS_PER_SEC;
			if(y % 20 == 0)
            	debug("\t\tTwenty rows done. Average time per row: %f s*\n", totTime / (y + 1));
            	//about the seconds* there, that value is not quite seconds, but it should be close and
            	//consistant in time.
		}

#ifdef TEX_SYN_USE_MULTIRESOLUTION
		//reset the timer every level
		totTime = 0.0;

		//blur the curent level (if it isn't the last)
		if(l > 0)
			gaussianBlur(curLevel);
	}
#endif

	//reconstruct the pyramid
	SDL_Surface *toReturn = outPyramid->reconstructPyramid();

	//free output bitmap
	debug("Cleaning up\n");
	delete outPyramid;
	delete inHoodPyramid;
	delete inPyramid;

	//return it up.
	return toReturn;
}
Exemple #30
0
 void drawChicken(int offsetX, int offsetY){
    #pragma pack(push)  // push current alignment to stack
    #pragma pack(1)     // set alignment to 1 byte boundary
    typedef struct
    {
        unsigned short int Type; /* Magic identifier */
        unsigned int Size; /* File size in bytes */
        unsigned short int Reserved1;
        unsigned short int Reserved2;
        unsigned int Offset; /* Offset to data (in B)*/
    }HEADER; /* -- 14 Bytes -- */

    typedef struct
    {
        unsigned int Size; /* Header size in bytes */
        int Width;
        int Height; /* Width / Height of image */
        unsigned short int Planes; /* Number of colour planes */
        unsigned short int Bits; /* Bits per pixel */
        unsigned int Compression; /* Compression type */
        unsigned int ImageSize; /* Image size in bytes */
        int xResolution;
        int yResolution;/* Pixels per meter */
        unsigned int Colors; /* Number of colors */
        unsigned int ImportantColors;/* Important colors */
    }INFOHEADER; /* -- 40 Bytes -- */

    typedef struct
    {
        //unsigned char Alpha;
        unsigned char Blue;
        unsigned char Green;
        unsigned char Red;
    }PIXEL; /*---- 24 bytes----*/
    #pragma pack(pop)   // restore original alignment from stack


      //make instance of all three structures
        HEADER data;
        INFOHEADER data2;
        PIXEL pixel;

        //declare file read pointer
        FILE *file;

        //declare fileout read pointer
        //FILE *fileout; //declare file printed file pointer


        if( !(file = fopen( "img.bmp","r"))){
            printf("no file found in location");

        }




        //read HEADER data into data
        fread(&data,sizeof(HEADER),1,file);
        //read IB+NFOHEADER data into data2
        fread(&data2,sizeof(INFOHEADER),1,file);

        if(data2.Bits != 24){
            printf("the BMP file has to be 24 bits per pixel");
        }
        //Print PIXEL data
        fseek(file, data.Offset, 0);
        //Allocate space for pixelarray
        PIXEL **pixelarray;
        int r=0,c=0,rows=data2.Height,collumns=data2.Width;
        pixelarray= malloc(rows*sizeof(PIXEL *));

        printf("%d %d\n",rows, collumns);

        int pixelnum=1;


          // read pixel data from image
        //printf("\nPixel %10d: %02X %02X %02X",0xFF,0xFF,0xFF);
            for( r=0; r<rows; r++ )
            {
            pixelarray[r]=malloc(collumns*sizeof(PIXEL));
                for( c=0; c<collumns; c++ )     // read pixel data from image
                {
                    fread(&pixelarray[r][c] , 1, sizeof(PIXEL), file);
                    pixelnum++;

                }
            }


            printf("R:%02X G:%02X B:%02X",pixelarray[5][200].Red,pixelarray[5][200].Green,pixelarray[5][200].Blue);
             r=0;c=0;
            for(r =0; r < rows;r++){
             for(c =0; c < collumns;c++){
                  putPixel((r+1)+offsetX,(c+1)+offsetY,pixelarray[r][c].Red,pixelarray[r][c].Green,pixelarray[r][c].Blue);


             }

            }


        int picOffset = 1;


        //fill pixel array with pixel structs





        fclose(file);  //close the files prior to exiting
}