/usr/share/perl5/PDF/API2/Resource/XObject/Image/JPEG.pm is in libpdf-api2-perl 2.025-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | package PDF::API2::Resource::XObject::Image::JPEG;
our $VERSION = '2.025'; # VERSION
use base 'PDF::API2::Resource::XObject::Image';
use IO::File;
use PDF::API2::Util;
use PDF::API2::Basic::PDF::Utils;
no warnings qw[ deprecated recursion uninitialized ];
sub new
{
my ($class,$pdf,$file,$name) = @_;
my $self;
my $fh = IO::File->new;
$class = ref $class if ref $class;
$self=$class->SUPER::new($pdf,$name|| 'Jx'.pdfkey());
$pdf->new_obj($self) unless($self->is_obj($pdf));
$self->{' apipdf'}=$pdf;
if(ref $file)
{
$fh=$file;
}
else
{
open($fh,$file);
}
binmode($fh,':raw');
$self->read_jpeg($fh);
if(ref $file)
{
seek($fh,0,0);
$self->{' stream'}='';
my $buf='';
while(!eof($fh)) {
read($fh,$buf,512);
$self->{' stream'}.=$buf;
}
$self->{Length}=PDFNum(length $self->{' stream'});
}
else
{
$self->{Length}=PDFNum(-s $file);
$self->{' streamfile'}=$file;
}
$self->filters('DCTDecode');
$self->{' nofilt'}=1;
return($self);
}
sub new_api {
my ($class,$api,@opts)=@_;
my $obj=$class->new($api->{pdf},@opts);
$obj->{' api'}=$api;
return($obj);
}
sub read_jpeg {
my $self = shift @_;
my $fh = shift @_;
my ($buf, $p, $h, $w, $c, $ff, $mark, $len);
$fh->seek(0,0);
$fh->read($buf,2);
while (1) {
$fh->read($buf,4);
my($ff, $mark, $len) = unpack("CCn", $buf);
last if( $ff != 0xFF);
last if( $mark == 0xDA || $mark == 0xD9); # SOS/EOI
last if( $len < 2);
last if( $fh->eof);
$fh->read($buf,$len-2);
next if ($mark == 0xFE);
next if ($mark >= 0xE0 && $mark <= 0xEF);
if (($mark >= 0xC0) && ($mark <= 0xCF) &&
($mark != 0xC4) && ($mark != 0xC8) && ($mark != 0xCC)) {
($p, $h, $w, $c) = unpack("CnnC", substr($buf, 0, 6));
last;
}
}
$self->width($w);
$self->height($h);
$self->bpc($p);
if($c==3) {
$self->colorspace('DeviceRGB');
} elsif($c==4) {
$self->colorspace('DeviceCMYK');
} elsif($c==1) {
$self->colorspace('DeviceGray');
}
return($self);
}
1;
|