xref: /imagick/imagickpixeliterator_class.c (revision 3e8bdc15)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5 / Imagick	                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 2006-2013 Mikko Koppanen, Scott MacVicar               |
6    | ImageMagick (c) ImageMagick Studio LLC                               |
7    +----------------------------------------------------------------------+
8    | This source file is subject to version 3.01 of the PHP license,      |
9    | that is bundled with this package in the file LICENSE, and is        |
10    | available through the world-wide-web at the following url:           |
11    | http://www.php.net/license/3_01.txt                                  |
12    | If you did not receive a copy of the PHP license and are unable to   |
13    | obtain it through the world-wide-web, please send a note to          |
14    | license@php.net so we can mail you a copy immediately.               |
15    +----------------------------------------------------------------------+
16    | Author: Mikko Kopppanen <mkoppanen@php.net>                          |
17    |         Scott MacVicar <scottmac@php.net>                            |
18    +----------------------------------------------------------------------+
19 */
20 
21 #include "php_imagick.h"
22 #include "php_imagick_defs.h"
23 #include "php_imagick_macros.h"
24 #include "php_imagick_helpers.h"
25 
26 #if MagickLibVersion <= 0x628
27 static
s_count_pixeliterator_rows(php_imagickpixeliterator_object * internpix)28 long s_count_pixeliterator_rows(php_imagickpixeliterator_object *internpix)
29 {
30 	long rows = 0, tmp;
31 	PixelWand **row;
32 	PixelResetIterator(internpix->pixel_iterator);
33 
34 	while ((row = PixelGetNextIteratorRow(internpix->pixel_iterator, &tmp)) != NULL)
35 		rows++;
36 
37 	return rows;
38 }
39 #endif
40 
php_imagick_pixel_iterator_new(PixelIterator * pixel_it,zval * return_value TSRMLS_DC)41 void php_imagick_pixel_iterator_new (PixelIterator *pixel_it, zval *return_value TSRMLS_DC)
42 {
43 	php_imagickpixeliterator_object *internpix;
44 
45 	object_init_ex(return_value, php_imagickpixeliterator_sc_entry);
46 	internpix = Z_IMAGICKPIXELITERATOR_P(return_value);
47 
48 	internpix->pixel_iterator = pixel_it;
49 	internpix->initialized = 1;
50 
51 #if MagickLibVersion <= 0x628
52 	internpix->rows = s_count_pixeliterator_rows (internpix);
53 #endif
54 }
55 
56 /* {{{ proto ImagickPixelIterator ImagickPixelIterator::__construct(Imagick source)
57    The ImagickPixelIterator constructor
58 */
PHP_METHOD(ImagickPixelIterator,__construct)59 PHP_METHOD(ImagickPixelIterator, __construct)
60 {
61 	zval *magick_object;
62 	php_imagickpixeliterator_object *internpix;
63 	php_imagick_object *intern;
64 
65 	/* Parse parameters given to function */
66 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|llll", &magick_object, php_imagick_sc_entry) == FAILURE) {
67 		return;
68 	}
69 
70 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
71 	intern = Z_IMAGICK_P(magick_object);
72 
73 	if (!intern->magick_wand) {
74 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Invalid Imagick object passed" TSRMLS_CC);
75 		return;
76 	}
77 
78 	if (php_imagick_ensure_not_empty (intern->magick_wand) == 0)
79 		return;
80 
81 	internpix->pixel_iterator = NewPixelIterator(intern->magick_wand);
82 
83 	if (!internpix->pixel_iterator) {
84 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Can not allocate ImagickPixelIterator" TSRMLS_CC);
85 		return;
86 	}
87 
88 #if MagickLibVersion <= 0x628
89 	internpix->rows = s_count_pixeliterator_rows (internpix);
90 #endif
91 
92 	internpix->initialized = 1;
93 	RETURN_TRUE;
94 }
95 /* }}} */
96 
97 /* {{{ proto bool ImagickPixelIterator::resetIterator()
98 	Resets the pixel iterator.  Use it in conjunction with PixelGetNextIteratorRow() to iterate over all the pixels in a pixel container.
99 */
PHP_METHOD(ImagickPixelIterator,resetIterator)100 PHP_METHOD(ImagickPixelIterator, resetIterator)
101 {
102 	php_imagickpixeliterator_object *internpix;
103 
104 	if (zend_parse_parameters_none() == FAILURE) {
105 		return;
106 	}
107 
108 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
109 
110 	if (!internpix->initialized) {
111 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
112 		return;
113 	}
114 
115 	PixelResetIterator(internpix->pixel_iterator);
116 #if MagickLibVersion <= 0x628
117 	internpix->iterator_position = 0;
118 #endif
119 	RETURN_TRUE;
120 }
121 /* }}} */
122 
123 /* {{{ proto bool ImagickPixelIterator::syncIterator()
124 	Syncs the pixel iterator.
125 */
PHP_METHOD(ImagickPixelIterator,syncIterator)126 PHP_METHOD(ImagickPixelIterator, syncIterator)
127 {
128 	php_imagickpixeliterator_object *internpix;
129 
130 	if (zend_parse_parameters_none() == FAILURE) {
131 		return;
132 	}
133 
134 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
135 
136 	if (!internpix->initialized) {
137 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
138 		return;
139 	}
140 
141 	PixelSyncIterator(internpix->pixel_iterator);
142 	RETURN_TRUE;
143 }
144 /* }}} */
145 
146 /* {{{ proto bool ImagickPixelIterator::setIteratorFirstRow()
147 	Sets the pixel iterator to the first pixel row.
148 */
PHP_METHOD(ImagickPixelIterator,setIteratorFirstRow)149 PHP_METHOD(ImagickPixelIterator, setIteratorFirstRow)
150 {
151 	php_imagickpixeliterator_object *internpix;
152 
153 	if (zend_parse_parameters_none() == FAILURE) {
154 		return;
155 	}
156 
157 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
158 
159 	if (!internpix->initialized) {
160 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
161 		return;
162 	}
163 
164 	PixelSetFirstIteratorRow(internpix->pixel_iterator);
165 #if MagickLibVersion <= 0x628
166 	internpix->iterator_position = 0;
167 #endif
168 	RETURN_TRUE;
169 }
170 /* }}} */
171 
172 /* {{{ proto bool ImagickPixelIterator::setIteratorLastRow()
173 	Sets the pixel iterator to the last pixel row.
174 */
PHP_METHOD(ImagickPixelIterator,setIteratorLastRow)175 PHP_METHOD(ImagickPixelIterator, setIteratorLastRow)
176 {
177 	php_imagickpixeliterator_object *internpix;
178 
179 	if (zend_parse_parameters_none() == FAILURE) {
180 		return;
181 	}
182 
183 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
184 
185 	if (!internpix->initialized) {
186 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
187 		return;
188 	}
189 
190 	PixelSetLastIteratorRow(internpix->pixel_iterator);
191 #if MagickLibVersion <= 0x628
192 	internpix->iterator_position = (internpix->rows - 1);
193 #endif
194 	RETURN_TRUE;
195 }
196 /* }}} */
197 
198 /* {{{ proto ImagickPixelIterator ImagickPixelIterator::getPixelIterator(Imagick source)
199 	Returns a new pixel iterator, static method. This is equivalent to Imagick::getPixelIterator
200 	which probably ought to be used in preference to this method.
201 */
PHP_METHOD(ImagickPixelIterator,getPixelIterator)202 PHP_METHOD(ImagickPixelIterator, getPixelIterator)
203 {
204 	PixelIterator *pixel_it;
205 	zval *magick_object;
206 	php_imagick_object *intern;
207 
208 	/* Parse parameters given to function */
209 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &magick_object, php_imagick_sc_entry) == FAILURE) {
210 		return;
211 	}
212 
213 	intern = Z_IMAGICK_P(magick_object);
214 
215 	if (!intern->magick_wand) {
216 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Invalid Imagick object passed" TSRMLS_CC);
217 		return;
218 	}
219 
220 	if (php_imagick_ensure_not_empty (intern->magick_wand) == 0)
221 		return;
222 
223 	pixel_it = NewPixelIterator (intern->magick_wand);
224 	if (!pixel_it) {
225 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Can not allocate ImagickPixelIterator" TSRMLS_CC);
226 		return;
227 	}
228 
229 	php_imagick_pixel_iterator_new (pixel_it, return_value TSRMLS_CC);
230 	return;
231 }
232 /* }}} */
233 
234 /* {{{ proto ImagickPixelIterator ImagickPixelIterator::newPixelIterator(Imagick source)
235 	Returns a new pixel iterator.
236 */
PHP_METHOD(ImagickPixelIterator,newPixelIterator)237 PHP_METHOD(ImagickPixelIterator, newPixelIterator)
238 {
239 	PixelIterator *pixel_it;
240 	zval *magick_object;
241 	php_imagickpixeliterator_object *internpix;
242 	php_imagick_object *intern;
243 
244 	/* Parse parameters given to function */
245 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &magick_object, php_imagick_sc_entry) == FAILURE) {
246 		return;
247 	}
248 
249 	IMAGICK_METHOD_DEPRECATED_USE_INSTEAD("ImagickPixelIterator", "newPixelIterator", "ImagickPixelIterator", "getPixelIterator");
250 
251 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis() );
252 	intern = Z_IMAGICK_P(magick_object);
253 
254 	if (!intern->magick_wand) {
255 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Invalid Imagick object passed" TSRMLS_CC);
256 		return;
257 	}
258 
259 	if (php_imagick_ensure_not_empty (intern->magick_wand) == 0)
260 		return;
261 
262 	pixel_it = NewPixelIterator(intern->magick_wand);
263 
264 	if (!pixel_it) {
265 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Can not allocate ImagickPixelIterator" TSRMLS_CC);
266 		return;
267 	}
268 
269 	if (internpix->initialized && internpix->pixel_iterator)
270 		DestroyPixelIterator (internpix->pixel_iterator);
271 
272 	internpix->pixel_iterator = pixel_it;
273 #if MagickLibVersion <= 0x628
274 	internpix->rows = s_count_pixeliterator_rows (internpix);
275 #endif
276 
277 	internpix->initialized = 1;
278 	RETURN_TRUE;
279 }
280 /* }}} */
281 
282 /* {{{ proto ImagickPixelIterator ImagickPixelIterator::getPixelRegionIterator(Imagick source, int x, int y, int columns, int rows)
283 	Returns a new pixel region iterator, static method. This is equivalent to the non-static
284 	Imagick::getPixelRegionIterator which ought to be used in preference to this method.
285 */
PHP_METHOD(ImagickPixelIterator,getPixelRegionIterator)286 PHP_METHOD(ImagickPixelIterator, getPixelRegionIterator)
287 {
288 	PixelIterator *pixel_it;
289 	zval *magick_object;
290 	php_imagick_object *intern;
291 	long x, y, columns, rows;
292 
293 	/* Parse parameters given to function */
294 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ollll", &magick_object, php_imagick_sc_entry, &x, &y, &columns, &rows) == FAILURE) {
295 		return;
296 	}
297 
298 	intern = Z_IMAGICK_P(magick_object);
299 
300 	if (!intern->magick_wand) {
301 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Invalid Imagick object passed" TSRMLS_CC);
302 		return;
303 	}
304 
305 	if (php_imagick_ensure_not_empty (intern->magick_wand) == 0)
306 		return;
307 
308 	pixel_it = NewPixelRegionIterator(intern->magick_wand, x, y, columns, rows);
309 	if (!pixel_it) {
310 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Can not allocate ImagickPixelIterator" TSRMLS_CC);
311 		return;
312 	}
313 
314 	php_imagick_pixel_iterator_new (pixel_it, return_value TSRMLS_CC);
315 	return;
316 }
317 /* }}} */
318 
319 /* {{{ proto bool ImagickPixelIterator::newPixelRegionIterator(Imagick source, int x, int y, int columns, int rows)
320 	Returns a new pixel iterator.
321 */
PHP_METHOD(ImagickPixelIterator,newPixelRegionIterator)322 PHP_METHOD(ImagickPixelIterator, newPixelRegionIterator)
323 {
324 	PixelIterator *pixel_it;
325 	zval *magick_object;
326 	php_imagickpixeliterator_object *internpix;
327 	php_imagick_object *intern;
328 	long x, y, columns, rows;
329 
330 	/* Parse parameters given to function */
331 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ollll", &magick_object, php_imagick_sc_entry, &x, &y, &columns, &rows) == FAILURE) {
332 		return;
333 	}
334 
335 	IMAGICK_METHOD_DEPRECATED_USE_INSTEAD("ImagickPixelIterator", "newPixelRegionIterator", "ImagickPixelIterator", "getPixelRegionIterator");
336 
337 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
338 	intern = Z_IMAGICK_P(magick_object);
339 
340 	if (!intern->magick_wand) {
341 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Invalid Imagick object passed" TSRMLS_CC);
342 		return;
343 	}
344 
345 	if (php_imagick_ensure_not_empty (intern->magick_wand) == 0)
346 		return;
347 
348 	pixel_it = NewPixelRegionIterator(intern->magick_wand, x, y, columns, rows);
349 
350 	if (!pixel_it) {
351 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "Can not allocate ImagickPixelIterator" TSRMLS_CC);
352 		return;
353 	}
354 
355 	if (internpix->initialized && internpix->pixel_iterator)
356 		DestroyPixelIterator (internpix->pixel_iterator);
357 
358 	internpix->pixel_iterator = pixel_it;
359 
360 #if MagickLibVersion <= 0x628
361 	internpix->rows = s_count_pixeliterator_rows (internpix);
362 #endif
363 	internpix->initialized = 1;
364 	RETURN_TRUE;
365 }
366 /* }}} */
367 
368 /* {{{ proto int ImagickPixelIterator::getIteratorRow()
369 	Returns the crurent pixel iterator row.
370 */
PHP_METHOD(ImagickPixelIterator,getIteratorRow)371 PHP_METHOD(ImagickPixelIterator, getIteratorRow)
372 {
373 	php_imagickpixeliterator_object *internpix;
374 
375 	if (zend_parse_parameters_none() == FAILURE) {
376 		return;
377 	}
378 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
379 
380 	if (!internpix->initialized) {
381 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
382 		return;
383 	}
384 
385 #if MagickLibVersion <= 0x628
386 	ZVAL_LONG(return_value, internpix->iterator_position);
387 #else
388 	ZVAL_LONG(return_value, (long) PixelGetIteratorRow(internpix->pixel_iterator));
389 #endif
390 	return;
391 }
392 /* }}} */
393 
394 /* {{{ proto bool ImagickPixelIterator::setIteratorRow(int row)
395 	Set the pixel iterator row.
396 */
PHP_METHOD(ImagickPixelIterator,setIteratorRow)397 PHP_METHOD(ImagickPixelIterator, setIteratorRow)
398 {
399 	php_imagickpixeliterator_object *internpix;
400 	MagickBooleanType status;
401 	long row;
402 
403 	/* Parse parameters given to function */
404 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &row) == FAILURE) {
405 		return;
406 	}
407 
408 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
409 
410 	if (!internpix->initialized) {
411 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
412 		return;
413 	}
414 
415 	status = PixelSetIteratorRow(internpix->pixel_iterator, row);
416 
417 	if (status == MagickFalse) {
418 		php_imagick_convert_imagickpixeliterator_exception(internpix->pixel_iterator, "Unable to set iterator row" TSRMLS_CC);
419 		return;
420 	}
421 #if MagickLibVersion <= 0x628
422 	internpix->iterator_position = row;
423 #endif
424 	RETURN_TRUE;
425 }
426 /* }}} */
427 
428 static
s_pixelwands_to_zval(PixelWand ** wand_array,unsigned long num_wands,zval * return_value TSRMLS_DC)429 void s_pixelwands_to_zval (PixelWand **wand_array, unsigned long num_wands, zval *return_value TSRMLS_DC)
430 {
431 	php_imagickpixel_object *internp;
432 #if PHP_VERSION_ID >= 70000
433 	zval obj;
434 #else
435 	zval *obj;
436 #endif
437 
438 	unsigned long i;
439 
440 	array_init(return_value);
441 
442 	for (i = 0; i < num_wands; i++) {
443 #if PHP_VERSION_ID >= 70000
444 		object_init_ex(&obj, php_imagickpixel_sc_entry);
445 		internp = Z_IMAGICKPIXEL_P(&obj);
446 #else
447 		MAKE_STD_ZVAL(obj);
448 		object_init_ex(obj, php_imagickpixel_sc_entry);
449 		internp = Z_IMAGICKPIXEL_P(obj);
450 #endif
451 
452 		internp->initialized_via_iterator = 1;
453 
454 		php_imagick_replace_pixelwand(internp, wand_array[i]);
455 #if PHP_VERSION_ID >= 70000
456 		add_next_index_zval(return_value, &obj);
457 #else
458 		add_next_index_zval(return_value, obj);
459 #endif
460 	}
461 
462 }
463 
464 /* {{{ proto array ImagickPixelIterator::getPreviousIteratorRow()
465 	Returns the previous row as an array of pixel wands from the pixel iterator.
466 */
PHP_METHOD(ImagickPixelIterator,getPreviousIteratorRow)467 PHP_METHOD(ImagickPixelIterator, getPreviousIteratorRow)
468 {
469 	php_imagickpixeliterator_object *internpix;
470 	PixelWand **wand_array;
471 	size_t num_wands;
472 
473 	if (zend_parse_parameters_none() == FAILURE) {
474 		return;
475 	}
476 
477 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
478 
479 	if (!internpix->initialized) {
480 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
481 		return;
482 	}
483 
484 	wand_array = PixelGetPreviousIteratorRow(internpix->pixel_iterator, &num_wands);
485 
486 #if MagickLibVersion <= 0x628
487 	if (internpix->iterator_position > 0) {
488 		internpix->iterator_position--;
489 	}
490 #endif
491 
492 	if (!wand_array) {
493 		RETURN_NULL();
494 	}
495 
496 	s_pixelwands_to_zval (wand_array, num_wands, return_value TSRMLS_CC);
497 	return;
498 }
499 /* }}} */
500 
501 
502 /* {{{ proto array ImagickPixelIterator::getCurrentIteratorRow()
503 	Returns the current row as an array of pixel wands from the pixel iterator.
504 */
PHP_METHOD(ImagickPixelIterator,getCurrentIteratorRow)505 PHP_METHOD(ImagickPixelIterator, getCurrentIteratorRow)
506 {
507 	php_imagickpixeliterator_object *internpix;
508 	PixelWand **wand_array;
509 	size_t num_wands;
510 
511 	if (zend_parse_parameters_none() == FAILURE) {
512 		return;
513 	}
514 
515 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
516 
517 	if (!internpix->initialized) {
518 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
519 		return;
520 	}
521 
522 #if MagickLibVersion <= 0x628
523 	if (internpix->iterator_position >= internpix->rows) {
524 		RETURN_NULL();
525 	} else if (internpix->iterator_position != 0) {
526 		long tmp;
527 		(void)PixelGetPreviousIteratorRow(internpix->pixel_iterator, &tmp);
528 	}
529 	wand_array = PixelGetNextIteratorRow(internpix->pixel_iterator, &num_wands);
530 #else
531 	wand_array = PixelGetCurrentIteratorRow(internpix->pixel_iterator, &num_wands);
532 #endif
533 
534 	if (!wand_array) {
535 		RETURN_NULL();
536 	}
537 
538 	s_pixelwands_to_zval (wand_array, num_wands, return_value TSRMLS_CC);
539 	return;
540 }
541 /* }}} */
542 
543 /* {{{ proto array ImagickPixelIterator::getNextIteratorRow()
544 	Returns the next row as an array of pixel wands from the pixel iterator.
545 */
PHP_METHOD(ImagickPixelIterator,getNextIteratorRow)546 PHP_METHOD(ImagickPixelIterator, getNextIteratorRow)
547 {
548 	php_imagickpixeliterator_object *internpix;
549 	PixelWand **wand_array;
550 	size_t num_wands;
551 
552 	if (zend_parse_parameters_none() == FAILURE) {
553 		return;
554 	}
555 
556 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
557 
558 	if (!internpix->initialized) {
559 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
560 		return;
561 	}
562 
563 	wand_array = PixelGetNextIteratorRow(internpix->pixel_iterator, &num_wands);
564 
565 #if MagickLibVersion <= 0x628
566 	internpix->iterator_position++;
567 #endif
568 
569 	if (!wand_array) {
570 		RETURN_NULL();
571 	}
572 
573 	s_pixelwands_to_zval (wand_array, num_wands, return_value TSRMLS_CC);
574 	return;
575 }
576 /* }}} */
577 
578 /* {{{ proto bool ImagickPixelIterator::clear()
579 	Clear resources associated with a PixelIterator.
580 */
PHP_METHOD(ImagickPixelIterator,clear)581 PHP_METHOD(ImagickPixelIterator, clear)
582 {
583 	php_imagickpixeliterator_object *internpix;
584 
585 	if (zend_parse_parameters_none() == FAILURE) {
586 		return;
587 	}
588 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
589 
590 	if (!internpix->initialized) {
591 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
592 		return;
593 	}
594 /* Assertion failure with earlier versions */
595 #if MagickLibVersion <= 0x628
596 	RETURN_TRUE;
597 #else
598 	ClearPixelIterator(internpix->pixel_iterator);
599 	RETURN_TRUE;
600 #endif
601 }
602 /* }}} */
603 
604 /* {{{ proto bool ImagickPixelIterator::valid()
605 	The if the current iterator row is valid
606 */
PHP_METHOD(ImagickPixelIterator,valid)607 PHP_METHOD(ImagickPixelIterator, valid)
608 {
609 	php_imagickpixeliterator_object *internpix;
610 
611 	if (zend_parse_parameters_none() == FAILURE) {
612 		return;
613 	}
614 
615 	internpix = Z_IMAGICKPIXELITERATOR_P(getThis());
616 
617 	if (!internpix->initialized) {
618 		php_imagick_throw_exception (IMAGICKPIXELITERATOR_CLASS, "ImagickPixelIterator is not initialized correctly" TSRMLS_CC);
619 		return;
620 	}
621 #if MagickLibVersion <= 0x628
622 	if (internpix->iterator_position < internpix->rows) {
623 		RETURN_TRUE;
624 	}
625 #else
626 	/* Test if the current row is valid */
627 	if (PixelSetIteratorRow(internpix->pixel_iterator, PixelGetIteratorRow(internpix->pixel_iterator))) {
628 		 RETURN_TRUE;
629 	}
630 #endif
631 	RETURN_FALSE;
632 }
633 /* }}} */
634 
635 /* END OF PIXELITERATOR */
636