Mercurial > hg > digilib
changeset 1231:21441a3f5208
trying to fix problem with scaled image size being off from dw and dh.
changed calculation of scaling factor to double precision.
(still issues with sizes though)
author | robcast |
---|---|
date | Tue, 22 Oct 2013 15:46:47 +0200 |
parents | e7171b0fd914 |
children | e5281d63f03f |
files | common/src/main/java/digilib/conf/DigilibConfiguration.java common/src/main/java/digilib/image/ImageJobDescription.java common/src/main/java/digilib/image/ImageWorker.java |
diffstat | 3 files changed, 32 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/common/src/main/java/digilib/conf/DigilibConfiguration.java Tue Oct 22 11:27:26 2013 +0200 +++ b/common/src/main/java/digilib/conf/DigilibConfiguration.java Tue Oct 22 15:46:47 2013 +0200 @@ -48,7 +48,7 @@ /** digilib version */ public static String getVersion() { - return "2.2.2"; + return "2.2.3"; } /**
--- a/common/src/main/java/digilib/image/ImageJobDescription.java Tue Oct 22 11:27:26 2013 +0200 +++ b/common/src/main/java/digilib/image/ImageJobDescription.java Tue Oct 22 15:46:47 2013 +0200 @@ -71,7 +71,7 @@ DocuImage docuImage = null; String filePath = null; ImageSize expectedSourceSize = null; - Float scaleXY = null; + Double scaleXY = null; Rectangle2D userImgArea = null; Rectangle2D outerUserImgArea = null; Boolean imageSendable = null; @@ -405,17 +405,17 @@ * @throws IOException * @throws ImageOpException */ - public float getScaleXY() throws IOException, ImageOpException { + public double getScaleXY() throws IOException, ImageOpException { // logger.debug("get_scaleXY()"); if (scaleXY != null) { - return (float) scaleXY; + return scaleXY.doubleValue(); } /* * calculate region of interest */ - float areaWidth; - float areaHeight; + double areaWidth; + double areaHeight; // size of the currently selected input image ImageSize imgSize = getInput().getSize(); if (!options.hasOption("pxarea")) { @@ -438,10 +438,10 @@ /* * scale to fit -- scaling factor based on destination size and user area */ - areaWidth = (float) userImgArea.getWidth(); - areaHeight = (float) userImgArea.getHeight(); - float scaleX = getDw() / areaWidth * ws; - float scaleY = getDh() / areaHeight * ws; + areaWidth = (double) userImgArea.getWidth(); + areaHeight = (double) userImgArea.getHeight(); + double scaleX = getDw() / areaWidth * ws; + double scaleY = getDh() / areaHeight * ws; scaleXY = (scaleX > scaleY) ? scaleY : scaleX; } else if (isAbsoluteScale()) { /* @@ -450,15 +450,15 @@ if (hasOption("osize")) { // get original resolution from metadata imageSet.checkMeta(); - float origResX = imageSet.getResX(); - float origResY = imageSet.getResY(); + double origResX = imageSet.getResX(); + double origResY = imageSet.getResY(); if ((origResX == 0) || (origResY == 0)) { throw new ImageOpException("Missing image DPI information!"); } - float ddpix = getAsFloat("ddpix"); - float ddpiy = getAsFloat("ddpiy"); + double ddpix = getAsFloat("ddpix"); + double ddpiy = getAsFloat("ddpiy"); if (ddpix == 0 || ddpiy == 0) { - float ddpi = getAsFloat("ddpi"); + double ddpi = getAsFloat("ddpi"); if (ddpi == 0) { throw new ImageOpException("Missing display DPI information!"); } else { @@ -467,13 +467,13 @@ } } // calculate absolute scale factor - float sx = ddpix / origResX; - float sy = ddpiy / origResY; + double sx = ddpix / origResX; + double sy = ddpiy / origResY; // currently only same scale -- mean value scaleXY = (sx + sy) / 2f; } else { // absolute scale factor - scaleXY = getAsFloat("scale"); + scaleXY = (double) getAsFloat("scale"); // use original size if no destination size given if (getDw() == 0 && getDh() == 0) { paramDW = (int) userImgArea.getWidth(); @@ -483,7 +483,7 @@ // we need to correct the factor if we use a pre-scaled image ImageSize hiresSize = getHiresSize(); if (imgSize.getWidth() != hiresSize.getWidth()) { - scaleXY *= (float) hiresSize.getWidth() / (float) imgSize.getWidth(); + scaleXY *= (double) hiresSize.getWidth() / (double) imgSize.getWidth(); } areaWidth = getDw() / scaleXY * ws; areaHeight = getDh() / scaleXY * ws; @@ -497,9 +497,9 @@ areaHeight = getDh() * ws; // reset user area size userImgArea.setRect(userImgArea.getX(), userImgArea.getY(), areaWidth, areaHeight); - scaleXY = 1f; + scaleXY = 1d; } - return (float) scaleXY; + return scaleXY.doubleValue(); } /**
--- a/common/src/main/java/digilib/image/ImageWorker.java Tue Oct 22 11:27:26 2013 +0200 +++ b/common/src/main/java/digilib/image/ImageWorker.java Tue Oct 22 15:46:47 2013 +0200 @@ -79,7 +79,7 @@ docuImage.setQuality(jobinfo.getScaleQual()); Rectangle loadRect = jobinfo.getOuterUserImgArea().getBounds(); - float scaleXY = jobinfo.getScaleXY(); + double scaleXY = jobinfo.getScaleXY(); if (stopNow) { logger.debug("ImageWorker stopping (after setup)"); @@ -88,26 +88,28 @@ // use subimage loading if possible if (docuImage.isSubimageSupported()) { logger.debug("Subimage: scale " + scaleXY + " = " + (1 / scaleXY)); - float subf = 1f; - float subsamp = 1f; + double subf = 1d; + double subsamp = 1d; if (scaleXY < 1) { subf = 1 / scaleXY; // for higher quality reduce subsample factor by minSubsample if (jobinfo.getScaleQual() > 0) { - subsamp = (float) Math.max(Math.floor(subf / dlConfig.getAsFloat("subsample-minimum")), 1d); + subsamp = Math.max(Math.floor(subf / dlConfig.getAsFloat("subsample-minimum")), 1d); } else { - subsamp = (float) Math.floor(subf); + subsamp = Math.floor(subf); } - scaleXY = subsamp / subf; - logger.debug("Using subsampling: " + subsamp + " rest " - + scaleXY); + // correct scaling factor by subsampling factor + scaleXY *= subsamp; + logger.debug("Using subsampling: " + subsamp + " rest " + scaleXY); } + // load region with subsampling docuImage.loadSubimage(jobinfo.getInput(), loadRect, (int) subsamp); - logger.debug("SUBSAMP: " + subsamp + " -> " + docuImage.getSize()); + logger.debug("SUBSAMP: " + subsamp + ": " + jobinfo.getInput().getSize() + " -> " + docuImage.getSize()); if (stopNow) { logger.debug("ImageWorker stopping (after loading and cropping)"); return null; } + // and scale docuImage.scale(scaleXY, scaleXY); } else { // else load and crop the whole file