< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -572,11 +572,10 @@
     private void write(boolean writeHeader,
                        boolean writeTrailer,
                        IIOMetadata sm,
                        IIOImage iioimage,
                        ImageWriteParam p) throws IOException {
-        clearAbortRequest();
 
         RenderedImage image = iioimage.getRenderedImage();
 
         // Check for ability to encode image.
         if (needToCreateIndex(image)) {

@@ -827,15 +826,15 @@
         Raster raster =
             image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ?
             image.getTile(0, 0) : image.getData();
         for (int y = dy; y < dh; y += ddy) {
             if (numRowsWritten % progressReportRowPeriod == 0) {
+                processImageProgress((numRowsWritten*100.0F)/dh);
                 if (abortRequested()) {
                     processWriteAborted();
                     return;
                 }
-                processImageProgress((numRowsWritten*100.0F)/dh);
             }
 
             raster.getSamples(sx, sy, sw, 1, 0, sbuf);
             for (int i = 0, j = 0; i < dw; i++, j += sdx) {
                 dbuf[i] = (byte)sbuf[j];

@@ -855,15 +854,15 @@
 
         offset += dy*lineStride;
         lineStride *= ddy;
         for (int y = dy; y < dh; y += ddy) {
             if (numRowsWritten % progressReportRowPeriod == 0) {
+                processImageProgress((numRowsWritten*100.0F)/dh);
                 if (abortRequested()) {
                     processWriteAborted();
                     return;
                 }
-                processImageProgress((numRowsWritten*100.0F)/dh);
             }
 
             compressor.compress(data, offset, dw);
             numRowsWritten++;
             offset += lineStride;

@@ -922,11 +921,16 @@
 
         int numRowsWritten = 0;
 
         int progressReportRowPeriod = Math.max(destHeight/20, 1);
 
+        clearAbortRequest();
         processImageStarted(imageIndex);
+        if (abortRequested()) {
+            processWriteAborted();
+            return;
+        }
 
         if (interlaceFlag) {
             if (DEBUG) System.out.println("Writing interlaced");
 
             if (isOptimizedCase) {

@@ -971,10 +975,13 @@
                 numRowsWritten += (destHeight - 2)/4;
 
                 writeRowsOpt(data, offset, lineStride, compressor,
                              1, 2, destWidth, destHeight,
                              numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             } else {
                 writeRows(image, compressor,
                           sourceXOffset, periodX,
                           sourceYOffset, 8*periodY,
                           sourceWidth,

@@ -1014,10 +1021,13 @@
                 writeRows(image, compressor, sourceXOffset, periodX,
                           sourceYOffset + periodY, 2*periodY,
                           sourceWidth,
                           1, 2, destWidth, destHeight,
                           numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             }
         } else {
             if (DEBUG) System.out.println("Writing non-interlaced");
 
             if (isOptimizedCase) {

@@ -1029,25 +1039,25 @@
                 int lineStride = csm.getScanlineStride();
 
                 writeRowsOpt(data, offset, lineStride, compressor,
                              0, 1, destWidth, destHeight,
                              numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             } else {
                 writeRows(image, compressor,
                           sourceXOffset, periodX,
                           sourceYOffset, periodY,
                           sourceWidth,
                           0, 1, destWidth, destHeight,
                           numRowsWritten, progressReportRowPeriod);
-            }
-        }
-
         if (abortRequested()) {
             return;
         }
-
-        processImageProgress(100.0F);
+            }
+        }
 
         compressor.flush();
 
         stream.write(0x00);
 
< prev index next >