@Implementation protected void copyPixelsToBuffer(Buffer dst) { // Ensure that the Bitmap uses 4 bytes per pixel, since we always use 4 bytes per pixels // internally. Clients of this API probably expect that the buffer size must be >= // getByteCount(), but if we don't enforce this restriction then for RGB_4444 and other // configs that value would be smaller then the buffer size we actually need. if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; for (int color : colors) { byteBuffer.putInt(color); } }
@Implementation protected void copyPixelsFromBuffer(Buffer dst) { if (isRecycled()) { throw new IllegalStateException("Can't call copyPixelsFromBuffer() on a recycled bitmap"); } // See the related comment in #copyPixelsToBuffer(Buffer). if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; if (byteBuffer.remaining() < colors.length * INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Buffer not large enough for pixels"); } for (int i = 0; i < colors.length; i++) { colors[i] = byteBuffer.getInt(); } }
@Implementation protected int getRowBytes() { return getBytesPerPixel(config) * getWidth(); }
@Test public void getBytesPerPixel_preO() { assertThat(ShadowBitmap.getBytesPerPixel(Bitmap.Config.ARGB_8888)).isEqualTo(4); assertThat(ShadowBitmap.getBytesPerPixel(Bitmap.Config.RGB_565)).isEqualTo(2); assertThat(ShadowBitmap.getBytesPerPixel(Bitmap.Config.ARGB_4444)).isEqualTo(2); assertThat(ShadowBitmap.getBytesPerPixel(Bitmap.Config.ALPHA_8)).isEqualTo(1); }
@Config(sdk = Build.VERSION_CODES.O) @Test public void getBytesPerPixel_O() { assertThat(ShadowBitmap.getBytesPerPixel(Bitmap.Config.RGBA_F16)).isEqualTo(8); }
@Implementation public void copyPixelsToBuffer(Buffer dst) { // Ensure that the Bitmap uses 4 bytes per pixel, since we always use 4 bytes per pixels // internally. Clients of this API probably expect that the buffer size must be >= // getByteCount(), but if we don't enforce this restriction then for RGB_4444 and other // configs that value would be smaller then the buffer size we actually need. if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; for (int color : colors) { byteBuffer.putInt(color); } }
@Implementation public void copyPixelsToBuffer(Buffer dst) { // Ensure that the Bitmap uses 4 bytes per pixel, since we always use 4 bytes per pixels // internally. Clients of this API probably expect that the buffer size must be >= // getByteCount(), but if we don't enforce this restriction then for RGB_4444 and other // configs that value would be smaller then the buffer size we actually need. if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; for (int color : colors) { byteBuffer.putInt(color); } }
@Implementation protected void copyPixelsToBuffer(Buffer dst) { // Ensure that the Bitmap uses 4 bytes per pixel, since we always use 4 bytes per pixels // internally. Clients of this API probably expect that the buffer size must be >= // getByteCount(), but if we don't enforce this restriction then for RGB_4444 and other // configs that value would be smaller then the buffer size we actually need. if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; for (int color : colors) { byteBuffer.putInt(color); } }
@Implementation public void copyPixelsToBuffer(Buffer dst) { // Ensure that the Bitmap uses 4 bytes per pixel, since we always use 4 bytes per pixels // internally. Clients of this API probably expect that the buffer size must be >= // getByteCount(), but if we don't enforce this restriction then for RGB_4444 and other // configs that value would be smaller then the buffer size we actually need. if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; for (int color : colors) { byteBuffer.putInt(color); } }
@Implementation public void copyPixelsFromBuffer(Buffer dst) { if (isRecycled()) { throw new IllegalStateException("Can't call copyPixelsFromBuffer() on a recycled bitmap"); } // See the related comment in #copyPixelsToBuffer(Buffer). if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; if (byteBuffer.remaining() < colors.length * INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Buffer not large enough for pixels"); } for (int i = 0; i < colors.length; i++) { colors[i] = byteBuffer.getInt(); } }
@Implementation protected void copyPixelsFromBuffer(Buffer dst) { if (isRecycled()) { throw new IllegalStateException("Can't call copyPixelsFromBuffer() on a recycled bitmap"); } // See the related comment in #copyPixelsToBuffer(Buffer). if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; if (byteBuffer.remaining() < colors.length * INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Buffer not large enough for pixels"); } for (int i = 0; i < colors.length; i++) { colors[i] = byteBuffer.getInt(); } }
@Implementation public void copyPixelsFromBuffer(Buffer dst) { if (isRecycled()) { throw new IllegalStateException("Can't call copyPixelsFromBuffer() on a recycled bitmap"); } // See the related comment in #copyPixelsToBuffer(Buffer). if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; if (byteBuffer.remaining() < colors.length * INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Buffer not large enough for pixels"); } for (int i = 0; i < colors.length; i++) { colors[i] = byteBuffer.getInt(); } }
@Implementation public void copyPixelsFromBuffer(Buffer dst) { if (isRecycled()) { throw new IllegalStateException("Can't call copyPixelsFromBuffer() on a recycled bitmap"); } // See the related comment in #copyPixelsToBuffer(Buffer). if (getBytesPerPixel(config) != INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Not implemented: only Bitmaps with " + INTERNAL_BYTES_PER_PIXEL + " bytes per pixel are supported"); } if (!(dst instanceof ByteBuffer)) { throw new RuntimeException("Not implemented: unsupported Buffer subclass"); } ByteBuffer byteBuffer = (ByteBuffer) dst; if (byteBuffer.remaining() < colors.length * INTERNAL_BYTES_PER_PIXEL) { throw new RuntimeException("Buffer not large enough for pixels"); } for (int i = 0; i < colors.length; i++) { colors[i] = byteBuffer.getInt(); } }
@Implementation public int getRowBytes() { return getBytesPerPixel(config) * getWidth(); }
@Implementation public int getRowBytes() { return getBytesPerPixel(config) * getWidth(); }
@Implementation public int getRowBytes() { return getBytesPerPixel(config) * getWidth(); }
@Implementation protected int getRowBytes() { return getBytesPerPixel(config) * getWidth(); }