xref: /imagick/tests/020-pixeliterator.phpt (revision f970f3cf)
1--TEST--
2Pixel Iterator tests
3--SKIPIF--
4<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5--FILE--
6<?php
7
8function count_rows ($pix)
9{
10	$rows = 0;
11
12	foreach ($pix as $r)
13		$rows++;
14
15	return $rows;
16}
17
18function count_objects ($pix)
19{
20	$objects = 0;
21
22	foreach ($pix as $r)
23		foreach ($r as $o)
24			$objects++;
25
26	return $objects;
27}
28
29function count_objects_with_iterator ($pixelRegion)
30{
31	$objects = 0;
32	$row = 0;
33
34	$pixelRegion->rewind();
35	$pixelRegion->resetIterator();
36
37	while($pixelRow = $pixelRegion->current()) {
38		$row++;
39		foreach ($pixelRow as $pixel) {
40			$objects++;
41		}
42
43		$pixelRegion->syncIterator();
44		$pixelRegion->next();
45		if (!$pixelRegion->valid()) {
46			break;
47		}
48	}
49
50	return $objects;
51}
52
53$im = new Imagick ('magick:rose');
54$it1 = new ImagickPixelIterator ($im);
55$it2 = ImagickPixelIterator::getPixelIterator ($im);
56$it3 = $im->getPixelIterator();
57
58
59$count1 = count_rows ($it1);
60$count2 = count_rows ($it2);
61$count3 = count_rows ($it3);
62
63if ($count1 != $count2 ||
64    $count1 != $count3) {
65    printf(
66        "Row counts do not match %d %d %d",
67        $count1,
68        $count2,
69        $count3
70    );
71}
72
73if ($count1 != $count2 ||
74    $count1 != $count3) {
75    printf(
76        "Object counts do not match %d %d %d",
77        $count1,
78        $count2,
79        $count3
80    );
81}
82
83$objects = array($it1, $it2, $it3);
84
85foreach ($objects as $object) {
86	$loop = 0;
87	$count = count_objects($object);
88	$countIterator = count_objects_with_iterator($object);
89	if ($countIterator != $count) {
90    	echo "Counting with iterator doesn't match counting with foreach $loop, $count != $countIterator.";
91    	$loop++;
92	}
93}
94
95
96$it1->newPixelIterator (new Imagick ('magick:rose'));
97
98echo 'done' . PHP_EOL;
99?>
100--EXPECTF--
101
102%s: ImagickPixelIterator::newPixelIterator is deprecated. ImagickPixelIterator::getPixelIterator should be used instead in %s on line %d
103done