commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r935812 [18/46] - in /websites/production/commons/content/proper/commons-imaging: ./ apidocs/ apidocs/org/apache/commons/imaging/ apidocs/org/apache/commons/imaging/class-use/ apidocs/org/apache/commons/imaging/color/ apidocs/org/apache/com...
Date Sun, 11 Jan 2015 12:33:28 GMT
Modified: websites/production/commons/content/proper/commons-imaging/apidocs/src-html/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.html
==============================================================================
--- websites/production/commons/content/proper/commons-imaging/apidocs/src-html/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.html (original)
+++ websites/production/commons/content/proper/commons-imaging/apidocs/src-html/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.html Sun Jan 11 12:33:25 2015
@@ -280,327 +280,345 @@
 <span class="sourceLineNo">272</span>        final int height = src.getHeight();<a name="line.272"></a>
 <span class="sourceLineNo">273</span><a name="line.273"></a>
 <span class="sourceLineNo">274</span>        int compression = TIFF_COMPRESSION_LZW; // LZW is default<a name="line.274"></a>
-<span class="sourceLineNo">275</span>        if (params.containsKey(PARAM_KEY_COMPRESSION)) {<a name="line.275"></a>
-<span class="sourceLineNo">276</span>            final Object value = params.get(PARAM_KEY_COMPRESSION);<a name="line.276"></a>
-<span class="sourceLineNo">277</span>            if (value != null) {<a name="line.277"></a>
-<span class="sourceLineNo">278</span>                if (!(value instanceof Number)) {<a name="line.278"></a>
-<span class="sourceLineNo">279</span>                    throw new ImageWriteException(<a name="line.279"></a>
-<span class="sourceLineNo">280</span>                            "Invalid compression parameter: " + value);<a name="line.280"></a>
-<span class="sourceLineNo">281</span>                }<a name="line.281"></a>
-<span class="sourceLineNo">282</span>                compression = ((Number) value).intValue();<a name="line.282"></a>
-<span class="sourceLineNo">283</span>            }<a name="line.283"></a>
-<span class="sourceLineNo">284</span>            params.remove(PARAM_KEY_COMPRESSION);<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        }<a name="line.285"></a>
-<span class="sourceLineNo">286</span>        final HashMap&lt;String, Object&gt; rawParams = new HashMap&lt;String, Object&gt;(params);<a name="line.286"></a>
-<span class="sourceLineNo">287</span>        params.remove(PARAM_KEY_T4_OPTIONS);<a name="line.287"></a>
-<span class="sourceLineNo">288</span>        params.remove(PARAM_KEY_T6_OPTIONS);<a name="line.288"></a>
-<span class="sourceLineNo">289</span>        if (!params.isEmpty()) {<a name="line.289"></a>
-<span class="sourceLineNo">290</span>            final Object firstKey = params.keySet().iterator().next();<a name="line.290"></a>
-<span class="sourceLineNo">291</span>            throw new ImageWriteException("Unknown parameter: " + firstKey);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>        }<a name="line.292"></a>
-<span class="sourceLineNo">293</span><a name="line.293"></a>
-<span class="sourceLineNo">294</span>        int samplesPerPixel;<a name="line.294"></a>
-<span class="sourceLineNo">295</span>        int bitsPerSample;<a name="line.295"></a>
-<span class="sourceLineNo">296</span>        int photometricInterpretation;<a name="line.296"></a>
-<span class="sourceLineNo">297</span>        if (compression == TIFF_COMPRESSION_CCITT_1D<a name="line.297"></a>
-<span class="sourceLineNo">298</span>                || compression == TIFF_COMPRESSION_CCITT_GROUP_3<a name="line.298"></a>
-<span class="sourceLineNo">299</span>                || compression == TIFF_COMPRESSION_CCITT_GROUP_4) {<a name="line.299"></a>
-<span class="sourceLineNo">300</span>            samplesPerPixel = 1;<a name="line.300"></a>
-<span class="sourceLineNo">301</span>            bitsPerSample = 1;<a name="line.301"></a>
-<span class="sourceLineNo">302</span>            photometricInterpretation = 0;<a name="line.302"></a>
-<span class="sourceLineNo">303</span>        } else {<a name="line.303"></a>
-<span class="sourceLineNo">304</span>            samplesPerPixel = 3;<a name="line.304"></a>
-<span class="sourceLineNo">305</span>            bitsPerSample = 8;<a name="line.305"></a>
-<span class="sourceLineNo">306</span>            photometricInterpretation = 2;<a name="line.306"></a>
-<span class="sourceLineNo">307</span>        }<a name="line.307"></a>
-<span class="sourceLineNo">308</span><a name="line.308"></a>
-<span class="sourceLineNo">309</span>        int rowsPerStrip = 64000 / (width * bitsPerSample * samplesPerPixel); // TODO:<a name="line.309"></a>
-<span class="sourceLineNo">310</span>        rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.<a name="line.310"></a>
+<span class="sourceLineNo">275</span>        int stripSizeInBits = 64000; // the default from legacy implementation<a name="line.275"></a>
+<span class="sourceLineNo">276</span>        if (params.containsKey(PARAM_KEY_COMPRESSION)) {<a name="line.276"></a>
+<span class="sourceLineNo">277</span>            final Object value = params.get(PARAM_KEY_COMPRESSION);<a name="line.277"></a>
+<span class="sourceLineNo">278</span>            if (value != null) {<a name="line.278"></a>
+<span class="sourceLineNo">279</span>                if (!(value instanceof Number)) {<a name="line.279"></a>
+<span class="sourceLineNo">280</span>                    throw new ImageWriteException(<a name="line.280"></a>
+<span class="sourceLineNo">281</span>                            "Invalid compression parameter, must be numeric: "<a name="line.281"></a>
+<span class="sourceLineNo">282</span>                                    + value);<a name="line.282"></a>
+<span class="sourceLineNo">283</span>                }<a name="line.283"></a>
+<span class="sourceLineNo">284</span>                compression = ((Number) value).intValue();<a name="line.284"></a>
+<span class="sourceLineNo">285</span>            }<a name="line.285"></a>
+<span class="sourceLineNo">286</span>            params.remove(PARAM_KEY_COMPRESSION);<a name="line.286"></a>
+<span class="sourceLineNo">287</span>            if (params.containsKey(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE)) {<a name="line.287"></a>
+<span class="sourceLineNo">288</span>                final Object bValue =<a name="line.288"></a>
+<span class="sourceLineNo">289</span>                    params.get(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE);<a name="line.289"></a>
+<span class="sourceLineNo">290</span>                if (!(bValue instanceof Number)) {<a name="line.290"></a>
+<span class="sourceLineNo">291</span>                    throw new ImageWriteException(<a name="line.291"></a>
+<span class="sourceLineNo">292</span>                            "Invalid compression block-size parameter: " + value);<a name="line.292"></a>
+<span class="sourceLineNo">293</span>                }<a name="line.293"></a>
+<span class="sourceLineNo">294</span>                final int stripSizeInBytes = ((Number) bValue).intValue();<a name="line.294"></a>
+<span class="sourceLineNo">295</span>                if (stripSizeInBytes &lt; 8000) {<a name="line.295"></a>
+<span class="sourceLineNo">296</span>                    throw new ImageWriteException(<a name="line.296"></a>
+<span class="sourceLineNo">297</span>                            "Block size parameter " + stripSizeInBytes<a name="line.297"></a>
+<span class="sourceLineNo">298</span>                            + " is less than 8000 minimum");<a name="line.298"></a>
+<span class="sourceLineNo">299</span>                }<a name="line.299"></a>
+<span class="sourceLineNo">300</span>                stripSizeInBits = stripSizeInBytes*8;<a name="line.300"></a>
+<span class="sourceLineNo">301</span>                params.remove(PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE);<a name="line.301"></a>
+<span class="sourceLineNo">302</span>            }<a name="line.302"></a>
+<span class="sourceLineNo">303</span>        }<a name="line.303"></a>
+<span class="sourceLineNo">304</span>        final HashMap&lt;String, Object&gt; rawParams = new HashMap&lt;String, Object&gt;(params);<a name="line.304"></a>
+<span class="sourceLineNo">305</span>        params.remove(PARAM_KEY_T4_OPTIONS);<a name="line.305"></a>
+<span class="sourceLineNo">306</span>        params.remove(PARAM_KEY_T6_OPTIONS);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        if (!params.isEmpty()) {<a name="line.307"></a>
+<span class="sourceLineNo">308</span>            final Object firstKey = params.keySet().iterator().next();<a name="line.308"></a>
+<span class="sourceLineNo">309</span>            throw new ImageWriteException("Unknown parameter: " + firstKey);<a name="line.309"></a>
+<span class="sourceLineNo">310</span>        }<a name="line.310"></a>
 <span class="sourceLineNo">311</span><a name="line.311"></a>
