jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java
changeset 41403 be56daafbeaa
parent 35667 ed476aba94de
child 41784 c1e614077765
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java	Wed Sep 28 03:40:45 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/gif/GIFImageWriter.java	Thu Sep 29 10:57:34 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -574,7 +574,6 @@
                        IIOMetadata sm,
                        IIOImage iioimage,
                        ImageWriteParam p) throws IOException {
-        clearAbortRequest();
 
         RenderedImage image = iioimage.getRenderedImage();
 
@@ -829,11 +828,11 @@
             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);
@@ -857,11 +856,11 @@
         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);
@@ -924,7 +923,12 @@
 
         int progressReportRowPeriod = Math.max(destHeight/20, 1);
 
+        clearAbortRequest();
         processImageStarted(imageIndex);
+        if (abortRequested()) {
+            processWriteAborted();
+            return;
+        }
 
         if (interlaceFlag) {
             if (DEBUG) System.out.println("Writing interlaced");
@@ -973,6 +977,9 @@
                 writeRowsOpt(data, offset, lineStride, compressor,
                              1, 2, destWidth, destHeight,
                              numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             } else {
                 writeRows(image, compressor,
                           sourceXOffset, periodX,
@@ -1016,6 +1023,9 @@
                           sourceWidth,
                           1, 2, destWidth, destHeight,
                           numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             }
         } else {
             if (DEBUG) System.out.println("Writing non-interlaced");
@@ -1031,6 +1041,9 @@
                 writeRowsOpt(data, offset, lineStride, compressor,
                              0, 1, destWidth, destHeight,
                              numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             } else {
                 writeRows(image, compressor,
                           sourceXOffset, periodX,
@@ -1038,15 +1051,12 @@
                           sourceWidth,
                           0, 1, destWidth, destHeight,
                           numRowsWritten, progressReportRowPeriod);
+                if (abortRequested()) {
+                    return;
+                }
             }
         }
 
-        if (abortRequested()) {
-            return;
-        }
-
-        processImageProgress(100.0F);
-
         compressor.flush();
 
         stream.write(0x00);