Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/RegionIterator.java
41159 views
/*1* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pipe;262728/**29* This class defines the API for iterating through the bands30* of a region object.31*/32public class RegionIterator {33Region region;34int curIndex;35int numXbands;3637RegionIterator(Region r) {38region = r;39}4041/**42* Returns a new RegionIterator object representing the same43* iteration state as this object to allow multiple iteration44* branches from the current position.45*/46public RegionIterator createCopy() {47RegionIterator r = new RegionIterator(region);48r.curIndex = this.curIndex;49r.numXbands = this.numXbands;50return r;51}5253/**54* Copies the iteration state from this RegionIterator object55* into another RegionIterator object to allow multiple iteration56* branches from the current position.57*/58public void copyStateFrom(RegionIterator ri) {59if (this.region != ri.region) {60throw new InternalError("region mismatch");61}62this.curIndex = ri.curIndex;63this.numXbands = ri.numXbands;64}6566/**67* Moves the iteration state to the beginning of the next68* Y range in the region returning true if one is found69* and recording the low and high Y coordinates of the70* range in the array at locations 1 and 3 respectively.71*/72public boolean nextYRange(int[] range) {73curIndex += numXbands * 2;74numXbands = 0;75if (curIndex >= region.endIndex) {76return false;77}78range[1] = region.bands[curIndex++];79range[3] = region.bands[curIndex++];80numXbands = region.bands[curIndex++];81return true;82}8384/**85* Moves the iteration state to the beginning of the next86* X band in the current Y range returning true if one is87* found and recording the low and high X coordinates of88* the range in the array at locations 0 and 2 respectively.89*/90public boolean nextXBand(int[] range) {91if (numXbands <= 0) {92return false;93}94numXbands--;95range[0] = region.bands[curIndex++];96range[2] = region.bands[curIndex++];97return true;98}99}100101102