Skip to content

Commit

Permalink
Merge pull request #94 from kinow/IMAGING-264
Browse files Browse the repository at this point in the history
[IMAGING-264]: use Math.round before casting the image dpi into an int value.
  • Loading branch information
kinow committed Aug 19, 2020
2 parents 51d204a + 5898b20 commit 2b3e71c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="1.0-alpha3" date="2020-??-??" description="Third 1.0 alpha release">
<action issue="IMAGING-263" dev="kinow" type="fix" due-to"Gary Lucas">
<action issue="IMAGING-264" dev="kinow" type="fix">
BMP Parser physicalWidthDpi and physicalHeightDpi truncated before rounding off.
</action>
<action issue="IMAGING-263" dev="kinow" type="fix" due-to="Gary Lucas">
Failure when reading a partial raster from a floating-point TIFF
</action>
</release>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,10 @@ public ImageInfo getImageInfo(final ByteSource byteSource, Map<String, Object> p
// boolean progressive = (fPNGChunkIHDR.InterlaceMethod != 0);
//
// pixels per meter
final int physicalWidthDpi = (int) (bhi.hResolution * .0254);
final int physicalWidthDpi = (int) Math.round(bhi.hResolution * .0254);
final float physicalWidthInch = (float) ((double) width / (double) physicalWidthDpi);
// int physicalHeightDpi = 72;
final int physicalHeightDpi = (int) (bhi.vResolution * .0254);
final int physicalHeightDpi = (int) Math.round(bhi.vResolution * .0254);
final float physicalHeightInch = (float) ((double) height / (double) physicalHeightDpi);

final String formatDetails = "Bmp (" + (char) bhi.identifier1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.bmp;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
import java.util.Collections;

import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.junit.jupiter.api.Test;

/**
* Tests for the {@link BmpImageParser}.
* @since 1.0-alpha3
*/
public class BmpImageParserTest {

/**
* For https://issues.apache.org/jira/browse/IMAGING-264.
* @throws IOException
* @throws ImageReadException
*/
@Test
public void testImageWidthRounding() throws ImageReadException, IOException {
String file = "/images/bmp/IMAGING-264/test-72_6-dpi.bmp";
File bmp = new File(BmpImageParser.class.getResource(file).getFile());
final BmpImageParser parser = new BmpImageParser();
ImageInfo imageInfo = parser.getImageInfo(bmp, Collections.emptyMap());
assertEquals(73, imageInfo.getPhysicalWidthDpi(), "Expected 72.6 resolution to be rounded to 73");
}
}
Binary file not shown.

0 comments on commit 2b3e71c

Please sign in to comment.