< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/wbmp/WBMPImageWriter.java

Print this page




  80         byte[] multiBytes = new byte[(numBitsLeft + 6)/7];
  81 
  82         int maxIndex = multiBytes.length - 1;
  83         for(int b = 0; b <= maxIndex; b++) {
  84             multiBytes[b] = (byte)((intValue >>> ((maxIndex - b)*7))&0x7f);
  85             if(b != maxIndex) {
  86                 multiBytes[b] |= (byte)0x80;
  87             }
  88         }
  89 
  90         return multiBytes;
  91     }
  92 
  93     /** Constructs {@code WBMPImageWriter} based on the provided
  94      *  {@code ImageWriterSpi}.
  95      */
  96     public WBMPImageWriter(ImageWriterSpi originator) {
  97         super(originator);
  98     }
  99 

 100     public void setOutput(Object output) {
 101         super.setOutput(output); // validates output
 102         if (output != null) {
 103             if (!(output instanceof ImageOutputStream))
 104                 throw new IllegalArgumentException(I18N.getString("WBMPImageWriter"));
 105             this.stream = (ImageOutputStream)output;
 106         } else
 107             this.stream = null;
 108     }
 109 

 110     public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
 111         return null;
 112     }
 113 

 114     public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
 115                                                ImageWriteParam param) {
 116         WBMPMetadata meta = new WBMPMetadata();
 117         meta.wbmpType = 0; // default wbmp level
 118         return meta;
 119     }
 120 

 121     public IIOMetadata convertStreamMetadata(IIOMetadata inData,
 122                                              ImageWriteParam param) {
 123         return null;
 124     }
 125 

 126     public IIOMetadata convertImageMetadata(IIOMetadata metadata,
 127                                             ImageTypeSpecifier type,
 128                                             ImageWriteParam param) {
 129         return null;
 130     }
 131 
 132     public boolean canWriteRasters() {
 133         return true;
 134     }
 135 

 136     public void write(IIOMetadata streamMetadata,
 137                       IIOImage image,
 138                       ImageWriteParam param) throws IOException {
 139 
 140         if (stream == null) {
 141             throw new IllegalStateException(I18N.getString("WBMPImageWriter3"));
 142         }
 143 
 144         if (image == null) {
 145             throw new IllegalArgumentException(I18N.getString("WBMPImageWriter4"));
 146         }
 147 
 148         clearAbortRequest();
 149         processImageStarted(0);
 150         if (param == null)
 151             param = getDefaultWriteParam();
 152 
 153         RenderedImage input = null;
 154         Raster inputRaster = null;
 155         boolean writeRaster = image.hasRaster();


 282                     if (abortRequested())
 283                         break;
 284                     for(int col = 0; col < bytesPerRow; col++) {
 285                         inverted[col] = (byte)(~(bdata[col+offset]));
 286                     }
 287                     stream.write(inverted, 0, bytesPerRow);
 288                     offset += lineStride;
 289                     processImageProgress(100.0F * row / h);
 290                 }
 291             }
 292         }
 293 
 294         if (abortRequested())
 295             processWriteAborted();
 296         else {
 297             processImageComplete();
 298             stream.flushBefore(stream.getStreamPosition());
 299         }
 300     }
 301 

 302     public void reset() {
 303         super.reset();
 304         stream = null;
 305     }
 306 
 307     private void checkSampleModel(SampleModel sm) {
 308         int type = sm.getDataType();
 309         if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
 310             || sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
 311             throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
 312     }
 313 }


  80         byte[] multiBytes = new byte[(numBitsLeft + 6)/7];
  81 
  82         int maxIndex = multiBytes.length - 1;
  83         for(int b = 0; b <= maxIndex; b++) {
  84             multiBytes[b] = (byte)((intValue >>> ((maxIndex - b)*7))&0x7f);
  85             if(b != maxIndex) {
  86                 multiBytes[b] |= (byte)0x80;
  87             }
  88         }
  89 
  90         return multiBytes;
  91     }
  92 
  93     /** Constructs {@code WBMPImageWriter} based on the provided
  94      *  {@code ImageWriterSpi}.
  95      */
  96     public WBMPImageWriter(ImageWriterSpi originator) {
  97         super(originator);
  98     }
  99 
 100     @Override
 101     public void setOutput(Object output) {
 102         super.setOutput(output); // validates output
 103         if (output != null) {
 104             if (!(output instanceof ImageOutputStream))
 105                 throw new IllegalArgumentException(I18N.getString("WBMPImageWriter"));
 106             this.stream = (ImageOutputStream)output;
 107         } else
 108             this.stream = null;
 109     }
 110 
 111     @Override
 112     public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
 113         return null;
 114     }
 115 
 116     @Override
 117     public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
 118                                                ImageWriteParam param) {
 119         WBMPMetadata meta = new WBMPMetadata();
 120         meta.wbmpType = 0; // default wbmp level
 121         return meta;
 122     }
 123 
 124     @Override
 125     public IIOMetadata convertStreamMetadata(IIOMetadata inData,
 126                                              ImageWriteParam param) {
 127         return null;
 128     }
 129 
 130     @Override
 131     public IIOMetadata convertImageMetadata(IIOMetadata metadata,
 132                                             ImageTypeSpecifier type,
 133                                             ImageWriteParam param) {
 134         return null;
 135     }
 136 
 137     public boolean canWriteRasters() {
 138         return true;
 139     }
 140 
 141     @Override
 142     public void write(IIOMetadata streamMetadata,
 143                       IIOImage image,
 144                       ImageWriteParam param) throws IOException {
 145 
 146         if (stream == null) {
 147             throw new IllegalStateException(I18N.getString("WBMPImageWriter3"));
 148         }
 149 
 150         if (image == null) {
 151             throw new IllegalArgumentException(I18N.getString("WBMPImageWriter4"));
 152         }
 153 
 154         clearAbortRequest();
 155         processImageStarted(0);
 156         if (param == null)
 157             param = getDefaultWriteParam();
 158 
 159         RenderedImage input = null;
 160         Raster inputRaster = null;
 161         boolean writeRaster = image.hasRaster();


 288                     if (abortRequested())
 289                         break;
 290                     for(int col = 0; col < bytesPerRow; col++) {
 291                         inverted[col] = (byte)(~(bdata[col+offset]));
 292                     }
 293                     stream.write(inverted, 0, bytesPerRow);
 294                     offset += lineStride;
 295                     processImageProgress(100.0F * row / h);
 296                 }
 297             }
 298         }
 299 
 300         if (abortRequested())
 301             processWriteAborted();
 302         else {
 303             processImageComplete();
 304             stream.flushBefore(stream.getStreamPosition());
 305         }
 306     }
 307 
 308     @Override
 309     public void reset() {
 310         super.reset();
 311         stream = null;
 312     }
 313 
 314     private void checkSampleModel(SampleModel sm) {
 315         int type = sm.getDataType();
 316         if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
 317             || sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
 318             throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
 319     }
 320 }
< prev index next >