Bonjour j'ai un code qui permet de coller les pièces d'un puzzle, mais je ne comprends pas tres bien cette partie de code, est-ce qu'il permet de faire un test sur la même pièce ou bien sur les deux pièces voisines, pour information le tableau data[] contient les bits d'une seul pièce de l'image finale.



Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
int[] data = new int[width*height];
    PixelGrabber grabber = 
      new PixelGrabber (image, box.x, box.y,
        width, height, data, 0, width);
    grabber.grabPixels();
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
  	static void bevel (int[] data, int width, int height)
  	{
  		// Scan diagonal NW-SE lines.  The first and last lines can be skipped.
  		for (int i = 0; i < width+height-3; i++) 
  		{
  			int x = Math.max (0, i-height+2);
  			int y = Math.max (0, height-i-2);
  			boolean nw, c, se; // true iff that pixel is opaque
  			nw = c = se = false;
  			c = (((data[y*width+x] >> 24) & 0xff) > 0);
  			while ((x < width) && (y < height)) {
  				if ((x+1 < width) && (y+1 < height))
  				{
  					se = (((data[(y+1)*width+(x+1)] >> 24) & 0xff) > 0);
  				}
  				else 
  				{	
  					se = false;
  				} 
 
  				if (c) 
  				{
  					int datum = data[y*width+x];
  					if ( nw && !se) 
  					{
  						data[y*width+x] =   darker (datum);
  					}
  					if (!nw &&  se) 
  					{
  						data[y*width+x] = brighter (datum);
  					}
  				}
  				nw = c;
  				c = se;
  				x++; y++;
  			}
  		}
  	}
 
        static final int fn = 10;
  	static final int fd =  7;
  	static final int maxB =  255 * fd / fn;
  	static final int brighter (int val) {
  		int r = (val >> 16) & 0xff;
  		int g = (val >>  8) & 0xff;
  		int b = (val      ) & 0xff;
  		//  #030303 gris
  		if ((r==0) && (g==0) && (b==0)) return 0xff030303;
  		r = (r < 3) ? 3 : r;
  		g = (g < 3) ? 3 : g;
  		b = (b < 3) ? 3 : b;
  		r = (r >= maxB) ? 255 : (r * fn / fd);
  		g = (g >= maxB) ? 255 : (g * fn / fd);
  		b = (b >= maxB) ? 255 : (b * fn / fd);
  		return ((((0xff00 | r) << 8) | g) << 8) | b;
  	}
 
  	static final int darker (int val) {
  		int r = (val >> 16) & 0xff;
  		int g = (val >>  8) & 0xff;
  		int b = (val      ) & 0xff;
  		r = r * fd / fn;
  		g = g * fd / fn;
  		b = b * fd / fn;
  		return ((((0xff00 | r) << 8) | g) << 8) | b;
  	}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
bevel(curData, curWidth, curHeight);
  		image = Toolkit.getDefaultToolkit().createImage (
  			new MemoryImageSource (curWidth,curHeight, curData, 0, curWidth));


Merci pour votre aide.