File: fuzz.pl

package info (click to toggle)
exactimage 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,040 kB
  • sloc: cpp: 35,940; ansic: 1,952; xml: 1,447; makefile: 338; perl: 138; sh: 110; python: 45; php: 37; ruby: 12
file content (60 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download
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
# ExactImage Perl Example
# Copyright (C) 2008 Rene Rebe, ExactCODE GmbH

use strict;

# the ExactImage module
use lib './objdir/api/perl';

use Math::Trig;
use ExactImage;

# create an ExactImage
my $image = ExactImage::newImage ();

# easy use, use on-disc files:

if (ExactImage::decodeImageFile ($image, "testsuite/281-4.2.04.tif"))
{
	print "image decoded all fine.\n";
} else {
	print "something went wrong ...\n";
	exit;
}

my $width = ExactImage::imageWidth($image);
my $height = ExactImage::imageHeight($image);

my $i = 0;

# TODO: a loop over all common color spaces
# ExactImage::imageConvertColorspace($image, "gray1");

for (my $n = 100; $n > 0; $n--, $i++)
{
  my $x = int rand(2 * $width) - $width;
  my $y = int rand(2 * $height) - $height;
  my $w = int rand($width);
  my $h = int rand($height);
  my $a = rand(2*pi) - pi;
  
  print ("crop: $x $y $w $h $a\n");
  
  my $newimage = ExactImage::copyImageCropRotate($image, $x, $y, $w, $h, $a);
  
  if (ExactImage::encodeImageFile ($newimage, "fuzz-out-$i.pnm"))
    {
      print "image written all fine.\n";
    } else {
      print "something went wrong writing the image ...\n";
      exit;
    }
  ExactImage::deleteImage ($newimage);
}


# we do not want to leak memory, always delete the image
# when you are done with it!
ExactImage::deleteImage ($image);

print "ok, here the example ends (for now) ...\n";