adding noise to an image



After figuring out how to draw shapes in a drawing area with a pixbuf in
the background, now I need to add noise, by moving a slider (VScale).
The shapes are only in the DrawingArea, not in the pixbuf, and the noise
most go over the entire thing. Randomly, some pixels will be altered,
others won't. The noise is uniform random between [0,255] (not just black
and white), so I need to have all 256 gray levels allocated, don't I? 

I'm thinking this way:

Gdk::Colors gray[256];

// allocate colors somewhere.

for(int y=0; y<Darea->get_height(); y++){
	for(int x=0; x<Dara->get_width(); y++){

	// Decide if (x,y) should be altered, and if so, 
		// choose a random index say, g, between 0 and 255.
		gc_->set_foreground(gray[g]);
		Darea->get_window()->draw_point(gc_, x,y);
	}
}

Is this the right way to go about this? 
How do I allocate the 256 gray levels? I do need to allocate them, don't I?






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]