@Override public int estimateBufferSize(Picture frame) { return frame.getCroppedWidth() * frame.getCroppedHeight() * 4; } }
@Override public int estimateBufferSize(Picture frame) { int fullPlaneSize = frame.getWidth() * frame.getCroppedHeight(); ColorSpace color = frame.getColor(); int totalSize = 0; for (int i = 0; i < color.nComp; i++) { totalSize += (fullPlaneSize >> color.compWidth[i]) >> color.compHeight[i]; } return totalSize; }
@Override public EncodedFrame encodeFrame(Picture pic, ByteBuffer buffer) { ByteBuffer out = buffer.duplicate(); ByteBuffer fork = out.duplicate(); int[] scan = interlaced ? interlaced_scan : progressive_scan; writeFrameHeader(out, new ProresConsts.FrameHeader(0, pic.getCroppedWidth(), pic.getCroppedHeight(), interlaced ? 1 : 0, true, scan, profile.qmatLuma, profile.qmatChroma, 2)); encodePicture(out, scaledLuma, scaledChroma, scan, pic, interlaced ? 1 : 0, 0); if (interlaced) encodePicture(out, scaledLuma, scaledChroma, scan, pic, interlaced ? 1 : 0, 1); out.flip(); fork.putInt(out.remaining()); return new EncodedFrame(out, true); }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Picture)) return false; Picture other = (Picture) obj; if (other.getCroppedWidth() != getCroppedWidth() || other.getCroppedHeight() != getCroppedHeight() || other.getColor() != color) return false; for (int i = 0; i < getData().length; i++) if (!planeEquals(other, i)) return false; return true; }
IHDR ihdr = new IHDR(); ihdr.width = pic.getCroppedWidth(); ihdr.height = pic.getCroppedHeight(); ihdr.bitDepth = 8; ihdr.colorType = PNG_COLOR_MASK_COLOR; for (int row = 0, bptr = 0; row < pic.getCroppedHeight() + 1; row++) { int count; while ((count = deflater.deflate(buffer, ptr, len)) > 0) { if (row >= pic.getCroppedHeight()) break; if (row >= pic.getCroppedHeight() - 1) deflater.finish();
int startY = pic.getStartY(); int cropW = pic.getCroppedWidth() >> color.compWidth[plane]; int cropH = pic.getCroppedHeight() >> color.compHeight[plane]; byte[] planeData = pic.getPlaneData(plane); int startY = pic.getStartY(); int cropW = pic.getCroppedWidth(); int cropH = pic.getCroppedHeight(); byte[] planeData = pic.getPlaneData(0);
@Override public Picture decodeField(ByteBuffer data, byte[][] data2, int field, int step) { Picture res = super.decodeField(data, data2, field, step); return new Picture(res.getWidth() >> 2, res.getHeight() >> 2, res.getData(), null, res.getColor(), 0, new Rect( 0, 0, res.getCroppedWidth() >> 2, res.getCroppedHeight() >> 2)); } }
@Override public Picture decodeField(ByteBuffer data, byte[][] data2, int field, int step) { Picture res = super.decodeField(data, data2, field, step); return new Picture(res.getWidth() >> 1, res.getHeight() >> 1, res.getData(), null, res.getColor(), 0, new Rect( 0, 0, res.getCroppedWidth() >> 1, res.getCroppedHeight() >> 1)); } }
sps = initSPS(new Size(pic.getCroppedWidth(), pic.getCroppedHeight())); pps = initPPS();
private boolean planeEquals(Picture other, int plane) { int cw = color.compWidth[plane]; int ch = color.compHeight[plane]; int offA = other.getCrop() == null ? 0 : ((other.getCrop().getX() >> cw) + (other.getCrop().getY() >> ch) * (other.getWidth() >> cw)); int offB = crop == null ? 0 : ((crop.getX() >> cw) + (crop.getY() >> ch) * (width >> cw)); byte[] planeData = other.getPlaneData(plane); for (int i = 0; i < getCroppedHeight() >> ch; i++, offA += (other.getWidth() >> cw), offB += (width >> cw)) { for (int j = 0; j < getCroppedWidth() >> cw; j++) { if (planeData[offA + j] != data[plane][offB + j]) return false; } } return true; }
public static BufferedImage toBufferedImage(Picture src) { if (src.getColor() != ColorSpace.BGR) { Picture bgr = Picture.createCropped(src.getWidth(), src.getHeight(), ColorSpace.BGR, src.getCrop()); if (src.getColor() == ColorSpace.RGB) { new RgbToBgr().transform(src, bgr); } else { Transform transform = ColorUtil.getTransform(src.getColor(), ColorSpace.RGB); transform.transform(src, bgr); new RgbToBgr().transform(bgr, bgr); } src = bgr; } BufferedImage dst = new BufferedImage(src.getCroppedWidth(), src.getCroppedHeight(), BufferedImage.TYPE_3BYTE_BGR); if (src.getCrop() == null) toBufferedImage(src, dst); else toBufferedImageCropped(src, dst); return dst; }
public static BufferedImage toBufferedImage(Picture src, DemuxerTrackMeta.Orientation orientation) { if (src.getColor() != ColorSpace.BGR) { Picture bgr = Picture.createCropped(src.getWidth(), src.getHeight(), ColorSpace.BGR, src.getCrop()); if (src.getColor() == ColorSpace.RGB) { new RgbToBgr().transform(src, bgr); } else { Transform transform = ColorUtil.getTransform(src.getColor(), ColorSpace.RGB); transform.transform(src, bgr); new RgbToBgr().transform(bgr, bgr); } src = bgr; } BufferedImage dst = new BufferedImage(src.getCroppedWidth(), src.getCroppedHeight(), BufferedImage.TYPE_3BYTE_BGR); if (src.getCrop() == null) toBufferedImage(src, dst); else toBufferedImageCropped(src, dst); if (orientation.equals(DemuxerTrackMeta.Orientation.D_90)) return rotate90ToRight(dst); else if (orientation.equals(DemuxerTrackMeta.Orientation.D_180)) return rotate180(dst); else if (orientation.equals(DemuxerTrackMeta.Orientation.D_270)) return rotate90ToLeft(dst); return dst; }