Changeset 415
- Timestamp:
- Feb 4, 2013, 10:37:29 PM (13 years ago)
- Location:
- trunk/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java
r247 r415 1 /* JPEGCodec.java -- 1 /* JPEGCodec.java -- 2 2 Copyright (C) 2007 Free Software Foundation, Inc. 3 3 Copyright (C) 2007 Matthew Flaschen … … 39 39 package com.sun.image.codec.jpeg; 40 40 41 import java.lang.RuntimeException; 42 import java.lang.UnsupportedOperationException; 43 41 44 import java.io.InputStream; 42 45 import java.io.OutputStream; 43 46 import java.io.IOException; 44 47 48 import java.awt.Graphics2D; 45 49 import java.awt.image.BufferedImage; 46 50 import java.awt.image.Raster; 51 import java.awt.image.ColorModel; 47 52 48 53 import javax.imageio.*; … … 62 67 public static JPEGImageEncoder createJPEGEncoder(OutputStream os) 63 68 { 64 return n ull;69 return new ImageIOJPEGImageEncoder(os); 65 70 } 66 71 67 72 public static JPEGImageDecoder createJPEGDecoder(InputStream src, JPEGDecodeParam jdp) 68 73 { 69 return null; 70 } 71 74 return new ImageIOJPEGImageDecoder(src); 75 } 76 72 77 public static JPEGImageEncoder createJPEGEncoder(OutputStream dest, JPEGEncodeParam jep) 73 78 { 74 return null;75 } 76 79 return new ImageIOJPEGImageEncoder(dest); 80 } 81 77 82 public static JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) 78 79 return null;80 81 83 { 84 throw new UnsupportedOperationException("FIX ME!"); 85 } 86 82 87 public static JPEGEncodeParam getDefaultJPEGEncodeParam(int numBands, int colorID) 83 84 return null;85 86 88 { 89 throw new UnsupportedOperationException("FIX ME!"); 90 } 91 87 92 public static JPEGEncodeParam getDefaultJPEGEncodeParam(JPEGDecodeParam jdp) 88 89 return null;90 91 93 { 94 throw new UnsupportedOperationException("FIX ME!"); 95 } 96 92 97 public static JPEGEncodeParam getDefaultJPEGEncodeParam(Raster ras, int colorID) 93 94 return null;95 96 98 { 99 throw new UnsupportedOperationException("FIX ME!"); 100 } 101 97 102 98 103 private static class ImageIOJPEGImageDecoder implements JPEGImageDecoder 99 104 { 100 105 101 106 private static final String JPGMime = "image/jpeg"; 102 107 103 108 private ImageReader JPGReader; 104 109 105 110 private InputStream in; 106 111 107 112 private ImageIOJPEGImageDecoder (InputStream newIs) 108 113 { 109 114 in = newIs; 110 115 111 116 Iterator<ImageReader> JPGReaderIter = ImageIO.getImageReadersByMIMEType(JPGMime); 112 117 if(JPGReaderIter.hasNext()) … … 114 119 JPGReader = JPGReaderIter.next(); 115 120 } 116 121 117 122 JPGReader.setInput(new MemoryCacheImageInputStream(in)); 118 123 } … … 122 127 return JPGReader.read(0); 123 128 } 124 129 125 130 public Raster decodeAsRaster() throws IOException, ImageFormatException 126 131 { 127 132 return JPGReader.readRaster(0, null); 128 133 } 129 134 130 135 public InputStream getInputStream() 131 136 { 132 137 return in; 133 138 } 134 139 135 140 public JPEGDecodeParam getJPEGDecodeParam() 136 137 return null;138 141 { 142 throw new UnsupportedOperationException("FIX ME!"); 143 } 139 144 140 145 public void setJPEGDecodeParam(JPEGDecodeParam jdp) 141 { 142 return; 143 } 144 145 } 146 { 147 throw new UnsupportedOperationException("FIX ME!"); 148 } 149 150 } 151 152 private static class ImageIOJPEGEncodeParam implements JPEGEncodeParam 153 { 154 private ImageWriter writer; 155 private ImageWriteParam p; 156 private int width; 157 private int height; 158 159 private ImageIOJPEGEncodeParam (ImageWriter _writer, int _width, int _height) 160 { 161 writer = _writer; 162 p = _writer.getDefaultWriteParam(); 163 width = _width; 164 height = _height; 165 } 166 167 private ImageWriteParam getImageWriteParam() 168 { 169 return p; 170 } 171 172 public void setQuality(float i, boolean b) 173 { 174 p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); 175 p.setCompressionQuality(i); 176 } 177 178 public JPEGEncodeParam clone() 179 { 180 return new ImageIOJPEGEncodeParam(writer, width, height); 181 } 182 183 public void setTableInfoValid(boolean b) 184 { 185 throw new UnsupportedOperationException("FIX ME!"); 186 } 187 188 public void setImageInfoValid(boolean b) 189 { 190 throw new UnsupportedOperationException("FIX ME!"); 191 } 192 193 public int getHorizontalSubsampling(int i) 194 { 195 throw new UnsupportedOperationException("FIX ME!"); 196 } 197 198 public int getVerticalSubsampling(int i) 199 { 200 throw new UnsupportedOperationException("FIX ME!"); 201 } 202 203 public int getWidth() 204 { 205 return width; 206 } 207 208 public int getHeight() 209 { 210 return height; 211 } 212 213 public int getDensityUnit() 214 { 215 throw new UnsupportedOperationException("FIX ME!"); 216 } 217 218 public int getXDensity() 219 { 220 throw new UnsupportedOperationException("FIX ME!"); 221 } 222 223 public int getYDensity() 224 { 225 throw new UnsupportedOperationException("FIX ME!"); 226 } 227 228 public int getRestartInterval() 229 { 230 throw new UnsupportedOperationException("FIX ME!"); 231 } 232 233 public JPEGQTable getQTable(int i) 234 { 235 throw new UnsupportedOperationException("FIX ME!"); 236 } 237 238 public void setDensityUnit(int i) 239 { 240 throw new UnsupportedOperationException("FIX ME!"); 241 } 242 243 public void setXDensity(int i) 244 { 245 throw new UnsupportedOperationException("FIX ME!"); 246 } 247 248 public void setYDensity(int i) 249 { 250 throw new UnsupportedOperationException("FIX ME!"); 251 } 252 253 public void setRestartInterval(int i) 254 { 255 throw new UnsupportedOperationException("FIX ME!"); 256 } 257 258 public void setQTable(int i, JPEGQTable jqt) 259 { 260 throw new UnsupportedOperationException("FIX ME!"); 261 } 262 } 263 264 private static class ImageIOJPEGImageEncoder implements JPEGImageEncoder 265 { 266 267 private static final String JPGMime = "image/jpeg"; 268 269 private ImageWriter JPGWriter; 270 private OutputStream out; 271 private ImageIOJPEGEncodeParam param; 272 273 private ImageIOJPEGImageEncoder (OutputStream newOs) 274 { 275 out = newOs; 276 param = null; 277 278 Iterator<ImageWriter> JPGWriterIter = ImageIO.getImageWritersByMIMEType(JPGMime); 279 if(JPGWriterIter.hasNext()) 280 { 281 JPGWriter = JPGWriterIter.next(); 282 } 283 284 JPGWriter.setOutput(new MemoryCacheImageOutputStream(out)); 285 } 286 287 private BufferedImage checkImage(BufferedImage bi) 288 { 289 boolean needsConversion = false; 290 291 int[] bandSizes = bi.getSampleModel().getSampleSize(); 292 for (int i = 0; i < bandSizes.length; i++) 293 { 294 if (bandSizes[i] > 8) 295 { 296 needsConversion = true; 297 break; 298 } 299 } 300 301 if (needsConversion) 302 { 303 BufferedImage newBi = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB); 304 Graphics2D g = newBi.createGraphics(); 305 g.drawImage(bi, 0, 0, null); 306 bi = newBi; 307 } 308 309 return bi; 310 } 311 312 public JPEGEncodeParam getJPEGEncodeParam() 313 { 314 return param; 315 } 316 317 public void setJPEGEncodeParam(JPEGEncodeParam jep) 318 { 319 if (!(jep instanceof ImageIOJPEGEncodeParam)) 320 throw new RuntimeException("Must specify object returned by getDefaultJPEGEncodeParam()"); 321 param = (ImageIOJPEGEncodeParam)jep; 322 } 323 324 public JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) 325 { 326 return new ImageIOJPEGEncodeParam(JPGWriter, bi.getWidth(), bi.getHeight()); 327 } 328 329 public JPEGEncodeParam getDefaultJPEGEncodeParam(Raster ras, int colorID) throws ImageFormatException 330 { 331 return new ImageIOJPEGEncodeParam(JPGWriter, ras.getWidth(), ras.getHeight()); 332 } 333 334 public JPEGEncodeParam getDefaultJPEGEncodeParam(int numBands, int colorID) throws ImageFormatException 335 { 336 throw new UnsupportedOperationException("FIX ME!"); 337 } 338 339 public JPEGEncodeParam getDefaultJPEGEncodeParam(JPEGDecodeParam jdp) throws ImageFormatException 340 { 341 throw new UnsupportedOperationException("FIX ME!"); 342 } 343 344 public int getDefaultColorId(ColorModel cm) 345 { 346 throw new UnsupportedOperationException("FIX ME!"); 347 } 348 349 public OutputStream getOutputStream() 350 { 351 return out; 352 } 353 354 public void encode(BufferedImage bi, JPEGEncodeParam p) throws IOException, ImageFormatException 355 { 356 if (!(p instanceof ImageIOJPEGEncodeParam)) 357 throw new RuntimeException("Must specify object returned by getDefaultJPEGEncodeParam()"); 358 bi = checkImage(bi); 359 JPGWriter.write(null, new IIOImage(bi, null, null), ((ImageIOJPEGEncodeParam)p).getImageWriteParam()); 360 } 361 362 public void encode(Raster ras) throws IOException, ImageFormatException 363 { 364 JPGWriter.write(null, new IIOImage(ras, null, null), param.getImageWriteParam()); 365 } 366 367 public void encode(BufferedImage bi) throws IOException, ImageFormatException 368 { 369 bi = checkImage(bi); 370 JPGWriter.write(null, new IIOImage(bi, null, null), param.getImageWriteParam()); 371 } 372 373 public void encode(Raster ras, JPEGEncodeParam p) throws IOException, ImageFormatException 374 { 375 if (!(p instanceof ImageIOJPEGEncodeParam)) 376 throw new RuntimeException("Must specify object returned by getDefaultJPEGEncodeParam()"); 377 JPGWriter.write(null, new IIOImage(ras, null, null), ((ImageIOJPEGEncodeParam)p).getImageWriteParam()); 378 } 379 } 146 380 } -
trunk/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGEncodeParam.java
r247 r415 1 /* JPEGEncodeParam.java -- 1 /* JPEGEncodeParam.java -- 2 2 Copyright (C) 2007 Free Software Foundation, Inc. 3 3 … … 38 38 package com.sun.image.codec.jpeg; 39 39 40 public classJPEGEncodeParam40 public interface JPEGEncodeParam 41 41 { 42 42 public static final int COLOR_ID_UNKNOWN = 0; … … 48 48 public static final int COLOR_ID_YCbCr = 6; 49 49 50 public JPEGEncodeParam() 51 { 52 } 50 public void setQuality(float i, boolean b); 53 51 54 public void setQuality(float i, boolean b) 55 { 56 } 52 public JPEGEncodeParam clone(); 57 53 58 public void setQuality(int i, boolean b) 59 { 60 } 54 public void setTableInfoValid(boolean b); 61 55 62 public JPEGEncodeParam clone() 63 { 64 return null; 65 } 56 public void setImageInfoValid(boolean b); 66 57 67 public void setTableInfoValid(boolean b) 68 { 69 } 58 public int getHorizontalSubsampling(int i); 70 59 71 public void setImageInfoValid(boolean b) 72 { 73 } 60 public int getVerticalSubsampling(int i); 74 61 75 public int getHorizontalSubsampling(int i) 76 { 77 return 0; 78 } 62 public int getWidth(); 79 63 80 public int getVerticalSubsampling(int i) 81 { 82 return 0; 83 } 64 public int getHeight(); 84 65 85 public int getWidth() 86 { 87 return 0; 88 } 66 public int getDensityUnit(); 89 67 90 public int getHeight() 91 { 92 return 0; 93 } 68 public int getXDensity(); 94 69 95 public int getDensityUnit() 96 { 97 return 0; 98 } 70 public int getYDensity(); 99 71 100 public int getXDensity() 101 { 102 return 0; 103 } 72 public int getRestartInterval(); 104 73 105 public int getYDensity() 106 { 107 return 0; 108 } 74 public JPEGQTable getQTable(int i); 109 75 110 public int getRestartInterval() 111 { 112 return 0; 113 } 76 public void setDensityUnit(int i); 114 77 115 public JPEGQTable getQTable(int i) 116 { 117 return new JPEGQTable(); 118 } 78 public void setXDensity(int i); 119 79 120 public void setDensityUnit(int i) 121 { 122 } 80 public void setYDensity(int i); 123 81 124 public void setXDensity(int i) 125 { 126 } 82 public void setRestartInterval(int i); 127 83 128 public void setYDensity(int i) 129 { 130 } 131 132 public void setRestartInterval(int i) 133 { 134 } 135 136 public void setQTable(int i, JPEGQTable jqt) 137 { 138 } 84 public void setQTable(int i, JPEGQTable jqt); 139 85 } -
trunk/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageEncoder.java
r247 r415 1 /* JPEGImageEncoder.java -- 1 /* JPEGImageEncoder.java -- 2 2 Copyright (C) 2007 Free Software Foundation, Inc. 3 3 … … 41 41 import java.awt.image.BufferedImage; 42 42 import java.awt.image.Raster; 43 import java.awt.image.ColorModel; 44 import java.io.OutputStream; 45 import java.io.IOException; 43 46 44 public classJPEGImageEncoder47 public interface JPEGImageEncoder 45 48 { 46 public JPEGImageEncoder() 47 { 48 } 49 50 public JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) 51 { 52 return null; 53 } 49 public JPEGEncodeParam getJPEGEncodeParam(); 54 50 55 public void encode(BufferedImage bi, JPEGEncodeParam p) 56 { 57 } 51 public void setJPEGEncodeParam(JPEGEncodeParam jep); 58 52 59 public void encode(Raster bi) 60 { 61 } 53 public JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) throws ImageFormatException; 62 54 63 public void encode(BufferedImage bi) 64 { 65 } 55 public JPEGEncodeParam getDefaultJPEGEncodeParam(Raster ras, int colorID) throws ImageFormatException; 66 56 57 public JPEGEncodeParam getDefaultJPEGEncodeParam(int numBands, int colorID) throws ImageFormatException; 58 59 public JPEGEncodeParam getDefaultJPEGEncodeParam(JPEGDecodeParam jdp) throws ImageFormatException; 60 61 public int getDefaultColorId(ColorModel cm); 62 63 public OutputStream getOutputStream(); 64 65 public void encode(BufferedImage bi, JPEGEncodeParam p) throws IOException, ImageFormatException; 66 67 public void encode(Raster ras) throws IOException, ImageFormatException; 68 69 public void encode(BufferedImage bi) throws IOException, ImageFormatException; 70 71 public void encode(Raster ras, JPEGEncodeParam p) throws IOException, ImageFormatException; 67 72 }
Note:
See TracChangeset
for help on using the changeset viewer.