< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2014, 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


1311             for (int i = 0; i<srcBands.length;i++)
1312                 System.out.print(" " + srcBands[i]);
1313             System.out.println();
1314             System.out.println("destination bands is " + destinationBands);
1315             if (destinationBands != null) {
1316                 for (int i = 0; i < destinationBands.length; i++) {
1317                     System.out.print(" " + destinationBands[i]);
1318                 }
1319                 System.out.println();
1320             }
1321             System.out.println("sourceROI is " + srcROI);
1322             System.out.println("destROI is " + destROI);
1323             System.out.println("periodX is " + periodX);
1324             System.out.println("periodY is " + periodY);
1325             System.out.println("minProgressivePass is " + minProgressivePass);
1326             System.out.println("maxProgressivePass is " + maxProgressivePass);
1327             System.out.println("callbackUpdates is " + callbackUpdates);
1328         }
1329 
1330         // Finally, we are ready to read
1331 
1332         processImageStarted(currentImage);
1333 
1334         boolean aborted = false;
1335 
1336         // Note that getData disables acceleration on buffer, but it is
1337         // just a 1-line intermediate data transfer buffer that will not
1338         // affect the acceleration of the resulting image.




1339         aborted = readImage(structPointer,
1340                             buffer.getData(),
1341                             numRasterBands,
1342                             srcBands,
1343                             bandSizes,
1344                             srcROI.x, srcROI.y,
1345                             srcROI.width, srcROI.height,
1346                             periodX, periodY,
1347                             abbrevQTables,
1348                             abbrevDCHuffmanTables,
1349                             abbrevACHuffmanTables,
1350                             minProgressivePass, maxProgressivePass,
1351                             callbackUpdates);
1352 
1353         if (aborted) {
1354             processReadAborted();
1355         } else {
1356             processImageComplete();
1357         }
1358 


1495         }
1496     }
1497 
1498     /**
1499      * Returns {@code true} if the read was aborted.
1500      */
1501     private native boolean readImage(long structPointer,
1502                                      byte [] buffer,
1503                                      int numRasterBands,
1504                                      int [] srcBands,
1505                                      int [] bandSizes,
1506                                      int sourceXOffset, int sourceYOffset,
1507                                      int sourceWidth, int sourceHeight,
1508                                      int periodX, int periodY,
1509                                      JPEGQTable [] abbrevQTables,
1510                                      JPEGHuffmanTable [] abbrevDCHuffmanTables,
1511                                      JPEGHuffmanTable [] abbrevACHuffmanTables,
1512                                      int minProgressivePass,
1513                                      int maxProgressivePass,
1514                                      boolean wantUpdates);






1515 
1516     public void abort() {
1517         setThreadLock();
1518         try {
1519             /**
1520              * NB: we do not check the call back lock here,
1521              * we allow to abort the reader any time.
1522              */
1523 
1524             super.abort();
1525             abortRead(structPointer);
1526         } finally {
1527             clearThreadLock();
1528         }
1529     }
1530 
1531     /** Set the C level abort flag. Keep it atomic for thread safety. */
1532     private native void abortRead(long structPointer);
1533 
1534     /** Resets library state when an exception occurred during a read. */


   1 /*
   2  * Copyright (c) 2000, 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


1311             for (int i = 0; i<srcBands.length;i++)
1312                 System.out.print(" " + srcBands[i]);
1313             System.out.println();
1314             System.out.println("destination bands is " + destinationBands);
1315             if (destinationBands != null) {
1316                 for (int i = 0; i < destinationBands.length; i++) {
1317                     System.out.print(" " + destinationBands[i]);
1318                 }
1319                 System.out.println();
1320             }
1321             System.out.println("sourceROI is " + srcROI);
1322             System.out.println("destROI is " + destROI);
1323             System.out.println("periodX is " + periodX);
1324             System.out.println("periodY is " + periodY);
1325             System.out.println("minProgressivePass is " + minProgressivePass);
1326             System.out.println("maxProgressivePass is " + maxProgressivePass);
1327             System.out.println("callbackUpdates is " + callbackUpdates);
1328         }
1329 
1330         // Finally, we are ready to read



1331         boolean aborted = false;
1332         /*
1333          * All the Jpeg processing happens in native, we should clear
1334          * abortFlag of imageIODataStruct in imageioJPEG.c. And we need
1335          * clear abortFlag because without that consecutive read calls
1336          * will become invalid.
1337          */
1338         clearNativeReadAbortFlag(structPointer);
1339         processImageStarted(currentImage);
1340         aborted = readImage(structPointer,
1341                             buffer.getData(),
1342                             numRasterBands,
1343                             srcBands,
1344                             bandSizes,
1345                             srcROI.x, srcROI.y,
1346                             srcROI.width, srcROI.height,
1347                             periodX, periodY,
1348                             abbrevQTables,
1349                             abbrevDCHuffmanTables,
1350                             abbrevACHuffmanTables,
1351                             minProgressivePass, maxProgressivePass,
1352                             callbackUpdates);
1353 
1354         if (aborted) {
1355             processReadAborted();
1356         } else {
1357             processImageComplete();
1358         }
1359 


1496         }
1497     }
1498 
1499     /**
1500      * Returns {@code true} if the read was aborted.
1501      */
1502     private native boolean readImage(long structPointer,
1503                                      byte [] buffer,
1504                                      int numRasterBands,
1505                                      int [] srcBands,
1506                                      int [] bandSizes,
1507                                      int sourceXOffset, int sourceYOffset,
1508                                      int sourceWidth, int sourceHeight,
1509                                      int periodX, int periodY,
1510                                      JPEGQTable [] abbrevQTables,
1511                                      JPEGHuffmanTable [] abbrevDCHuffmanTables,
1512                                      JPEGHuffmanTable [] abbrevACHuffmanTables,
1513                                      int minProgressivePass,
1514                                      int maxProgressivePass,
1515                                      boolean wantUpdates);
1516 
1517     /*
1518      * We should call clearNativeReadAbortFlag() before we start reading
1519      * jpeg image as image processing happens at native side.
1520      */
1521     private native void clearNativeReadAbortFlag(long structPointer);
1522 
1523     public void abort() {
1524         setThreadLock();
1525         try {
1526             /**
1527              * NB: we do not check the call back lock here,
1528              * we allow to abort the reader any time.
1529              */
1530 
1531             super.abort();
1532             abortRead(structPointer);
1533         } finally {
1534             clearThreadLock();
1535         }
1536     }
1537 
1538     /** Set the C level abort flag. Keep it atomic for thread safety. */
1539     private native void abortRead(long structPointer);
1540 
1541     /** Resets library state when an exception occurred during a read. */


< prev index next >