jdk/src/share/classes/java/awt/image/SampleModel.java
changeset 6631 8bb1126f01d3
parent 5506 202f599c92aa
child 6815 eba82865cf06
equal deleted inserted replaced
6605:f960f117f162 6631:8bb1126f01d3
   935      */
   935      */
   936     public int[] getSamples(int x, int y, int w, int h, int b,
   936     public int[] getSamples(int x, int y, int w, int h, int b,
   937                             int iArray[], DataBuffer data) {
   937                             int iArray[], DataBuffer data) {
   938         int pixels[];
   938         int pixels[];
   939         int Offset=0;
   939         int Offset=0;
       
   940         int x1 = x + w;
       
   941         int y1 = y + h;
       
   942 
       
   943         if (x < 0 || x1 < x || x1 > width ||
       
   944             y < 0 || y1 < y || y1 > height)
       
   945         {
       
   946             throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
       
   947         }
   940 
   948 
   941         if (iArray != null)
   949         if (iArray != null)
   942             pixels = iArray;
   950             pixels = iArray;
   943         else
   951         else
   944             pixels = new int[w * h];
   952             pixels = new int[w * h];
   945 
   953 
   946         for(int i=y; i<(h+y); i++) {
   954         for(int i=y; i<y1; i++) {
   947             for (int j=x; j<(w+x); j++) {
   955             for (int j=x; j<x1; j++) {
   948                 pixels[Offset++] = getSample(j, i, b, data);
   956                 pixels[Offset++] = getSample(j, i, b, data);
   949             }
   957             }
   950         }
   958         }
   951 
   959 
   952         return pixels;
   960         return pixels;
   976     public float[] getSamples(int x, int y, int w, int h,
   984     public float[] getSamples(int x, int y, int w, int h,
   977                               int b, float fArray[],
   985                               int b, float fArray[],
   978                               DataBuffer data) {
   986                               DataBuffer data) {
   979         float pixels[];
   987         float pixels[];
   980         int   Offset=0;
   988         int   Offset=0;
       
   989         int x1 = x + w;
       
   990         int y1 = y + h;
       
   991 
       
   992         if (x < 0 || x1 < x || x1 > width ||
       
   993             y < 0 || y1 < y || y1 > height)
       
   994         {
       
   995             throw new ArrayIndexOutOfBoundsException("Invalid coordinates");
       
   996         }
   981 
   997 
   982         if (fArray != null)
   998         if (fArray != null)
   983             pixels = fArray;
   999             pixels = fArray;
   984         else
  1000         else
   985             pixels = new float[w * h];
  1001             pixels = new float[w * h];
   986 
  1002 
   987         for (int i=y; i<(h+y); i++) {
  1003         for (int i=y; i<y1; i++) {
   988             for (int j=x; j<(w+x); j++) {
  1004             for (int j=x; j<x1; j++) {
   989                 pixels[Offset++] = getSampleFloat(j, i, b, data);
  1005                 pixels[Offset++] = getSampleFloat(j, i, b, data);
   990             }
  1006             }
   991         }
  1007         }
   992 
  1008 
   993         return pixels;
  1009         return pixels;
  1017     public double[] getSamples(int x, int y, int w, int h,
  1033     public double[] getSamples(int x, int y, int w, int h,
  1018                                int b, double dArray[],
  1034                                int b, double dArray[],
  1019                                DataBuffer data) {
  1035                                DataBuffer data) {
  1020         double pixels[];
  1036         double pixels[];
  1021         int    Offset=0;
  1037         int    Offset=0;
       
  1038         int x1 = x + w;
       
  1039         int y1 = y + h;
       
  1040 
       
  1041         if (x < 0 || x1 < x || x1 > width ||
       
  1042             y < 0 || y1 < y || y1 > height)
       
  1043         {
       
  1044             throw new ArrayIndexOutOfBoundsException("Invalid coordinates");
       
  1045         }
  1022 
  1046 
  1023         if (dArray != null)
  1047         if (dArray != null)
  1024             pixels = dArray;
  1048             pixels = dArray;
  1025         else
  1049         else
  1026             pixels = new double[w * h];
  1050             pixels = new double[w * h];
  1027 
  1051 
  1028         for (int i=y; i<(y+h); i++) {
  1052         for (int i=y; i<y1; i++) {
  1029             for (int j=x; j<(x+w); j++) {
  1053             for (int j=x; j<x1; j++) {
  1030                 pixels[Offset++] = getSampleDouble(j, i, b, data);
  1054                 pixels[Offset++] = getSampleDouble(j, i, b, data);
  1031             }
  1055             }
  1032         }
  1056         }
  1033 
  1057 
  1034         return pixels;
  1058         return pixels;