Lines 20-25
Link Here
|
20 |
package org.apache.xmlgraphics.image.loader.impl; |
20 |
package org.apache.xmlgraphics.image.loader.impl; |
21 |
|
21 |
|
22 |
import java.awt.color.ColorSpace; |
22 |
import java.awt.color.ColorSpace; |
|
|
23 |
import java.awt.color.ICC_ColorSpace; |
23 |
import java.awt.color.ICC_Profile; |
24 |
import java.awt.color.ICC_Profile; |
24 |
import java.awt.image.ColorModel; |
25 |
import java.awt.image.ColorModel; |
25 |
import java.awt.image.ComponentColorModel; |
26 |
import java.awt.image.ComponentColorModel; |
Lines 34-39
Link Here
|
34 |
import java.util.ArrayList; |
35 |
import java.util.ArrayList; |
35 |
import java.util.Collections; |
36 |
import java.util.Collections; |
36 |
import java.util.List; |
37 |
import java.util.List; |
|
|
38 |
import java.util.zip.Inflater; |
39 |
import java.util.zip.InflaterInputStream; |
37 |
|
40 |
|
38 |
import org.apache.xmlgraphics.image.codec.png.PNGChunk; |
41 |
import org.apache.xmlgraphics.image.codec.png.PNGChunk; |
39 |
import org.apache.xmlgraphics.image.codec.util.PropertyUtil; |
42 |
import org.apache.xmlgraphics.image.codec.util.PropertyUtil; |
Lines 49-54
Link Here
|
49 |
|
52 |
|
50 |
private ColorModel colorModel; |
53 |
private ColorModel colorModel; |
51 |
private ICC_Profile iccProfile; |
54 |
private ICC_Profile iccProfile; |
|
|
55 |
private int sRGBRenderingIntent = -1; |
52 |
private int bitDepth; |
56 |
private int bitDepth; |
53 |
private int colorType; |
57 |
private int colorType; |
54 |
private boolean isTransparent; |
58 |
private boolean isTransparent; |
Lines 96-101
Link Here
|
96 |
} else if (chunkType.equals(PNGChunk.ChunkType.tRNS.name())) { |
100 |
} else if (chunkType.equals(PNGChunk.ChunkType.tRNS.name())) { |
97 |
chunk = PNGChunk.readChunk(distream); |
101 |
chunk = PNGChunk.readChunk(distream); |
98 |
parse_tRNS_chunk(chunk); |
102 |
parse_tRNS_chunk(chunk); |
|
|
103 |
} else if (chunkType.equals(PNGChunk.ChunkType.iCCP.name())) { |
104 |
chunk = PNGChunk.readChunk(distream); |
105 |
parse_iCCP_chunk(chunk); |
106 |
} else if (chunkType.equals(PNGChunk.ChunkType.sRGB.name())) { |
107 |
chunk = PNGChunk.readChunk(distream); |
108 |
parse_sRGB_chunk(chunk); |
99 |
} else { |
109 |
} else { |
100 |
// chunk = PNGChunk.readChunk(distream); |
110 |
// chunk = PNGChunk.readChunk(distream); |
101 |
PNGChunk.skipChunk(distream); |
111 |
PNGChunk.skipChunk(distream); |
Lines 110-115
Link Here
|
110 |
|
120 |
|
111 |
public ImageRawPNG getImageRawPNG(ImageInfo info) throws ImageException { |
121 |
public ImageRawPNG getImageRawPNG(ImageInfo info) throws ImageException { |
112 |
InputStream seqStream = new SequenceInputStream(Collections.enumeration(streamVec)); |
122 |
InputStream seqStream = new SequenceInputStream(Collections.enumeration(streamVec)); |
|
|
123 |
ColorSpace rgbCS = null; |
113 |
switch (colorType) { |
124 |
switch (colorType) { |
114 |
case PNG_COLOR_GRAY: |
125 |
case PNG_COLOR_GRAY: |
115 |
if (hasPalette) { |
126 |
if (hasPalette) { |
Lines 119-127
Link Here
|
119 |
ColorModel.OPAQUE, DataBuffer.TYPE_BYTE); |
130 |
ColorModel.OPAQUE, DataBuffer.TYPE_BYTE); |
120 |
break; |
131 |
break; |
121 |
case PNG_COLOR_RGB: |
132 |
case PNG_COLOR_RGB: |
122 |
// actually a check of the sRGB chunk would be necessary to confirm if it's really sRGB |
133 |
if (iccProfile != null) { |
123 |
colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, |
134 |
rgbCS = new ICC_ColorSpace(iccProfile); |
124 |
ColorModel.OPAQUE, DataBuffer.TYPE_BYTE); |
135 |
} else if (sRGBRenderingIntent != -1) { |
|
|
136 |
rgbCS = ColorSpace.getInstance(ColorSpace.CS_sRGB); |
137 |
} else { |
138 |
rgbCS = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB); |
139 |
} |
140 |
colorModel = new ComponentColorModel(rgbCS, false, false, ColorModel.OPAQUE, DataBuffer.TYPE_BYTE); |
125 |
break; |
141 |
break; |
126 |
case PNG_COLOR_PALETTE: |
142 |
case PNG_COLOR_PALETTE: |
127 |
if (hasAlphaPalette) { |
143 |
if (hasAlphaPalette) { |
Lines 140-148
Link Here
|
140 |
ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE); |
156 |
ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE); |
141 |
break; |
157 |
break; |
142 |
case PNG_COLOR_RGB_ALPHA: |
158 |
case PNG_COLOR_RGB_ALPHA: |
143 |
// actually a check of the sRGB chunk would be necessary to confirm if it's really sRGB |
159 |
if (iccProfile != null) { |
144 |
colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false, |
160 |
rgbCS = new ICC_ColorSpace(iccProfile); |
145 |
ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE); |
161 |
} else if (sRGBRenderingIntent != -1) { |
|
|
162 |
rgbCS = ColorSpace.getInstance(ColorSpace.CS_sRGB); |
163 |
} else { |
164 |
rgbCS = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB); |
165 |
} |
166 |
colorModel = new ComponentColorModel(rgbCS, true, false, ColorModel.TRANSLUCENT, |
167 |
DataBuffer.TYPE_BYTE); |
146 |
break; |
168 |
break; |
147 |
default: |
169 |
default: |
148 |
throw new ImageException("Unsupported color type: " + colorType); |
170 |
throw new ImageException("Unsupported color type: " + colorType); |
Lines 161-166
Link Here
|
161 |
// |
183 |
// |
162 |
} |
184 |
} |
163 |
} |
185 |
} |
|
|
186 |
if (sRGBRenderingIntent != -1) { |
187 |
rawImage.setRenderingIntent(sRGBRenderingIntent); |
188 |
} |
164 |
return rawImage; |
189 |
return rawImage; |
165 |
} |
190 |
} |
166 |
|
191 |
|
Lines 235-238
Link Here
|
235 |
isTransparent = true; |
260 |
isTransparent = true; |
236 |
} |
261 |
} |
237 |
|
262 |
|
|
|
263 |
private void parse_iCCP_chunk(PNGChunk chunk) { |
264 |
int length = chunk.getLength(); |
265 |
String name = ""; // todo simplify this |
266 |
byte b; |
267 |
int textIndex = 0; |
268 |
while ((b = chunk.getByte(textIndex++)) != 0) { |
269 |
name += (char) b; |
270 |
} |
271 |
byte compression = chunk.getByte(textIndex++); |
272 |
byte[] profile = new byte[length - textIndex]; |
273 |
System.arraycopy(chunk.getData(), textIndex, profile, 0, length - textIndex); |
274 |
ByteArrayInputStream bais = new ByteArrayInputStream(profile); |
275 |
InflaterInputStream iis = new InflaterInputStream(bais, new Inflater()); |
276 |
try { |
277 |
iccProfile = ICC_Profile.getInstance(iis); |
278 |
} catch (IOException ioe) { |
279 |
// this is OK; the profile will be null |
280 |
} |
281 |
} |
282 |
|
283 |
private void parse_sRGB_chunk(PNGChunk chunk) { |
284 |
sRGBRenderingIntent = chunk.getByte(0); |
285 |
} |
286 |
|
238 |
} |
287 |
} |