public TIFFImageEncoder(OutputStream output, ImageEncodeParam param) { super(output, param); if (this.param == null) { this.param = new TIFFEncodeParam(); } }
static ImageType getTypeFromColorSpace(ColorSpace colorSpace, TIFFEncodeParam params) { switch (colorSpace.getType()) { case ColorSpace.TYPE_CMYK: return CMYK; case ColorSpace.TYPE_GRAY: return GRAY; case ColorSpace.TYPE_Lab: return CIELAB; case ColorSpace.TYPE_RGB: if (params.getJPEGCompressRGBToYCbCr()) { return ImageType.YCBCR; } else { return ImageType.RGB; } case ColorSpace.TYPE_YCbCr: return YCBCR; default: return GENERIC; } } }
private TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params) { TIFFEncodeParam encodeParams = new TIFFEncodeParam(); if (params == null) { encodeParams.setCompression(CompressionValue.NONE); } else { encodeParams.setCompression(CompressionValue.getValue(params.getCompressionMethod())); new long[][] {yRational}) }; encodeParams.setExtraFields(fields);
private int encode(RenderedImage im, TIFFEncodeParam encodeParam, int ifdOffset, boolean isLast) throws IOException { CompressionValue compression = encodeParam.getCompression(); boolean isTiled = encodeParam.getWriteTiled(); TIFFField[] extraFields = encodeParam.getExtraFields(); List extantTags = new ArrayList(fields.size()); for (TIFFField fld : fields) { case DEFLATE: bufSize = (int) bytesPerTile; deflater = new Deflater(encodeParam.getDeflateLevel()); break; default:
if (params.getWriteTiled()) { builder.tileWidth = params.getTileWidth() > 0 ? params.getTileWidth() : width; builder.tileHeight = params.getTileHeight() > 0 ? params.getTileHeight() : height; } else { builder.tileWidth = width; builder.tileHeight = params.getTileHeight() > 0 ? params.getTileHeight() : DEFAULT_ROWS_PER_STRIP; builder.numTiles = (int) Math.ceil(height / (double) builder.tileHeight);
Iterator iter = encodeParam.getExtraImages(); if (iter != null) { int ifdOffset = 8;
/** * Encodes a RenderedImage as part of a multi-page file and writes the output to the * OutputStream associated with this ImageEncoder. * <p> * When you sent all pages, make sure you call finishMultiple() in the end. Otherwise, * the generated file will be corrupted. * @param context the context object you receive as return value to a previous call to * encodeMultiple(). Set null for the first image. * @param img the image * @return a context object needed for writing multiple pages for a single image file * @throws IOException In case of an I/O error */ public Object encodeMultiple(Object context, RenderedImage img) throws IOException { // Get the encoding parameters. TIFFEncodeParam encodeParam = (TIFFEncodeParam)param; if (encodeParam.getExtraImages() != null) { throw new IllegalStateException(PropertyUtil.getString("TIFFImageEncoder11")); } Context c = (Context)context; if (c == null) { c = new Context(); // Write the file header (8 bytes). writeFileHeader(); } else { //write image c.ifdOffset = encode(c.nextImage, encodeParam, c.ifdOffset, false); } c.nextImage = img; return c; }
/** * Use Batik to save a TIFF file of the graph * * @param filename * name of the file to store the image into * @param image * to be stored */ public void saveTIFFWithBatik(String filename, BufferedImage image) { File outfile = new File(filename); OutputStream fos = createFile(outfile); if (fos == null) { return; } TIFFEncodeParam param = new TIFFEncodeParam(); TIFFImageEncoder encoder = new TIFFImageEncoder(fos, param); try { encoder.encode(image); } catch (IOException e) { JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file"); } catch (Error e) { // NOSONAR TIFFImageEncoder uses Error to report runtime problems JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file"); if (e.getClass() != Error.class){// NOSONAR rethrow other errors throw e; } } finally { JOrphanUtils.closeQuietly(fos); } }