/** * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int) */ @Override public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { checkParams(no, buf, x, y, w, h); if (!isFullPlane(x, y, w, h)) { throw new FormatException( "APNGWriter does not yet support saving image tiles."); } MetadataRetrieve meta = getMetadataRetrieve(); int width = meta.getPixelsSizeX(series).getValue().intValue(); int height = meta.getPixelsSizeY(series).getValue().intValue(); out.seek(footerPointer); if (!initialized[series][no]) { writeFCTL(width, height); if (numFrames == 0) writePLTE(); initialized[series][no] = true; } writePixels(numFrames == 0 ? "IDAT" : "fdAT", buf, x, y, w, h); numFrames++; writeFooter(); }
private int crc(byte[] buf) { return crc(buf, 0, buf.length); }
private void writePixels(String chunk, byte[] stream, int x, int y, int width, int height) throws FormatException, IOException MetadataRetrieve r = getMetadataRetrieve(); int sizeC = getSamplesPerPixel(); String type = r.getPixelsType(series).toString(); int pixelType = FormatTools.pixelTypeFromString(type); boolean signed = FormatTools.isSigned(pixelType); if (!isFullPlane(x, y, width, height)) { throw new FormatException("APNGWriter does not support writing tiles."); out.writeInt(crc(b));
numFrames = 0; MetadataRetrieve r = getMetadataRetrieve(); int width = r.getPixelsSizeX(series).getValue().intValue(); int height = r.getPixelsSizeY(series).getValue().intValue(); int bytesPerPixel = FormatTools.getBytesPerPixel(r.getPixelsType(series).toString()); int nChannels = getSamplesPerPixel(); boolean indexed = getColorModel() != null && (getColorModel() instanceof IndexColorModel); if (r.getPixelsBigEndian(series) != null) { littleEndian = !r.getPixelsBigEndian(series).booleanValue(); out.writeInt(crc(b));
private void writePLTE() throws IOException { if (!(getColorModel() instanceof IndexColorModel)) return; IndexColorModel model = (IndexColorModel) getColorModel(); byte[][] lut = new byte[3][256]; model.getReds(lut[0]); model.getGreens(lut[1]); model.getBlues(lut[2]); out.writeInt(768); byte[] b = new byte[772]; b[0] = 'P'; b[1] = 'L'; b[2] = 'T'; b[3] = 'E'; for (int i=0; i<lut[0].length; i++) { for (int j=0; j<lut.length; j++) { b[i*lut.length + j + 4] = lut[j][i]; } } out.write(b); out.writeInt(crc(b)); }
private void writePixels(String chunk, byte[] stream, int x, int y, int width, int height) throws FormatException, IOException MetadataRetrieve r = getMetadataRetrieve(); int sizeC = getSamplesPerPixel(); String type = r.getPixelsType(series).toString(); int pixelType = FormatTools.pixelTypeFromString(type); boolean signed = FormatTools.isSigned(pixelType); if (!isFullPlane(x, y, width, height)) { throw new FormatException("APNGWriter does not support writing tiles."); out.writeInt(crc(b));
numFrames = 0; MetadataRetrieve r = getMetadataRetrieve(); int width = r.getPixelsSizeX(series).getValue().intValue(); int height = r.getPixelsSizeY(series).getValue().intValue(); int bytesPerPixel = FormatTools.getBytesPerPixel(r.getPixelsType(series).toString()); int nChannels = getSamplesPerPixel(); boolean indexed = getColorModel() != null && (getColorModel() instanceof IndexColorModel); if (r.getPixelsBigEndian(series) != null) { littleEndian = !r.getPixelsBigEndian(series).booleanValue(); out.writeInt(crc(b));
private void writePLTE() throws IOException { if (!(getColorModel() instanceof IndexColorModel)) return; IndexColorModel model = (IndexColorModel) getColorModel(); byte[][] lut = new byte[3][256]; model.getReds(lut[0]); model.getGreens(lut[1]); model.getBlues(lut[2]); out.writeInt(768); byte[] b = new byte[772]; b[0] = 'P'; b[1] = 'L'; b[2] = 'T'; b[3] = 'E'; for (int i=0; i<lut[0].length; i++) { for (int j=0; j<lut.length; j++) { b[i*lut.length + j + 4] = lut[j][i]; } } out.write(b); out.writeInt(crc(b)); }
/** * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int) */ @Override public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { checkParams(no, buf, x, y, w, h); if (!isFullPlane(x, y, w, h)) { throw new FormatException( "APNGWriter does not yet support saving image tiles."); } MetadataRetrieve meta = getMetadataRetrieve(); int width = meta.getPixelsSizeX(series).getValue().intValue(); int height = meta.getPixelsSizeY(series).getValue().intValue(); out.seek(footerPointer); if (!initialized[series][no]) { writeFCTL(width, height); if (numFrames == 0) writePLTE(); initialized[series][no] = true; } writePixels(numFrames == 0 ? "IDAT" : "fdAT", buf, x, y, w, h); numFrames++; writeFooter(); }
private int crc(byte[] buf) { return crc(buf, 0, buf.length); }
private void writeFooter() throws IOException { footerPointer = out.getFilePointer(); // write IEND chunk out.writeInt(0); out.writeBytes("IEND"); out.writeInt(crc("IEND".getBytes(Constants.ENCODING))); // update frame count out.seek(numFramesPointer); out.writeInt(numFrames); out.skipBytes(4); byte[] b = new byte[12]; b[0] = 'a'; b[1] = 'c'; b[2] = 'T'; b[3] = 'L'; DataTools.unpackBytes(numFrames, b, 4, 4, false); DataTools.unpackBytes(0, b, 8, 4, false); out.writeInt(crc(b)); }
private void writeFooter() throws IOException { footerPointer = out.getFilePointer(); // write IEND chunk out.writeInt(0); out.writeBytes("IEND"); out.writeInt(crc("IEND".getBytes(Constants.ENCODING))); // update frame count out.seek(numFramesPointer); out.writeInt(numFrames); out.skipBytes(4); byte[] b = new byte[12]; b[0] = 'a'; b[1] = 'c'; b[2] = 'T'; b[3] = 'L'; DataTools.unpackBytes(numFrames, b, 4, 4, false); DataTools.unpackBytes(0, b, 8, 4, false); out.writeInt(crc(b)); }
private void writeFCTL(int width, int height) throws IOException { out.writeInt(26); byte[] b = new byte[30]; b[0] = 'f'; b[1] = 'c'; b[2] = 'T'; b[3] = 'L'; DataTools.unpackBytes(nextSequenceNumber++, b, 4, 4, false); DataTools.unpackBytes(width, b, 8, 4, false); DataTools.unpackBytes(height, b, 12, 4, false); DataTools.unpackBytes(0, b, 16, 4, false); DataTools.unpackBytes(0, b, 20, 4, false); DataTools.unpackBytes(1, b, 24, 2, false); DataTools.unpackBytes(fps, b, 26, 2, false); b[28] = (byte) 1; b[29] = (byte) 0; out.write(b); out.writeInt(crc(b)); }
private void writeFCTL(int width, int height) throws IOException { out.writeInt(26); byte[] b = new byte[30]; b[0] = 'f'; b[1] = 'c'; b[2] = 'T'; b[3] = 'L'; DataTools.unpackBytes(nextSequenceNumber++, b, 4, 4, false); DataTools.unpackBytes(width, b, 8, 4, false); DataTools.unpackBytes(height, b, 12, 4, false); DataTools.unpackBytes(0, b, 16, 4, false); DataTools.unpackBytes(0, b, 20, 4, false); DataTools.unpackBytes(1, b, 24, 2, false); DataTools.unpackBytes(fps, b, 26, 2, false); b[28] = (byte) 1; b[29] = (byte) 0; out.write(b); out.writeInt(crc(b)); }