You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2018/04/07 15:30:00 UTC
[jira] [Commented] (PDFBOX-4184) [PATCH]: Support simple lossless
compression of 16 bit RGB images
[ https://issues.apache.org/jira/browse/PDFBOX-4184?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16429420#comment-16429420 ]
Tilman Hausherr commented on PDFBOX-4184:
-----------------------------------------
Thanks... I'll commit this within the next few days... I managed to create such an image so we can also have a local test but I didn't manage to have a failure, i.e. a bad PDF like with the image from your issue:
{code}
ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_USHORT);
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT, 256, 256, 4, null);
BufferedImage image = new BufferedImage(colorModel, raster, false, null);
for (int x = 0; x < image.getWidth(); ++x)
{
for (int y = 0; y < image.getHeight(); ++y)
{
if (x == y)
{
switch (x % 4)
{
case 0:
image.setRGB(x, y, 0xFFFF0000);
break;
case 1:
image.setRGB(x, y, 0xFF00FF00);
break;
case 2:
image.setRGB(x, y, 0xFF0000FF);
break;
case 3:
image.setRGB(x, y, 0xFFFFFFFF);
break;
}
}
}
}
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(page);
try (PDPageContentStream cs = new PDPageContentStream(doc, page))
{
cs.drawImage(LosslessFactory.createFromImage(doc, image), 0f, page.getMediaBox().getHeight() - image.getHeight());
}
{code}
> [PATCH]: Support simple lossless compression of 16 bit RGB images
> -----------------------------------------------------------------
>
> Key: PDFBOX-4184
> URL: https://issues.apache.org/jira/browse/PDFBOX-4184
> Project: PDFBox
> Issue Type: Improvement
> Components: Writing
> Affects Versions: 2.0.9
> Reporter: Emmeran Seehuber
> Priority: Minor
> Fix For: 2.0.10, 3.0.0 PDFBox
>
> Attachments: pdfbox_support_16bit_image_write.patch
>
>
> The attached patch add support to write 16 bit per component images correctly. I've integrated a test for this here: [https://github.com/rototor/pdfbox-graphics2d/commit/8bf089cb74945bd4f0f15054754f51dd5b361fe9]
> It only supports 16-Bit TYPE_CUSTOM with DataType == USHORT images - but this is what you usually get when you read a 16 bit PNG file.
> This would also fix [https://github.com/danfickle/openhtmltopdf/issues/173].
> The patch is against 2.0.9, but should apply to 3.0.0 too.
> There is still some room for improvements when writing lossless images, as the images are currently not efficiently encoded. I.e. you could use PNG encodings to get a better compression. (By adding a COSName.DECODE_PARMS with a COSName.PREDICTOR == 15 and encoding the images as PNG). But this is something for a later patch. It would also need another API, as there is a tradeoff speed vs compression ratio.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org