1113 throws IOException {
1114 setThreadLock();
1115 try {
1116 cbLock.check();
1117
1118 prepareWriteSequenceOnThread(streamMetadata);
1119 } finally {
1120 clearThreadLock();
1121 }
1122 }
1123
1124 private void prepareWriteSequenceOnThread(IIOMetadata streamMetadata)
1125 throws IOException {
1126 if (ios == null) {
1127 throw new IllegalStateException("Output has not been set!");
1128 }
1129
1130 /*
1131 * from jpeg_metadata.html:
1132 * If no stream metadata is supplied to
1133 * <code>ImageWriter.prepareWriteSequence</code>, then no
1134 * tables-only image is written. If stream metadata containing
1135 * no tables is supplied to
1136 * <code>ImageWriter.prepareWriteSequence</code>, then a tables-only
1137 * image containing default visually lossless tables is written.
1138 */
1139 if (streamMetadata != null) {
1140 if (streamMetadata instanceof JPEGMetadata) {
1141 // write a complete tables-only image at the beginning of
1142 // the stream.
1143 JPEGMetadata jmeta = (JPEGMetadata) streamMetadata;
1144 if (jmeta.isStream == false) {
1145 throw new IllegalArgumentException
1146 ("Invalid stream metadata object.");
1147 }
1148 // Check that we are
1149 // at the beginning of the stream, or can go there, and haven't
1150 // written out the metadata already.
1151 if (currentImage != 0) {
1152 throw new IIOException
1153 ("JPEG Stream metadata must precede all images");
1154 }
1155 if (sequencePrepared == true) {
1156 throw new IIOException("Stream metadata already written!");
1682 return true;
1683 }
1684 return false;
1685 }
1686
1687 ////////////// End of ColorSpace conversion
1688
1689 ////////////// Native methods and callbacks
1690
1691 /** Sets up static native structures. */
1692 private static native void initWriterIDs(Class<?> qTableClass,
1693 Class<?> huffClass);
1694
1695 /** Sets up per-writer native structure and returns a pointer to it. */
1696 private native long initJPEGImageWriter();
1697
1698 /** Sets up native structures for output stream */
1699 private native void setDest(long structPointer);
1700
1701 /**
1702 * Returns <code>true</code> if the write was aborted.
1703 */
1704 private native boolean writeImage(long structPointer,
1705 byte [] data,
1706 int inCsType, int outCsType,
1707 int numBands,
1708 int [] bandSizes,
1709 int srcWidth,
1710 int destWidth, int destHeight,
1711 int stepX, int stepY,
1712 JPEGQTable [] qtables,
1713 boolean writeDQT,
1714 JPEGHuffmanTable[] DCHuffmanTables,
1715 JPEGHuffmanTable[] ACHuffmanTables,
1716 boolean writeDHT,
1717 boolean optimizeHuffman,
1718 boolean progressive,
1719 int numScans,
1720 int [] scans,
1721 int [] componentIds,
1722 int [] HsamplingFactors,
|
1113 throws IOException {
1114 setThreadLock();
1115 try {
1116 cbLock.check();
1117
1118 prepareWriteSequenceOnThread(streamMetadata);
1119 } finally {
1120 clearThreadLock();
1121 }
1122 }
1123
1124 private void prepareWriteSequenceOnThread(IIOMetadata streamMetadata)
1125 throws IOException {
1126 if (ios == null) {
1127 throw new IllegalStateException("Output has not been set!");
1128 }
1129
1130 /*
1131 * from jpeg_metadata.html:
1132 * If no stream metadata is supplied to
1133 * {@code ImageWriter.prepareWriteSequence}, then no
1134 * tables-only image is written. If stream metadata containing
1135 * no tables is supplied to
1136 * {@code ImageWriter.prepareWriteSequence}, then a tables-only
1137 * image containing default visually lossless tables is written.
1138 */
1139 if (streamMetadata != null) {
1140 if (streamMetadata instanceof JPEGMetadata) {
1141 // write a complete tables-only image at the beginning of
1142 // the stream.
1143 JPEGMetadata jmeta = (JPEGMetadata) streamMetadata;
1144 if (jmeta.isStream == false) {
1145 throw new IllegalArgumentException
1146 ("Invalid stream metadata object.");
1147 }
1148 // Check that we are
1149 // at the beginning of the stream, or can go there, and haven't
1150 // written out the metadata already.
1151 if (currentImage != 0) {
1152 throw new IIOException
1153 ("JPEG Stream metadata must precede all images");
1154 }
1155 if (sequencePrepared == true) {
1156 throw new IIOException("Stream metadata already written!");
1682 return true;
1683 }
1684 return false;
1685 }
1686
1687 ////////////// End of ColorSpace conversion
1688
1689 ////////////// Native methods and callbacks
1690
1691 /** Sets up static native structures. */
1692 private static native void initWriterIDs(Class<?> qTableClass,
1693 Class<?> huffClass);
1694
1695 /** Sets up per-writer native structure and returns a pointer to it. */
1696 private native long initJPEGImageWriter();
1697
1698 /** Sets up native structures for output stream */
1699 private native void setDest(long structPointer);
1700
1701 /**
1702 * Returns {@code true} if the write was aborted.
1703 */
1704 private native boolean writeImage(long structPointer,
1705 byte [] data,
1706 int inCsType, int outCsType,
1707 int numBands,
1708 int [] bandSizes,
1709 int srcWidth,
1710 int destWidth, int destHeight,
1711 int stepX, int stepY,
1712 JPEGQTable [] qtables,
1713 boolean writeDQT,
1714 JPEGHuffmanTable[] DCHuffmanTables,
1715 JPEGHuffmanTable[] ACHuffmanTables,
1716 boolean writeDHT,
1717 boolean optimizeHuffman,
1718 boolean progressive,
1719 int numScans,
1720 int [] scans,
1721 int [] componentIds,
1722 int [] HsamplingFactors,
|