< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java

Print this page




1142                            sourceMaxProgressivePass,
1143                            updateMinX, updateMinY,
1144                            updateXStep, updateYStep,
1145                            destinationBands);
1146 
1147         // Handle source and destination bands
1148         if (sourceBands != null) {
1149             passRow = passRow.createWritableChild(0, 0,
1150                                                   passRow.getWidth(), 1,
1151                                                   0, 0,
1152                                                   sourceBands);
1153         }
1154         if (destinationBands != null) {
1155             imRas = imRas.createWritableChild(0, 0,
1156                                               imRas.getWidth(),
1157                                               imRas.getHeight(),
1158                                               0, 0,
1159                                               destinationBands);
1160         }
1161 



1162         // Determine if all of the relevant output bands have the
1163         // same bit depth as the source data
1164         boolean adjustBitDepths = false;
1165         int[] outputSampleSize = imRas.getSampleModel().getSampleSize();
1166         int numBands = outputSampleSize.length;





1167         for (int b = 0; b < numBands; b++) {
1168             if (outputSampleSize[b] != bitDepth) {
1169                 adjustBitDepths = true;
1170                 break;
1171             }
1172         }
1173 
1174         // If the bit depths differ, create a lookup table per band to perform
1175         // the conversion
1176         int[][] scale = null;
1177         if (adjustBitDepths) {
1178             int maxInSample = (1 << bitDepth) - 1;
1179             int halfMaxInSample = maxInSample/2;
1180             scale = new int[numBands][];
1181             for (int b = 0; b < numBands; b++) {
1182                 int maxOutSample = (1 << outputSampleSize[b]) - 1;
1183                 scale[b] = new int[maxInSample + 1];
1184                 for (int s = 0; s <= maxInSample; s++) {
1185                     scale[b][s] =
1186                         (s*maxOutSample + halfMaxInSample)/maxInSample;


1266             if ((sourceY >= sourceRegion.y) &&
1267                 (sourceY < sourceRegion.y + sourceRegion.height) &&
1268                 (((sourceY - sourceRegion.y) %
1269                   sourceYSubsampling) == 0)) {
1270 
1271                 int dstY = destinationOffset.y +
1272                     (sourceY - sourceRegion.y)/sourceYSubsampling;
1273                 if (dstY < dstMinY) {
1274                     continue;
1275                 }
1276                 if (dstY > dstMaxY) {
1277                     break;
1278                 }
1279 
1280                /*
1281                 * For PNG images of color type PNG_COLOR_RGB or PNG_COLOR_GRAY
1282                 * that contain a specific transparent color (given by tRNS
1283                 * chunk), we compare the decoded pixel color with the color
1284                 * given by tRNS chunk to set the alpha on the destination.
1285                 */
1286                 boolean tRNSTransparentPixelPresent =
1287                     theImage.getSampleModel().getNumBands() == inputBands + 1 &&
1288                     metadata.hasTransparentColor();
1289                 if (useSetRect &&
1290                     !tRNSTransparentPixelPresent) {
1291                     imRas.setRect(updateMinX, dstY, passRow);
1292                 } else {
1293                     int newSrcX = srcX;
1294 
1295                     /*
1296                      * Create intermediate array to fill the extra alpha
1297                      * channel when tRNSTransparentPixelPresent is true.
1298                      */
1299                     final int[] temp = new int[inputBands + 1];
1300                     final int opaque = (bitDepth < 16) ? 255 : 65535;
1301                     for (int dstX = updateMinX;
1302                          dstX < updateMinX + updateWidth;
1303                          dstX += updateXStep) {
1304 
1305                         passRow.getPixel(newSrcX, 0, ps);
1306                         if (adjustBitDepths) {
1307                             for (int b = 0; b < numBands; b++) {
1308                                 ps[b] = scale[b][ps[b]];




1142                            sourceMaxProgressivePass,
1143                            updateMinX, updateMinY,
1144                            updateXStep, updateYStep,
1145                            destinationBands);
1146 
1147         // Handle source and destination bands
1148         if (sourceBands != null) {
1149             passRow = passRow.createWritableChild(0, 0,
1150                                                   passRow.getWidth(), 1,
1151                                                   0, 0,
1152                                                   sourceBands);
1153         }
1154         if (destinationBands != null) {
1155             imRas = imRas.createWritableChild(0, 0,
1156                                               imRas.getWidth(),
1157                                               imRas.getHeight(),
1158                                               0, 0,
1159                                               destinationBands);
1160         }
1161 
1162         boolean tRNSTransparentPixelPresent =
1163                 theImage.getSampleModel().getNumBands() == inputBands + 1 &&
1164                 metadata.hasTransparentColor();
1165         // Determine if all of the relevant output bands have the
1166         // same bit depth as the source data
1167         boolean adjustBitDepths = false;
1168         int[] outputSampleSize = imRas.getSampleModel().getSampleSize();
1169         int numBands;
1170         if (tRNSTransparentPixelPresent) {
1171             numBands = outputSampleSize.length - 1;
1172         } else {
1173             numBands = outputSampleSize.length;
1174         }
1175         for (int b = 0; b < numBands; b++) {
1176             if (outputSampleSize[b] != bitDepth) {
1177                 adjustBitDepths = true;
1178                 break;
1179             }
1180         }
1181 
1182         // If the bit depths differ, create a lookup table per band to perform
1183         // the conversion
1184         int[][] scale = null;
1185         if (adjustBitDepths) {
1186             int maxInSample = (1 << bitDepth) - 1;
1187             int halfMaxInSample = maxInSample/2;
1188             scale = new int[numBands][];
1189             for (int b = 0; b < numBands; b++) {
1190                 int maxOutSample = (1 << outputSampleSize[b]) - 1;
1191                 scale[b] = new int[maxInSample + 1];
1192                 for (int s = 0; s <= maxInSample; s++) {
1193                     scale[b][s] =
1194                         (s*maxOutSample + halfMaxInSample)/maxInSample;


1274             if ((sourceY >= sourceRegion.y) &&
1275                 (sourceY < sourceRegion.y + sourceRegion.height) &&
1276                 (((sourceY - sourceRegion.y) %
1277                   sourceYSubsampling) == 0)) {
1278 
1279                 int dstY = destinationOffset.y +
1280                     (sourceY - sourceRegion.y)/sourceYSubsampling;
1281                 if (dstY < dstMinY) {
1282                     continue;
1283                 }
1284                 if (dstY > dstMaxY) {
1285                     break;
1286                 }
1287 
1288                /*
1289                 * For PNG images of color type PNG_COLOR_RGB or PNG_COLOR_GRAY
1290                 * that contain a specific transparent color (given by tRNS
1291                 * chunk), we compare the decoded pixel color with the color
1292                 * given by tRNS chunk to set the alpha on the destination.
1293                 */



1294                 if (useSetRect &&
1295                     !tRNSTransparentPixelPresent) {
1296                     imRas.setRect(updateMinX, dstY, passRow);
1297                 } else {
1298                     int newSrcX = srcX;
1299 
1300                     /*
1301                      * Create intermediate array to fill the extra alpha
1302                      * channel when tRNSTransparentPixelPresent is true.
1303                      */
1304                     final int[] temp = new int[inputBands + 1];
1305                     final int opaque = (bitDepth < 16) ? 255 : 65535;
1306                     for (int dstX = updateMinX;
1307                          dstX < updateMinX + updateWidth;
1308                          dstX += updateXStep) {
1309 
1310                         passRow.getPixel(newSrcX, 0, ps);
1311                         if (adjustBitDepths) {
1312                             for (int b = 0; b < numBands; b++) {
1313                                 ps[b] = scale[b][ps[b]];


< prev index next >