示例#1
0
static void
copy(statusbox *box, statusbox *dup)
{
  sendsuper(vobjectCOPY,(box,dup));
  send(box, statusboxZERO, (dup));

  if (box->message) 
    dup->message = vstrClone(box->message);

  dup->wholeshared = vFALSE;
  if (box->wholeimage)
    dup->wholeimage = vimageClone(box->wholeimage);
  else
    dup->wholeimage = NULL;

  dup->pieceshared = vFALSE;
  if (box->pieceimage)
    dup->pieceimage = vimageClone(box->pieceimage);
  else
    dup->pieceimage = NULL;

  if ((dup->number = box->number)) 
    makeimage(dup); /* after check images */

  dup->gmode   = box->gmode;
  dup->flashes = 0;
  dup->delay   = box->delay;

  return;
}
示例#2
0
/**
 * Calculate the mandelbrot set
 * standard: flops=mandelbrotX(img,4096,-2.0,1.0,1.5,-1.5);
 */
int main(void) {
  double secs,flops;
  IMAGE *img=makeimage(1024,1024);
  start_timer();
  flops=mandelbrot(img,4096,-1.2,-0.7,0.5,0.0);
  secs = stop_timer();
  printf("%10.3e %10.3e %10.3e\n",secs,flops,1.0e-9*flops/secs);
  saveimage(img,"mandel.ppm");
  return 0;
}
示例#3
0
static void
setrect(statusbox *box, const vrect *r)
{
  sendsuper(vdialogSET_ITEM_RECT, (box,r));
  if (box->image) {
    vimageDestroy(box->image);
    box->image = NULL;
    makeimage(box);
  }
  return;
}
示例#4
0
int main(void)
{
  // make and save
  IMAGE *img=makeimage(500,800);
  saveimage(img,"image3.ppm");
  freeimage(img);
  // read and save
  img=readimage("image3.ppm");
  image2hsv(img);
  saveimage(img,"image3c.ppm");
  return 0;
}
示例#5
0
static void
setnumber(register statusbox *box, int number)
{
  if (!box->image) {
    box->number = number;
    makeimage(box);
  }
  else
  if (number!=box->number) {
    box->number = number;
    eraseimage(box), formimage(box);
  }
  vdialogInvalItem(&box->item, vwindowINVAL_OPAQUE);
  return;
}
示例#6
0
文件: recover.c 项目: Rohithzr/CS50
int main(int argc, char* argv[])
{
    // make sure the user did not enter any command line arguments.
    if (argc != 1)
    {
        return 0;
    }
    
    // open the file from which we are going to recover jpgs. 
    // check for null pointer if file did not exist.
    FILE* file = fopen("card.raw", "r");
    if (file == NULL)
    {
        printf("Could not open card.raw");
        return 1;
    }
    
    // declare a buffer of size 512 and allocate space for the title.
    char buffer[512];
    char* title = malloc(sizeof(char) * 7);
    
    // declare and initialize integers that will be used later.
    int elements = 0;
    int i = -1;
    
    do
    {
        // start reading until program reaches the start of a jpg.
        // the numbers correspond to the starting values of a jpg.
        elements = fread(&buffer, sizeof(char), 512, file);
        if (buffer[0] == (char) 255 && buffer[1] == (char) 216 && buffer[2] 
                == (char) 255 && (buffer[3] == (char) 224 || buffer[3] 
                == (char) 225))
        {
            // i will be used for the fielename, and fseek moves back to 
            // the start of the jpg so that the function makeimage can 
            // process the whole jpg.
            i++;
            fseek(file, -512, SEEK_CUR);
            makeimage(i, file, buffer, title);	
        }
    }
    while (elements == 512);
    
    // close the file and free memory.
    fclose(file);
    free(title);
}   
QPixmap FopLeader::DummyImage()
{
			QPixmap pError = QPixmap(area.size().width(),area.size().height());
	    qreal hic = qBound (0.8,area.size().height() / 3,2.0);
	    QLineF linear(QPointF(0,area.size().height() - hic),QPointF(area.size().width(),area.size().height() - hic));
	    pError.fill(QColor(Qt::transparent));
	  
				
				
			if (!makeimage()) {
				/* not hidden && no use-content */
				QPainter p( &pError );
				if (co.alpha() < 10) {
				co = QColor(Qt::black);
				} 
				///// pattern ==== << "space" << "rule" << "dots" << "use-content" << "inherit";
				if ( leaderpattern == 11 || leaderpattern == 22 ) {
					/* fill color */
					p.setPen(Qt::NoPen);
					p.setBrush( QBrush(co) );
					p.drawRect(area);
				} else if ( leaderpattern == 2 ) {
					/* dots */
					
					///////////////qDebug() << "### paint dots ........................................ " << leaderpattern;
					p.setPen(Qt::NoPen);
					/////p.setBrush( QBrush(Qt::transparent) );
					//////p.drawRect(area);
					
					p.setPen(QPen(QBrush(co),hic,Qt::DotLine,Qt::RoundCap));
					p.drawLine(linear);
					
				}  else if (  leaderpattern == 4 || leaderpattern == 1 ) {
					/* dots */
					p.setPen(QPen(QBrush(co),area.size().height(),Qt::SolidLine,Qt::SquareCap));
					p.drawLine(linear);
				}
				
			}
			
			///////qDebug() << "### paint leaderpattern........................................ " << leaderpattern;
			
			
			return pError;
}
示例#8
0
int main(int argv ,char* argc)
{

    int i,j,k;
    const uchar*  data;					// pointer to the unaligned origin of image data
    int channels;
    char  name[50];

    IplImage *img = NULL;
    gets(name);
    img=cvLoadImage(name,1);				// load an image
    if(!img) {
        printf("cannot open image error");
        exit(1);
    }


// get the image data
    height = img->height;  				// image height in pixels
    width = img->width;   					// image width in pixels
    step = img->widthStep/sizeof(uchar); 			// size of aligned image row in bytes
    channels = img->nChannels;    				// Number of color channels (1,2,3,4)
    data = (uchar *)img->imageData;

    printf("Height=%d\nWidth=%d\n",height,width);

// display pixel value of each pixel
    /* for(i=0;i<height;i++)
     {
    	for(j=0;j<width;j++)
    		printf("%d ",data[i*width+j]);
    	printf("\n");
     }
    */
    /************************************************
        * Step 1: Apply a Gaussian blur
        * Step 2: Find edge Gradient strength and direction
        * Step 3: Trace along the edges
        * Step 4: Non-maximum Suppression
    **************************************************/



    int newPixel;						// Sum pixel values for gaussian


//scan  Gaussian Mask (5*5 matrix)
    int Gm[5][5]= {
        {2,4,5,4,2},
        {4,9,12,9,4},
        {5,12,15,12,5},
        {4,9,12,9,4},
        {2,4,5,4,2}
    };

//scan  Sobel operator (3x3 convolution masks) for estimating the Gradient in the x-direction
    int Gx[3][3]= {
        {-1,0,1},
        {-2,0,2},
        {-1,0,1}
    };

//scan  Sobel operator (3x3 convolution masks) for estimating the Gradient in the y-direction
    int Gy[3][3]= {
        {1,2,1},
        {0,0,0},
        {-1,-2,-1}
    };

// Convert the RGB image into Grayscale using Formula [Y = 0.3*R + 0.59*G + 0.11*B]
    for(i=0; i<height; i++) {
        for(j=0; j<width; j++) {
            Result[i][j]= (int)(0.3*(int)(data[i*step + j*channels +2])+0.59*(int)(data[i*step + j*channels +1])+0.11*(int)(data[i*step + j*channels +0]));
        }
    }


// Step:: 1  Apply a Gaussian blur


    int row,row1,col,col1;

    for (row=2; row<height-2; row++)
    {
        for (col=2; col<width-2; col++)
        {
            newPixel = 0;
            for (row1=-2; row1<=2; row1++)
            {
                for (col1=-2; col1<=2; col1++)
                    newPixel +=Result[row+row1][col+col1]*Gm[2+col1][2+row1];
            }
            Result[row][col]=newPixel/159;
        }
    }


// Step :: 2    Find edge Gradient strength and direction


    Direction = (int *)malloc(height*width*sizeof(int));
    Gradient = (int *)malloc(height*width*sizeof(int));

    int x,y;
    double Angle;

    for (row=1; row<height-1; row++)
    {
        for (col=1; col<width-1; col++)
        {
            x = 0;
            y = 0;
            /* Calculate the sum of the Sobel mask times the nine surrounding pixels in the x and y direction */
            for (row1=-1; row1<=1; row1++)
            {
                for (col1=-1; col1<=1; col1++)
                {
                    x+=Result[row+row1][col+col1]*Gx[1+col1][1+row1];
                    y+=Result[row+row1][col+col1]*Gy[1+col1][1+row1];
                }
            }

            Gradient[row*width+col] = (int)(sqrt(pow(x,2) + pow(y,2)));	// Calculate Gradient strength
            Angle = (atan2(x,y)/3.14159) * 180.0;		// Calculate actual direction of edge

            //printf("%d %d %lf\n",x,y,Gradient[row*width+col]);

            /* Convert actual edge direction to approximate value */
            if (((Angle<22.5)&&(Angle>-22.5)) || (Angle>157.5) || (Angle< -157.5))
                Angle = 0;
            if (((Angle > 22.5) && (Angle<67.5)) || ((Angle<-112.5) && (Angle>-157.5)))
                Angle = 45;
            if ( ( (Angle>67.5) && (Angle<112.5)) || ((Angle<-67.5) && (Angle>-112.5)))
                Angle = 90;
            if ( ( (Angle>112.5) && (Angle<157.5)) || ((Angle < -22.5) && (Angle > -67.5)))
                Angle = 135;

            Direction[row*width+col] = Angle;		// Store the approximate edge direction of each pixel in one array
        }
    }


//Step :: 3     Trace along the edges
    int flag;					// Stores whether or not the edge is at the edge of the possible image


    /* Trace along all the edges in the image */
    for (row=1; row<height-1; row++)
    {
        for (col=1; col<width-1; col++)
        {

            flag =0;
            if (Gradient[row*width+col] > upperThreshold) {
                /* Switch based on current pixel's edge direction */
                switch (Direction[row*width+col]) {
                case 0:
                    Edge(0,1,row,col,0);
                    break;
                case 45:
                    Edge(1,1,row,col,45);
                    break;
                case 90:
                    Edge(1,0,row,col,90);
                    break;
                case 135:
                    Edge(1,-1,row,col,135);
                    break;
                default :
                    Result[row][col]=0;
                    break;
                }
            }
            else {
                Result[row][col]=0;
            }
        }
    }



    /* Suppress any pixels not changed by the edge tracing */
    for (row=0; row<height; row++)
    {
        for (col=0; col<width; col++)
        {

            // If a pixel's grayValue is not black or white make it black
            if((Result[row][col]!= 255) && (Result[row][col]!= 0))
                Result[row][col]= 0 ;
        }
    }

    makeimage("output1.jpg");

// Step :: 4    Non-maximum Suppression


    for (row = 1; row < height-1; row++) {
        for (col = 1; col < width-1; col++) {
            if (Result[row][col] == 255) {		// Check to see if current pixel is an edge
                /* Switch based on current pixel's edge direction */
                switch (Direction[row*width+col]) {
                case 0:
                    suppress( 1, 0, row, col, 0);
                    break;
                case 45:
                    suppress( 1, -1, row, col, 45);
                    break;
                case 90:
                    suppress( 0, 1, row, col, 90);
                    break;
                case 135:
                    suppress( 1, 1, row, col, 135);
                    break;
                default :
                    break;
                }
            }
        }
    }


    makeimage("output2.jpg");

}// End of Main Function