jdk/src/share/classes/java/awt/image/ReplicateScaleFilter.java
author prr
Thu, 10 Apr 2008 16:28:45 -0700
changeset 539 7952521a4ad3
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6662775: Move imaging and color classes from closed to open Reviewed-by: tdv, campbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2004 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.ImageConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * An ImageFilter class for scaling images using the simplest algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class extends the basic ImageFilter Class to scale an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * image and provide a source for a new image containing the resampled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * image.  The pixels in the source image are sampled to produce pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * for an image of the specified size by replicating rows and columns of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * pixels to scale up or omitting rows and columns of pixels to scale
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>It is meant to be used in conjunction with a FilteredImageSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * object to produce scaled versions of existing images.  Due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * implementation dependencies, there may be differences in pixel values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * of an image filtered on different platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @see FilteredImageSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see ImageFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class ReplicateScaleFilter extends ImageFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * The width of the source image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected int srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * The height of the source image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected int srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The target width to scale the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected int destWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The target height to scale the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected int destHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * An <code>int</code> array containing information about a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * row of pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected int srcrows[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * An <code>int</code> array containing information about a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * column of pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected int srccols[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * A <code>byte</code> array initialized with a size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * {@link #destWidth} and used to deliver a row of pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * data to the {@link ImageConsumer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected Object outpixbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Constructs a ReplicateScaleFilter that scales the pixels from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * its source Image as specified by the width and height parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param width the target width to scale the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param height the target height to scale the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @throws IllegalArgumentException if <code>width</code> equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *         zero or <code>height</code> equals zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public ReplicateScaleFilter(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (width == 0 || height == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new IllegalArgumentException("Width ("+width+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                                ") and height ("+height+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                                ") must be non-zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        destWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        destHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Passes along the properties from the source object after adding a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * property indicating the scale applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * This method invokes <code>super.setProperties</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * which might result in additional properties being added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Note: This method is intended to be called by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <code>ImageProducer</code> of the <code>Image</code> whose pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * are being filtered. Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void setProperties(Hashtable<?,?> props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        String key = "rescale";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        String val = destWidth + "x" + destHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Object o = p.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (o != null && o instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            val = ((String) o) + ", " + val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        p.put(key, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super.setProperties(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Override the dimensions of the source image and pass the dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * of the new scaled size to the ImageConsumer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Note: This method is intended to be called by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <code>ImageProducer</code> of the <code>Image</code> whose pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * are being filtered. Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see ImageConsumer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void setDimensions(int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        srcWidth = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        srcHeight = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (destWidth < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            if (destHeight < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                destWidth = srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                destHeight = srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                destWidth = srcWidth * destHeight / srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } else if (destHeight < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            destHeight = srcHeight * destWidth / srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        consumer.setDimensions(destWidth, destHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private void calculateMaps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        srcrows = new int[destHeight + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        for (int y = 0; y <= destHeight; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            srcrows[y] = (2 * y * srcHeight + srcHeight) / (2 * destHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        srccols = new int[destWidth + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        for (int x = 0; x <= destWidth; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            srccols[x] = (2 * x * srcWidth + srcWidth) / (2 * destWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Choose which rows and columns of the delivered byte pixels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * needed for the destination scaled image and pass through just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * those rows and columns that are needed, replicated as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Note: This method is intended to be called by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <code>ImageProducer</code> of the <code>Image</code> whose pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * are being filtered. Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public void setPixels(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                          ColorModel model, byte pixels[], int off,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                          int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (srcrows == null || srccols == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            calculateMaps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        int sx, sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        int dx1 = (2 * x * destWidth + srcWidth - 1) / (2 * srcWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        int dy1 = (2 * y * destHeight + srcHeight - 1) / (2 * srcHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        byte outpix[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (outpixbuf != null && outpixbuf instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            outpix = (byte[]) outpixbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            outpix = new byte[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            outpixbuf = outpix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        for (int dy = dy1; (sy = srcrows[dy]) < y + h; dy++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            int srcoff = off + scansize * (sy - y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            int dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            for (dx = dx1; (sx = srccols[dx]) < x + w; dx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                outpix[dx] = pixels[srcoff + sx - x];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (dx > dx1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                consumer.setPixels(dx1, dy, dx - dx1, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                   model, outpix, dx1, destWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
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
     * Choose which rows and columns of the delivered int pixels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * needed for the destination scaled image and pass through just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * those rows and columns that are needed, replicated as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Note: This method is intended to be called by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <code>ImageProducer</code> of the <code>Image</code> whose pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * are being filtered. Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void setPixels(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                          ColorModel model, int pixels[], int off,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                          int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (srcrows == null || srccols == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            calculateMaps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        int sx, sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        int dx1 = (2 * x * destWidth + srcWidth - 1) / (2 * srcWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        int dy1 = (2 * y * destHeight + srcHeight - 1) / (2 * srcHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        int outpix[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (outpixbuf != null && outpixbuf instanceof int[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            outpix = (int[]) outpixbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            outpix = new int[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            outpixbuf = outpix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        for (int dy = dy1; (sy = srcrows[dy]) < y + h; dy++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            int srcoff = off + scansize * (sy - y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            int dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            for (dx = dx1; (sx = srccols[dx]) < x + w; dx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                outpix[dx] = pixels[srcoff + sx - x];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (dx > dx1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                consumer.setPixels(dx1, dy, dx - dx1, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                   model, outpix, dx1, destWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}