-<span class="sourceLineNo">312</span>        final byte[][] strips = getStrips(src, samplesPerPixel, bitsPerSample, rowsPerStrip);<a name="line.312"></a>
-<span class="sourceLineNo">313</span><a name="line.313"></a>
-<span class="sourceLineNo">314</span>        // System.out.println("width: " + width);<a name="line.314"></a>
-<span class="sourceLineNo">315</span>        // System.out.println("height: " + height);<a name="line.315"></a>
-<span class="sourceLineNo">316</span>        // System.out.println("fRowsPerStrip: " + fRowsPerStrip);<a name="line.316"></a>
-<span class="sourceLineNo">317</span>        // System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);<a name="line.317"></a>
-<span class="sourceLineNo">318</span>        // System.out.println("stripCount: " + stripCount);<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span>        int t4Options = 0;<a name="line.320"></a>
-<span class="sourceLineNo">321</span>        int t6Options = 0;<a name="line.321"></a>
-<span class="sourceLineNo">322</span>        if (compression == TIFF_COMPRESSION_CCITT_1D) {<a name="line.322"></a>
-<span class="sourceLineNo">323</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.323"></a>
-<span class="sourceLineNo">324</span>                strips[i] = T4AndT6Compression.compressModifiedHuffman(<a name="line.324"></a>
-<span class="sourceLineNo">325</span>                        strips[i], width, strips[i].length / ((width + 7) / 8));<a name="line.325"></a>
-<span class="sourceLineNo">326</span>            }<a name="line.326"></a>
-<span class="sourceLineNo">327</span>        } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_3) {<a name="line.327"></a>
-<span class="sourceLineNo">328</span>            final Integer t4Parameter = (Integer) rawParams.get(PARAM_KEY_T4_OPTIONS);<a name="line.328"></a>
-<span class="sourceLineNo">329</span>            if (t4Parameter != null) {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>                t4Options = t4Parameter.intValue();<a name="line.330"></a>
-<span class="sourceLineNo">331</span>            }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>            t4Options &amp;= 0x7;<a name="line.332"></a>
-<span class="sourceLineNo">333</span>            final boolean is2D = (t4Options &amp; 1) != 0;<a name="line.333"></a>
-<span class="sourceLineNo">334</span>            final boolean usesUncompressedMode = (t4Options &amp; 2) != 0;<a name="line.334"></a>
-<span class="sourceLineNo">335</span>            if (usesUncompressedMode) {<a name="line.335"></a>
-<span class="sourceLineNo">336</span>                throw new ImageWriteException(<a name="line.336"></a>
-<span class="sourceLineNo">337</span>                        "T.4 compression with the uncompressed mode extension is not yet supported");<a name="line.337"></a>
-<span class="sourceLineNo">338</span>            }<a name="line.338"></a>
-<span class="sourceLineNo">339</span>            final boolean hasFillBitsBeforeEOL = (t4Options &amp; 4) != 0;<a name="line.339"></a>
-<span class="sourceLineNo">340</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.340"></a>
-<span class="sourceLineNo">341</span>                if (is2D) {<a name="line.341"></a>
-<span class="sourceLineNo">342</span>                    strips[i] = T4AndT6Compression.compressT4_2D(strips[i],<a name="line.342"></a>
-<span class="sourceLineNo">343</span>                            width, strips[i].length / ((width + 7) / 8),<a name="line.343"></a>
-<span class="sourceLineNo">344</span>                            hasFillBitsBeforeEOL, rowsPerStrip);<a name="line.344"></a>
-<span class="sourceLineNo">345</span>                } else {<a name="line.345"></a>
-<span class="sourceLineNo">346</span>                    strips[i] = T4AndT6Compression.compressT4_1D(strips[i],<a name="line.346"></a>
-<span class="sourceLineNo">347</span>                            width, strips[i].length / ((width + 7) / 8),<a name="line.347"></a>
-<span class="sourceLineNo">348</span>                            hasFillBitsBeforeEOL);<a name="line.348"></a>
-<span class="sourceLineNo">349</span>                }<a name="line.349"></a>
-<span class="sourceLineNo">350</span>            }<a name="line.350"></a>
-<span class="sourceLineNo">351</span>        } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_4) {<a name="line.351"></a>
-<span class="sourceLineNo">352</span>            final Integer t6Parameter = (Integer) rawParams.get(PARAM_KEY_T6_OPTIONS);<a name="line.352"></a>
-<span class="sourceLineNo">353</span>            if (t6Parameter != null) {<a name="line.353"></a>
-<span class="sourceLineNo">354</span>                t6Options = t6Parameter.intValue();<a name="line.354"></a>
-<span class="sourceLineNo">355</span>            }<a name="line.355"></a>
-<span class="sourceLineNo">356</span>            t6Options &amp;= 0x4;<a name="line.356"></a>
-<span class="sourceLineNo">357</span>            final boolean usesUncompressedMode = (t6Options &amp; TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE) != 0;<a name="line.357"></a>
-<span class="sourceLineNo">358</span>            if (usesUncompressedMode) {<a name="line.358"></a>
-<span class="sourceLineNo">359</span>                throw new ImageWriteException(<a name="line.359"></a>
-<span class="sourceLineNo">360</span>                        "T.6 compression with the uncompressed mode extension is not yet supported");<a name="line.360"></a>
-<span class="sourceLineNo">361</span>            }<a name="line.361"></a>
-<span class="sourceLineNo">362</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>                strips[i] = T4AndT6Compression.compressT6(strips[i], width,<a name="line.363"></a>
-<span class="sourceLineNo">364</span>                        strips[i].length / ((width + 7) / 8));<a name="line.364"></a>
-<span class="sourceLineNo">365</span>            }<a name="line.365"></a>
-<span class="sourceLineNo">366</span>        } else if (compression == TIFF_COMPRESSION_PACKBITS) {<a name="line.366"></a>
-<span class="sourceLineNo">367</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.367"></a>
-<span class="sourceLineNo">368</span>                strips[i] = new PackBits().compress(strips[i]);<a name="line.368"></a>
-<span class="sourceLineNo">369</span>            }<a name="line.369"></a>
-<span class="sourceLineNo">370</span>        } else if (compression == TIFF_COMPRESSION_LZW) {<a name="line.370"></a>
-<span class="sourceLineNo">371</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.371"></a>
-<span class="sourceLineNo">372</span>                final byte[] uncompressed = strips[i];<a name="line.372"></a>
-<span class="sourceLineNo">373</span><a name="line.373"></a>
-<span class="sourceLineNo">374</span>                final int LZW_MINIMUM_CODE_SIZE = 8;<a name="line.374"></a>
-<span class="sourceLineNo">375</span><a name="line.375"></a>
-<span class="sourceLineNo">376</span>                final MyLzwCompressor compressor = new MyLzwCompressor(<a name="line.376"></a>
-<span class="sourceLineNo">377</span>                        LZW_MINIMUM_CODE_SIZE, ByteOrder.BIG_ENDIAN, true);<a name="line.377"></a>
-<span class="sourceLineNo">378</span>                final byte[] compressed = compressor.compress(uncompressed);<a name="line.378"></a>
-<span class="sourceLineNo">379</span><a name="line.379"></a>
-<span class="sourceLineNo">380</span>                strips[i] = compressed;<a name="line.380"></a>
-<span class="sourceLineNo">381</span>            }<a name="line.381"></a>
-<span class="sourceLineNo">382</span>        } else if (compression == TIFF_COMPRESSION_UNCOMPRESSED) {<a name="line.382"></a>
-<span class="sourceLineNo">383</span>            // do nothing.<a name="line.383"></a>
-<span class="sourceLineNo">384</span>        } else {<a name="line.384"></a>
-<span class="sourceLineNo">385</span>            throw new ImageWriteException(<a name="line.385"></a>
-<span class="sourceLineNo">386</span>                    "Invalid compression parameter (Only CCITT 1D/Group 3/Group 4, LZW, Packbits and uncompressed supported).");<a name="line.386"></a>
-<span class="sourceLineNo">387</span>        }<a name="line.387"></a>
-<span class="sourceLineNo">388</span><a name="line.388"></a>
-<span class="sourceLineNo">389</span>        final TiffElement.DataElement[] imageData = new TiffElement.DataElement[strips.length];<a name="line.389"></a>
-<span class="sourceLineNo">390</span>        for (int i = 0; i &lt; strips.length; i++) {<a name="line.390"></a>
-<span class="sourceLineNo">391</span>            imageData[i] = new TiffImageData.Data(0, strips[i].length, strips[i]);<a name="line.391"></a>
-<span class="sourceLineNo">392</span>        }<a name="line.392"></a>
+<span class="sourceLineNo">312</span>        int samplesPerPixel;<a name="line.312"></a>
+<span class="sourceLineNo">313</span>        int bitsPerSample;<a name="line.313"></a>
+<span class="sourceLineNo">314</span>        int photometricInterpretation;<a name="line.314"></a>
+<span class="sourceLineNo">315</span>        if (compression == TIFF_COMPRESSION_CCITT_1D<a name="line.315"></a>
+<span class="sourceLineNo">316</span>                || compression == TIFF_COMPRESSION_CCITT_GROUP_3<a name="line.316"></a>
+<span class="sourceLineNo">317</span>                || compression == TIFF_COMPRESSION_CCITT_GROUP_4) {<a name="line.317"></a>
+<span class="sourceLineNo">318</span>            samplesPerPixel = 1;<a name="line.318"></a>
+<span class="sourceLineNo">319</span>            bitsPerSample = 1;<a name="line.319"></a>
+<span class="sourceLineNo">320</span>            photometricInterpretation = 0;<a name="line.320"></a>
+<span class="sourceLineNo">321</span>        } else {<a name="line.321"></a>
+<span class="sourceLineNo">322</span>            samplesPerPixel = 3;<a name="line.322"></a>
+<span class="sourceLineNo">323</span>            bitsPerSample = 8;<a name="line.323"></a>
+<span class="sourceLineNo">324</span>            photometricInterpretation = 2;<a name="line.324"></a>
+<span class="sourceLineNo">325</span>        }<a name="line.325"></a>
+<span class="sourceLineNo">326</span><a name="line.326"></a>
+<span class="sourceLineNo">327</span>        int rowsPerStrip = stripSizeInBits / (width * bitsPerSample * samplesPerPixel);<a name="line.327"></a>
+<span class="sourceLineNo">328</span>        rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.<a name="line.328"></a>
+<span class="sourceLineNo">329</span><a name="line.329"></a>
+<span class="sourceLineNo">330</span>        final byte[][] strips = getStrips(src, samplesPerPixel, bitsPerSample, rowsPerStrip);<a name="line.330"></a>
+<span class="sourceLineNo">331</span><a name="line.331"></a>
+<span class="sourceLineNo">332</span>        // System.out.println("width: " + width);<a name="line.332"></a>
+<span class="sourceLineNo">333</span>        // System.out.println("height: " + height);<a name="line.333"></a>
+<span class="sourceLineNo">334</span>        // System.out.println("fRowsPerStrip: " + fRowsPerStrip);<a name="line.334"></a>
+<span class="sourceLineNo">335</span>        // System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);<a name="line.335"></a>
+<span class="sourceLineNo">336</span>        // System.out.println("stripCount: " + stripCount);<a name="line.336"></a>
+<span class="sourceLineNo">337</span><a name="line.337"></a>
+<span class="sourceLineNo">338</span>        int t4Options = 0;<a name="line.338"></a>
+<span class="sourceLineNo">339</span>        int t6Options = 0;<a name="line.339"></a>
+<span class="sourceLineNo">340</span>        if (compression == TIFF_COMPRESSION_CCITT_1D) {<a name="line.340"></a>
+<span class="sourceLineNo">341</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.341"></a>
+<span class="sourceLineNo">342</span>                strips[i] = T4AndT6Compression.compressModifiedHuffman(<a name="line.342"></a>
+<span class="sourceLineNo">343</span>                        strips[i], width, strips[i].length / ((width + 7) / 8));<a name="line.343"></a>
+<span class="sourceLineNo">344</span>            }<a name="line.344"></a>
+<span class="sourceLineNo">345</span>        } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_3) {<a name="line.345"></a>
+<span class="sourceLineNo">346</span>            final Integer t4Parameter = (Integer) rawParams.get(PARAM_KEY_T4_OPTIONS);<a name="line.346"></a>
+<span class="sourceLineNo">347</span>            if (t4Parameter != null) {<a name="line.347"></a>
+<span class="sourceLineNo">348</span>                t4Options = t4Parameter.intValue();<a name="line.348"></a>
+<span class="sourceLineNo">349</span>            }<a name="line.349"></a>
+<span class="sourceLineNo">350</span>            t4Options &amp;= 0x7;<a name="line.350"></a>
+<span class="sourceLineNo">351</span>            final boolean is2D = (t4Options &amp; 1) != 0;<a name="line.351"></a>
+<span class="sourceLineNo">352</span>            final boolean usesUncompressedMode = (t4Options &amp; 2) != 0;<a name="line.352"></a>
+<span class="sourceLineNo">353</span>            if (usesUncompressedMode) {<a name="line.353"></a>
+<span class="sourceLineNo">354</span>                throw new ImageWriteException(<a name="line.354"></a>
+<span class="sourceLineNo">355</span>                        "T.4 compression with the uncompressed mode extension is not yet supported");<a name="line.355"></a>
+<span class="sourceLineNo">356</span>            }<a name="line.356"></a>
+<span class="sourceLineNo">357</span>            final boolean hasFillBitsBeforeEOL = (t4Options &amp; 4) != 0;<a name="line.357"></a>
+<span class="sourceLineNo">358</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>                if (is2D) {<a name="line.359"></a>
+<span class="sourceLineNo">360</span>                    strips[i] = T4AndT6Compression.compressT4_2D(strips[i],<a name="line.360"></a>
+<span class="sourceLineNo">361</span>                            width, strips[i].length / ((width + 7) / 8),<a name="line.361"></a>
+<span class="sourceLineNo">362</span>                            hasFillBitsBeforeEOL, rowsPerStrip);<a name="line.362"></a>
+<span class="sourceLineNo">363</span>                } else {<a name="line.363"></a>
+<span class="sourceLineNo">364</span>                    strips[i] = T4AndT6Compression.compressT4_1D(strips[i],<a name="line.364"></a>
+<span class="sourceLineNo">365</span>                            width, strips[i].length / ((width + 7) / 8),<a name="line.365"></a>
+<span class="sourceLineNo">366</span>                            hasFillBitsBeforeEOL);<a name="line.366"></a>
+<span class="sourceLineNo">367</span>                }<a name="line.367"></a>
+<span class="sourceLineNo">368</span>            }<a name="line.368"></a>
+<span class="sourceLineNo">369</span>        } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_4) {<a name="line.369"></a>
+<span class="sourceLineNo">370</span>            final Integer t6Parameter = (Integer) rawParams.get(PARAM_KEY_T6_OPTIONS);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>            if (t6Parameter != null) {<a name="line.371"></a>
+<span class="sourceLineNo">372</span>                t6Options = t6Parameter.intValue();<a name="line.372"></a>
+<span class="sourceLineNo">373</span>            }<a name="line.373"></a>
+<span class="sourceLineNo">374</span>            t6Options &amp;= 0x4;<a name="line.374"></a>
+<span class="sourceLineNo">375</span>            final boolean usesUncompressedMode = (t6Options &amp; TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE) != 0;<a name="line.375"></a>
+<span class="sourceLineNo">376</span>            if (usesUncompressedMode) {<a name="line.376"></a>
+<span class="sourceLineNo">377</span>                throw new ImageWriteException(<a name="line.377"></a>
+<span class="sourceLineNo">378</span>                        "T.6 compression with the uncompressed mode extension is not yet supported");<a name="line.378"></a>
+<span class="sourceLineNo">379</span>            }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.380"></a>
+<span class="sourceLineNo">381</span>                strips[i] = T4AndT6Compression.compressT6(strips[i], width,<a name="line.381"></a>
+<span class="sourceLineNo">382</span>                        strips[i].length / ((width + 7) / 8));<a name="line.382"></a>
+<span class="sourceLineNo">383</span>            }<a name="line.383"></a>
+<span class="sourceLineNo">384</span>        } else if (compression == TIFF_COMPRESSION_PACKBITS) {<a name="line.384"></a>
+<span class="sourceLineNo">385</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.385"></a>
+<span class="sourceLineNo">386</span>                strips[i] = new PackBits().compress(strips[i]);<a name="line.386"></a>
+<span class="sourceLineNo">387</span>            }<a name="line.387"></a>
+<span class="sourceLineNo">388</span>        } else if (compression == TIFF_COMPRESSION_LZW) {<a name="line.388"></a>
+<span class="sourceLineNo">389</span>            for (int i = 0; i &lt; strips.length; i++) {<a name="line.389"></a>
+<span class="sourceLineNo">390</span>                final byte[] uncompressed = strips[i];<a name="line.390"></a>
+<span class="sourceLineNo">391</span><a name="line.391"></a>
+<span class="sourceLineNo">392</span>                final int LZW_MINIMUM_CODE_SIZE = 8;<a name="line.392"></a>
 <span class="sourceLineNo">393</span><a name="line.393"></a>
-<span class="sourceLineNo">394</span>        final TiffOutputSet outputSet = new TiffOutputSet(byteOrder);<a name="line.394"></a>
-<span class="sourceLineNo">395</span>        final TiffOutputDirectory directory = outputSet.addRootDirectory();<a name="line.395"></a>
-<span class="sourceLineNo">396</span><a name="line.396"></a>
-<span class="sourceLineNo">397</span>        // WriteField stripOffsetsField;<a name="line.397"></a>
-<span class="sourceLineNo">398</span><a name="line.398"></a>
-<span class="sourceLineNo">399</span>        {<a name="line.399"></a>
-<span class="sourceLineNo">400</span><a name="line.400"></a>
-<span class="sourceLineNo">401</span>            directory.add(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, width);<a name="line.401"></a>
-<span class="sourceLineNo">402</span>            directory.add(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, height);<a name="line.402"></a>
-<span class="sourceLineNo">403</span>            directory.add(TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION,<a name="line.403"></a>
-<span class="sourceLineNo">404</span>                    (short) photometricInterpretation);<a name="line.404"></a>
-<span class="sourceLineNo">405</span>            directory.add(TiffTagConstants.TIFF_TAG_COMPRESSION,<a name="line.405"></a>
-<span class="sourceLineNo">406</span>                    (short) compression);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>            directory.add(TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL,<a name="line.407"></a>
-<span class="sourceLineNo">408</span>                    (short) samplesPerPixel);<a name="line.408"></a>
-<span class="sourceLineNo">409</span><a name="line.409"></a>
-<span class="sourceLineNo">410</span>            if (samplesPerPixel == 3) {<a name="line.410"></a>
-<span class="sourceLineNo">411</span>                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE,<a name="line.411"></a>
-<span class="sourceLineNo">412</span>                        (short) bitsPerSample, (short) bitsPerSample,<a name="line.412"></a>
-<span class="sourceLineNo">413</span>                        (short) bitsPerSample);<a name="line.413"></a>
-<span class="sourceLineNo">414</span>            } else if (samplesPerPixel == 1) {<a name="line.414"></a>
-<span class="sourceLineNo">415</span>                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE,<a name="line.415"></a>
-<span class="sourceLineNo">416</span>                        (short) bitsPerSample);<a name="line.416"></a>
-<span class="sourceLineNo">417</span>            }<a name="line.417"></a>
-<span class="sourceLineNo">418</span>            // {<a name="line.418"></a>
-<span class="sourceLineNo">419</span>            // stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,<a name="line.419"></a>
-<span class="sourceLineNo">420</span>            // FIELD_TYPE_LONG, stripOffsets.length, FIELD_TYPE_LONG<a name="line.420"></a>
-<span class="sourceLineNo">421</span>            // .writeData(stripOffsets, byteOrder));<a name="line.421"></a>
-<span class="sourceLineNo">422</span>            // directory.add(stripOffsetsField);<a name="line.422"></a>
-<span class="sourceLineNo">423</span>            // }<a name="line.423"></a>
-<span class="sourceLineNo">424</span>            // {<a name="line.424"></a>
-<span class="sourceLineNo">425</span>            // WriteField field = new WriteField(TIFF_TAG_STRIP_BYTE_COUNTS,<a name="line.425"></a>
-<span class="sourceLineNo">426</span>            // FIELD_TYPE_LONG, stripByteCounts.length,<a name="line.426"></a>
-<span class="sourceLineNo">427</span>            // FIELD_TYPE_LONG.writeData(stripByteCounts,<a name="line.427"></a>
-<span class="sourceLineNo">428</span>            // WRITE_BYTE_ORDER));<a name="line.428"></a>
-<span class="sourceLineNo">429</span>            // directory.add(field);<a name="line.429"></a>
-<span class="sourceLineNo">430</span>            // }<a name="line.430"></a>
-<span class="sourceLineNo">431</span>            directory.add(TiffTagConstants.TIFF_TAG_ROWS_PER_STRIP,<a name="line.431"></a>
-<span class="sourceLineNo">432</span>                    rowsPerStrip);<a name="line.432"></a>
-<span class="sourceLineNo">433</span>            if (pixelDensity.isUnitless()) {<a name="line.433"></a>
-<span class="sourceLineNo">434</span>                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,<a name="line.434"></a>
-<span class="sourceLineNo">435</span>                        (short) 0);<a name="line.435"></a>
-<span class="sourceLineNo">436</span>                directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,<a name="line.436"></a>
-<span class="sourceLineNo">437</span>                        RationalNumber.valueOf(pixelDensity.getRawHorizontalDensity()));<a name="line.437"></a>
-<span class="sourceLineNo">438</span>                directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION, <a name="line.438"></a>
-<span class="sourceLineNo">439</span>                        RationalNumber.valueOf(pixelDensity.getRawVerticalDensity()));<a name="line.439"></a>
-<span class="sourceLineNo">440</span>            } else if (pixelDensity.isInInches()) {<a name="line.440"></a>
-<span class="sourceLineNo">441</span>                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,<a name="line.441"></a>
-<span class="sourceLineNo">442</span>                        (short) 2);<a name="line.442"></a>
-<span class="sourceLineNo">443</span>                directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,<a name="line.443"></a>
-<span class="sourceLineNo">444</span>                        RationalNumber.valueOf(pixelDensity.horizontalDensityInches()));<a name="line.444"></a>
-<span class="sourceLineNo">445</span>                directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,<a name="line.445"></a>
-<span class="sourceLineNo">446</span>                        RationalNumber.valueOf(pixelDensity.verticalDensityInches()));<a name="line.446"></a>
-<span class="sourceLineNo">447</span>            } else {<a name="line.447"></a>
-<span class="sourceLineNo">448</span>                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,<a name="line.448"></a>
-<span class="sourceLineNo">449</span>                        (short) 1);<a name="line.449"></a>
-<span class="sourceLineNo">450</span>                directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,<a name="line.450"></a>
-<span class="sourceLineNo">451</span>                        RationalNumber.valueOf(pixelDensity.horizontalDensityCentimetres()));<a name="line.451"></a>
-<span class="sourceLineNo">452</span>                directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,<a name="line.452"></a>
-<span class="sourceLineNo">453</span>                        RationalNumber.valueOf(pixelDensity.verticalDensityCentimetres()));<a name="line.453"></a>
-<span class="sourceLineNo">454</span>            }<a name="line.454"></a>
-<span class="sourceLineNo">455</span>            if (t4Options != 0) {<a name="line.455"></a>
-<span class="sourceLineNo">456</span>                directory.add(TiffTagConstants.TIFF_TAG_T4_OPTIONS, t4Options);<a name="line.456"></a>
-<span class="sourceLineNo">457</span>            }<a name="line.457"></a>
-<span class="sourceLineNo">458</span>            if (t6Options != 0) {<a name="line.458"></a>
-<span class="sourceLineNo">459</span>                directory.add(TiffTagConstants.TIFF_TAG_T6_OPTIONS, t6Options);<a name="line.459"></a>
-<span class="sourceLineNo">460</span>            }<a name="line.460"></a>
-<span class="sourceLineNo">461</span><a name="line.461"></a>
-<span class="sourceLineNo">462</span>            if (null != xmpXml) {<a name="line.462"></a>
-<span class="sourceLineNo">463</span>                final byte[] xmpXmlBytes = xmpXml.getBytes("utf-8");<a name="line.463"></a>
-<span class="sourceLineNo">464</span>                directory.add(TiffTagConstants.TIFF_TAG_XMP, xmpXmlBytes);<a name="line.464"></a>
-<span class="sourceLineNo">465</span>            }<a name="line.465"></a>
-<span class="sourceLineNo">466</span><a name="line.466"></a>
-<span class="sourceLineNo">467</span>        }<a name="line.467"></a>
-<span class="sourceLineNo">468</span><a name="line.468"></a>
-<span class="sourceLineNo">469</span>        final TiffImageData tiffImageData = new TiffImageData.Strips(imageData,<a name="line.469"></a>
-<span class="sourceLineNo">470</span>                rowsPerStrip);<a name="line.470"></a>
-<span class="sourceLineNo">471</span>        directory.setTiffImageData(tiffImageData);<a name="line.471"></a>
-<span class="sourceLineNo">472</span><a name="line.472"></a>
-<span class="sourceLineNo">473</span>        if (userExif != null) {<a name="line.473"></a>
-<span class="sourceLineNo">474</span>            combineUserExifIntoFinalExif(userExif, outputSet);<a name="line.474"></a>
-<span class="sourceLineNo">475</span>        }<a name="line.475"></a>
-<span class="sourceLineNo">476</span><a name="line.476"></a>
-<span class="sourceLineNo">477</span>        write(os, outputSet);<a name="line.477"></a>
-<span class="sourceLineNo">478</span>    }<a name="line.478"></a>
+<span class="sourceLineNo">394</span>                final MyLzwCompressor compressor = new MyLzwCompressor(<a name="line.394"></a>
+<span class="sourceLineNo">395</span>                        LZW_MINIMUM_CODE_SIZE, ByteOrder.BIG_ENDIAN, true);<a name="line.395"></a>
+<span class="sourceLineNo">396</span>                final byte[] compressed = compressor.compress(uncompressed);<a name="line.396"></a>
+<span class="sourceLineNo">397</span><a name="line.397"></a>
+<span class="sourceLineNo">398</span>                strips[i] = compressed;<a name="line.398"></a>
+<span class="sourceLineNo">399</span>            }<a name="line.399"></a>
+<span class="sourceLineNo">400</span>        } else if (compression == TIFF_COMPRESSION_UNCOMPRESSED) {<a name="line.400"></a>
+<span class="sourceLineNo">401</span>            // do nothing.<a name="line.401"></a>
+<span class="sourceLineNo">402</span>        } else {<a name="line.402"></a>
+<span class="sourceLineNo">403</span>            throw new ImageWriteException(<a name="line.403"></a>
+<span class="sourceLineNo">404</span>                    "Invalid compression parameter (Only CCITT 1D/Group 3/Group 4, LZW, Packbits and uncompressed supported).");<a name="line.404"></a>
+<span class="sourceLineNo">405</span>        }<a name="line.405"></a>
+<span class="sourceLineNo">406</span><a name="line.406"></a>
+<span class="sourceLineNo">407</span>        final TiffElement.DataElement[] imageData = new TiffElement.DataElement[strips.length];<a name="line.407"></a>
+<span class="sourceLineNo">408</span>        for (int i = 0; i &lt; strips.length; i++) {<a name="line.408"></a>
+<span class="sourceLineNo">409</span>            imageData[i] = new TiffImageData.Data(0, strips[i].length, strips[i]);<a name="line.409"></a>
+<span class="sourceLineNo">410</span>        }<a name="line.410"></a>
+<span class="sourceLineNo">411</span><a name="line.411"></a>
+<span class="sourceLineNo">412</span>        final TiffOutputSet outputSet = new TiffOutputSet(byteOrder);<a name="line.412"></a>
+<span class="sourceLineNo">413</span>        final TiffOutputDirectory directory = outputSet.addRootDirectory();<a name="line.413"></a>
+<span class="sourceLineNo">414</span><a name="line.414"></a>
+<span class="sourceLineNo">415</span>        // WriteField stripOffsetsField;<a name="line.415"></a>
+<span class="sourceLineNo">416</span><a name="line.416"></a>
+<span class="sourceLineNo">417</span>        {<a name="line.417"></a>
+<span class="sourceLineNo">418</span><a name="line.418"></a>
+<span class="sourceLineNo">419</span>            directory.add(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, width);<a name="line.419"></a>
+<span class="sourceLineNo">420</span>            directory.add(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, height);<a name="line.420"></a>
+<span class="sourceLineNo">421</span>            directory.add(TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION,<a name="line.421"></a>
+<span class="sourceLineNo">422</span>                    (short) photometricInterpretation);<a name="line.422"></a>
+<span class="sourceLineNo">423</span>            directory.add(TiffTagConstants.TIFF_TAG_COMPRESSION,<a name="line.423"></a>
+<span class="sourceLineNo">424</span>                    (short) compression);<a name="line.424"></a>
+<span class="sourceLineNo">425</span>            directory.add(TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL,<a name="line.425"></a>
+<span class="sourceLineNo">426</span>                    (short) samplesPerPixel);<a name="line.426"></a>
+<span class="sourceLineNo">427</span><a name="line.427"></a>
+<span class="sourceLineNo">428</span>            if (samplesPerPixel == 3) {<a name="line.428"></a>
+<span class="sourceLineNo">429</span>                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE,<a name="line.429"></a>
+<span class="sourceLineNo">430</span>                        (short) bitsPerSample, (short) bitsPerSample,<a name="line.430"></a>
+<span class="sourceLineNo">431</span>                        (short) bitsPerSample);<a name="line.431"></a>
+<span class="sourceLineNo">432</span>            } else if (samplesPerPixel == 1) {<a name="line.432"></a>
+<span class="sourceLineNo">433</span>                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE,<a name="line.433"></a>
+<span class="sourceLineNo">434</span>                        (short) bitsPerSample);<a name="line.434"></a>
+<span class="sourceLineNo">435</span>            }<a name="line.435"></a>
+<span class="sourceLineNo">436</span>            // {<a name="line.436"></a>
+<span class="sourceLineNo">437</span>            // stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,<a name="line.437"></a>
+<span class="sourceLineNo">438</span>            // FIELD_TYPE_LONG, stripOffsets.length, FIELD_TYPE_LONG<a name="line.438"></a>
+<span class="sourceLineNo">439</span>            // .writeData(stripOffsets, byteOrder));<a name="line.439"></a>
+<span class="sourceLineNo">440</span>            // directory.add(stripOffsetsField);<a name="line.440"></a>
+<span class="sourceLineNo">441</span>            // }<a name="line.441"></a>
+<span class="sourceLineNo">442</span>            // {<a name="line.442"></a>
+<span class="sourceLineNo">443</span>            // WriteField field = new WriteField(TIFF_TAG_STRIP_BYTE_COUNTS,<a name="line.443"></a>
+<span class="sourceLineNo">444</span>            // FIELD_TYPE_LONG, stripByteCounts.length,<a name="line.444"></a>
+<span class="sourceLineNo">445</span>            // FIELD_TYPE_LONG.writeData(stripByteCounts,<a name="line.445"></a>
+<span class="sourceLineNo">446</span>            // WRITE_BYTE_ORDER));<a name="line.446"></a>
+<span class="sourceLineNo">447</span>            // directory.add(field);<a name="line.447"></a>
+<span class="sourceLineNo">448</span>            // }<a name="line.448"></a>
+<span class="sourceLineNo">449</span>            directory.add(TiffTagConstants.TIFF_TAG_ROWS_PER_STRIP,<a name="line.449"></a>
+<span class="sourceLineNo">450</span>                    rowsPerStrip);<a name="line.450"></a>
+<span class="sourceLineNo">451</span>            if (pixelDensity.isUnitless()) {<a name="line.451"></a>
+<span class="sourceLineNo">452</span>                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,<a name="line.452"></a>
+<span class="sourceLineNo">453</span>                        (short) 0);<a name="line.453"></a>
+<span class="sourceLineNo">454</span>                directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,<a name="line.454"></a>
+<span class="sourceLineNo">455</span>                        RationalNumber.valueOf(pixelDensity.getRawHorizontalDensity()));<a name="line.455"></a>
+<span class="sourceLineNo">456</span>                directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION, <a name="line.456"></a>
+<span class="sourceLineNo">457</span>                        RationalNumber.valueOf(pixelDensity.getRawVerticalDensity()));<a name="line.457"></a>
+<span class="sourceLineNo">458</span>            } else if (pixelDensity.isInInches()) {<a name="line.458"></a>
+<span class="sourceLineNo">459</span>                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,<a name="line.459"></a>
+<span class="sourceLineNo">460</span>                        (short) 2);<a name="line.460"></a>
+<span class="sourceLineNo">461</span>                directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,<a name="line.461"></a>
+<span class="sourceLineNo">462</span>                        RationalNumber.valueOf(pixelDensity.horizontalDensityInches()));<a name="line.462"></a>
+<span class="sourceLineNo">463</span>                directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,<a name="line.463"></a>
+<span class="sourceLineNo">464</span>                        RationalNumber.valueOf(pixelDensity.verticalDensityInches()));<a name="line.464"></a>
+<span class="sourceLineNo">465</span>            } else {<a name="line.465"></a>
+<span class="sourceLineNo">466</span>                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,<a name="line.466"></a>
+<span class="sourceLineNo">467</span>                        (short) 1);<a name="line.467"></a>
+<span class="sourceLineNo">468</span>                directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,<a name="line.468"></a>
+<span class="sourceLineNo">469</span>                        RationalNumber.valueOf(pixelDensity.horizontalDensityCentimetres()));<a name="line.469"></a>
+<span class="sourceLineNo">470</span>                directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,<a name="line.470"></a>
+<span class="sourceLineNo">471</span>                        RationalNumber.valueOf(pixelDensity.verticalDensityCentimetres()));<a name="line.471"></a>
+<span class="sourceLineNo">472</span>            }<a name="line.472"></a>
+<span class="sourceLineNo">473</span>            if (t4Options != 0) {<a name="line.473"></a>
+<span class="sourceLineNo">474</span>                directory.add(TiffTagConstants.TIFF_TAG_T4_OPTIONS, t4Options);<a name="line.474"></a>
+<span class="sourceLineNo">475</span>            }<a name="line.475"></a>
+<span class="sourceLineNo">476</span>            if (t6Options != 0) {<a name="line.476"></a>
+<span class="sourceLineNo">477</span>                directory.add(TiffTagConstants.TIFF_TAG_T6_OPTIONS, t6Options);<a name="line.477"></a>
+<span class="sourceLineNo">478</span>            }<a name="line.478"></a>
 <span class="sourceLineNo">479</span><a name="line.479"></a>
