#490: Minor API clean-up and documentation.

This commit is contained in:
Harald Kuhr 2020-01-22 20:35:41 +01:00
parent 8b86b57e63
commit c48af5acc7
3 changed files with 30 additions and 12 deletions

View File

@ -44,7 +44,7 @@ import static com.twelvemonkeys.lang.Validate.isTrue;
import static com.twelvemonkeys.lang.Validate.notNull;
/**
* Creates a {@code Shape} object from an Adobe Photoshop Path resource.
* Reads a {@code Shape} object from an Adobe Photoshop Path resource.
*
* @see <a href="http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_17587">Adobe Photoshop Path resource format</a>
* @author <a href="mailto:jpalmer@itemmaster.com">Jason Palmer, itemMaster LLC</a>

View File

@ -49,7 +49,10 @@ import static com.twelvemonkeys.lang.Validate.isTrue;
import static com.twelvemonkeys.lang.Validate.notNull;
/**
* AdobePathWriter
* Writes a {@code Shape} object to an Adobe Photoshop Path or Path resource.
*
* @see <a href="http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_17587">Adobe Photoshop Path resource format</a>
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
*/
public final class AdobePathWriter {
@ -181,14 +184,15 @@ public final class AdobePathWriter {
}
/**
* Writes the path as a complete Photoshop clipping path resource to the given stream.
* Writes the path as a complete Adobe Photoshop clipping path resource to the given stream.
*
* @param output the stream to write to.
* @param resourceId the resource id, typically {@link PSD#RES_CLIPPING_PATH} (0x07D0).
* @throws IOException if an I/O exception happens during writing.
*/
void writePathResource(final DataOutput output) throws IOException {
public void writePathResource(final DataOutput output, int resourceId) throws IOException {
output.writeInt(PSD.RESOURCE_TYPE);
output.writeShort(PSD.RES_CLIPPING_PATH);
output.writeShort(resourceId);
output.writeShort(0); // Path name (Pascal string) empty + pad
output.writeInt(segments.size() * 26); // Resource size
@ -196,7 +200,7 @@ public final class AdobePathWriter {
}
/**
* Writes the path as a set of Adobe path segments to the given stream.
* Writes the path as a set of Adobe Photoshop path segments to the given stream.
*
* @param output the stream to write to.
* @throws IOException if an I/O exception happens during writing.
@ -235,13 +239,17 @@ public final class AdobePathWriter {
}
}
// TODO: Do we need to care about endianness for TIFF files?
// TODO: Better name?
byte[] writePathResource() {
/**
* Transforms the path to a byte array, containing a complete Adobe Photoshop path resource.
*
* @param resourceId the resource id, typically {@link PSD#RES_CLIPPING_PATH} (0x07D0).
* @return a new byte array, containing the clipping path resource.
*/
public byte[] writePathResource(int resourceId) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (DataOutputStream stream = new DataOutputStream(bytes)) {
writePathResource(stream);
writePathResource(stream, resourceId);
}
catch (IOException e) {
throw new AssertionError("ByteArrayOutputStream threw IOException", e);
@ -250,6 +258,11 @@ public final class AdobePathWriter {
return bytes.toByteArray();
}
/**
* Transforms the path to a byte array, containing a set of Adobe Photoshop path segments.
*
* @return a new byte array, containing the path segments.
*/
public byte[] writePath() {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();

View File

@ -260,7 +260,7 @@ public final class Paths {
}
/**
* Writes the image along with a clipping path resource, in the given format to the supplied output.
* Writes the image along with a clipping path resource, in the given format, to the supplied output.
* The image is written to the
* {@code ImageOutputStream} starting at the current stream
* pointer, overwriting existing stream data from that point
@ -270,6 +270,11 @@ public final class Paths {
* <em>not</em> close the output stream.
* It is the responsibility of the caller to close the stream, if desired.
* </p>
* <p>
* Implementation note: Only JPEG (using the "javax_imageio_jpeg_image_1.0" metadata format) and
* TIFF (using the "javax_imageio_tiff_image_1.0" or "com_sun_media_imageio_plugins_tiff_image_1.0" metadata formats)
* formats are currently supported.
* </p>
*
* @param image the image to be written, may not be {@code null}.
* @param clipPath the clip path, may not be {@code null}.
@ -303,7 +308,7 @@ public final class Paths {
IIOMetadata metadata = writer.getDefaultImageMetadata(type, param);
List<String> metadataFormats = asList(metadata.getMetadataFormatNames());
byte[] pathResource = new AdobePathWriter(clipPath).writePathResource();
byte[] pathResource = new AdobePathWriter(clipPath).writePathResource(PSD.RES_CLIPPING_PATH);
if (metadataFormats.contains("javax_imageio_tiff_image_1.0") || metadataFormats.contains("com_sun_media_imageio_plugins_tiff_image_1.0")) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);