"Universal" image reading
So I've written a limited Java EPS creator for image files using
BufferedImage and Image I/O, but it's not perfect.
I need to determine if it's RGB, CMYK, or grayscale (including 1-bit
B&W), get the bits per component, collect the samples in per-pixel
sequence in a certain order (RGB not BGR), and write my EPS. Oh, and
if there's an alpha channel, I need to get those values and handle
BufferedImage#getColorModel#getColorSpace#getType works for CMYK, but
for 1-bit B&W, it reports 8-bit RGB. BufferedImage#getType works for
1-bit B&W (BufferedImage.TYPE_BYTE_BINARY), but not for CMYK
So already, I'm forced to use a different strategy for different kinds
of images. Do I have the right idea?
Accessing sample information with a ColorModel is easy.
final Object reusableDataArray = raster.getDataElements(x, y, null)
final int reusableSampleArray =
colorModel.getComponents(sampleArray, null, 0);
final int bitsPerComponent = colorModel.getComponentSize(0);
Accessing sample information from a Raster/SampleModel
(TYPE_BYTE_BINARY) isn't quite so easy.
BufferedImage#getType provides enough information to interpret the
output of Raster#getPixel, but that means I have to write new logic
for each #getType.
So right now, through trial and error I'm typing up a list of
BufferedImage.TYPE_*s that work well with ColorModel, and handling
them consistently. For each types that don't work well with
ColorModel, I'm writing special logic to interpret Raster#getPixel.
Am I on the right track, or am I just making this hard for myself?
To unsubscribe, send email to email@example.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
firstname.lastname@example.org and include in the body of the message "help".