Skip to content

Commit be290a4

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #425
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1932456 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8a411c3 commit be290a4

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,14 @@ private static void readRasterFromAny(PDImage pdImage, WritableRaster raster)
285285
final boolean isIndexed = colorSpace instanceof PDIndexed;
286286

287287
// calculate row padding
288-
int padding = 0;
289-
if (inputWidth * numComponents * bitsPerComponent % 8 > 0)
288+
int padding = inputWidth * numComponents * bitsPerComponent % 8;
289+
if (padding > 0)
290290
{
291-
padding = 8 - (inputWidth * numComponents * bitsPerComponent % 8);
291+
padding = 8 - padding;
292+
}
293+
else
294+
{
295+
padding = 0;
292296
}
293297

294298
// read stream
@@ -498,7 +502,7 @@ private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster, Re
498502
{
499503
// we just need to copy all sample data, then convert to RGB image.
500504
int inputResult = input.readNBytes(bank, 0, bank.length);
501-
if (inputResult != (long) width * height * numComponents)
505+
if (LOG.isDebugEnabled() && inputResult != (long) width * height * numComponents)
502506
{
503507
LOG.debug("Tried reading {} bytes but only {} bytes read",
504508
(long) width * height * numComponents, inputResult);
@@ -616,10 +620,14 @@ private static BufferedImage fromAny(PDImage pdImage, WritableRaster raster, COS
616620
}
617621

618622
// calculate row padding
619-
int padding = 0;
620-
if (inputWidth * numComponents * bitsPerComponent % 8 > 0)
623+
int padding = inputWidth * numComponents * bitsPerComponent % 8;
624+
if (padding > 0)
625+
{
626+
padding = 8 - padding;
627+
}
628+
else
621629
{
622-
padding = 8 - (inputWidth * numComponents * bitsPerComponent % 8);
630+
padding = 0;
623631
}
624632

625633
// read stream

0 commit comments

Comments
 (0)