Java Code Examples for javax.imageio.ImageWriteParam#MODE_EXPLICIT

The following examples show how to use javax.imageio.ImageWriteParam#MODE_EXPLICIT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompressionModeTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) {
    int[] iModes = { ImageWriteParam.MODE_DISABLED,
                     ImageWriteParam.MODE_EXPLICIT,
                     ImageWriteParam.MODE_COPY_FROM_METADATA,
                     ImageWriteParam.MODE_DEFAULT };

    String[] strModes = { "ImageWriteParam.MODE_DISABLED",
                          "ImageWriteParam.MODE_EXPLICIT",
                          "ImageWriteParam.MODE_COPY_FROM_METADATA",
                          "ImageWriteParam.MODE_DEFAULT" };

    for(int i=0; i<iModes.length; i++) {
        System.out.println("Test compression mode "+strModes[i]);
        doTest(iModes[i]);
    }
}
 
Example 2
Source File: RleEncodingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {
        int mode = ImageWriteParam.MODE_EXPLICIT;
        String type = "BI_RLE4";
        doTest(type, mode);

        type = "BI_RLE8";
        doTest(type, mode);

        mode = ImageWriteParam.MODE_DEFAULT;
        type = "BI_RLE4";
        doTest(type, mode);

        type = "BI_RLE8";
        doTest(type, mode);

        System.out.println("Test 4bpp image.");
        encodeRLE4Test();

        System.out.println("Test 8bpp image.");
        encodeRLE8Test();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Unexpected exception. Test failed");
    }
}
 
Example 3
Source File: RleEncodingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {
        int mode = ImageWriteParam.MODE_EXPLICIT;
        String type = "BI_RLE4";
        doTest(type, mode);

        type = "BI_RLE8";
        doTest(type, mode);

        mode = ImageWriteParam.MODE_DEFAULT;
        type = "BI_RLE4";
        doTest(type, mode);

        type = "BI_RLE8";
        doTest(type, mode);

        System.out.println("Test 4bpp image.");
        encodeRLE4Test();

        System.out.println("Test 8bpp image.");
        encodeRLE8Test();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Unexpected exception. Test failed");
    }
}
 
Example 4
Source File: TIFFDeflater.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public TIFFDeflater(String compressionType,
                    int compressionTagValue,
                    ImageWriteParam param,
                    int predictorValue) {
    super(compressionType, compressionTagValue, true);

    this.predictor = predictorValue;

    // Set the deflate level.
    int deflateLevel;
    if(param != null &&
       param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        float quality = param.getCompressionQuality();
        deflateLevel = (int)(1 + 8*quality);
    } else {
        deflateLevel = Deflater.DEFAULT_COMPRESSION;
    }

    this.deflater = new Deflater(deflateLevel);
}
 
Example 5
Source File: TIFFDeflater.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public TIFFDeflater(String compressionType,
                    int compressionTagValue,
                    ImageWriteParam param,
                    int predictorValue) {
    super(compressionType, compressionTagValue, true);

    this.predictor = predictorValue;

    // Set the deflate level.
    int deflateLevel;
    if(param != null &&
       param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        float quality = param.getCompressionQuality();
        deflateLevel = (int)(1 + 8*quality);
    } else {
        deflateLevel = Deflater.DEFAULT_COMPRESSION;
    }

    this.deflater = new Deflater(deflateLevel);
}
 
Example 6
Source File: BMPImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 7
Source File: BMPImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 8
Source File: BMPImageWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 9
Source File: BMPImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 10
Source File: DisableCompressionTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String getModeName(int mode) {
    switch(mode) {
        case ImageWriteParam.MODE_COPY_FROM_METADATA:
            return "MODE_COPY_FROM_METADATA";
        case ImageWriteParam.MODE_DEFAULT:
            return "MODE_DEFAULT";
        case ImageWriteParam.MODE_DISABLED:
            return "MODE_DISABLED";
        case ImageWriteParam.MODE_EXPLICIT:
            return "MODE_EXPLICIT";
        default:
            throw new IllegalArgumentException("Unknown mode: " + mode);
    }
}
 
