Inverse colors when converting png -> pdf

Bug #1063198 reported by Jesusfreak on 2012-10-07
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libpdf-api2-perl (Ubuntu)
Medium
Unassigned

Bug Description

I have a b/w png file which I want to convert to pdf. For compression I choose "LZW". The pdf generated by gscan2pdf has inverted colors, which it shouldn't have. (see files attached)

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: gscan2pdf 0.9.32-1
ProcVersionSignature: Ubuntu 3.2.0-31.50-generic 3.2.28
Uname: Linux 3.2.0-31-generic x86_64
NonfreeKernelModules: fglrx
ApportVersion: 2.0.1-0ubuntu13
Architecture: amd64
Date: Sun Oct 7 13:39:02 2012
EcryptfsInUse: Yes
InstallationMedia: Xubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
PackageArchitecture: all
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: gscan2pdf
UpgradeStatus: No upgrade log present (probably fresh install)

Jesusfreak (launchpad-bikelab) wrote :
Jesusfreak (launchpad-bikelab) wrote :
Dave Gilbert (ubuntu-treblig) wrote :

Confirmed on 1.0.4-5 on quantal.

Changed in gscan2pdf (Ubuntu):
importance: Undecided → Medium
status: New → Confirmed

I confirm the bug, which I assume to be in libpdf-api2 - perl, but I'll have to work up a script to demonstrate.

In the mean time, using PNG or automatic compression is a workaround.

In this case, PNG or automatic compression produces a PDF half the size of that from LZW.

Another problem is that although input.png is black & white, it has a depth of 8. Thresholding first produces a PDF with correct colours and 10x smaller:

input-LZW-depth8.pdf 6289138
input-PNG-depth8.pdf 3285386
input-depth1.pdf 461471

For me, unchecking downsampling option is also a workaround. It seems that libpdf-api2-perl doesn't like

convert -depth 8 -resize 516x730 input.png input.tif

Then the script below with PDF::API2 produces the inverted colours.

input.png[1] PNG 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 226KB 0.000u 0:00.000
input.tif[2] TIFF 516x730 516x730+0+0 8-bit DirectClass 228KB 0.000u 0:00.000

Without the -resize option, the colours are fine.

input.png[1] PNG 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 226KB 0.000u 0:00.009
input.tif[2] TIFF 2481x3508 2481x3508+0+0 8-bit PseudoClass 256c 239KB 0.000u 0:00.000

So it looks as though libpdf-api2-perl doesn't like DirectClass TIFFs:

convert -depth 8 -resize 516x730 -type palette input.png input.tif

input.tif TIFF 516x730 516x730+0+0 8-bit PseudoClass 256c 93.5KB 0.000u 0:00.000

And yes - the colours are then correct.

#!/usr/bin/perl -w
use strict;
use PDF::API2;
use Image::Magick;
my $pdf = PDF::API2-> new(-file => 'test.pdf');
my $image = Image::Magick->new;
$image->Read('input.tif');
my $resolution = $image->Get('x-resolution');
my $w = $image->Get('width') / $resolution;
my $h = $image->Get('height') / $resolution;
my $page = $pdf->page;
$page->mediabox( $w * 72, $h * 72 );
my $gfx = $page->gfx;
my $img = $pdf->image_tiff($tiff);
$gfx->image( $img, 0, 0, $w * 72, $h * 72 );
$pdf->save;
$pdf->end;

affects: gscan2pdf (Ubuntu) → libpdf-api2-perl (Ubuntu)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers