jdk/src/share/classes/sun/java2d/loops/CustomComponent.java
author michaelm
Thu, 24 Oct 2013 20:39:21 +0100
changeset 22339 e91bfaf4360d
parent 5506 202f599c92aa
child 24522 3a0bbf9f5e81
permissions -rw-r--r--
8011786: Better applet networking Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author Charlton Innovations, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.java2d.loops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.image.IntegerComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.java2d.pipe.SpanIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   CustomComponent, collection of GraphicsPrimitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   Basically, this collection of components performs conversion from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   ANY to ANY via opaque copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public final class CustomComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static void register() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        // REMIND: This does not work for all destinations yet since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        // the screen SurfaceData objects do not implement getRaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        Class owner = CustomComponent.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        GraphicsPrimitive[] primitives = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            new GraphicsPrimitiveProxy(owner, "OpaqueCopyAnyToArgb",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                       Blit.methodSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                       Blit.primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                                       SurfaceType.Any,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                       CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                       SurfaceType.IntArgb),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            new GraphicsPrimitiveProxy(owner, "OpaqueCopyArgbToAny",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                       Blit.methodSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                       Blit.primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                       SurfaceType.IntArgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                       CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                       SurfaceType.Any),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            new GraphicsPrimitiveProxy(owner, "XorCopyArgbToAny",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                       Blit.methodSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                       Blit.primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                       SurfaceType.IntArgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                       CompositeType.Xor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                       SurfaceType.Any),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        GraphicsPrimitiveMgr.register(primitives);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                             Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                             int srcx, int srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                             int dstx, int dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                             int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * Intersect all of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         *   - operation area (dstx, dsty, w, h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         *   - destination bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         *   - (translated) src bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         *   - supplied clip (may be non-rectangular)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * Intersect the rectangular regions first since those are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * simpler operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        ret = ret.getIntersection(dst.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        Rectangle r = src.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // srcxy in src space maps to dstxy in dst space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        r.translate(dstx - srcx, dsty - srcy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        ret = ret.getIntersection(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (clip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            // Intersect with clip last since it may be non-rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            ret = ret.getIntersection(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *   ANY format to ARGB format Blit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
class OpaqueCopyAnyToArgb extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    OpaqueCopyAnyToArgb() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        super(SurfaceType.Any,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
              CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              SurfaceType.IntArgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                     Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                     int srcx, int srcy, int dstx, int dsty, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Raster srcRast = src.getRaster(srcx, srcy, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        ColorModel srcCM = src.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Raster dstRast = dst.getRaster(dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        IntegerComponentRaster icr = (IntegerComponentRaster) dstRast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        int[] dstPix = icr.getDataStorage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                                         srcx, srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                                         dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        SpanIterator si = roi.getSpanIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Object srcPix = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        int dstScan = icr.getScanlineStride();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // assert(icr.getPixelStride() == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        srcx -= dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        srcy -= dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        int span[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        while (si.nextSpan(span)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            int rowoff = icr.getDataOffset(0) + span[1] * dstScan + span[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            for (int y = span[1]; y < span[3]; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                int off = rowoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                for (int x = span[0]; x < span[2]; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    srcPix = srcRast.getDataElements(x+srcx, y+srcy, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    dstPix[off++] = srcCM.getRGB(srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                rowoff += dstScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // Pixels in the dest were modified directly, we must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // manually notify the raster that it was modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        icr.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // REMIND: We need to do something to make sure that dstRast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // is put back to the destination (as in the native Release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // function)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // src.releaseRaster(srcRast);  // NOP?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // dst.releaseRaster(dstRast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *   ARGB format to ANY format Blit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
class OpaqueCopyArgbToAny extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    OpaqueCopyArgbToAny() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        super(SurfaceType.IntArgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
              CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
              SurfaceType.Any);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                     Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                     int srcx, int srcy, int dstx, int dsty, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        Raster srcRast = src.getRaster(srcx, srcy, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        int[] srcPix = icr.getDataStorage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        WritableRaster dstRast =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            (WritableRaster) dst.getRaster(dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        ColorModel dstCM = dst.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                                         srcx, srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                                         dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        SpanIterator si = roi.getSpanIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Object dstPix = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int srcScan = icr.getScanlineStride();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        // assert(icr.getPixelStride() == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        srcx -= dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        srcy -= dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        int span[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        while (si.nextSpan(span)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            int rowoff = (icr.getDataOffset(0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                          (srcy + span[1]) * srcScan +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                          (srcx + span[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            for (int y = span[1]; y < span[3]; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                int off = rowoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                for (int x = span[0]; x < span[2]; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    dstRast.setDataElements(x, y, dstPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                rowoff += srcScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // REMIND: We need to do something to make sure that dstRast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // is put back to the destination (as in the native Release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // function)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // src.releaseRaster(srcRast);  // NOP?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // dst.releaseRaster(dstRast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *   ARGB format to ANY format Blit (pixels are XORed together with XOR pixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
class XorCopyArgbToAny extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    XorCopyArgbToAny() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        super(SurfaceType.IntArgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
              CompositeType.Xor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
              SurfaceType.Any);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                     Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                     int srcx, int srcy, int dstx, int dsty, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        Raster srcRast = src.getRaster(srcx, srcy, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        int[] srcPix = icr.getDataStorage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        WritableRaster dstRast =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            (WritableRaster) dst.getRaster(dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        ColorModel dstCM = dst.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                                         srcx, srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                                         dstx, dsty, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        SpanIterator si = roi.getSpanIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int xorrgb = ((XORComposite)comp).getXorColor().getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Object xorPixel = dstCM.getDataElements(xorrgb, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        Object srcPixel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Object dstPixel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        int srcScan = icr.getScanlineStride();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        // assert(icr.getPixelStride() == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        srcx -= dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        srcy -= dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        int span[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        while (si.nextSpan(span)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            int rowoff = (icr.getDataOffset(0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                          (srcy + span[1]) * srcScan +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                          (srcx + span[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            for (int y = span[1]; y < span[3]; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                int off = rowoff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                for (int x = span[0]; x < span[2]; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    // REMIND: alpha bits of the destination pixel are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    // currently altered by the XOR operation, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    // should be left untouched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    srcPixel = dstCM.getDataElements(srcPix[off++], srcPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    dstPixel = dstRast.getDataElements(x, y, dstPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    switch (dstCM.getTransferType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    case DataBuffer.TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        byte[] bytesrcarr = (byte[]) srcPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        byte[] bytedstarr = (byte[]) dstPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        byte[] bytexorarr = (byte[]) xorPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        for (int i = 0; i < bytedstarr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                            bytedstarr[i] ^= bytesrcarr[i] ^ bytexorarr[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    case DataBuffer.TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    case DataBuffer.TYPE_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        short[] shortsrcarr = (short[]) srcPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        short[] shortdstarr = (short[]) dstPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        short[] shortxorarr = (short[]) xorPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                        for (int i = 0; i < shortdstarr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                            shortdstarr[i] ^= shortsrcarr[i] ^ shortxorarr[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    case DataBuffer.TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        int[] intsrcarr = (int[]) srcPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        int[] intdstarr = (int[]) dstPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        int[] intxorarr = (int[]) xorPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        for (int i = 0; i < intdstarr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                            intdstarr[i] ^= intsrcarr[i] ^ intxorarr[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    case DataBuffer.TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        float[] floatsrcarr = (float[]) srcPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        float[] floatdstarr = (float[]) dstPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        float[] floatxorarr = (float[]) xorPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        for (int i = 0; i < floatdstarr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                            int v = (Float.floatToIntBits(floatdstarr[i]) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                     Float.floatToIntBits(floatsrcarr[i]) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                     Float.floatToIntBits(floatxorarr[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                            floatdstarr[i] = Float.intBitsToFloat(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    case DataBuffer.TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        double[] doublesrcarr = (double[]) srcPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        double[] doubledstarr = (double[]) dstPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        double[] doublexorarr = (double[]) xorPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        for (int i = 0; i < doubledstarr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                            long v = (Double.doubleToLongBits(doubledstarr[i]) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                      Double.doubleToLongBits(doublesrcarr[i]) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                                      Double.doubleToLongBits(doublexorarr[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            doubledstarr[i] = Double.longBitsToDouble(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        throw new InternalError("Unsupported XOR pixel type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    dstRast.setDataElements(x, y, dstPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                rowoff += srcScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // REMIND: We need to do something to make sure that dstRast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // is put back to the destination (as in the native Release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // function)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // src.releaseRaster(srcRast);  // NOP?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // dst.releaseRaster(dstRast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}