< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java

Print this page




  56               JPEG.nativeStreamMetadataFormatName,
  57               JPEG.nativeStreamMetadataFormatClassName,
  58               null, null,
  59               true,
  60               JPEG.nativeImageMetadataFormatName,
  61               JPEG.nativeImageMetadataFormatClassName,
  62               null, null
  63               );
  64     }
  65 
  66     public String getDescription(Locale locale) {
  67         return "Standard JPEG Image Writer";
  68     }
  69 
  70     public boolean isFormatLossless() {
  71         return false;
  72     }
  73 
  74     public boolean canEncodeImage(ImageTypeSpecifier type) {
  75         SampleModel sampleModel = type.getSampleModel();

  76 



  77         // Find the maximum bit depth across all channels
  78         int[] sampleSize = sampleModel.getSampleSize();
  79         int bitDepth = sampleSize[0];
  80         for (int i = 1; i < sampleSize.length; i++) {
  81             if (sampleSize[i] > bitDepth) {
  82                 bitDepth = sampleSize[i];
  83             }
  84         }
  85 
  86         // 4450894: Ensure bitDepth is between 1 and 8
  87         if (bitDepth < 1 || bitDepth > 8) {
  88             return false;
  89         }
  90 
  91         return true;
  92     }
  93 
  94     public ImageWriter createWriterInstance(Object extension)
  95         throws IIOException {
  96         return new JPEGImageWriter(this);


  56               JPEG.nativeStreamMetadataFormatName,
  57               JPEG.nativeStreamMetadataFormatClassName,
  58               null, null,
  59               true,
  60               JPEG.nativeImageMetadataFormatName,
  61               JPEG.nativeImageMetadataFormatClassName,
  62               null, null
  63               );
  64     }
  65 
  66     public String getDescription(Locale locale) {
  67         return "Standard JPEG Image Writer";
  68     }
  69 
  70     public boolean isFormatLossless() {
  71         return false;
  72     }
  73 
  74     public boolean canEncodeImage(ImageTypeSpecifier type) {
  75         SampleModel sampleModel = type.getSampleModel();
  76         ColorModel cm = type.getColorModel();
  77 
  78         if (cm.hasAlpha()) {
  79             return false;
  80         }
  81         // Find the maximum bit depth across all channels
  82         int[] sampleSize = sampleModel.getSampleSize();
  83         int bitDepth = sampleSize[0];
  84         for (int i = 1; i < sampleSize.length; i++) {
  85             if (sampleSize[i] > bitDepth) {
  86                 bitDepth = sampleSize[i];
  87             }
  88         }
  89 
  90         // 4450894: Ensure bitDepth is between 1 and 8
  91         if (bitDepth < 1 || bitDepth > 8) {
  92             return false;
  93         }
  94 
  95         return true;
  96     }
  97 
  98     public ImageWriter createWriterInstance(Object extension)
  99         throws IIOException {
 100         return new JPEGImageWriter(this);
< prev index next >