-<span class="sourceLineNo">480</span>    private void combineUserExifIntoFinalExif(final TiffOutputSet userExif,<a name="line.480"></a>
-<span class="sourceLineNo">481</span>            final TiffOutputSet outputSet) throws ImageWriteException {<a name="line.481"></a>
-<span class="sourceLineNo">482</span>        final List&lt;TiffOutputDirectory&gt; outputDirectories = outputSet<a name="line.482"></a>
-<span class="sourceLineNo">483</span>                .getDirectories();<a name="line.483"></a>
-<span class="sourceLineNo">484</span>        Collections.sort(outputDirectories, TiffOutputDirectory.COMPARATOR);<a name="line.484"></a>
-<span class="sourceLineNo">485</span>        for (final TiffOutputDirectory userDirectory : userExif.getDirectories()) {<a name="line.485"></a>
-<span class="sourceLineNo">486</span>            final int location = Collections.binarySearch(outputDirectories,<a name="line.486"></a>
-<span class="sourceLineNo">487</span>                    userDirectory, TiffOutputDirectory.COMPARATOR);<a name="line.487"></a>
-<span class="sourceLineNo">488</span>            if (location &lt; 0) {<a name="line.488"></a>
-<span class="sourceLineNo">489</span>                outputSet.addDirectory(userDirectory);<a name="line.489"></a>
-<span class="sourceLineNo">490</span>            } else {<a name="line.490"></a>
-<span class="sourceLineNo">491</span>                final TiffOutputDirectory outputDirectory = outputDirectories<a name="line.491"></a>
-<span class="sourceLineNo">492</span>                        .get(location);<a name="line.492"></a>
-<span class="sourceLineNo">493</span>                for (final TiffOutputField userField : userDirectory.getFields()) {<a name="line.493"></a>
-<span class="sourceLineNo">494</span>                    if (outputDirectory.findField(userField.tagInfo) == null) {<a name="line.494"></a>
-<span class="sourceLineNo">495</span>                        outputDirectory.add(userField);<a name="line.495"></a>
-<span class="sourceLineNo">496</span>                    }<a name="line.496"></a>
-<span class="sourceLineNo">497</span>                }<a name="line.497"></a>
-<span class="sourceLineNo">498</span>            }<a name="line.498"></a>
-<span class="sourceLineNo">499</span>        }<a name="line.499"></a>
-<span class="sourceLineNo">500</span>    }<a name="line.500"></a>
-<span class="sourceLineNo">501</span><a name="line.501"></a>
-<span class="sourceLineNo">502</span>    private byte[][] getStrips(final BufferedImage src, final int samplesPerPixel,<a name="line.502"></a>
-<span class="sourceLineNo">503</span>            final int bitsPerSample, final int rowsPerStrip) {<a name="line.503"></a>
-<span class="sourceLineNo">504</span>        final int width = src.getWidth();<a name="line.504"></a>
-<span class="sourceLineNo">505</span>        final int height = src.getHeight();<a name="line.505"></a>
-<span class="sourceLineNo">506</span><a name="line.506"></a>
-<span class="sourceLineNo">507</span>        final int stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;<a name="line.507"></a>
-<span class="sourceLineNo">508</span><a name="line.508"></a>
-<span class="sourceLineNo">509</span>        byte[][] result;<a name="line.509"></a>
-<span class="sourceLineNo">510</span>        { // Write Strips<a name="line.510"></a>
-<span class="sourceLineNo">511</span>            result = new byte[stripCount][];<a name="line.511"></a>
-<span class="sourceLineNo">512</span><a name="line.512"></a>
-<span class="sourceLineNo">513</span>            int remainingRows = height;<a name="line.513"></a>
-<span class="sourceLineNo">514</span><a name="line.514"></a>
-<span class="sourceLineNo">515</span>            for (int i = 0; i &lt; stripCount; i++) {<a name="line.515"></a>
-<span class="sourceLineNo">516</span>                final int rowsInStrip = Math.min(rowsPerStrip, remainingRows);<a name="line.516"></a>
-<span class="sourceLineNo">517</span>                remainingRows -= rowsInStrip;<a name="line.517"></a>
-<span class="sourceLineNo">518</span><a name="line.518"></a>
-<span class="sourceLineNo">519</span>                final int bitsInRow = bitsPerSample * samplesPerPixel * width;<a name="line.519"></a>
-<span class="sourceLineNo">520</span>                final int bytesPerRow = (bitsInRow + 7) / 8;<a name="line.520"></a>
-<span class="sourceLineNo">521</span>                final int bytesInStrip = rowsInStrip * bytesPerRow;<a name="line.521"></a>
-<span class="sourceLineNo">522</span><a name="line.522"></a>
-<span class="sourceLineNo">523</span>                final byte[] uncompressed = new byte[bytesInStrip];<a name="line.523"></a>
+<span class="sourceLineNo">480</span>            if (null != xmpXml) {<a name="line.480"></a>
+<span class="sourceLineNo">481</span>                final byte[] xmpXmlBytes = xmpXml.getBytes("utf-8");<a name="line.481"></a>
+<span class="sourceLineNo">482</span>                directory.add(TiffTagConstants.TIFF_TAG_XMP, xmpXmlBytes);<a name="line.482"></a>
+<span class="sourceLineNo">483</span>            }<a name="line.483"></a>
+<span class="sourceLineNo">484</span><a name="line.484"></a>
+<span class="sourceLineNo">485</span>        }<a name="line.485"></a>
+<span class="sourceLineNo">486</span><a name="line.486"></a>
+<span class="sourceLineNo">487</span>        final TiffImageData tiffImageData = new TiffImageData.Strips(imageData,<a name="line.487"></a>
+<span class="sourceLineNo">488</span>                rowsPerStrip);<a name="line.488"></a>
+<span class="sourceLineNo">489</span>        directory.setTiffImageData(tiffImageData);<a name="line.489"></a>
+<span class="sourceLineNo">490</span><a name="line.490"></a>
+<span class="sourceLineNo">491</span>        if (userExif != null) {<a name="line.491"></a>
+<span class="sourceLineNo">492</span>            combineUserExifIntoFinalExif(userExif, outputSet);<a name="line.492"></a>
+<span class="sourceLineNo">493</span>        }<a name="line.493"></a>
+<span class="sourceLineNo">494</span><a name="line.494"></a>
+<span class="sourceLineNo">495</span>        write(os, outputSet);<a name="line.495"></a>
+<span class="sourceLineNo">496</span>    }<a name="line.496"></a>
+<span class="sourceLineNo">497</span><a name="line.497"></a>
+<span class="sourceLineNo">498</span>    private void combineUserExifIntoFinalExif(final TiffOutputSet userExif,<a name="line.498"></a>
+<span class="sourceLineNo">499</span>            final TiffOutputSet outputSet) throws ImageWriteException {<a name="line.499"></a>
+<span class="sourceLineNo">500</span>        final List&lt;TiffOutputDirectory&gt; outputDirectories = outputSet<a name="line.500"></a>
+<span class="sourceLineNo">501</span>                .getDirectories();<a name="line.501"></a>
+<span class="sourceLineNo">502</span>        Collections.sort(outputDirectories, TiffOutputDirectory.COMPARATOR);<a name="line.502"></a>
+<span class="sourceLineNo">503</span>        for (final TiffOutputDirectory userDirectory : userExif.getDirectories()) {<a name="line.503"></a>
+<span class="sourceLineNo">504</span>            final int location = Collections.binarySearch(outputDirectories,<a name="line.504"></a>
+<span class="sourceLineNo">505</span>                    userDirectory, TiffOutputDirectory.COMPARATOR);<a name="line.505"></a>
+<span class="sourceLineNo">506</span>            if (location &lt; 0) {<a name="line.506"></a>
+<span class="sourceLineNo">507</span>                outputSet.addDirectory(userDirectory);<a name="line.507"></a>
+<span class="sourceLineNo">508</span>            } else {<a name="line.508"></a>
+<span class="sourceLineNo">509</span>                final TiffOutputDirectory outputDirectory = outputDirectories<a name="line.509"></a>
+<span class="sourceLineNo">510</span>                        .get(location);<a name="line.510"></a>
+<span class="sourceLineNo">511</span>                for (final TiffOutputField userField : userDirectory.getFields()) {<a name="line.511"></a>
+<span class="sourceLineNo">512</span>                    if (outputDirectory.findField(userField.tagInfo) == null) {<a name="line.512"></a>
+<span class="sourceLineNo">513</span>                        outputDirectory.add(userField);<a name="line.513"></a>
+<span class="sourceLineNo">514</span>                    }<a name="line.514"></a>
+<span class="sourceLineNo">515</span>                }<a name="line.515"></a>
+<span class="sourceLineNo">516</span>            }<a name="line.516"></a>
+<span class="sourceLineNo">517</span>        }<a name="line.517"></a>
+<span class="sourceLineNo">518</span>    }<a name="line.518"></a>
+<span class="sourceLineNo">519</span><a name="line.519"></a>
+<span class="sourceLineNo">520</span>    private byte[][] getStrips(final BufferedImage src, final int samplesPerPixel,<a name="line.520"></a>
+<span class="sourceLineNo">521</span>            final int bitsPerSample, final int rowsPerStrip) {<a name="line.521"></a>
+<span class="sourceLineNo">522</span>        final int width = src.getWidth();<a name="line.522"></a>
+<span class="sourceLineNo">523</span>        final int height = src.getHeight();<a name="line.523"></a>
 <span class="sourceLineNo">524</span><a name="line.524"></a>
-<span class="sourceLineNo">525</span>                int counter = 0;<a name="line.525"></a>
-<span class="sourceLineNo">526</span>                int y = i * rowsPerStrip;<a name="line.526"></a>
-<span class="sourceLineNo">527</span>                final int stop = i * rowsPerStrip + rowsPerStrip;<a name="line.527"></a>
-<span class="sourceLineNo">528</span><a name="line.528"></a>
-<span class="sourceLineNo">529</span>                for (; (y &lt; height) &amp;&amp; (y &lt; stop); y++) {<a name="line.529"></a>
-<span class="sourceLineNo">530</span>                    int bitCache = 0;<a name="line.530"></a>
-<span class="sourceLineNo">531</span>                    int bitsInCache = 0;<a name="line.531"></a>
-<span class="sourceLineNo">532</span>                    for (int x = 0; x &lt; width; x++) {<a name="line.532"></a>
-<span class="sourceLineNo">533</span>                        final int rgb = src.getRGB(x, y);<a name="line.533"></a>
-<span class="sourceLineNo">534</span>                        final int red = 0xff &amp; (rgb &gt;&gt; 16);<a name="line.534"></a>
-<span class="sourceLineNo">535</span>                        final int green = 0xff &amp; (rgb &gt;&gt; 8);<a name="line.535"></a>
-<span class="sourceLineNo">536</span>                        final int blue = 0xff &amp; (rgb &gt;&gt; 0);<a name="line.536"></a>
-<span class="sourceLineNo">537</span><a name="line.537"></a>
-<span class="sourceLineNo">538</span>                        if (bitsPerSample == 1) {<a name="line.538"></a>
-<span class="sourceLineNo">539</span>                            int sample = (red + green + blue) / 3;<a name="line.539"></a>
-<span class="sourceLineNo">540</span>                            if (sample &gt; 127) {<a name="line.540"></a>
-<span class="sourceLineNo">541</span>                                sample = 0;<a name="line.541"></a>
-<span class="sourceLineNo">542</span>                            } else {<a name="line.542"></a>
-<span class="sourceLineNo">543</span>                                sample = 1;<a name="line.543"></a>
-<span class="sourceLineNo">544</span>                            }<a name="line.544"></a>
-<span class="sourceLineNo">545</span>                            bitCache &lt;&lt;= 1;<a name="line.545"></a>
-<span class="sourceLineNo">546</span>                            bitCache |= sample;<a name="line.546"></a>
-<span class="sourceLineNo">547</span>                            bitsInCache++;<a name="line.547"></a>
-<span class="sourceLineNo">548</span>                            if (bitsInCache == 8) {<a name="line.548"></a>
-<span class="sourceLineNo">549</span>                                uncompressed[counter++] = (byte) bitCache;<a name="line.549"></a>
-<span class="sourceLineNo">550</span>                                bitCache = 0;<a name="line.550"></a>
-<span class="sourceLineNo">551</span>                                bitsInCache = 0;<a name="line.551"></a>
-<span class="sourceLineNo">552</span>                            }<a name="line.552"></a>
-<span class="sourceLineNo">553</span>                        } else {<a name="line.553"></a>
-<span class="sourceLineNo">554</span>                            uncompressed[counter++] = (byte) red;<a name="line.554"></a>
-<span class="sourceLineNo">555</span>                            uncompressed[counter++] = (byte) green;<a name="line.555"></a>
-<span class="sourceLineNo">556</span>                            uncompressed[counter++] = (byte) blue;<a name="line.556"></a>
-<span class="sourceLineNo">557</span>                        }<a name="line.557"></a>
-<span class="sourceLineNo">558</span>                    }<a name="line.558"></a>
-<span class="sourceLineNo">559</span>                    if (bitsInCache &gt; 0) {<a name="line.559"></a>
-<span class="sourceLineNo">560</span>                        bitCache &lt;&lt;= (8 - bitsInCache);<a name="line.560"></a>
-<span class="sourceLineNo">561</span>                        uncompressed[counter++] = (byte) bitCache;<a name="line.561"></a>
-<span class="sourceLineNo">562</span>                    }<a name="line.562"></a>
-<span class="sourceLineNo">563</span>                }<a name="line.563"></a>
-<span class="sourceLineNo">564</span><a name="line.564"></a>
-<span class="sourceLineNo">565</span>                result[i] = uncompressed;<a name="line.565"></a>
-<span class="sourceLineNo">566</span>            }<a name="line.566"></a>
-<span class="sourceLineNo">567</span><a name="line.567"></a>
-<span class="sourceLineNo">568</span>        }<a name="line.568"></a>
-<span class="sourceLineNo">569</span><a name="line.569"></a>
-<span class="sourceLineNo">570</span>        return result;<a name="line.570"></a>
-<span class="sourceLineNo">571</span>    }<a name="line.571"></a>
-<span class="sourceLineNo">572</span><a name="line.572"></a>
-<span class="sourceLineNo">573</span>    protected void writeImageFileHeader(final BinaryOutputStream bos)<a name="line.573"></a>
-<span class="sourceLineNo">574</span>            throws IOException {<a name="line.574"></a>
-<span class="sourceLineNo">575</span>        final int offsetToFirstIFD = TIFF_HEADER_SIZE;<a name="line.575"></a>
-<span class="sourceLineNo">576</span><a name="line.576"></a>
-<span class="sourceLineNo">577</span>        writeImageFileHeader(bos, offsetToFirstIFD);<a name="line.577"></a>
-<span class="sourceLineNo">578</span>    }<a name="line.578"></a>
-<span class="sourceLineNo">579</span><a name="line.579"></a>
-<span class="sourceLineNo">580</span>    protected void writeImageFileHeader(final BinaryOutputStream bos,<a name="line.580"></a>
-<span class="sourceLineNo">581</span>            final long offsetToFirstIFD) throws IOException {<a name="line.581"></a>
-<span class="sourceLineNo">582</span>        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {<a name="line.582"></a>
-<span class="sourceLineNo">583</span>            bos.write('I');<a name="line.583"></a>
-<span class="sourceLineNo">584</span>            bos.write('I');<a name="line.584"></a>
-<span class="sourceLineNo">585</span>        } else {<a name="line.585"></a>
-<span class="sourceLineNo">586</span>            bos.write('M');<a name="line.586"></a>
-<span class="sourceLineNo">587</span>            bos.write('M');<a name="line.587"></a>
-<span class="sourceLineNo">588</span>        }<a name="line.588"></a>
-<span class="sourceLineNo">589</span><a name="line.589"></a>
-<span class="sourceLineNo">590</span>        bos.write2Bytes(42); // tiffVersion<a name="line.590"></a>
-<span class="sourceLineNo">591</span><a name="line.591"></a>
-<span class="sourceLineNo">592</span>        bos.write4Bytes((int) offsetToFirstIFD);<a name="line.592"></a>
-<span class="sourceLineNo">593</span>    }<a name="line.593"></a>
+<span class="sourceLineNo">525</span>        final int stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;<a name="line.525"></a>
+<span class="sourceLineNo">526</span><a name="line.526"></a>
+<span class="sourceLineNo">527</span>        byte[][] result;<a name="line.527"></a>
+<span class="sourceLineNo">528</span>        { // Write Strips<a name="line.528"></a>
+<span class="sourceLineNo">529</span>            result = new byte[stripCount][];<a name="line.529"></a>
+<span class="sourceLineNo">530</span><a name="line.530"></a>
+<span class="sourceLineNo">531</span>            int remainingRows = height;<a name="line.531"></a>
+<span class="sourceLineNo">532</span><a name="line.532"></a>
+<span class="sourceLineNo">533</span>            for (int i = 0; i &lt; stripCount; i++) {<a name="line.533"></a>
+<span class="sourceLineNo">534</span>                final int rowsInStrip = Math.min(rowsPerStrip, remainingRows);<a name="line.534"></a>
+<span class="sourceLineNo">535</span>                remainingRows -= rowsInStrip;<a name="line.535"></a>
+<span class="sourceLineNo">536</span><a name="line.536"></a>
+<span class="sourceLineNo">537</span>                final int bitsInRow = bitsPerSample * samplesPerPixel * width;<a name="line.537"></a>
+<span class="sourceLineNo">538</span>                final int bytesPerRow = (bitsInRow + 7) / 8;<a name="line.538"></a>
+<span class="sourceLineNo">539</span>                final int bytesInStrip = rowsInStrip * bytesPerRow;<a name="line.539"></a>
+<span class="sourceLineNo">540</span><a name="line.540"></a>
+<span class="sourceLineNo">541</span>                final byte[] uncompressed = new byte[bytesInStrip];<a name="line.541"></a>
+<span class="sourceLineNo">542</span><a name="line.542"></a>
+<span class="sourceLineNo">543</span>                int counter = 0;<a name="line.543"></a>
+<span class="sourceLineNo">544</span>                int y = i * rowsPerStrip;<a name="line.544"></a>
+<span class="sourceLineNo">545</span>                final int stop = i * rowsPerStrip + rowsPerStrip;<a name="line.545"></a>
+<span class="sourceLineNo">546</span><a name="line.546"></a>
+<span class="sourceLineNo">547</span>                for (; (y &lt; height) &amp;&amp; (y &lt; stop); y++) {<a name="line.547"></a>
+<span class="sourceLineNo">548</span>                    int bitCache = 0;<a name="line.548"></a>
+<span class="sourceLineNo">549</span>                    int bitsInCache = 0;<a name="line.549"></a>
+<span class="sourceLineNo">550</span>                    for (int x = 0; x &lt; width; x++) {<a name="line.550"></a>
+<span class="sourceLineNo">551</span>                        final int rgb = src.getRGB(x, y);<a name="line.551"></a>
+<span class="sourceLineNo">552</span>                        final int red = 0xff &amp; (rgb &gt;&gt; 16);<a name="line.552"></a>
+<span class="sourceLineNo">553</span>                        final int green = 0xff &amp; (rgb &gt;&gt; 8);<a name="line.553"></a>
+<span class="sourceLineNo">554</span>                        final int blue = 0xff &amp; (rgb &gt;&gt; 0);<a name="line.554"></a>
+<span class="sourceLineNo">555</span><a name="line.555"></a>
+<span class="sourceLineNo">556</span>                        if (bitsPerSample == 1) {<a name="line.556"></a>
+<span class="sourceLineNo">557</span>                            int sample = (red + green + blue) / 3;<a name="line.557"></a>
+<span class="sourceLineNo">558</span>                            if (sample &gt; 127) {<a name="line.558"></a>
+<span class="sourceLineNo">559</span>                                sample = 0;<a name="line.559"></a>
+<span class="sourceLineNo">560</span>                            } else {<a name="line.560"></a>
+<span class="sourceLineNo">561</span>                                sample = 1;<a name="line.561"></a>
+<span class="sourceLineNo">562</span>                            }<a name="line.562"></a>
+<span class="sourceLineNo">563</span>                            bitCache &lt;&lt;= 1;<a name="line.563"></a>
+<span class="sourceLineNo">564</span>                            bitCache |= sample;<a name="line.564"></a>
+<span class="sourceLineNo">565</span>                            bitsInCache++;<a name="line.565"></a>
+<span class="sourceLineNo">566</span>                            if (bitsInCache == 8) {<a name="line.566"></a>
+<span class="sourceLineNo">567</span>                                uncompressed[counter++] = (byte) bitCache;<a name="line.567"></a>
+<span class="sourceLineNo">568</span>                                bitCache = 0;<a name="line.568"></a>
+<span class="sourceLineNo">569</span>                                bitsInCache = 0;<a name="line.569"></a>
+<span class="sourceLineNo">570</span>                            }<a name="line.570"></a>
+<span class="sourceLineNo">571</span>                        } else {<a name="line.571"></a>
+<span class="sourceLineNo">572</span>                            uncompressed[counter++] = (byte) red;<a name="line.572"></a>
+<span class="sourceLineNo">573</span>                            uncompressed[counter++] = (byte) green;<a name="line.573"></a>
+<span class="sourceLineNo">574</span>                            uncompressed[counter++] = (byte) blue;<a name="line.574"></a>
+<span class="sourceLineNo">575</span>                        }<a name="line.575"></a>
+<span class="sourceLineNo">576</span>                    }<a name="line.576"></a>
+<span class="sourceLineNo">577</span>                    if (bitsInCache &gt; 0) {<a name="line.577"></a>
+<span class="sourceLineNo">578</span>                        bitCache &lt;&lt;= (8 - bitsInCache);<a name="line.578"></a>
+<span class="sourceLineNo">579</span>                        uncompressed[counter++] = (byte) bitCache;<a name="line.579"></a>
+<span class="sourceLineNo">580</span>                    }<a name="line.580"></a>
+<span class="sourceLineNo">581</span>                }<a name="line.581"></a>
+<span class="sourceLineNo">582</span><a name="line.582"></a>
+<span class="sourceLineNo">583</span>                result[i] = uncompressed;<a name="line.583"></a>
+<span class="sourceLineNo">584</span>            }<a name="line.584"></a>
+<span class="sourceLineNo">585</span><a name="line.585"></a>
+<span class="sourceLineNo">586</span>        }<a name="line.586"></a>
+<span class="sourceLineNo">587</span><a name="line.587"></a>
+<span class="sourceLineNo">588</span>        return result;<a name="line.588"></a>
+<span class="sourceLineNo">589</span>    }<a name="line.589"></a>
+<span class="sourceLineNo">590</span><a name="line.590"></a>
+<span class="sourceLineNo">591</span>    protected void writeImageFileHeader(final BinaryOutputStream bos)<a name="line.591"></a>
+<span class="sourceLineNo">592</span>            throws IOException {<a name="line.592"></a>
+<span class="sourceLineNo">593</span>        final int offsetToFirstIFD = TIFF_HEADER_SIZE;<a name="line.593"></a>
 <span class="sourceLineNo">594</span><a name="line.594"></a>
-<span class="sourceLineNo">595</span>}<a name="line.595"></a>
+<span class="sourceLineNo">595</span>        writeImageFileHeader(bos, offsetToFirstIFD);<a name="line.595"></a>
+<span class="sourceLineNo">596</span>    }<a name="line.596"></a>
+<span class="sourceLineNo">597</span><a name="line.597"></a>
+<span class="sourceLineNo">598</span>    protected void writeImageFileHeader(final BinaryOutputStream bos,<a name="line.598"></a>
+<span class="sourceLineNo">599</span>            final long offsetToFirstIFD) throws IOException {<a name="line.599"></a>
+<span class="sourceLineNo">600</span>        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {<a name="line.600"></a>
+<span class="sourceLineNo">601</span>            bos.write('I');<a name="line.601"></a>
+<span class="sourceLineNo">602</span>            bos.write('I');<a name="line.602"></a>
+<span class="sourceLineNo">603</span>        } else {<a name="line.603"></a>
+<span class="sourceLineNo">604</span>            bos.write('M');<a name="line.604"></a>
+<span class="sourceLineNo">605</span>            bos.write('M');<a name="line.605"></a>
+<span class="sourceLineNo">606</span>        }<a name="line.606"></a>
+<span class="sourceLineNo">607</span><a name="line.607"></a>
+<span class="sourceLineNo">608</span>        bos.write2Bytes(42); // tiffVersion<a name="line.608"></a>
+<span class="sourceLineNo">609</span><a name="line.609"></a>
+<span class="sourceLineNo">610</span>        bos.write4Bytes((int) offsetToFirstIFD);<a name="line.610"></a>
+<span class="sourceLineNo">611</span>    }<a name="line.611"></a>
+<span class="sourceLineNo">612</span><a name="line.612"></a>
+<span class="sourceLineNo">613</span>}<a name="line.613"></a>
 
 
 



Mime
View raw message