3 import java.awt.image.*;
9 private int width, height;
11 private int transparent = 0xffffff;
22 transparent = c.getRGB()&0xffffff;
27 int srcIndex, dstIndex;
28 int xSrcBase, ySrcBase;
33 Rectangle rect1 =
new Rectangle(srcWidth, srcHeight);
34 rect1.setLocation(xloc, yloc);
35 Rectangle rect2 =
new Rectangle(width, height);
36 if (!rect1.intersects(rect2))
42 srcPixels =
new int[size];
44 for (
int i=0; i<size; i++)
45 srcPixels[i] = cm.getRGB(pixels8[i]&255);
48 rect1 = rect1.intersection(rect2);
49 xSrcBase = (xloc<0)?-xloc:0;
50 ySrcBase = (yloc<0)?-yloc:0;
51 int c1, c2, r1, g1, b1, r2, g2, b2;
55 for (
int y=rect1.y; y<(rect1.y+rect1.height); y++) {
56 srcIndex = (y-yloc)*srcWidth + (rect1.x-xloc);
57 dstIndex = y * width + rect1.x;
59 for (
int i=rect1.width; --i>=0;)
60 pixels[dstIndex++] = srcPixels[srcIndex++];
62 for (
int i=rect1.width; --i>=0;) {
63 src = srcPixels[srcIndex++];
64 dst = pixels[dstIndex];
65 pixels[dstIndex++] = (src&0xffffff)==transparent?dst:src;
71 for (
int y=rect1.y; y<(rect1.y+rect1.height); y++) {
72 srcIndex = (y-yloc)*srcWidth + (rect1.x-xloc);
73 dstIndex = y * width + rect1.x;
74 for (
int i=rect1.width; --i>=0;) {
75 c1 = srcPixels[srcIndex++];
76 r1 = (c1&0xff0000)>>16;
79 c2 = pixels[dstIndex];
80 r2 = (c2&0xff0000)>>16;
87 r2=r1+r2; g2=g1+g2; b2=b1+b2;
88 if (r2>255) r2=255;
if (g2>255) g2=255;
if (b2>255) b2=255;
91 r2=(r1+r2)/2; g2=(g1+g2)/2; b2=(b1+b2)/2;
94 r2=r2-r1; g2=g2-g1; b2=b2-b1;
95 if (r2<0) r2=0;
if (g2<0) g2=0;
if (b2<0) b2=0;
98 r2=r2-r1;
if (r2<0) r2=-r2;
99 g2=g2-g1;
if (g2<0) g2=-g2;
100 b2=b2-b1;
if (b2<0) b2=-b2;
103 r2=r1*r2; g2=g1*g2; b2=b1*b2;
104 if (r2>255) r2=255;
if (g2>255) g2=255;
if (b2>255) b2=255;
107 if (r1==0) r2=255;
else r2=r2/r1;
108 if (g1==0) g2=255;
else g2=g2/g1;
109 if (b1==0) b2=255;
else b2=b2/b1;
112 r2=r1&r2; g2=g1&g2; b2=b1&b2;
115 r2=r1|r2; g2=g1|g2; b2=b1|b2;
118 r2=r1^r2; g2=g1^g2; b2=b1^b2;
131 pixels[dstIndex++] = 0xff000000 + (r2<<16) + (g2<<8) + b2;
134 ip.showProgress((
double)(y-rect1.y)/rect1.height);