comparison src/name/blackcap/imageprep/Menus.kt @ 7:801cdc780ca8

Work around ImageIO bug.
author David Barts <n5jrn@me.com>
date Fri, 17 Jul 2020 19:56:25 -0700
parents 884f1415a330
children 9e9fe34052a6
comparison
equal deleted inserted replaced
6:9129ae110146 7:801cdc780ca8
95 } 95 }
96 w.setVisible(false) 96 w.setVisible(false)
97 w.dispose() 97 w.dispose()
98 } 98 }
99 99
100 /* xxx - ImageIO bug? */
101 private class NullOutputStream : java.io.OutputStream() {
102 override fun write(b: Int): Unit {}
103 }
104
100 private fun doClose() { 105 private fun doClose() {
101 val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog 106 val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog
102 if (w == null) { 107 if (w == null) {
108 LOGGER.log(Level.INFO, "beep!")
103 Toolkit.getDefaultToolkit().beep() 109 Toolkit.getDefaultToolkit().beep()
104 return 110 return
105 } 111 }
106 val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg" 112 val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg"
107 val chooser = JFileChooser().apply { 113 val chooser = JFileChooser().apply {
123 } 129 }
124 w.useWaitCursor() 130 w.useWaitCursor()
125 swingWorker<IOException?> { 131 swingWorker<IOException?> {
126 inBackground { 132 inBackground {
127 try { 133 try {
128 val ios = ImageIO.createImageOutputStream(file) 134 /* xxx - ImageIO bug? */
135 val devNull = java.io.PrintStream(NullOutputStream())
136 val oldOut = System.out
137 System.setOut(devNull)
138 val oldErr = System.err
139 System.setErr(devNull)
140 val ios = try {
141 ImageIO.createImageOutputStream(file)
142 } finally {
143 System.setErr(oldErr)
144 System.setOut(oldOut)
145 }
146 if (ios == null)
147 throw IOException()
148 /* xxx - end workaround */
129 val writer = ImageIO.getImageWritersByFormatName("jpeg").next() 149 val writer = ImageIO.getImageWritersByFormatName("jpeg").next()
130 val iwp = writer.getDefaultWriteParam().apply { 150 val iwp = writer.getDefaultWriteParam().apply {
131 setCompressionMode(ImageWriteParam.MODE_EXPLICIT) 151 setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
132 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) 152 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f)
133 } 153 }