File: 2.t

package info (click to toggle)
libgraphics-tiff-perl 21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: perl: 3,783; ansic: 10; makefile: 3
file content (77 lines) | stat: -rw-r--r-- 2,424 bytes parent folder | download | duplicates (2)
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
use warnings;
use strict;
use Graphics::TIFF ':all';
use Test::More tests => 12;
use Test::Deep;
use File::Temp;
use File::Spec;
BEGIN { use_ok('Graphics::TIFF') }

#########################

like( Graphics::TIFF->GetVersion, qr/LIBTIFF, Version/, 'version string' );

my $version = Graphics::TIFF->get_version_scalar;
isnt $version, undef, 'version';

if ( $version < 4.000003 ) {
    plan skip_all => 'libtiff 4.0.3 or better required';
    exit;
}

ok( Graphics::TIFF->IsCODECConfigured(COMPRESSION_DEFLATE),
    'IsCODECConfigured' );
my $directory = File::Temp->newdir;

#########################

my $width        = 200;
my $height       = 200;
my $depth        = 1;
my $resolution   = 100;
my $bit_per_byte = 8;

# start with blank white image
my @buffer;
my $buffer_size = int( $width * $height / $bit_per_byte ) +
  ( $width * $height ) % $bit_per_byte;
for my $i ( 0 .. $buffer_size - 1 ) {
    $buffer[$i] = 0;
}
my $expected = pack "C*", @buffer;

# write TIFF
my $file = File::Spec->catfile( $directory, 'test.tif' );
my $tif = Graphics::TIFF->Open( $file, 'w' );
$tif->SetField( TIFFTAG_IMAGEWIDTH,      $width );
$tif->SetField( TIFFTAG_IMAGELENGTH,     $height );
$tif->SetField( TIFFTAG_SAMPLESPERPIXEL, $depth );
$tif->SetField( TIFFTAG_BITSPERSAMPLE,   $depth );
$tif->SetField( TIFFTAG_XRESOLUTION,     $resolution );
$tif->SetField( TIFFTAG_YRESOLUTION,     $resolution );
$tif->SetField( TIFFTAG_PHOTOMETRIC,     PHOTOMETRIC_MINISWHITE );
$tif->WriteEncodedStrip( 0, $expected, length($expected) );
$tif->WriteDirectory;
$tif->Close;

# read TIFF
$tif = Graphics::TIFF->Open( $file, 'r' );
my $stripsize = $tif->StripSize;
my $example   = '';
for my $i ( 0 .. $tif->NumberOfStrips - 1 ) {
    $example .= $tif->ReadEncodedStrip( $i, $stripsize );
}

is( $example,                                $expected,   'buffer' );
is( $tif->GetField(TIFFTAG_IMAGEWIDTH),      $width,      'IMAGEWIDTH' );
is( $tif->GetField(TIFFTAG_IMAGELENGTH),     $height,     'IMAGELENGTH' );
is( $tif->GetField(TIFFTAG_SAMPLESPERPIXEL), $depth,      'SAMPLESPERPIXEL' );
is( $tif->GetField(TIFFTAG_BITSPERSAMPLE),   $depth,      'BITSPERSAMPLE' );
is( $tif->GetField(TIFFTAG_XRESOLUTION),     $resolution, 'XRESOLUTION' );
is( $tif->GetField(TIFFTAG_YRESOLUTION),     $resolution, 'YRESOLUTION' );
is( $tif->GetField(TIFFTAG_PHOTOMETRIC), PHOTOMETRIC_MINISWHITE,
    'PHOTOMETRIC' );
$tif->Close;

#########################