The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | /** |
| 18 | * @author Sergey I. Salishev |
| 19 | * @version $Revision: 1.2 $ |
| 20 | */ |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 21 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | package javax.imageio; |
| 23 | |
| 24 | import java.awt.Dimension; |
| 25 | import java.awt.image.BufferedImage; |
| 26 | |
| 27 | /* |
| 28 | * @author Sergey I. Salishev |
| 29 | * @version $Revision: 1.2 $ |
| 30 | */ |
| 31 | |
| 32 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 33 | * The ImageReadParam class provides information to the ImageReader about how an |
| 34 | * image is to be decoded. |
| 35 | * |
| 36 | * @since Android 1.0 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 38 | public class ImageReadParam extends IIOParam { |
| 39 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 40 | /** |
| 41 | * This flag indicates if this ImageReadParam supports setting the source |
| 42 | * rendering size. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 43 | */ |
| 44 | protected boolean canSetSourceRenderSize; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * The destination BufferedImage. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | */ |
| 49 | protected BufferedImage destination; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * The destination bands. |
| 53 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 54 | protected int[] destinationBands; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * The minimum progressive pass. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 58 | */ |
| 59 | protected int minProgressivePass; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * The number of progressive passes. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 63 | */ |
| 64 | protected int numProgressivePasses; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * The source render size. |
| 68 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | protected Dimension sourceRenderSize; |
| 70 | |
| 71 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 72 | * Returns true if this ImageReaderParam supports rendering a source image |
| 73 | * at an arbitrary size. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 74 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 75 | * @return true, if this ImageReaderParam supports rendering a source image |
| 76 | * at an arbitrary size, false otherwise. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | */ |
| 78 | public boolean canSetSourceRenderSize() { |
| 79 | return canSetSourceRenderSize; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Gets the current destination image as BufferedImage. |
| 84 | * |
| 85 | * @return the BufferedImage which represents the destination. |
| 86 | */ |
| 87 | public BufferedImage getDestination() { |
| 88 | return destination; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets the indices of destination bands. |
| 93 | * |
| 94 | * @return the array of destination bands. |
| 95 | */ |
| 96 | public int[] getDestinationBands() { |
| 97 | return destinationBands; |
| 98 | } |
| 99 | |
| 100 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 101 | * Gets the index of the maximum pass to be decoded. This method returns |
| 102 | * Integer.MAX_VALUE, if getSourceNumProgressivePasses() method returns |
| 103 | * value that is equal to Integer.MAX_VALUE. Otherwise this method returns |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | * getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1. |
| 105 | * |
| 106 | * @return the index of the maximum pass to be decoded. |
| 107 | */ |
| 108 | public int getSourceMaxProgressivePass() { |
| 109 | if (getSourceNumProgressivePasses() == Integer.MAX_VALUE) { |
| 110 | return Integer.MAX_VALUE; |
| 111 | } |
| 112 | return getSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1; |
| 113 | } |
| 114 | |
| 115 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 116 | * Gets the index of the minimum progressive pass that is decoded, default |
| 117 | * is 0. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | * |
| 119 | * @return the index of the minimum progressive pass that is decoded, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 120 | * default is 0. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 121 | */ |
| 122 | public int getSourceMinProgressivePass() { |
| 123 | return minProgressivePass; |
| 124 | } |
| 125 | |
| 126 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 127 | * Gets the number of progressive passes. The default value is |
| 128 | * Integer.MAX_VALUE. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 129 | * |
| 130 | * @return the number of progressive passes. |
| 131 | */ |
| 132 | public int getSourceNumProgressivePasses() { |
| 133 | return numProgressivePasses; |
| 134 | } |
| 135 | |
| 136 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 137 | * Gets the dimension of source image which will be rendered during decoding |
| 138 | * process. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 139 | * |
| 140 | * @return the source render size. |
| 141 | */ |
| 142 | public Dimension getSourceRenderSize() { |
| 143 | return sourceRenderSize; |
| 144 | } |
| 145 | |
| 146 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 147 | * Sets the specified destination image. This image will be used by read, |
| 148 | * readAll, and readRaster methods, and a reference to it will be returned |
| 149 | * by those methods. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 150 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 151 | * @param destination |
| 152 | * the destination image. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 153 | */ |
| 154 | public void setDestination(BufferedImage destination) { |
| 155 | this.destination = destination; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Sets the indices of the destination bands. |
| 160 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 161 | * @param destinationBands |
| 162 | * the indices of the destination bands. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 163 | */ |
| 164 | public void setDestinationBands(int[] destinationBands) { |
| 165 | this.destinationBands = destinationBands; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void setDestinationType(ImageTypeSpecifier destinationType) { |
| 170 | this.destinationType = destinationType; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Sets the source progressive passes. |
| 175 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 176 | * @param minPass |
| 177 | * the index of the minimum pass to be decoded. |
| 178 | * @param numPasses |
| 179 | * the number of passes to be decoded. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 180 | */ |
| 181 | public void setSourceProgressivePasses(int minPass, int numPasses) { |
| 182 | minProgressivePass = minPass; |
| 183 | numProgressivePasses = numPasses; |
| 184 | } |
| 185 | |
| 186 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 187 | * Sets the dimension size of source image if an image can be rendered at an |
| 188 | * arbitrary size. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 189 | * |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 190 | * @param size |
| 191 | * the size of rendered image. |
| 192 | * @throws UnsupportedOperationException |
| 193 | * the unsupported operation exception. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 194 | */ |
| 195 | public void setSourceRenderSize(Dimension size) throws UnsupportedOperationException { |
| 196 | if (!canSetSourceRenderSize) { |
| 197 | throw new UnsupportedOperationException("can't set source renderer size"); |
| 198 | } |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 199 | sourceRenderSize = size; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 200 | } |
| 201 | } |