Example 11
Source File: DisableCompressionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static String getModeName(int mode) {
    switch(mode) {
        case ImageWriteParam.MODE_COPY_FROM_METADATA:
            return "MODE_COPY_FROM_METADATA";
        case ImageWriteParam.MODE_DEFAULT:
            return "MODE_DEFAULT";
        case ImageWriteParam.MODE_DISABLED:
            return "MODE_DISABLED";
        case ImageWriteParam.MODE_EXPLICIT:
            return "MODE_EXPLICIT";
        default:
            throw new IllegalArgumentException("Unknown mode: " + mode);
    }
}
 
Example 12
Source File: BMPImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 13
Source File: BMPImageWriter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 14
Source File: BMPImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 15
Source File: BMPImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 16
Source File: BMPImageWriter.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 17
Source File: BMPImageWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 18
Source File: BMPImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 19
Source File: BMPCompressionTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() {
    try {
        System.out.println(this.getDescription());
        if (param.getCompressionMode() != ImageWriteParam.MODE_EXPLICIT) {
            System.out.println("Warning: compression mode is not MODE_EXPLICIT");
        }
        // change metadata according to ImageWriteParam
        IIOMetadata new_meta = iw.convertImageMetadata(meta, new ImageTypeSpecifier(img), param);

        IIOImage iio_img = new IIOImage(img, null, new_meta);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
        iw.setOutput(ios);
        System.out.print("write image...");
        System.out.println("Current compression Type is \""+param.getCompressionType()+"\"");
        iw.write(new_meta, iio_img, param);
        //iw.write(iio_img);
        System.out.println("OK");
        System.out.print("read image ... ");
        ios.flush();

        byte[] ba_image = baos.toByteArray();

        System.out.println("Array length=" + ba_image.length);
        FileOutputStream fos = new FileOutputStream(new File(param.getCompressionType()+".bmp"));
        fos.write(ba_image);
        fos.flush();
        fos = null;
        ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);

        ImageReader ir = ImageIO.getImageReader(iw);
        ir.setInput(ImageIO.createImageInputStream(bais));

        BufferedImage res = ir.read(0);
        System.out.println("OK");

        if (!param.getCompressionType().equals("BI_JPEG")) {
            System.out.print("compare images ... ");
            boolean r = compare(img,res);
            System.out.println(r?"OK":"FAILED");
            if (!r) {
                throw new RuntimeException("Compared images are not equals. Test failed.");
            }
        }


        BMPMetadata mdata = (BMPMetadata)ir.getImageMetadata(0);

        if (!param.getCompressionType().equals(param.getCompressionTypes()[mdata.compression])) {
            throw new RuntimeException("Different compression value");
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException("Unexpected exception: " + ex);
    }

}
 
Example 20
Source File: BMPCompressionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() {
    try {
        System.out.println(this.getDescription());
        if (param.getCompressionMode() != ImageWriteParam.MODE_EXPLICIT) {
            System.out.println("Warning: compression mode is not MODE_EXPLICIT");
        }
        // change metadata according to ImageWriteParam
        IIOMetadata new_meta = iw.convertImageMetadata(meta, new ImageTypeSpecifier(img), param);

        IIOImage iio_img = new IIOImage(img, null, new_meta);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
        iw.setOutput(ios);
        System.out.print("write image...");
        System.out.println("Current compression Type is \""+param.getCompressionType()+"\"");
        iw.write(new_meta, iio_img, param);
        //iw.write(iio_img);
        System.out.println("OK");
        System.out.print("read image ... ");
        ios.flush();

        byte[] ba_image = baos.toByteArray();

        System.out.println("Array length=" + ba_image.length);
        FileOutputStream fos = new FileOutputStream(new File(param.getCompressionType()+".bmp"));
        fos.write(ba_image);
        fos.flush();
        fos = null;
        ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);

        ImageReader ir = ImageIO.getImageReader(iw);
        ir.setInput(ImageIO.createImageInputStream(bais));

        BufferedImage res = ir.read(0);
        System.out.println("OK");

        if (!param.getCompressionType().equals("BI_JPEG")) {
            System.out.print("compare images ... ");
            boolean r = compare(img,res);
            System.out.println(r?"OK":"FAILED");
            if (!r) {
                throw new RuntimeException("Compared images are not equals. Test failed.");
            }
        }


        BMPMetadata mdata = (BMPMetadata)ir.getImageMetadata(0);

        if (!param.getCompressionType().equals(param.getCompressionTypes()[mdata.compression])) {
            throw new RuntimeException("Different compression value");
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException("Unexpected exception: " + ex);
    }

}