DiegoCatalano / Catalano-Framework

Framework
GNU Lesser General Public License v3.0
295 stars 99 forks source link

How does fastbitmap.setGray affects this.bufferedImage #68

Open xyloww opened 2 years ago

xyloww commented 2 years ago

Hello Sir, In Catalano.Imaging.Filters, most methods alter pixelsGray[xstrideX+ystrideY] = (byte) value using FastBitmap.setGray method. How does pixelsGRAY affects this.bufferedImage in FastBitmap.toIcon/FastBitmap.saveAsJPG?

Also, I am having difficulties displaying images with DataBufferUShort after altering their FBM.pixelsGray[], may I ask if you have any advice to display/save the altered images?

Currently, Ive tried altering FastBitmap.java as follow private void refresh() { this.raster = getRaster();

    if (isGrayscale()){
        if (raster.getDataBuffer() instanceof DataBufferByte){
            pixelsGRAY = ((DataBufferByte) raster.getDataBuffer().getDat
            a();
            }
     else if (raster.getDataBuffer() instanceof DataBufferUShort){
            pixelData = ((DataBufferUShort) raster.getDataBuffer().getDat
            a();
            ByteBuffer byteBuffer = ByteBuffer.allocate(pixelData.length*2);
            byteBuffer.asShortBuffer().put(ShortBuffer.wrap(pixelData));
            pixelsGray = byteBuffer.array();

            }
        }

}

The values in pixelsGray became negative when using invert(), however the this.bufferedImage remains the same.