Skip to content

Commit

Permalink
Replace custom region-finding code with Kdu_region_decompressor.Find_…
Browse files Browse the repository at this point in the history
…render_dims()
  • Loading branch information
Alex Dolski committed Jul 31, 2019
1 parent eea4c8f commit 3de2ebb
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,16 @@ public BufferedImage readRegion(final Rectangle roi,
final Kdu_dims sourceDims = decompressor.Get_rendered_image_dims(
codestream, channels, -1, reductionFactor.factor,
expandNumerator, expandDenominator, accessMode);
final Kdu_coords sourcePos = sourceDims.Access_pos();

final Rectangle regionRect = new Rectangle(roi);

// Adjust the ROI coordinates for the selected decomposition level.
// Note that some wacky source images have a non-0,0 origin,
// in which case the ROI origin must be shifted to match.
final double reducedScale = reductionFactor.getScale();
regionRect.moveRight(sourcePos.Get_x());
regionRect.moveDown(sourcePos.Get_y());
regionRect.scaleX(diffScales[0] * reducedScale);
regionRect.scaleY(diffScales[1] * reducedScale);
final Kdu_dims regionDims = toKduDims(regionRect);
// Adjust the ROI coordinates for the image size on the canvas.
final double rfScale = reductionFactor.getScale();
roi.scaleX(rfScale);
roi.scaleY(rfScale);
Kdu_dims regionDims = toKduDims(roi);
Kdu_coords refSubs = new Kdu_coords();
codestream.Get_subsampling(referenceComponent, refSubs);
regionDims = decompressor.Find_render_dims(regionDims, refSubs,
expandNumerator, expandDenominator);

LOGGER.debug("Rendered region {},{}/{}x{}; source {},{}/{}x{}; " +
"{}x reduction factor; differential scale {}/{}",
Expand Down Expand Up @@ -611,8 +608,7 @@ public BufferedImage readRegion(final Rectangle roi,

private static Kdu_dims toKduDims(Rectangle rect) throws KduException {
Kdu_dims regionDims = new Kdu_dims();
regionDims.From_u32(rect.intX(), rect.intY(),
rect.intWidth(), rect.intHeight());
regionDims.From_double(rect.x(), rect.y(), rect.width(), rect.height());
return regionDims;
}

Expand Down

0 comments on commit 3de2ebb

Please sign in to comment.