src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java
changeset 52750 6bdbd601d31c
parent 52742 b9f3606b2f83
child 52751 abed2967ec3a
equal deleted inserted replaced
52749:a4db2f17e1be 52750:6bdbd601d31c
  1161 
  1161 
  1162         // Determine if all of the relevant output bands have the
  1162         // Determine if all of the relevant output bands have the
  1163         // same bit depth as the source data
  1163         // same bit depth as the source data
  1164         boolean adjustBitDepths = false;
  1164         boolean adjustBitDepths = false;
  1165         int[] outputSampleSize = imRas.getSampleModel().getSampleSize();
  1165         int[] outputSampleSize = imRas.getSampleModel().getSampleSize();
  1166         int numBands = outputSampleSize.length;
  1166         for (int b = 0; b < inputBands; b++) {
  1167         for (int b = 0; b < numBands; b++) {
       
  1168             if (outputSampleSize[b] != bitDepth) {
  1167             if (outputSampleSize[b] != bitDepth) {
  1169                 adjustBitDepths = true;
  1168                 adjustBitDepths = true;
  1170                 break;
  1169                 break;
  1171             }
  1170             }
  1172         }
  1171         }
  1175         // the conversion
  1174         // the conversion
  1176         int[][] scale = null;
  1175         int[][] scale = null;
  1177         if (adjustBitDepths) {
  1176         if (adjustBitDepths) {
  1178             int maxInSample = (1 << bitDepth) - 1;
  1177             int maxInSample = (1 << bitDepth) - 1;
  1179             int halfMaxInSample = maxInSample/2;
  1178             int halfMaxInSample = maxInSample/2;
  1180             scale = new int[numBands][];
  1179             scale = new int[inputBands][];
  1181             for (int b = 0; b < numBands; b++) {
  1180             for (int b = 0; b < inputBands; b++) {
  1182                 int maxOutSample = (1 << outputSampleSize[b]) - 1;
  1181                 int maxOutSample = (1 << outputSampleSize[b]) - 1;
  1183                 scale[b] = new int[maxInSample + 1];
  1182                 scale[b] = new int[maxInSample + 1];
  1184                 for (int s = 0; s <= maxInSample; s++) {
  1183                 for (int s = 0; s <= maxInSample; s++) {
  1185                     scale[b][s] =
  1184                     scale[b][s] =
  1186                         (s*maxOutSample + halfMaxInSample)/maxInSample;
  1185                         (s*maxOutSample + halfMaxInSample)/maxInSample;
  1302                          dstX < updateMinX + updateWidth;
  1301                          dstX < updateMinX + updateWidth;
  1303                          dstX += updateXStep) {
  1302                          dstX += updateXStep) {
  1304 
  1303 
  1305                         passRow.getPixel(newSrcX, 0, ps);
  1304                         passRow.getPixel(newSrcX, 0, ps);
  1306                         if (adjustBitDepths) {
  1305                         if (adjustBitDepths) {
  1307                             for (int b = 0; b < numBands; b++) {
  1306                             for (int b = 0; b < inputBands; b++) {
  1308                                 ps[b] = scale[b][ps[b]];
  1307                                 ps[b] = scale[b][ps[b]];
  1309                             }
  1308                             }
  1310                         }
  1309                         }
  1311                         if (tRNSTransparentPixelPresent) {
  1310                         if (tRNSTransparentPixelPresent) {
  1312                             if (metadata.tRNS_colorType == PNG_COLOR_RGB) {
  1311                             if (metadata.tRNS_colorType == PNG_COLOR_RGB) {