⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagecomponentstate.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        encoder.encode( image );        byteStream.close();                byte[] buffer = byteStream.toByteArray();        out.writeInt( buffer.length );        out.write( buffer );    }        protected BufferedImage readBufferedImage( DataInput in ) throws IOException {        byte compression = in.readByte();                if (compression==NO_COMPRESSION)            return readBufferedImageNoCompression( in );        else if (compression==GZIP_COMPRESSION)            return readBufferedImageGzipCompression( in );        else if (compression==JPEG_COMPRESSION)            return readBufferedImageJpegCompression( in );	throw new SGIORuntimeException("Unknown Image Compression");    }            private BufferedImage readBufferedImageNoCompression( DataInput in ) throws IOException {          int size = in.readInt();        byte[] buffer = new byte[ size ];        in.readFully( buffer );        ByteArrayInputStream byteIn = new ByteArrayInputStream( buffer );        DataInputStream dataIn = new DataInputStream( byteIn );                ColorModel colorModel = readColorModel( dataIn );        WritableRaster raster = readWritableRaster( dataIn );        boolean alphaPreMult = dataIn.readBoolean();        dataIn.close();                return new BufferedImage( colorModel, raster, alphaPreMult, null );    }        private BufferedImage readBufferedImageGzipCompression( DataInput in ) throws IOException {          int size = in.readInt();        byte[] buffer = new byte[ size ];        in.readFully( buffer );        ByteArrayInputStream byteIn = new ByteArrayInputStream( buffer );        GZIPInputStream gzipIn = new GZIPInputStream( byteIn );        DataInputStream dataIn = new DataInputStream( gzipIn );                ColorModel colorModel = readColorModel( dataIn );        WritableRaster raster = readWritableRaster( dataIn );        boolean alphaPremult = dataIn.readBoolean();        dataIn.close();                return new BufferedImage( colorModel, raster, alphaPremult, null );    }        private BufferedImage readBufferedImageJpegCompression( DataInput in ) throws IOException {          int size = in.readInt();        byte[] buffer = new byte[ size ];        in.readFully( buffer );        ByteArrayInputStream byteStream = new ByteArrayInputStream( buffer );                JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( byteStream );        byteStream.close();                return decoder.decodeAsBufferedImage();    }        private void writeColorModel( DataOutput out, ColorModel colorModel ) throws IOException {        if (colorModel instanceof DirectColorModel) {            out.writeInt( DIRECT_COLOR_MODEL );            writeDirectColorModel( out, (DirectColorModel)colorModel );        }         else            throw new SGIORuntimeException("Unsupported ColorModel "+colorModel.getClass().getName() );    }        private ColorModel readColorModel( DataInput in ) throws IOException {        switch( in.readInt() ) {            case DIRECT_COLOR_MODEL:                return readDirectColorModel( in );        }                throw new SGIORuntimeException( "Invalid ColorModel - File corrupt" );    }    private void writeDirectColorModel( DataOutput out,					DirectColorModel colorModel ) throws IOException {        out.writeInt( colorModel.getPixelSize() );        out.writeInt( colorModel.getRedMask() );        out.writeInt( colorModel.getGreenMask() );        out.writeInt( colorModel.getBlueMask() );        out.writeInt( colorModel.getAlphaMask() );    }        private DirectColorModel readDirectColorModel( DataInput in ) throws IOException {        return new DirectColorModel( in.readInt(),                                     in.readInt(),                                     in.readInt(),                                     in.readInt(),                                     in.readInt() );    }        private void writeWritableRaster( DataOutput out, WritableRaster raster ) throws IOException{        writeSampleModel( out, raster.getSampleModel() );        writeDataBuffer( out, raster.getDataBuffer() );        Point origin = new Point();        // TODO Get the origin of the raster - seems to be missing from the raster API        out.writeInt( origin.x );        out.writeInt( origin.y );    }        private WritableRaster readWritableRaster( DataInput in ) throws IOException {        return Raster.createWritableRaster( readSampleModel( in ),                                   readDataBuffer( in ),                                   new Point( in.readInt(), in.readInt() ));    }        private void writeSampleModel( DataOutput out, SampleModel model ) throws IOException {        if (model instanceof SinglePixelPackedSampleModel) {            out.writeInt( SINGLE_PIXEL_PACKED_SAMPLE_MODEL );            writeSinglePixelPackedSampleModel( out, (SinglePixelPackedSampleModel)model );        } else            throw new SGIORuntimeException("Unsupported SampleModel "+model.getClass().getName() );    }        private SampleModel readSampleModel( DataInput in ) throws IOException {        switch( in.readInt() ) {            case SINGLE_PIXEL_PACKED_SAMPLE_MODEL:                return readSinglePixelPackedSampleModel( in );        }                throw new SGIORuntimeException("Invalid SampleModel - file corrupt");    }        private void writeSinglePixelPackedSampleModel( DataOutput out,        SinglePixelPackedSampleModel model ) throws IOException {        int[] masks = model.getBitMasks();        out.writeInt( masks.length );        for(int i=0; i<masks.length; i++)            out.writeInt( masks[i] );                out.writeInt( model.getDataType() );        out.writeInt( model.getWidth() );        out.writeInt( model.getHeight() );        out.writeInt( model.getScanlineStride() );            }        private SinglePixelPackedSampleModel readSinglePixelPackedSampleModel( DataInput in )	throws IOException {        int masks[] = new int[ in.readInt() ];        for(int i=0; i<masks.length; i++)            masks[i] = in.readInt();                return new SinglePixelPackedSampleModel( in.readInt(),                                                 in.readInt(),                                                 in.readInt(),                                                 in.readInt(),                                                 masks );    }        private void writeDataBuffer( DataOutput out, DataBuffer buffer ) throws IOException {        if (buffer instanceof DataBufferInt) {            out.writeInt( DATA_BUFFER_INT );            writeDataBufferInt( out, (DataBufferInt)buffer );        } else            throw new SGIORuntimeException("Unsupported DataBuffer "+buffer.getClass().getName() );    }        private DataBuffer readDataBuffer( DataInput in ) throws IOException {        switch( in.readInt() ) {            case DATA_BUFFER_INT:                return readDataBufferInt( in );        }                throw new SGIORuntimeException("Incorrect DataBuffer - file corrupt");    }        private void writeDataBufferInt( DataOutput out, DataBufferInt buffer ) throws IOException {        int[][] data = buffer.getBankData();        out.writeInt( data.length );        for(int i=0; i<data.length; i++) {            out.writeInt( data[i].length );            for( int j=0; j<data[i].length; j++)                out.writeInt( data[i][j] );        }                out.writeInt( buffer.getSize() );                // TODO Handle DataBufferInt offsets                }        private DataBufferInt readDataBufferInt( DataInput in ) throws IOException {        int[][] data = new int[in.readInt()][];        for(int i=0; i<data.length; i++) {            data[i] = new int[ in.readInt() ];            for( int j=0; j<data[i].length; j++)                data[i][j] = in.readInt();        }                        return new DataBufferInt( data, in.readInt() );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -