1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
217 public int getTransferType() {
218 return dataType;
219 }
220
221 /**
222 * Returns the samples for a specified pixel in an int array,
223 * one sample per array element.
224 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
225 * not in bounds.
226 * @param x The X coordinate of the pixel location
227 * @param y The Y coordinate of the pixel location
228 * @param iArray If non-null, returns the samples in this array
229 * @param data The DataBuffer containing the image data
230 * @return the samples for the specified pixel.
231 * @see #setPixel(int, int, int[], DataBuffer)
232 *
233 * @throws NullPointerException if data is null.
234 * @throws ArrayIndexOutOfBoundsException if the coordinates are
235 * not in bounds, or if iArray is too small to hold the output.
236 */
237 public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
238
239 int pixels[];
240
241 if (iArray != null)
242 pixels = iArray;
243 else
244 pixels = new int[numBands];
245
246 for (int i=0; i<numBands; i++) {
247 pixels[i] = getSample(x, y, i, data);
248 }
249
250 return pixels;
251 }
252
253 /**
254 * Returns data for a single pixel in a primitive array of type
255 * TransferType. For image data supported by the Java 2D API, this
256 * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
257 * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
258 * or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
259 * thus increasing efficiency for data transfers. Generally, obj
681 break;
682 }
683
684 }
685
686 /**
687 * Returns the samples for the specified pixel in an array of float.
688 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
689 * not in bounds.
690 * @param x The X coordinate of the pixel location.
691 * @param y The Y coordinate of the pixel location.
692 * @param fArray If non-null, returns the samples in this array.
693 * @param data The DataBuffer containing the image data.
694 * @return the samples for the specified pixel.
695 * @see #setPixel(int, int, float[], DataBuffer)
696 *
697 * @throws NullPointerException if data is null.
698 * @throws ArrayIndexOutOfBoundsException if the coordinates are
699 * not in bounds, or if fArray is too small to hold the output.
700 */
701 public float[] getPixel(int x, int y, float fArray[],
702 DataBuffer data) {
703
704 float pixels[];
705
706 if (fArray != null)
707 pixels = fArray;
708 else
709 pixels = new float[numBands];
710
711 for (int i=0; i<numBands; i++)
712 pixels[i] = getSampleFloat(x, y, i, data);
713
714 return pixels;
715 }
716
717 /**
718 * Returns the samples for the specified pixel in an array of double.
719 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
720 * not in bounds.
721 * @param x The X coordinate of the pixel location.
722 * @param y The Y coordinate of the pixel location.
723 * @param dArray If non-null, returns the samples in this array.
724 * @param data The DataBuffer containing the image data.
725 * @return the samples for the specified pixel.
726 * @see #setPixel(int, int, double[], DataBuffer)
727 *
728 * @throws NullPointerException if data is null.
729 * @throws ArrayIndexOutOfBoundsException if the coordinates are
730 * not in bounds, or if dArray is too small to hold the output.
731 */
732 public double[] getPixel(int x, int y, double dArray[],
733 DataBuffer data) {
734
735 double pixels[];
736
737 if(dArray != null)
738 pixels = dArray;
739 else
740 pixels = new double[numBands];
741
742 for (int i=0; i<numBands; i++)
743 pixels[i] = getSampleDouble(x, y, i, data);
744
745 return pixels;
746 }
747
748 /**
749 * Returns all samples for a rectangle of pixels in an
750 * int array, one sample per array element.
751 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
752 * not in bounds.
753 * @param x The X coordinate of the upper left pixel location.
754 * @param y The Y coordinate of the upper left pixel location.
755 * @param w The width of the pixel rectangle.
756 * @param h The height of the pixel rectangle.
757 * @param iArray If non-null, returns the samples in this array.
758 * @param data The DataBuffer containing the image data.
759 * @return the samples for the specified region of pixels.
760 * @see #setPixels(int, int, int, int, int[], DataBuffer)
761 *
762 * @throws NullPointerException if data is null.
763 * @throws ArrayIndexOutOfBoundsException if the coordinates are
764 * not in bounds, or if iArray is too small to hold the output.
765 */
766 public int[] getPixels(int x, int y, int w, int h,
767 int iArray[], DataBuffer data) {
768
769 int pixels[];
770 int Offset=0;
771 int x1 = x + w;
772 int y1 = y + h;
773
774 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
775 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
776 {
777 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
778 }
779
780 if (iArray != null)
781 pixels = iArray;
782 else
783 pixels = new int[numBands * w * h];
784
785 for (int i=y; i<y1; i++) {
786 for (int j=x; j<x1; j++) {
787 for(int k=0; k<numBands; k++) {
788 pixels[Offset++] = getSample(j, i, k, data);
789 }
795
796 /**
797 * Returns all samples for a rectangle of pixels in a float
798 * array, one sample per array element.
799 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
800 * not in bounds.
801 * @param x The X coordinate of the upper left pixel location.
802 * @param y The Y coordinate of the upper left pixel location.
803 * @param w The width of the pixel rectangle.
804 * @param h The height of the pixel rectangle.
805 * @param fArray If non-null, returns the samples in this array.
806 * @param data The DataBuffer containing the image data.
807 * @return the samples for the specified region of pixels.
808 * @see #setPixels(int, int, int, int, float[], DataBuffer)
809 *
810 * @throws NullPointerException if data is null.
811 * @throws ArrayIndexOutOfBoundsException if the coordinates are
812 * not in bounds, or if fArray is too small to hold the output.
813 */
814 public float[] getPixels(int x, int y, int w, int h,
815 float fArray[], DataBuffer data) {
816
817 float pixels[];
818 int Offset = 0;
819 int x1 = x + w;
820 int y1 = y + h;
821
822 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
823 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
824 {
825 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
826 }
827
828 if (fArray != null)
829 pixels = fArray;
830 else
831 pixels = new float[numBands * w * h];
832
833 for (int i=y; i<y1; i++) {
834 for(int j=x; j<x1; j++) {
835 for(int k=0; k<numBands; k++) {
836 pixels[Offset++] = getSampleFloat(j, i, k, data);
837 }
843
844 /**
845 * Returns all samples for a rectangle of pixels in a double
846 * array, one sample per array element.
847 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
848 * not in bounds.
849 * @param x The X coordinate of the upper left pixel location.
850 * @param y The Y coordinate of the upper left pixel location.
851 * @param w The width of the pixel rectangle.
852 * @param h The height of the pixel rectangle.
853 * @param dArray If non-null, returns the samples in this array.
854 * @param data The DataBuffer containing the image data.
855 * @return the samples for the specified region of pixels.
856 * @see #setPixels(int, int, int, int, double[], DataBuffer)
857 *
858 * @throws NullPointerException if data is null.
859 * @throws ArrayIndexOutOfBoundsException if the coordinates are
860 * not in bounds, or if dArray is too small to hold the output.
861 */
862 public double[] getPixels(int x, int y, int w, int h,
863 double dArray[], DataBuffer data) {
864 double pixels[];
865 int Offset = 0;
866 int x1 = x + w;
867 int y1 = y + h;
868
869 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
870 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
871 {
872 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
873 }
874
875 if (dArray != null)
876 pixels = dArray;
877 else
878 pixels = new double[numBands * w * h];
879
880 // Fix 4217412
881 for (int i=y; i<y1; i++) {
882 for (int j=x; j<x1; j++) {
883 for (int k=0; k<numBands; k++) {
884 pixels[Offset++] = getSampleDouble(j, i, k, data);
959 * of pixels in an int array, one sample per array element.
960 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
961 * not in bounds.
962 * @param x The X coordinate of the upper left pixel location.
963 * @param y The Y coordinate of the upper left pixel location.
964 * @param w The width of the pixel rectangle.
965 * @param h The height of the pixel rectangle.
966 * @param b The band to return.
967 * @param iArray If non-null, returns the samples in this array.
968 * @param data The DataBuffer containing the image data.
969 * @return the samples for the specified band for the specified region
970 * of pixels.
971 * @see #setSamples(int, int, int, int, int, int[], DataBuffer)
972 *
973 * @throws NullPointerException if data is null.
974 * @throws ArrayIndexOutOfBoundsException if the coordinates or
975 * the band index are not in bounds, or if iArray is too small to
976 * hold the output.
977 */
978 public int[] getSamples(int x, int y, int w, int h, int b,
979 int iArray[], DataBuffer data) {
980 int pixels[];
981 int Offset=0;
982 int x1 = x + w;
983 int y1 = y + h;
984
985 if (x < 0 || x1 < x || x1 > width ||
986 y < 0 || y1 < y || y1 > height)
987 {
988 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
989 }
990
991 if (iArray != null)
992 pixels = iArray;
993 else
994 pixels = new int[w * h];
995
996 for(int i=y; i<y1; i++) {
997 for (int j=x; j<x1; j++) {
998 pixels[Offset++] = getSample(j, i, b, data);
999 }
1000 }
1007 * of pixels in a float array, one sample per array element.
1008 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1009 * not in bounds.
1010 * @param x The X coordinate of the upper left pixel location.
1011 * @param y The Y coordinate of the upper left pixel location.
1012 * @param w The width of the pixel rectangle.
1013 * @param h The height of the pixel rectangle.
1014 * @param b The band to return.
1015 * @param fArray If non-null, returns the samples in this array.
1016 * @param data The DataBuffer containing the image data.
1017 * @return the samples for the specified band for the specified region
1018 * of pixels.
1019 * @see #setSamples(int, int, int, int, int, float[], DataBuffer)
1020 *
1021 * @throws NullPointerException if data is null.
1022 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1023 * the band index are not in bounds, or if fArray is too small to
1024 * hold the output.
1025 */
1026 public float[] getSamples(int x, int y, int w, int h,
1027 int b, float fArray[],
1028 DataBuffer data) {
1029 float pixels[];
1030 int Offset=0;
1031 int x1 = x + w;
1032 int y1 = y + h;
1033
1034 if (x < 0 || x1 < x || x1 > width ||
1035 y < 0 || y1 < y || y1 > height)
1036 {
1037 throw new ArrayIndexOutOfBoundsException("Invalid coordinates");
1038 }
1039
1040 if (fArray != null)
1041 pixels = fArray;
1042 else
1043 pixels = new float[w * h];
1044
1045 for (int i=y; i<y1; i++) {
1046 for (int j=x; j<x1; j++) {
1047 pixels[Offset++] = getSampleFloat(j, i, b, data);
1048 }
1049 }
1056 * of pixels in a double array, one sample per array element.
1057 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1058 * not in bounds.
1059 * @param x The X coordinate of the upper left pixel location.
1060 * @param y The Y coordinate of the upper left pixel location.
1061 * @param w The width of the pixel rectangle.
1062 * @param h The height of the pixel rectangle.
1063 * @param b The band to return.
1064 * @param dArray If non-null, returns the samples in this array.
1065 * @param data The DataBuffer containing the image data.
1066 * @return the samples for the specified band for the specified region
1067 * of pixels.
1068 * @see #setSamples(int, int, int, int, int, double[], DataBuffer)
1069 *
1070 * @throws NullPointerException if data is null.
1071 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1072 * the band index are not in bounds, or if dArray is too small to
1073 * hold the output.
1074 */
1075 public double[] getSamples(int x, int y, int w, int h,
1076 int b, double dArray[],
1077 DataBuffer data) {
1078 double pixels[];
1079 int Offset=0;
1080 int x1 = x + w;
1081 int y1 = y + h;
1082
1083 if (x < 0 || x1 < x || x1 > width ||
1084 y < 0 || y1 < y || y1 > height)
1085 {
1086 throw new ArrayIndexOutOfBoundsException("Invalid coordinates");
1087 }
1088
1089 if (dArray != null)
1090 pixels = dArray;
1091 else
1092 pixels = new double[w * h];
1093
1094 for (int i=y; i<y1; i++) {
1095 for (int j=x; j<x1; j++) {
1096 pixels[Offset++] = getSampleDouble(j, i, b, data);
1097 }
1098 }
1099
1100 return pixels;
1101 }
1102
1103 /**
1104 * Sets a pixel in the DataBuffer using an int array of samples for input.
1105 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1106 * not in bounds.
1107 * @param x The X coordinate of the pixel location.
1108 * @param y The Y coordinate of the pixel location.
1109 * @param iArray The input samples in an int array.
1110 * @param data The DataBuffer containing the image data.
1111 * @see #getPixel(int, int, int[], DataBuffer)
1112 *
1113 * @throws NullPointerException if iArray or data is null.
1114 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1115 * not in bounds, or if iArray is too small to hold the input.
1116 */
1117 public void setPixel(int x, int y, int iArray[], DataBuffer data) {
1118
1119 for (int i=0; i<numBands; i++)
1120 setSample(x, y, i, iArray[i], data);
1121 }
1122
1123 /**
1124 * Sets a pixel in the DataBuffer using a float array of samples for input.
1125 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1126 * not in bounds.
1127 * @param x The X coordinate of the pixel location.
1128 * @param y The Y coordinate of the pixel location.
1129 * @param fArray The input samples in a float array.
1130 * @param data The DataBuffer containing the image data.
1131 * @see #getPixel(int, int, float[], DataBuffer)
1132 *
1133 * @throws NullPointerException if fArray or data is null.
1134 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1135 * not in bounds, or if fArray is too small to hold the input.
1136 */
1137 public void setPixel(int x, int y, float fArray[], DataBuffer data) {
1138
1139 for (int i=0; i<numBands; i++)
1140 setSample(x, y, i, fArray[i], data);
1141 }
1142
1143 /**
1144 * Sets a pixel in the DataBuffer using a double array of samples
1145 * for input.
1146 * @param x The X coordinate of the pixel location.
1147 * @param y The Y coordinate of the pixel location.
1148 * @param dArray The input samples in a double array.
1149 * @param data The DataBuffer containing the image data.
1150 * @see #getPixel(int, int, double[], DataBuffer)
1151 *
1152 * @throws NullPointerException if dArray or data is null.
1153 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1154 * not in bounds, or if fArray is too small to hold the input.
1155 */
1156 public void setPixel(int x, int y, double dArray[], DataBuffer data) {
1157
1158 for (int i=0; i<numBands; i++)
1159 setSample(x, y, i, dArray[i], data);
1160 }
1161
1162 /**
1163 * Sets all samples for a rectangle of pixels from an int array containing
1164 * one sample per array element.
1165 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1166 * not in bounds.
1167 * @param x The X coordinate of the upper left pixel location.
1168 * @param y The Y coordinate of the upper left pixel location.
1169 * @param w The width of the pixel rectangle.
1170 * @param h The height of the pixel rectangle.
1171 * @param iArray The input samples in an int array.
1172 * @param data The DataBuffer containing the image data.
1173 * @see #getPixels(int, int, int, int, int[], DataBuffer)
1174 *
1175 * @throws NullPointerException if iArray or data is null.
1176 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1177 * not in bounds, or if iArray is too small to hold the input.
1178 */
1179 public void setPixels(int x, int y, int w, int h,
1180 int iArray[], DataBuffer data) {
1181 int Offset=0;
1182 int x1 = x + w;
1183 int y1 = y + h;
1184
1185 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1186 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1187 {
1188 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1189 }
1190
1191 for (int i=y; i<y1; i++) {
1192 for (int j=x; j<x1; j++) {
1193 for (int k=0; k<numBands; k++) {
1194 setSample(j, i, k, iArray[Offset++], data);
1195 }
1196 }
1197 }
1198 }
1199
1200 /**
1201 * Sets all samples for a rectangle of pixels from a float array containing
1202 * one sample per array element.
1203 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1204 * not in bounds.
1205 * @param x The X coordinate of the upper left pixel location.
1206 * @param y The Y coordinate of the upper left pixel location.
1207 * @param w The width of the pixel rectangle.
1208 * @param h The height of the pixel rectangle.
1209 * @param fArray The input samples in a float array.
1210 * @param data The DataBuffer containing the image data.
1211 * @see #getPixels(int, int, int, int, float[], DataBuffer)
1212 *
1213 * @throws NullPointerException if fArray or data is null.
1214 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1215 * not in bounds, or if fArray is too small to hold the input.
1216 */
1217 public void setPixels(int x, int y, int w, int h,
1218 float fArray[], DataBuffer data) {
1219 int Offset=0;
1220 int x1 = x + w;
1221 int y1 = y + h;
1222
1223 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width||
1224 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1225 {
1226 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1227 }
1228
1229 for (int i=y; i<y1; i++) {
1230 for (int j=x; j<x1; j++) {
1231 for(int k=0; k<numBands; k++) {
1232 setSample(j, i, k, fArray[Offset++], data);
1233 }
1234 }
1235 }
1236 }
1237
1238 /**
1239 * Sets all samples for a rectangle of pixels from a double array
1240 * containing one sample per array element.
1241 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1242 * not in bounds.
1243 * @param x The X coordinate of the upper left pixel location.
1244 * @param y The Y coordinate of the upper left pixel location.
1245 * @param w The width of the pixel rectangle.
1246 * @param h The height of the pixel rectangle.
1247 * @param dArray The input samples in a double array.
1248 * @param data The DataBuffer containing the image data.
1249 * @see #getPixels(int, int, int, int, double[], DataBuffer)
1250 *
1251 * @throws NullPointerException if dArray or data is null.
1252 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1253 * not in bounds, or if dArray is too small to hold the input.
1254 */
1255 public void setPixels(int x, int y, int w, int h,
1256 double dArray[], DataBuffer data) {
1257 int Offset=0;
1258 int x1 = x + w;
1259 int y1 = y + h;
1260
1261 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1262 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1263 {
1264 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1265 }
1266
1267 for (int i=y; i<y1; i++) {
1268 for (int j=x; j<x1; j++) {
1269 for (int k=0; k<numBands; k++) {
1270 setSample(j, i, k, dArray[Offset++], data);
1271 }
1272 }
1273 }
1274 }
1275
1276 /**
1352 /**
1353 * Sets the samples in the specified band for the specified rectangle
1354 * of pixels from an int array containing one sample per array element.
1355 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1356 * not in bounds.
1357 * @param x The X coordinate of the upper left pixel location.
1358 * @param y The Y coordinate of the upper left pixel location.
1359 * @param w The width of the pixel rectangle.
1360 * @param h The height of the pixel rectangle.
1361 * @param b The band to set.
1362 * @param iArray The input samples in an int array.
1363 * @param data The DataBuffer containing the image data.
1364 * @see #getSamples(int, int, int, int, int, int[], DataBuffer)
1365 *
1366 * @throws NullPointerException if iArray or data is null.
1367 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1368 * the band index are not in bounds, or if iArray is too small to
1369 * hold the input.
1370 */
1371 public void setSamples(int x, int y, int w, int h, int b,
1372 int iArray[], DataBuffer data) {
1373
1374 int Offset=0;
1375 int x1 = x + w;
1376 int y1 = y + h;
1377 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1378 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1379 {
1380 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1381 }
1382
1383 for (int i=y; i<y1; i++) {
1384 for (int j=x; j<x1; j++) {
1385 setSample(j, i, b, iArray[Offset++], data);
1386 }
1387 }
1388 }
1389
1390 /**
1391 * Sets the samples in the specified band for the specified rectangle
1392 * of pixels from a float array containing one sample per array element.
1393 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1394 * not in bounds.
1395 * @param x The X coordinate of the upper left pixel location.
1396 * @param y The Y coordinate of the upper left pixel location.
1397 * @param w The width of the pixel rectangle.
1398 * @param h The height of the pixel rectangle.
1399 * @param b The band to set.
1400 * @param fArray The input samples in a float array.
1401 * @param data The DataBuffer containing the image data.
1402 * @see #getSamples(int, int, int, int, int, float[], DataBuffer)
1403 *
1404 * @throws NullPointerException if fArray or data is null.
1405 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1406 * the band index are not in bounds, or if fArray is too small to
1407 * hold the input.
1408 */
1409 public void setSamples(int x, int y, int w, int h, int b,
1410 float fArray[], DataBuffer data) {
1411 int Offset=0;
1412 int x1 = x + w;
1413 int y1 = y + h;
1414
1415 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1416 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1417 {
1418 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1419 }
1420
1421 for (int i=y; i<y1; i++) {
1422 for (int j=x; j<x1; j++) {
1423 setSample(j, i, b, fArray[Offset++], data);
1424 }
1425 }
1426 }
1427
1428 /**
1429 * Sets the samples in the specified band for the specified rectangle
1430 * of pixels from a double array containing one sample per array element.
1431 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1432 * not in bounds.
1433 * @param x The X coordinate of the upper left pixel location.
1434 * @param y The Y coordinate of the upper left pixel location.
1435 * @param w The width of the pixel rectangle.
1436 * @param h The height of the pixel rectangle.
1437 * @param b The band to set.
1438 * @param dArray The input samples in a double array.
1439 * @param data The DataBuffer containing the image data.
1440 * @see #getSamples(int, int, int, int, int, double[], DataBuffer)
1441 *
1442 * @throws NullPointerException if dArray or data is null.
1443 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1444 * the band index are not in bounds, or if dArray is too small to
1445 * hold the input.
1446 */
1447 public void setSamples(int x, int y, int w, int h, int b,
1448 double dArray[], DataBuffer data) {
1449 int Offset=0;
1450 int x1 = x + w;
1451 int y1 = y + h;
1452
1453
1454 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1455 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1456 {
1457 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1458 }
1459
1460 for (int i=y; i<y1; i++) {
1461 for (int j=x; j<x1; j++) {
1462 setSample(j, i, b, dArray[Offset++], data);
1463 }
1464 }
1465 }
1466
1467 /**
1468 * Creates a SampleModel which describes data in this SampleModel's
1469 * format, but with a different width and height.
1470 * @param w the width of the image data
1471 * @param h the height of the image data
1472 * @return a {@code SampleModel} describing the same image
1473 * data as this {@code SampleModel}, but with a
1474 * different size.
1475 */
1476 public abstract SampleModel createCompatibleSampleModel(int w, int h);
1477
1478 /**
1479 * Creates a new SampleModel
1480 * with a subset of the bands of this
1481 * SampleModel.
1482 * @param bands the subset of bands of this {@code SampleModel}
1483 * @return a {@code SampleModel} with a subset of bands of this
1484 * {@code SampleModel}.
1485 */
1486 public abstract SampleModel createSubsetSampleModel(int bands[]);
1487
1488 /**
1489 * Creates a DataBuffer that corresponds to this SampleModel.
1490 * The DataBuffer's width and height will match this SampleModel's.
1491 * @return a {@code DataBuffer} corresponding to this
1492 * {@code SampleModel}.
1493 */
1494 public abstract DataBuffer createDataBuffer();
1495
1496 /** Returns the size in bits of samples for all bands.
1497 * @return the size of samples for all bands.
1498 */
1499 public abstract int[] getSampleSize();
1500
1501 /** Returns the size in bits of samples for the specified band.
1502 * @param band the specified band
1503 * @return the size of the samples of the specified band.
1504 */
1505 public abstract int getSampleSize(int band);
1506
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
217 public int getTransferType() {
218 return dataType;
219 }
220
221 /**
222 * Returns the samples for a specified pixel in an int array,
223 * one sample per array element.
224 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
225 * not in bounds.
226 * @param x The X coordinate of the pixel location
227 * @param y The Y coordinate of the pixel location
228 * @param iArray If non-null, returns the samples in this array
229 * @param data The DataBuffer containing the image data
230 * @return the samples for the specified pixel.
231 * @see #setPixel(int, int, int[], DataBuffer)
232 *
233 * @throws NullPointerException if data is null.
234 * @throws ArrayIndexOutOfBoundsException if the coordinates are
235 * not in bounds, or if iArray is too small to hold the output.
236 */
237 public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) {
238
239 int[] pixels;
240
241 if (iArray != null)
242 pixels = iArray;
243 else
244 pixels = new int[numBands];
245
246 for (int i=0; i<numBands; i++) {
247 pixels[i] = getSample(x, y, i, data);
248 }
249
250 return pixels;
251 }
252
253 /**
254 * Returns data for a single pixel in a primitive array of type
255 * TransferType. For image data supported by the Java 2D API, this
256 * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
257 * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
258 * or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
259 * thus increasing efficiency for data transfers. Generally, obj
681 break;
682 }
683
684 }
685
686 /**
687 * Returns the samples for the specified pixel in an array of float.
688 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
689 * not in bounds.
690 * @param x The X coordinate of the pixel location.
691 * @param y The Y coordinate of the pixel location.
692 * @param fArray If non-null, returns the samples in this array.
693 * @param data The DataBuffer containing the image data.
694 * @return the samples for the specified pixel.
695 * @see #setPixel(int, int, float[], DataBuffer)
696 *
697 * @throws NullPointerException if data is null.
698 * @throws ArrayIndexOutOfBoundsException if the coordinates are
699 * not in bounds, or if fArray is too small to hold the output.
700 */
701 public float[] getPixel(int x, int y, float[] fArray,
702 DataBuffer data) {
703
704 float[] pixels;
705
706 if (fArray != null)
707 pixels = fArray;
708 else
709 pixels = new float[numBands];
710
711 for (int i=0; i<numBands; i++)
712 pixels[i] = getSampleFloat(x, y, i, data);
713
714 return pixels;
715 }
716
717 /**
718 * Returns the samples for the specified pixel in an array of double.
719 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
720 * not in bounds.
721 * @param x The X coordinate of the pixel location.
722 * @param y The Y coordinate of the pixel location.
723 * @param dArray If non-null, returns the samples in this array.
724 * @param data The DataBuffer containing the image data.
725 * @return the samples for the specified pixel.
726 * @see #setPixel(int, int, double[], DataBuffer)
727 *
728 * @throws NullPointerException if data is null.
729 * @throws ArrayIndexOutOfBoundsException if the coordinates are
730 * not in bounds, or if dArray is too small to hold the output.
731 */
732 public double[] getPixel(int x, int y, double[] dArray,
733 DataBuffer data) {
734
735 double[] pixels;
736
737 if(dArray != null)
738 pixels = dArray;
739 else
740 pixels = new double[numBands];
741
742 for (int i=0; i<numBands; i++)
743 pixels[i] = getSampleDouble(x, y, i, data);
744
745 return pixels;
746 }
747
748 /**
749 * Returns all samples for a rectangle of pixels in an
750 * int array, one sample per array element.
751 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
752 * not in bounds.
753 * @param x The X coordinate of the upper left pixel location.
754 * @param y The Y coordinate of the upper left pixel location.
755 * @param w The width of the pixel rectangle.
756 * @param h The height of the pixel rectangle.
757 * @param iArray If non-null, returns the samples in this array.
758 * @param data The DataBuffer containing the image data.
759 * @return the samples for the specified region of pixels.
760 * @see #setPixels(int, int, int, int, int[], DataBuffer)
761 *
762 * @throws NullPointerException if data is null.
763 * @throws ArrayIndexOutOfBoundsException if the coordinates are
764 * not in bounds, or if iArray is too small to hold the output.
765 */
766 public int[] getPixels(int x, int y, int w, int h,
767 int[] iArray, DataBuffer data) {
768
769 int[] pixels;
770 int Offset=0;
771 int x1 = x + w;
772 int y1 = y + h;
773
774 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
775 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
776 {
777 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
778 }
779
780 if (iArray != null)
781 pixels = iArray;
782 else
783 pixels = new int[numBands * w * h];
784
785 for (int i=y; i<y1; i++) {
786 for (int j=x; j<x1; j++) {
787 for(int k=0; k<numBands; k++) {
788 pixels[Offset++] = getSample(j, i, k, data);
789 }
795
796 /**
797 * Returns all samples for a rectangle of pixels in a float
798 * array, one sample per array element.
799 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
800 * not in bounds.
801 * @param x The X coordinate of the upper left pixel location.
802 * @param y The Y coordinate of the upper left pixel location.
803 * @param w The width of the pixel rectangle.
804 * @param h The height of the pixel rectangle.
805 * @param fArray If non-null, returns the samples in this array.
806 * @param data The DataBuffer containing the image data.
807 * @return the samples for the specified region of pixels.
808 * @see #setPixels(int, int, int, int, float[], DataBuffer)
809 *
810 * @throws NullPointerException if data is null.
811 * @throws ArrayIndexOutOfBoundsException if the coordinates are
812 * not in bounds, or if fArray is too small to hold the output.
813 */
814 public float[] getPixels(int x, int y, int w, int h,
815 float[] fArray, DataBuffer data) {
816
817 float[] pixels;
818 int Offset = 0;
819 int x1 = x + w;
820 int y1 = y + h;
821
822 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
823 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
824 {
825 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
826 }
827
828 if (fArray != null)
829 pixels = fArray;
830 else
831 pixels = new float[numBands * w * h];
832
833 for (int i=y; i<y1; i++) {
834 for(int j=x; j<x1; j++) {
835 for(int k=0; k<numBands; k++) {
836 pixels[Offset++] = getSampleFloat(j, i, k, data);
837 }
843
844 /**
845 * Returns all samples for a rectangle of pixels in a double
846 * array, one sample per array element.
847 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
848 * not in bounds.
849 * @param x The X coordinate of the upper left pixel location.
850 * @param y The Y coordinate of the upper left pixel location.
851 * @param w The width of the pixel rectangle.
852 * @param h The height of the pixel rectangle.
853 * @param dArray If non-null, returns the samples in this array.
854 * @param data The DataBuffer containing the image data.
855 * @return the samples for the specified region of pixels.
856 * @see #setPixels(int, int, int, int, double[], DataBuffer)
857 *
858 * @throws NullPointerException if data is null.
859 * @throws ArrayIndexOutOfBoundsException if the coordinates are
860 * not in bounds, or if dArray is too small to hold the output.
861 */
862 public double[] getPixels(int x, int y, int w, int h,
863 double[] dArray, DataBuffer data) {
864 double[] pixels;
865 int Offset = 0;
866 int x1 = x + w;
867 int y1 = y + h;
868
869 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
870 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
871 {
872 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
873 }
874
875 if (dArray != null)
876 pixels = dArray;
877 else
878 pixels = new double[numBands * w * h];
879
880 // Fix 4217412
881 for (int i=y; i<y1; i++) {
882 for (int j=x; j<x1; j++) {
883 for (int k=0; k<numBands; k++) {
884 pixels[Offset++] = getSampleDouble(j, i, k, data);
959 * of pixels in an int array, one sample per array element.
960 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
961 * not in bounds.
962 * @param x The X coordinate of the upper left pixel location.
963 * @param y The Y coordinate of the upper left pixel location.
964 * @param w The width of the pixel rectangle.
965 * @param h The height of the pixel rectangle.
966 * @param b The band to return.
967 * @param iArray If non-null, returns the samples in this array.
968 * @param data The DataBuffer containing the image data.
969 * @return the samples for the specified band for the specified region
970 * of pixels.
971 * @see #setSamples(int, int, int, int, int, int[], DataBuffer)
972 *
973 * @throws NullPointerException if data is null.
974 * @throws ArrayIndexOutOfBoundsException if the coordinates or
975 * the band index are not in bounds, or if iArray is too small to
976 * hold the output.
977 */
978 public int[] getSamples(int x, int y, int w, int h, int b,
979 int[] iArray, DataBuffer data) {
980 int[] pixels;
981 int Offset=0;
982 int x1 = x + w;
983 int y1 = y + h;
984
985 if (x < 0 || x1 < x || x1 > width ||
986 y < 0 || y1 < y || y1 > height)
987 {
988 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
989 }
990
991 if (iArray != null)
992 pixels = iArray;
993 else
994 pixels = new int[w * h];
995
996 for(int i=y; i<y1; i++) {
997 for (int j=x; j<x1; j++) {
998 pixels[Offset++] = getSample(j, i, b, data);
999 }
1000 }
1007 * of pixels in a float array, one sample per array element.
1008 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1009 * not in bounds.
1010 * @param x The X coordinate of the upper left pixel location.
1011 * @param y The Y coordinate of the upper left pixel location.
1012 * @param w The width of the pixel rectangle.
1013 * @param h The height of the pixel rectangle.
1014 * @param b The band to return.
1015 * @param fArray If non-null, returns the samples in this array.
1016 * @param data The DataBuffer containing the image data.
1017 * @return the samples for the specified band for the specified region
1018 * of pixels.
1019 * @see #setSamples(int, int, int, int, int, float[], DataBuffer)
1020 *
1021 * @throws NullPointerException if data is null.
1022 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1023 * the band index are not in bounds, or if fArray is too small to
1024 * hold the output.
1025 */
1026 public float[] getSamples(int x, int y, int w, int h,
1027 int b, float[] fArray,
1028 DataBuffer data) {
1029 float[] pixels;
1030 int Offset=0;
1031 int x1 = x + w;
1032 int y1 = y + h;
1033
1034 if (x < 0 || x1 < x || x1 > width ||
1035 y < 0 || y1 < y || y1 > height)
1036 {
1037 throw new ArrayIndexOutOfBoundsException("Invalid coordinates");
1038 }
1039
1040 if (fArray != null)
1041 pixels = fArray;
1042 else
1043 pixels = new float[w * h];
1044
1045 for (int i=y; i<y1; i++) {
1046 for (int j=x; j<x1; j++) {
1047 pixels[Offset++] = getSampleFloat(j, i, b, data);
1048 }
1049 }
1056 * of pixels in a double array, one sample per array element.
1057 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1058 * not in bounds.
1059 * @param x The X coordinate of the upper left pixel location.
1060 * @param y The Y coordinate of the upper left pixel location.
1061 * @param w The width of the pixel rectangle.
1062 * @param h The height of the pixel rectangle.
1063 * @param b The band to return.
1064 * @param dArray If non-null, returns the samples in this array.
1065 * @param data The DataBuffer containing the image data.
1066 * @return the samples for the specified band for the specified region
1067 * of pixels.
1068 * @see #setSamples(int, int, int, int, int, double[], DataBuffer)
1069 *
1070 * @throws NullPointerException if data is null.
1071 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1072 * the band index are not in bounds, or if dArray is too small to
1073 * hold the output.
1074 */
1075 public double[] getSamples(int x, int y, int w, int h,
1076 int b, double[] dArray,
1077 DataBuffer data) {
1078 double[] pixels;
1079 int Offset=0;
1080 int x1 = x + w;
1081 int y1 = y + h;
1082
1083 if (x < 0 || x1 < x || x1 > width ||
1084 y < 0 || y1 < y || y1 > height)
1085 {
1086 throw new ArrayIndexOutOfBoundsException("Invalid coordinates");
1087 }
1088
1089 if (dArray != null)
1090 pixels = dArray;
1091 else
1092 pixels = new double[w * h];
1093
1094 for (int i=y; i<y1; i++) {
1095 for (int j=x; j<x1; j++) {
1096 pixels[Offset++] = getSampleDouble(j, i, b, data);
1097 }
1098 }
1099
1100 return pixels;
1101 }
1102
1103 /**
1104 * Sets a pixel in the DataBuffer using an int array of samples for input.
1105 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1106 * not in bounds.
1107 * @param x The X coordinate of the pixel location.
1108 * @param y The Y coordinate of the pixel location.
1109 * @param iArray The input samples in an int array.
1110 * @param data The DataBuffer containing the image data.
1111 * @see #getPixel(int, int, int[], DataBuffer)
1112 *
1113 * @throws NullPointerException if iArray or data is null.
1114 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1115 * not in bounds, or if iArray is too small to hold the input.
1116 */
1117 public void setPixel(int x, int y, int[] iArray, DataBuffer data) {
1118
1119 for (int i=0; i<numBands; i++)
1120 setSample(x, y, i, iArray[i], data);
1121 }
1122
1123 /**
1124 * Sets a pixel in the DataBuffer using a float array of samples for input.
1125 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1126 * not in bounds.
1127 * @param x The X coordinate of the pixel location.
1128 * @param y The Y coordinate of the pixel location.
1129 * @param fArray The input samples in a float array.
1130 * @param data The DataBuffer containing the image data.
1131 * @see #getPixel(int, int, float[], DataBuffer)
1132 *
1133 * @throws NullPointerException if fArray or data is null.
1134 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1135 * not in bounds, or if fArray is too small to hold the input.
1136 */
1137 public void setPixel(int x, int y, float[] fArray, DataBuffer data) {
1138
1139 for (int i=0; i<numBands; i++)
1140 setSample(x, y, i, fArray[i], data);
1141 }
1142
1143 /**
1144 * Sets a pixel in the DataBuffer using a double array of samples
1145 * for input.
1146 * @param x The X coordinate of the pixel location.
1147 * @param y The Y coordinate of the pixel location.
1148 * @param dArray The input samples in a double array.
1149 * @param data The DataBuffer containing the image data.
1150 * @see #getPixel(int, int, double[], DataBuffer)
1151 *
1152 * @throws NullPointerException if dArray or data is null.
1153 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1154 * not in bounds, or if fArray is too small to hold the input.
1155 */
1156 public void setPixel(int x, int y, double[] dArray, DataBuffer data) {
1157
1158 for (int i=0; i<numBands; i++)
1159 setSample(x, y, i, dArray[i], data);
1160 }
1161
1162 /**
1163 * Sets all samples for a rectangle of pixels from an int array containing
1164 * one sample per array element.
1165 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1166 * not in bounds.
1167 * @param x The X coordinate of the upper left pixel location.
1168 * @param y The Y coordinate of the upper left pixel location.
1169 * @param w The width of the pixel rectangle.
1170 * @param h The height of the pixel rectangle.
1171 * @param iArray The input samples in an int array.
1172 * @param data The DataBuffer containing the image data.
1173 * @see #getPixels(int, int, int, int, int[], DataBuffer)
1174 *
1175 * @throws NullPointerException if iArray or data is null.
1176 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1177 * not in bounds, or if iArray is too small to hold the input.
1178 */
1179 public void setPixels(int x, int y, int w, int h,
1180 int[] iArray, DataBuffer data) {
1181 int Offset=0;
1182 int x1 = x + w;
1183 int y1 = y + h;
1184
1185 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1186 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1187 {
1188 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1189 }
1190
1191 for (int i=y; i<y1; i++) {
1192 for (int j=x; j<x1; j++) {
1193 for (int k=0; k<numBands; k++) {
1194 setSample(j, i, k, iArray[Offset++], data);
1195 }
1196 }
1197 }
1198 }
1199
1200 /**
1201 * Sets all samples for a rectangle of pixels from a float array containing
1202 * one sample per array element.
1203 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1204 * not in bounds.
1205 * @param x The X coordinate of the upper left pixel location.
1206 * @param y The Y coordinate of the upper left pixel location.
1207 * @param w The width of the pixel rectangle.
1208 * @param h The height of the pixel rectangle.
1209 * @param fArray The input samples in a float array.
1210 * @param data The DataBuffer containing the image data.
1211 * @see #getPixels(int, int, int, int, float[], DataBuffer)
1212 *
1213 * @throws NullPointerException if fArray or data is null.
1214 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1215 * not in bounds, or if fArray is too small to hold the input.
1216 */
1217 public void setPixels(int x, int y, int w, int h,
1218 float[] fArray, DataBuffer data) {
1219 int Offset=0;
1220 int x1 = x + w;
1221 int y1 = y + h;
1222
1223 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width||
1224 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1225 {
1226 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1227 }
1228
1229 for (int i=y; i<y1; i++) {
1230 for (int j=x; j<x1; j++) {
1231 for(int k=0; k<numBands; k++) {
1232 setSample(j, i, k, fArray[Offset++], data);
1233 }
1234 }
1235 }
1236 }
1237
1238 /**
1239 * Sets all samples for a rectangle of pixels from a double array
1240 * containing one sample per array element.
1241 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1242 * not in bounds.
1243 * @param x The X coordinate of the upper left pixel location.
1244 * @param y The Y coordinate of the upper left pixel location.
1245 * @param w The width of the pixel rectangle.
1246 * @param h The height of the pixel rectangle.
1247 * @param dArray The input samples in a double array.
1248 * @param data The DataBuffer containing the image data.
1249 * @see #getPixels(int, int, int, int, double[], DataBuffer)
1250 *
1251 * @throws NullPointerException if dArray or data is null.
1252 * @throws ArrayIndexOutOfBoundsException if the coordinates are
1253 * not in bounds, or if dArray is too small to hold the input.
1254 */
1255 public void setPixels(int x, int y, int w, int h,
1256 double[] dArray, DataBuffer data) {
1257 int Offset=0;
1258 int x1 = x + w;
1259 int y1 = y + h;
1260
1261 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1262 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1263 {
1264 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1265 }
1266
1267 for (int i=y; i<y1; i++) {
1268 for (int j=x; j<x1; j++) {
1269 for (int k=0; k<numBands; k++) {
1270 setSample(j, i, k, dArray[Offset++], data);
1271 }
1272 }
1273 }
1274 }
1275
1276 /**
1352 /**
1353 * Sets the samples in the specified band for the specified rectangle
1354 * of pixels from an int array containing one sample per array element.
1355 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1356 * not in bounds.
1357 * @param x The X coordinate of the upper left pixel location.
1358 * @param y The Y coordinate of the upper left pixel location.
1359 * @param w The width of the pixel rectangle.
1360 * @param h The height of the pixel rectangle.
1361 * @param b The band to set.
1362 * @param iArray The input samples in an int array.
1363 * @param data The DataBuffer containing the image data.
1364 * @see #getSamples(int, int, int, int, int, int[], DataBuffer)
1365 *
1366 * @throws NullPointerException if iArray or data is null.
1367 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1368 * the band index are not in bounds, or if iArray is too small to
1369 * hold the input.
1370 */
1371 public void setSamples(int x, int y, int w, int h, int b,
1372 int[] iArray, DataBuffer data) {
1373
1374 int Offset=0;
1375 int x1 = x + w;
1376 int y1 = y + h;
1377 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1378 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1379 {
1380 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1381 }
1382
1383 for (int i=y; i<y1; i++) {
1384 for (int j=x; j<x1; j++) {
1385 setSample(j, i, b, iArray[Offset++], data);
1386 }
1387 }
1388 }
1389
1390 /**
1391 * Sets the samples in the specified band for the specified rectangle
1392 * of pixels from a float array containing one sample per array element.
1393 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1394 * not in bounds.
1395 * @param x The X coordinate of the upper left pixel location.
1396 * @param y The Y coordinate of the upper left pixel location.
1397 * @param w The width of the pixel rectangle.
1398 * @param h The height of the pixel rectangle.
1399 * @param b The band to set.
1400 * @param fArray The input samples in a float array.
1401 * @param data The DataBuffer containing the image data.
1402 * @see #getSamples(int, int, int, int, int, float[], DataBuffer)
1403 *
1404 * @throws NullPointerException if fArray or data is null.
1405 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1406 * the band index are not in bounds, or if fArray is too small to
1407 * hold the input.
1408 */
1409 public void setSamples(int x, int y, int w, int h, int b,
1410 float[] fArray, DataBuffer data) {
1411 int Offset=0;
1412 int x1 = x + w;
1413 int y1 = y + h;
1414
1415 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1416 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1417 {
1418 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1419 }
1420
1421 for (int i=y; i<y1; i++) {
1422 for (int j=x; j<x1; j++) {
1423 setSample(j, i, b, fArray[Offset++], data);
1424 }
1425 }
1426 }
1427
1428 /**
1429 * Sets the samples in the specified band for the specified rectangle
1430 * of pixels from a double array containing one sample per array element.
1431 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
1432 * not in bounds.
1433 * @param x The X coordinate of the upper left pixel location.
1434 * @param y The Y coordinate of the upper left pixel location.
1435 * @param w The width of the pixel rectangle.
1436 * @param h The height of the pixel rectangle.
1437 * @param b The band to set.
1438 * @param dArray The input samples in a double array.
1439 * @param data The DataBuffer containing the image data.
1440 * @see #getSamples(int, int, int, int, int, double[], DataBuffer)
1441 *
1442 * @throws NullPointerException if dArray or data is null.
1443 * @throws ArrayIndexOutOfBoundsException if the coordinates or
1444 * the band index are not in bounds, or if dArray is too small to
1445 * hold the input.
1446 */
1447 public void setSamples(int x, int y, int w, int h, int b,
1448 double[] dArray, DataBuffer data) {
1449 int Offset=0;
1450 int x1 = x + w;
1451 int y1 = y + h;
1452
1453
1454 if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
1455 y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
1456 {
1457 throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
1458 }
1459
1460 for (int i=y; i<y1; i++) {
1461 for (int j=x; j<x1; j++) {
1462 setSample(j, i, b, dArray[Offset++], data);
1463 }
1464 }
1465 }
1466
1467 /**
1468 * Creates a SampleModel which describes data in this SampleModel's
1469 * format, but with a different width and height.
1470 * @param w the width of the image data
1471 * @param h the height of the image data
1472 * @return a {@code SampleModel} describing the same image
1473 * data as this {@code SampleModel}, but with a
1474 * different size.
1475 */
1476 public abstract SampleModel createCompatibleSampleModel(int w, int h);
1477
1478 /**
1479 * Creates a new SampleModel
1480 * with a subset of the bands of this
1481 * SampleModel.
1482 * @param bands the subset of bands of this {@code SampleModel}
1483 * @return a {@code SampleModel} with a subset of bands of this
1484 * {@code SampleModel}.
1485 */
1486 public abstract SampleModel createSubsetSampleModel(int[] bands);
1487
1488 /**
1489 * Creates a DataBuffer that corresponds to this SampleModel.
1490 * The DataBuffer's width and height will match this SampleModel's.
1491 * @return a {@code DataBuffer} corresponding to this
1492 * {@code SampleModel}.
1493 */
1494 public abstract DataBuffer createDataBuffer();
1495
1496 /** Returns the size in bits of samples for all bands.
1497 * @return the size of samples for all bands.
1498 */
1499 public abstract int[] getSampleSize();
1500
1501 /** Returns the size in bits of samples for the specified band.
1502 * @param band the specified band
1503 * @return the size of the samples of the specified band.
1504 */
1505 public abstract int getSampleSize(int band);
1506
|