Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ Important notes

* Currently based on PDFBox v2.0.37

* Requires API 19 or greater for full functionality
* Requires API 23 or greater for full functionality
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ org.gradle.parallel=true
VERSION_NAME=2.0.37.0-SNAPSHOT
VERSION_CODE=1

ANDROID_BUILD_MIN_SDK_VERSION=21
ANDROID_BUILD_MIN_SDK_VERSION=23
ANDROID_BUILD_TARGET_SDK_VERSION=36
ANDROID_BUILD_SDK_VERSION=36

Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
agp = "8.7.3"
bouncycastle = "1.85"
appcompat = "1.7.0"
agp = "8.8.2"
bouncycastle = "1.86"
appcompat = "1.8.0"
junit = "4.13.2"
mockito = "5.12.0"
mockito = "5.24.0"
diffutils = "1.3.0"
testRunner = "1.6.2"
testRunner = "1.7.0"
jp2Android = "1.0.5"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
compileSdk = (project.findProperty("ANDROID_BUILD_SDK_VERSION") as String?)?.toInt() ?: 37

defaultConfig {
minSdk = (project.findProperty("ANDROID_BUILD_MIN_SDK_VERSION") as String?)?.toInt() ?: 21
minSdk = (project.findProperty("ANDROID_BUILD_MIN_SDK_VERSION") as String?)?.toInt() ?: 23
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["notAnnotation"] = "androidx.test.filters.FlakyTest"
consumerProguardFiles("consumer-proguard-rules.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public static InputStream getStream(String path) throws IOException
{
if (ASSET_MANAGER == null)
{
Log.e("PdfBox-Android",
"PDFBoxResourceLoader is not initialized, call PDFBoxResourceLoader.init() before use");
throw new IOException("PDFBoxResourceLoader is not initialized, call PDFBoxResourceLoader.init() before use");
}
return ASSET_MANAGER.open(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ else if (name == COSName.DEVICERGB)
{
return PDDeviceRGB.INSTANCE;
}
else if (name == COSName.DEVICEGRAY)
else if (name == COSName.DEVICEGRAY || name == COSName.CALGRAY)
{
return PDDeviceGray.INSTANCE;
}
Expand Down Expand Up @@ -169,8 +169,8 @@ else if (colorSpace instanceof COSArray)
if (name == COSName.CALGRAY)
{
// return new PDCalGray(array); TODO: PdfBox-Android
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
Log.w("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceGray instead");
return PDDeviceGray.INSTANCE;
}
else if (name == COSName.CALRGB)
{
Expand All @@ -186,15 +186,13 @@ else if (name == COSName.DEVICEN)
}
else if (name == COSName.INDEXED)
{
// return new PDIndexed(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
return new PDIndexed(array, resources);
}
else if (name == COSName.SEPARATION)
{
// return new PDSeparation(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
Log.w("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceGray instead");
return PDDeviceGray.INSTANCE;
}
else if (name == COSName.ICCBASED)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,31 @@ public Bitmap toRGBImage(Bitmap raster) throws IOException
{
int width = raster.getWidth();
int height = raster.getHeight();
int[] imgPixels = new int[width];
final int maxChunkPixels = 262144;
final int chunkRows = Math.min(height, Math.max(1, maxChunkPixels / width));
final int bufferSize = chunkRows * width;
int[] imgPixels = new int[bufferSize];
int[] outPixels = new int[bufferSize];
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] outPixels = new int[width];

for (int y = 0; y < height; y++)
for (int y = 0; y < height; y += chunkRows)
{
raster.getPixels(imgPixels, 0, width, 0, y, width, 1);
for (int x = 0; x < width; x++)
int currentChunkRows = Math.min(chunkRows, height - y);
int currentPixelCount = currentChunkRows * width;
raster.getPixels(imgPixels, 0, width, 0, y, width, currentChunkRows);
for (int i = 0; i < currentPixelCount; i++)
{
int pixel = imgPixels[x];
int pixel = imgPixels[i];
float c = android.graphics.Color.red(pixel) / 255.0f;
float m = android.graphics.Color.green(pixel) / 255.0f;
float yVal = android.graphics.Color.blue(pixel) / 255.0f;
float k = android.graphics.Color.alpha(pixel) / 255.0f;
int r = Math.round(255 * (1 - c) * (1 - k));
int g = Math.round(255 * (1 - m) * (1 - k));
int b = Math.round(255 * (1 - yVal) * (1 - k));
outPixels[x] = android.graphics.Color.argb(255, r, g, b);
outPixels[i] = android.graphics.Color.argb(255, r, g, b);
}
image.setPixels(outPixels, 0, width, 0, y, width, 1);
image.setPixels(outPixels, 0, width, 0, y, width, currentChunkRows);
}
return image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,25 @@ public Bitmap toRGBImage(Bitmap raster) throws IOException

int width = raster.getWidth();
int height = raster.getHeight();
int[] imgPixels = new int[width];
final int maxChunkPixels = 262144;
final int chunkRows = Math.min(height, Math.max(1, maxChunkPixels / width));
final int bufferSize = chunkRows * width;
int[] imgPixels = new int[bufferSize];
int[] outPixels = new int[bufferSize];

Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] outPixels = new int[width];

int gray;
int rgb;
for (int y = 0; y < height; y++)
for (int y = 0; y < height; y += chunkRows)
{
raster.getPixels(imgPixels, 0, width, 0, y, width, 1);
for (int x = 0; x < width; x++)
int currentChunkRows = Math.min(chunkRows, height - y);
int currentPixelCount = currentChunkRows * width;
raster.getPixels(imgPixels, 0, width, 0, y, width, currentChunkRows);
for (int i = 0; i < currentPixelCount; i++)
{
gray = Color.alpha(imgPixels[x]);
rgb = Color.argb(255, gray, gray, gray);
outPixels[x] = rgb;
int gray = Color.alpha(imgPixels[i]);
outPixels[i] = Color.argb(255, gray, gray, gray);
}
image.setPixels(outPixels, 0, width, 0, y, width, 1);
image.setPixels(outPixels, 0, width, 0, y, width, currentChunkRows);
}

return image;
Expand Down
Loading
Loading