### Question:
TurboJpegImageReader extends ImageReader { @Override public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException { checkIndex(imageIndex); ByteBuffer data = jpegData; try { int rotation = 0; Rectangle region = null; Rectangle extraCrop = null; if (param instanceof TurboJpegImageReadParam) { rotation = ((TurboJpegImageReadParam) param).getRotationDegree(); } if (param != null && param.getSourceRegion() != null) { region = param.getSourceRegion(); if (!isRegionFullImage(imageIndex, region)) { scaleRegion(imageIndex, region); extraCrop = adjustRegion(info.getMCUSize(), region, rotation); } else { region = null; } } if (region != null && (region.x + region.width > getWidth(0) || region.y + region.height > getHeight(0))) { throw new IllegalArgumentException( String.format( "Selected region (%dx%d+%d+%d) exceeds the image boundaries (%dx%d).", region.width, region.height, region.x, region.y, getWidth(imageIndex), getWidth(imageIndex))); } if (region != null || rotation != 0) { data = lib.transform(data.array(), info, region, rotation); } Info transformedInfo = lib.getInfo(data.array()); BufferedImage img = lib.decode( data.array(), transformedInfo, transformedInfo.getAvailableSizes().get(imageIndex)); if (extraCrop != null) { adjustExtraCrop(imageIndex, transformedInfo, extraCrop); img = img.getSubimage(extraCrop.x, extraCrop.y, extraCrop.width, extraCrop.height); } return img; } catch (TurboJpegException e) { throw new IOException(e); } } protected  TurboJpegImageReader(ImageReaderSpi originatingProvider, TurboJpeg lib); @Override void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata); @Override ImageReadParam getDefaultReadParam(); @Override int getNumImages(boolean allowSearch); @Override int getWidth(int imageIndex); @Override int getHeight(int imageIndex); @Override Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex); @Override BufferedImage read(int imageIndex, ImageReadParam param); @Override IIOMetadata getStreamMetadata(); @Override IIOMetadata getImageMetadata(int imageIndex);  }### Answer:
@Test public void testRead() throws IOException { ImageReader reader = getReader("rgb.jpg"); BufferedImage img = reader.read(0, null); assertThat(img).hasDimensions(512, 512); }
@Test public void testReadScaled() throws IOException { BufferedImage img = getReader("rgb.jpg").read(2, null); assertThat(img).hasDimensions(384, 384); }