Пример #1
0
		public Layer(Layer rgb, Channel a) {
			this.r = rgb.r;
			this.g = rgb.g;
			this.b = rgb.b;
			this.width = r.getWidth();
			this.height = r.getHeight();
			this.a = a;
		}
Пример #2
0
 public Layer place(Layer sprite, int x_offset, int y_offset)
 {
     r.place(sprite.r, x_offset, y_offset);
     g.place(sprite.g, x_offset, y_offset);
     b.place(sprite.b, x_offset, y_offset);
     if (a != null && sprite.a != null)
         a.place(sprite.a, x_offset, y_offset);
     return this;
 }
Пример #3
0
 public Layer layerSubtract(Layer layer)
 {
     r.channelSubtract(layer.r);
     g.channelSubtract(layer.g);
     b.channelSubtract(layer.b);
     return this;
 }
Пример #4
0
 public Layer layerMultiply(Layer layer)
 {
     r.channelMultiply(layer.r);
     g.channelMultiply(layer.g);
     b.channelMultiply(layer.b);
     return this;
 }
Пример #5
0
 public Layer layerDifference(Layer layer)
 {
     r.channelDifference(layer.r);
     g.channelDifference(layer.g);
     b.channelDifference(layer.b);
     return this;
 }
Пример #6
0
 public Layer layerDarkest(Layer layer)
 {
     r.channelDarkest(layer.r);
     g.channelDarkest(layer.g);
     b.channelDarkest(layer.b);
     return this;
 }
Пример #7
0
 public Layer layerBrightest(Layer layer)
 {
     r.channelBrightest(layer.r);
     g.channelBrightest(layer.g);
     b.channelBrightest(layer.b);
     return this;
 }
Пример #8
0
        public Layer layerBlend(Layer layer)
        {
            if(!(layer.a != null))
                throw new Exception("cannot blend RGB only layer");

            if (a == null) {
                r.channelBlend(layer.r, layer.a);
                g.channelBlend(layer.g, layer.a);
                b.channelBlend(layer.b, layer.a);
            } else {
                float alpha;
                float alpha_inv;
                float r1;
                float g1;
                float b1;
                float a2;
                for (int y = 0; y < height; y++) {
                    for (int x = 0; x < width; x++) {
                        if (a.getPixel(x, y) == 0) {
                            putPixel(x, y, layer.r.getPixel(x, y), layer.g.getPixel(x, y), layer.b.getPixel(x, y), layer.a.getPixel(x, y));
                        } else if (layer.a.getPixel(x, y) == 0) {
                            continue;
                        } else {
                            alpha = 1f - (1f - a.getPixel(x, y))*(1f - layer.a.getPixel(x, y));
                            alpha_inv = 1f/alpha;
                            r1 = r.getPixel(x, y);
                            g1 = g.getPixel(x, y);
                            b1 = b.getPixel(x, y);
                            a2 = layer.a.getPixel(x, y);
                            r.putPixel(x, y, r1 - r1*a2*alpha_inv + layer.r.getPixel(x, y)*a2*alpha_inv);
                            g.putPixel(x, y, g1 - g1*a2*alpha_inv + layer.g.getPixel(x, y)*a2*alpha_inv);
                            b.putPixel(x, y, b1 - b1*a2*alpha_inv + layer.b.getPixel(x, y)*a2*alpha_inv);
                            a.putPixel(x, y, alpha);
                        }
                    }
                }
            }
            return this;
        }
Пример #9
0
 public Layer layerBlend(Layer rgb, Channel a)
 {
     return layerBlend(new Layer(rgb.r, rgb.g, rgb.b, a));
 }
Пример #10
0
 public Layer layerBlend(Layer layer, float alpha)
 {
     r.channelBlend(layer.r, alpha);
     g.channelBlend(layer.g, alpha);
     b.channelBlend(layer.b, alpha);
     return this;
 }
Пример #11
0
 public Layer layerAverage(Layer layer)
 {
     r.channelAverage(layer.r);
     g.channelAverage(layer.g);
     b.channelAverage(layer.b);
     return this;
 }
Пример #12
0
 public Layer layerAdd(Layer layer)
 {
     r.channelAdd(layer.r);
     g.channelAdd(layer.g);
     b.channelAdd(layer.b);
     return this;
 }