feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,322 @@
/*
* Copyright (c) 2003, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.wbmp;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.MultiPixelPackedSampleModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import javax.imageio.IIOException;
import javax.imageio.ImageReader;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.ReaderUtil;
/** This class is the Java Image IO plugin reader for WBMP images.
* It may subsample the image, clip the image,
* and shift the decoded image origin if the proper decoding parameter
* are set in the provided <code>WBMPImageReadParam</code>.
*/
public class WBMPImageReader extends ImageReader {
/** The input stream where reads from */
private ImageInputStream iis = null;
/** Indicates whether the header is read. */
private boolean gotHeader = false;
/** The original image width. */
private int width;
/** The original image height. */
private int height;
private int wbmpType;
private WBMPMetadata metadata;
/** Constructs <code>WBMPImageReader</code> from the provided
* <code>ImageReaderSpi</code>.
*/
public WBMPImageReader(ImageReaderSpi originator) {
super(originator);
}
/** Overrides the method defined in the superclass. */
public void setInput(Object input,
boolean seekForwardOnly,
boolean ignoreMetadata) {
super.setInput(input, seekForwardOnly, ignoreMetadata);
iis = (ImageInputStream) input; // Always works
gotHeader = false;
}
/** Overrides the method defined in the superclass. */
public int getNumImages(boolean allowSearch) throws IOException {
if (iis == null) {
throw new IllegalStateException(I18N.getString("GetNumImages0"));
}
if (seekForwardOnly && allowSearch) {
throw new IllegalStateException(I18N.getString("GetNumImages1"));
}
return 1;
}
public int getWidth(int imageIndex) throws IOException {
checkIndex(imageIndex);
readHeader();
return width;
}
public int getHeight(int imageIndex) throws IOException {
checkIndex(imageIndex);
readHeader();
return height;
}
public boolean isRandomAccessEasy(int imageIndex) throws IOException {
checkIndex(imageIndex);
return true;
}
private void checkIndex(int imageIndex) {
if (imageIndex != 0) {
throw new IndexOutOfBoundsException(I18N.getString("WBMPImageReader0"));
}
}
public void readHeader() throws IOException {
if (gotHeader)
return;
if (iis == null) {
throw new IllegalStateException("Input source not set!");
}
metadata = new WBMPMetadata();
wbmpType = iis.readByte(); // TypeField
byte fixHeaderField = iis.readByte();
// check for valid wbmp image
if (fixHeaderField != 0
|| !isValidWbmpType(wbmpType))
{
throw new IIOException(I18N.getString("WBMPImageReader2"));
}
metadata.wbmpType = wbmpType;
// Read image width
width = ReaderUtil.readMultiByteInteger(iis);
metadata.width = width;
// Read image height
height = ReaderUtil.readMultiByteInteger(iis);
metadata.height = height;
gotHeader = true;
}
public Iterator getImageTypes(int imageIndex)
throws IOException {
checkIndex(imageIndex);
readHeader();
BufferedImage bi =
new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_BINARY);
ArrayList list = new ArrayList(1);
list.add(new ImageTypeSpecifier(bi));
return list.iterator();
}
public ImageReadParam getDefaultReadParam() {
return new ImageReadParam();
}
public IIOMetadata getImageMetadata(int imageIndex)
throws IOException {
checkIndex(imageIndex);
if (metadata == null) {
readHeader();
}
return metadata;
}
public IIOMetadata getStreamMetadata() throws IOException {
return null;
}
public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
if (iis == null) {
throw new IllegalStateException(I18N.getString("WBMPImageReader1"));
}
checkIndex(imageIndex);
clearAbortRequest();
processImageStarted(imageIndex);
if (param == null)
param = getDefaultReadParam();
//read header
readHeader();
Rectangle sourceRegion = new Rectangle(0, 0, 0, 0);
Rectangle destinationRegion = new Rectangle(0, 0, 0, 0);
computeRegions(param, this.width, this.height,
param.getDestination(),
sourceRegion,
destinationRegion);
int scaleX = param.getSourceXSubsampling();
int scaleY = param.getSourceYSubsampling();
int xOffset = param.getSubsamplingXOffset();
int yOffset = param.getSubsamplingYOffset();
// If the destination is provided, then use it. Otherwise, create new one
BufferedImage bi = param.getDestination();
if (bi == null)
bi = new BufferedImage(destinationRegion.x + destinationRegion.width,
destinationRegion.y + destinationRegion.height,
BufferedImage.TYPE_BYTE_BINARY);
boolean noTransform =
destinationRegion.equals(new Rectangle(0, 0, width, height)) &&
destinationRegion.equals(new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
// Get the image data.
WritableRaster tile = bi.getWritableTile(0, 0);
// Get the SampleModel.
MultiPixelPackedSampleModel sm =
(MultiPixelPackedSampleModel)bi.getSampleModel();
if (noTransform) {
if (abortRequested()) {
processReadAborted();
return bi;
}
// If noTransform is necessary, read the data.
iis.read(((DataBufferByte)tile.getDataBuffer()).getData(),
0, height*sm.getScanlineStride());
processImageUpdate(bi,
0, 0,
width, height, 1, 1,
new int[]{0});
processImageProgress(100.0F);
} else {
int len = (this.width + 7) / 8;
byte[] buf = new byte[len];
byte[] data = ((DataBufferByte)tile.getDataBuffer()).getData();
int lineStride = sm.getScanlineStride();
iis.skipBytes(len * sourceRegion.y);
int skipLength = len * (scaleY - 1);
// cache the values to avoid duplicated computation
int[] srcOff = new int[destinationRegion.width];
int[] destOff = new int[destinationRegion.width];
int[] srcPos = new int[destinationRegion.width];
int[] destPos = new int[destinationRegion.width];
for (int i = destinationRegion.x, x = sourceRegion.x, j = 0;
i < destinationRegion.x + destinationRegion.width;
i++, j++, x += scaleX) {
srcPos[j] = x >> 3;
srcOff[j] = 7 - (x & 7);
destPos[j] = i >> 3;
destOff[j] = 7 - (i & 7);
}
for (int j = 0, y = sourceRegion.y,
k = destinationRegion.y * lineStride;
j < destinationRegion.height; j++, y+=scaleY) {
if (abortRequested())
break;
iis.read(buf, 0, len);
for (int i = 0; i < destinationRegion.width; i++) {
//get the bit and assign to the data buffer of the raster
int v = (buf[srcPos[i]] >> srcOff[i]) & 1;
data[k + destPos[i]] |= v << destOff[i];
}
k += lineStride;
iis.skipBytes(skipLength);
processImageUpdate(bi,
0, j,
destinationRegion.width, 1, 1, 1,
new int[]{0});
processImageProgress(100.0F*j/destinationRegion.height);
}
}
if (abortRequested())
processReadAborted();
else
processImageComplete();
return bi;
}
public boolean canReadRaster() {
return true;
}
public Raster readRaster(int imageIndex,
ImageReadParam param) throws IOException {
BufferedImage bi = read(imageIndex, param);
return bi.getData();
}
public void reset() {
super.reset();
iis = null;
gotHeader = false;
}
/*
* This method verifies that given byte is valid wbmp type marker.
* At the moment only 0x0 marker is described by wbmp spec.
*/
boolean isValidWbmpType(int type) {
return type == 0;
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 2003, 2013, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.wbmp;
import java.util.Locale;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.spi.IIORegistry;
import javax.imageio.spi.ServiceRegistry;
import java.io.IOException;
import javax.imageio.ImageReader;
import javax.imageio.IIOException;
import com.sun.imageio.plugins.common.ReaderUtil;
public class WBMPImageReaderSpi extends ImageReaderSpi {
private static final int MAX_WBMP_WIDTH = 1024;
private static final int MAX_WBMP_HEIGHT = 768;
private static String [] writerSpiNames =
{"com.sun.imageio.plugins.wbmp.WBMPImageWriterSpi"};
private static String[] formatNames = {"wbmp", "WBMP"};
private static String[] entensions = {"wbmp"};
private static String[] mimeType = {"image/vnd.wap.wbmp"};
private boolean registered = false;
public WBMPImageReaderSpi() {
super("Oracle Corporation",
"1.0",
formatNames,
entensions,
mimeType,
"com.sun.imageio.plugins.wbmp.WBMPImageReader",
new Class[] { ImageInputStream.class },
writerSpiNames,
true,
null, null, null, null,
true,
WBMPMetadata.nativeMetadataFormatName,
"com.sun.imageio.plugins.wbmp.WBMPMetadataFormat",
null, null);
}
public void onRegistration(ServiceRegistry registry,
Class<?> category) {
if (registered) {
return;
}
registered = true;
}
public String getDescription(Locale locale) {
return "Standard WBMP Image Reader";
}
public boolean canDecodeInput(Object source) throws IOException {
if (!(source instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream)source;
stream.mark();
try {
int type = stream.readByte(); // TypeField
int fixHeaderField = stream.readByte();
// check WBMP "header"
if (type != 0 || fixHeaderField != 0) {
// while WBMP reader does not support ext WBMP headers
return false;
}
int width = ReaderUtil.readMultiByteInteger(stream);
int height = ReaderUtil.readMultiByteInteger(stream);
// check image dimension
if (width <= 0 || height <= 0) {
return false;
}
long dataLength = stream.length();
if (dataLength == -1) {
// We can't verify that amount of data in the stream
// corresponds to image dimension because we do not know
// the length of the data stream.
// Assuming that wbmp image are used for mobile devices,
// let's introduce an upper limit for image dimension.
// In case if exact amount of raster data is unknown,
// let's reject images with dimension above the limit.
return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
}
dataLength -= stream.getStreamPosition();
long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);
return (dataLength == scanSize * height);
} finally {
stream.reset();
}
}
public ImageReader createReaderInstance(Object extension)
throws IIOException {
return new WBMPImageReader(this);
}
}

View File

@@ -0,0 +1,315 @@
/*
* Copyright (c) 2003, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.wbmp;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.MultiPixelPackedSampleModel;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import javax.imageio.IIOImage;
import javax.imageio.IIOException;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
import com.sun.imageio.plugins.common.I18N;
/**
* The Java Image IO plugin writer for encoding a binary RenderedImage into
* a WBMP format.
*
* The encoding process may clip, subsample using the parameters
* specified in the <code>ImageWriteParam</code>.
*
* @see com.sun.media.imageio.plugins.WBMPImageWriteParam
*/
public class WBMPImageWriter extends ImageWriter {
/** The output stream to write into */
private ImageOutputStream stream = null;
// Get the number of bits required to represent an int.
private static int getNumBits(int intValue) {
int numBits = 32;
int mask = 0x80000000;
while(mask != 0 && (intValue & mask) == 0) {
numBits--;
mask >>>= 1;
}
return numBits;
}
// Convert an int value to WBMP multi-byte format.
private static byte[] intToMultiByte(int intValue) {
int numBitsLeft = getNumBits(intValue);
byte[] multiBytes = new byte[(numBitsLeft + 6)/7];
int maxIndex = multiBytes.length - 1;
for(int b = 0; b <= maxIndex; b++) {
multiBytes[b] = (byte)((intValue >>> ((maxIndex - b)*7))&0x7f);
if(b != maxIndex) {
multiBytes[b] |= (byte)0x80;
}
}
return multiBytes;
}
/** Constructs <code>WBMPImageWriter</code> based on the provided
* <code>ImageWriterSpi</code>.
*/
public WBMPImageWriter(ImageWriterSpi originator) {
super(originator);
}
public void setOutput(Object output) {
super.setOutput(output); // validates output
if (output != null) {
if (!(output instanceof ImageOutputStream))
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter"));
this.stream = (ImageOutputStream)output;
} else
this.stream = null;
}
public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
return null;
}
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param) {
WBMPMetadata meta = new WBMPMetadata();
meta.wbmpType = 0; // default wbmp level
return meta;
}
public IIOMetadata convertStreamMetadata(IIOMetadata inData,
ImageWriteParam param) {
return null;
}
public IIOMetadata convertImageMetadata(IIOMetadata metadata,
ImageTypeSpecifier type,
ImageWriteParam param) {
return null;
}
public boolean canWriteRasters() {
return true;
}
public void write(IIOMetadata streamMetadata,
IIOImage image,
ImageWriteParam param) throws IOException {
if (stream == null) {
throw new IllegalStateException(I18N.getString("WBMPImageWriter3"));
}
if (image == null) {
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter4"));
}
clearAbortRequest();
processImageStarted(0);
if (param == null)
param = getDefaultWriteParam();
RenderedImage input = null;
Raster inputRaster = null;
boolean writeRaster = image.hasRaster();
Rectangle sourceRegion = param.getSourceRegion();
SampleModel sampleModel = null;
if (writeRaster) {
inputRaster = image.getRaster();
sampleModel = inputRaster.getSampleModel();
} else {
input = image.getRenderedImage();
sampleModel = input.getSampleModel();
inputRaster = input.getData();
}
checkSampleModel(sampleModel);
if (sourceRegion == null)
sourceRegion = inputRaster.getBounds();
else
sourceRegion = sourceRegion.intersection(inputRaster.getBounds());
if (sourceRegion.isEmpty())
throw new RuntimeException(I18N.getString("WBMPImageWriter1"));
int scaleX = param.getSourceXSubsampling();
int scaleY = param.getSourceYSubsampling();
int xOffset = param.getSubsamplingXOffset();
int yOffset = param.getSubsamplingYOffset();
sourceRegion.translate(xOffset, yOffset);
sourceRegion.width -= xOffset;
sourceRegion.height -= yOffset;
int minX = sourceRegion.x / scaleX;
int minY = sourceRegion.y / scaleY;
int w = (sourceRegion.width + scaleX - 1) / scaleX;
int h = (sourceRegion.height + scaleY - 1) / scaleY;
Rectangle destinationRegion = new Rectangle(minX, minY, w, h);
sampleModel = sampleModel.createCompatibleSampleModel(w, h);
SampleModel destSM= sampleModel;
// If the data are not formatted nominally then reformat.
if(sampleModel.getDataType() != DataBuffer.TYPE_BYTE ||
!(sampleModel instanceof MultiPixelPackedSampleModel) ||
((MultiPixelPackedSampleModel)sampleModel).getDataBitOffset() != 0) {
destSM =
new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
w, h, 1,
w + 7 >> 3, 0);
}
if (!destinationRegion.equals(sourceRegion)) {
if (scaleX == 1 && scaleY == 1)
inputRaster = inputRaster.createChild(inputRaster.getMinX(),
inputRaster.getMinY(),
w, h, minX, minY, null);
else {
WritableRaster ras = Raster.createWritableRaster(destSM,
new Point(minX, minY));
byte[] data = ((DataBufferByte)ras.getDataBuffer()).getData();
for(int j = minY, y = sourceRegion.y, k = 0;
j < minY + h; j++, y += scaleY) {
for (int i = 0, x = sourceRegion.x;
i <w; i++, x +=scaleX) {
int v = inputRaster.getSample(x, y, 0);
data[k + (i >> 3)] |= v << (7 - (i & 7));
}
k += w + 7 >> 3;
}
inputRaster = ras;
}
}
// If the data are not formatted nominally then reformat.
if(!destSM.equals(inputRaster.getSampleModel())) {
WritableRaster raster =
Raster.createWritableRaster(destSM,
new Point(inputRaster.getMinX(),
inputRaster.getMinY()));
raster.setRect(inputRaster);
inputRaster = raster;
}
// Check whether the image is white-is-zero.
boolean isWhiteZero = false;
if(!writeRaster && input.getColorModel() instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel)input.getColorModel();
isWhiteZero = icm.getRed(0) > icm.getRed(1);
}
// Get the line stride, bytes per row, and data array.
int lineStride =
((MultiPixelPackedSampleModel)destSM).getScanlineStride();
int bytesPerRow = (w + 7)/8;
byte[] bdata = ((DataBufferByte)inputRaster.getDataBuffer()).getData();
// Write WBMP header.
stream.write(0); // TypeField
stream.write(0); // FixHeaderField
stream.write(intToMultiByte(w)); // width
stream.write(intToMultiByte(h)); // height
// Write the data.
if(!isWhiteZero && lineStride == bytesPerRow) {
// Write the entire image.
stream.write(bdata, 0, h * bytesPerRow);
processImageProgress(100.0F);
} else {
// Write the image row-by-row.
int offset = 0;
if(!isWhiteZero) {
// Black-is-zero
for(int row = 0; row < h; row++) {
if (abortRequested())
break;
stream.write(bdata, offset, bytesPerRow);
offset += lineStride;
processImageProgress(100.0F * row / h);
}
} else {
// White-is-zero: need to invert data.
byte[] inverted = new byte[bytesPerRow];
for(int row = 0; row < h; row++) {
if (abortRequested())
break;
for(int col = 0; col < bytesPerRow; col++) {
inverted[col] = (byte)(~(bdata[col+offset]));
}
stream.write(inverted, 0, bytesPerRow);
offset += lineStride;
processImageProgress(100.0F * row / h);
}
}
}
if (abortRequested())
processWriteAborted();
else {
processImageComplete();
stream.flushBefore(stream.getStreamPosition());
}
}
public void reset() {
super.reset();
stream = null;
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2003, 2010, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.wbmp;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.spi.ServiceRegistry;
import javax.imageio.spi.IIORegistry;
import javax.imageio.stream.ImageOutputStream;
import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.IIOException;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.image.MultiPixelPackedSampleModel;
import java.awt.image.SampleModel;
import java.util.Locale;
public class WBMPImageWriterSpi extends ImageWriterSpi {
private static String [] readerSpiNames =
{"com.sun.imageio.plugins.wbmp.WBMPImageReaderSpi"};
private static String[] formatNames = {"wbmp", "WBMP"};
private static String[] entensions = {"wbmp"};
private static String[] mimeType = {"image/vnd.wap.wbmp"};
private boolean registered = false;
public WBMPImageWriterSpi() {
super("Oracle Corporation",
"1.0",
formatNames,
entensions,
mimeType,
"com.sun.imageio.plugins.wbmp.WBMPImageWriter",
new Class[] { ImageOutputStream.class },
readerSpiNames,
true,
null, null, null, null,
true,
null, null, null, null);
}
public String getDescription(Locale locale) {
return "Standard WBMP Image Writer";
}
public void onRegistration(ServiceRegistry registry,
Class<?> category) {
if (registered) {
return;
}
registered = true;
}
public boolean canEncodeImage(ImageTypeSpecifier type) {
SampleModel sm = type.getSampleModel();
if (!(sm instanceof MultiPixelPackedSampleModel))
return false;
if (sm.getSampleSize(0) != 1)
return false;
return true;
}
public ImageWriter createWriterInstance(Object extension)
throws IIOException {
return new WBMPImageWriter(this);
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2003, 2004, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.wbmp;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import org.w3c.dom.Node;
import com.sun.imageio.plugins.common.I18N;
import com.sun.imageio.plugins.common.ImageUtil;
public class WBMPMetadata extends IIOMetadata {
static final String nativeMetadataFormatName =
"javax_imageio_wbmp_1.0";
public int wbmpType;
public int width;
public int height;
public WBMPMetadata() {
super(true,
nativeMetadataFormatName,
"com.sun.imageio.plugins.wbmp.WBMPMetadataFormat",
null, null);
}
public boolean isReadOnly() {
return true;
}
public Node getAsTree(String formatName) {
if (formatName.equals(nativeMetadataFormatName)) {
return getNativeTree();
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
return getStandardTree();
} else {
throw new IllegalArgumentException(I18N.getString("WBMPMetadata0"));
}
}
private Node getNativeTree() {
IIOMetadataNode root =
new IIOMetadataNode(nativeMetadataFormatName);
addChildNode(root, "WBMPType", new Integer(wbmpType));
addChildNode(root, "Width", new Integer(width));
addChildNode(root, "Height", new Integer(height));
return root;
}
public void setFromTree(String formatName, Node root) {
throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
}
public void mergeTree(String formatName, Node root) {
throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
}
public void reset() {
throw new IllegalStateException(I18N.getString("WBMPMetadata1"));
}
private IIOMetadataNode addChildNode(IIOMetadataNode root,
String name,
Object object) {
IIOMetadataNode child = new IIOMetadataNode(name);
if (object != null) {
child.setUserObject(object);
child.setNodeValue(ImageUtil.convertObjectToString(object));
}
root.appendChild(child);
return child;
}
protected IIOMetadataNode getStandardChromaNode() {
IIOMetadataNode node = new IIOMetadataNode("Chroma");
IIOMetadataNode subNode = new IIOMetadataNode("BlackIsZero");
subNode.setAttribute("value", "TRUE");
node.appendChild(subNode);
return node;
}
protected IIOMetadataNode getStandardDimensionNode() {
IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
IIOMetadataNode node = null; // scratch node
// PixelAspectRatio not in image
node = new IIOMetadataNode("ImageOrientation");
node.setAttribute("value", "Normal");
dimension_node.appendChild(node);
return dimension_node;
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2003, 2004, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.imageio.plugins.wbmp;
import java.util.Arrays;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
public class WBMPMetadataFormat extends IIOMetadataFormatImpl {
private static IIOMetadataFormat instance = null;
private WBMPMetadataFormat() {
super(WBMPMetadata.nativeMetadataFormatName,
CHILD_POLICY_SOME);
// root -> ImageDescriptor
addElement("ImageDescriptor",
WBMPMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("ImageDescriptor", "WBMPType",
DATATYPE_INTEGER, true, "0");
addAttribute("ImageDescriptor", "Width",
DATATYPE_INTEGER, true, null,
"0", "65535", true, true);
addAttribute("ImageDescriptor", "Height",
DATATYPE_INTEGER, true, null,
"1", "65535", true, true);
}
public boolean canNodeAppear(String elementName,
ImageTypeSpecifier imageType) {
return true;
}
public static synchronized IIOMetadataFormat getInstance() {
if (instance == null) {
instance = new WBMPMetadataFormat();
}
return instance;
}
}