Changeset 3080 for libpipi


Ignore:
Timestamp:
Oct 24, 2008, 1:20:18 AM (12 years ago)
Author:
nico
Message:

Add php binding for functions: pipi_render_histogram, pipi_get_image_histogram
Add a sample program: examples/histogram.php

Location:
libpipi/trunk/pipi-php
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi-php/php_pipi.c

    r3079 r3080  
    232232
    233233PHP_FUNCTION(pipi_copy) {
    234         pipi_image_t *src;
    235         FETCH_IMG(src);
    236         pipi_image_t *result;
     234        pipi_image_t *src, *result;
     235        FETCH_IMG(src);
    237236        result = pipi_copy(src);
    238237        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    310309                RETURN_FALSE;
    311310        }
    312         pipi_image_t *src;
    313         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    314 
    315         pipi_image_t *result;
     311        pipi_image_t *src, *result;
     312        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     313
    316314        result = pipi_resize(src, width, height);
    317315        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    354352        }
    355353
    356         pipi_image_t *img_r, *img_g, *img_b;
     354        pipi_image_t *img_r, *img_g, *img_b, *result;
    357355        ZEND_FETCH_RESOURCE(img_r, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    358356        ZEND_FETCH_RESOURCE(img_g, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    359357        ZEND_FETCH_RESOURCE(img_b, pipi_image_t*, &_zval3, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    360358
    361         pipi_image_t *result;
    362359        result = pipi_rgb(img_r, img_g, img_b);
    363360        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    365362
    366363PHP_FUNCTION(pipi_red) {
    367         pipi_image_t *src;
    368         FETCH_IMG(src);
    369         pipi_image_t *result;
     364        pipi_image_t *src, *result;
     365        FETCH_IMG(src);
    370366        result = pipi_red(src);
    371367        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    373369
    374370PHP_FUNCTION(pipi_green) {
    375         pipi_image_t *src;
    376         FETCH_IMG(src);
    377         pipi_image_t *result;
     371        pipi_image_t *src, *result;
     372        FETCH_IMG(src);
    378373        result = pipi_green(src);
    379374        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    381376
    382377PHP_FUNCTION(pipi_blue) {
    383         pipi_image_t *src;
    384         FETCH_IMG(src);
    385         pipi_image_t *result;
     378        pipi_image_t *src, *result;
     379        FETCH_IMG(src);
    386380        result = pipi_blue(src);
    387381        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    389383
    390384PHP_FUNCTION(pipi_mean) {
    391         pipi_image_t *img1, *img2;
    392         FETCH_IMG_IMG(img1, img2);
    393         pipi_image_t *result;
     385        pipi_image_t *img1, *img2, *result;
     386        FETCH_IMG_IMG(img1, img2);
    394387        result = pipi_mean(img1, img2);
    395388        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    397390
    398391PHP_FUNCTION(pipi_min) {
    399         pipi_image_t *img1, *img2;
    400         FETCH_IMG_IMG(img1, img2);
    401         pipi_image_t *result;
     392        pipi_image_t *img1, *img2, *result;
     393        FETCH_IMG_IMG(img1, img2);
    402394        result = pipi_min(img1, img2);
    403395        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    405397
    406398PHP_FUNCTION(pipi_max) {
    407         pipi_image_t *img1, *img2;
    408         FETCH_IMG_IMG(img1, img2);
    409         pipi_image_t *result;
     399        pipi_image_t *img1, *img2, *result;
     400        FETCH_IMG_IMG(img1, img2);
    410401        result = pipi_max(img1, img2);
    411402        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    413404
    414405PHP_FUNCTION(pipi_add) {
    415         pipi_image_t *img1, *img2;
    416         FETCH_IMG_IMG(img1, img2);
    417         pipi_image_t *result;
     406        pipi_image_t *img1, *img2, *result;
     407        FETCH_IMG_IMG(img1, img2);
    418408        result = pipi_add(img1, img2);
    419409        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    421411
    422412PHP_FUNCTION(pipi_sub) {
    423         pipi_image_t *img1, *img2;
    424         FETCH_IMG_IMG(img1, img2);
    425         pipi_image_t *result;
     413        pipi_image_t *img1, *img2, *result;
     414        FETCH_IMG_IMG(img1, img2);
    426415        result = pipi_sub(img1, img2);
    427416        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    429418
    430419PHP_FUNCTION(pipi_difference) {
    431         pipi_image_t *img1, *img2;
    432         FETCH_IMG_IMG(img1, img2);
    433         pipi_image_t *result;
     420        pipi_image_t *img1, *img2, *result;
     421        FETCH_IMG_IMG(img1, img2);
    434422        result = pipi_difference(img1, img2);
    435423        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    437425
    438426PHP_FUNCTION(pipi_multiply) {
    439         pipi_image_t *img1, *img2;
    440         FETCH_IMG_IMG(img1, img2);
    441         pipi_image_t *result;
     427        pipi_image_t *img1, *img2, *result;
     428        FETCH_IMG_IMG(img1, img2);
    442429        result = pipi_multiply(img1, img2);
    443430        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    445432
    446433PHP_FUNCTION(pipi_divide) {
    447         pipi_image_t *img1, *img2;
    448         FETCH_IMG_IMG(img1, img2);
    449         pipi_image_t *result;
     434        pipi_image_t *img1, *img2, *result;
     435        FETCH_IMG_IMG(img1, img2);
    450436        result = pipi_divide(img1, img2);
    451437        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    453439
    454440PHP_FUNCTION(pipi_screen) {
    455         pipi_image_t *img1, *img2;
    456         FETCH_IMG_IMG(img1, img2);
    457         pipi_image_t *result;
     441        pipi_image_t *img1, *img2, *result;
     442        FETCH_IMG_IMG(img1, img2);
    458443        result = pipi_screen(img1, img2);
    459444        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    461446
    462447PHP_FUNCTION(pipi_overlay) {
    463         pipi_image_t *img1, *img2;
    464         FETCH_IMG_IMG(img1, img2);
    465         pipi_image_t *result;
     448        pipi_image_t *img1, *img2, *result;
     449        FETCH_IMG_IMG(img1, img2);
    466450        result = pipi_overlay(img1, img2);
    467451        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    477461                RETURN_FALSE;
    478462        }
    479         pipi_image_t *src;
    480         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    481 
    482         pipi_image_t *result;
     463        pipi_image_t *src, *result;
     464        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     465
    483466        result = pipi_gaussian_blur(src, value);
    484467        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    491474                RETURN_FALSE;
    492475        }
    493         pipi_image_t *src;
    494         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    495 
    496         pipi_image_t *result;
     476        pipi_image_t *src, *result;
     477        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     478
    497479        result = pipi_gaussian_blur_ext(src, v1, v2, v3, v4, v5);
    498480        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    505487                RETURN_FALSE;
    506488        }
    507         pipi_image_t *src;
    508         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    509 
    510         pipi_image_t *result;
     489        pipi_image_t *src, *result;
     490        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     491
    511492        result = pipi_box_blur(src, value);
    512493        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    519500                RETURN_FALSE;
    520501        }
    521         pipi_image_t *src;
    522         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    523 
    524         pipi_image_t *result;
     502        pipi_image_t *src, *result;
     503        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     504
    525505        result = pipi_box_blur_ext(src, m, n);
    526506        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    533513                RETURN_FALSE;
    534514        }
    535         pipi_image_t *src;
    536         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    537 
    538         pipi_image_t *result;
     515        pipi_image_t *src, *result;
     516        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     517
    539518        result = pipi_brightness(src, value);
    540519        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    547526                RETURN_FALSE;
    548527        }
    549         pipi_image_t *src;
    550         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    551 
    552         pipi_image_t *result;
     528        pipi_image_t *src, *result;
     529        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     530
    553531        result = pipi_contrast(src, value);
    554532        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    556534
    557535PHP_FUNCTION(pipi_autocontrast) {
    558         pipi_image_t *src;
    559         FETCH_IMG(src);
    560         pipi_image_t *result;
     536        pipi_image_t *src, *result;
     537        FETCH_IMG(src);
    561538        result = pipi_autocontrast(src);
    562539        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    564541
    565542PHP_FUNCTION(pipi_invert) {
    566         pipi_image_t *src;
    567         FETCH_IMG(src);
    568         pipi_image_t *result;
     543        pipi_image_t *src, *result;
     544        FETCH_IMG(src);
    569545        result = pipi_invert(src);
    570546        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    577553                RETURN_FALSE;
    578554        }
    579         pipi_image_t *src;
    580         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    581 
    582         pipi_image_t *result;
     555        pipi_image_t *src, *result;
     556        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     557
    583558        result = pipi_threshold(src, value);
    584559        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    586561
    587562PHP_FUNCTION(pipi_hflip) {
    588         pipi_image_t *src;
    589         FETCH_IMG(src);
    590         pipi_image_t *result;
     563        pipi_image_t *src, *result;
     564        FETCH_IMG(src);
    591565        result = pipi_hflip(src);
    592566        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    594568
    595569PHP_FUNCTION(pipi_vflip) {
    596         pipi_image_t *src;
    597         FETCH_IMG(src);
    598         pipi_image_t *result;
     570        pipi_image_t *src, *result;
     571        FETCH_IMG(src);
    599572        result = pipi_vflip(src);
    600573        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    602575
    603576PHP_FUNCTION(pipi_rotate90) {
    604         pipi_image_t *src;
    605         FETCH_IMG(src);
    606         pipi_image_t *result;
     577        pipi_image_t *src, *result;
     578        FETCH_IMG(src);
    607579        result = pipi_rotate90(src);
    608580        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    610582
    611583PHP_FUNCTION(pipi_rotate180) {
    612         pipi_image_t *src;
    613         FETCH_IMG(src);
    614         pipi_image_t *result;
     584        pipi_image_t *src, *result;
     585        FETCH_IMG(src);
    615586        result = pipi_rotate180(src);
    616587        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    618589
    619590PHP_FUNCTION(pipi_rotate270) {
    620         pipi_image_t *src;
    621         FETCH_IMG(src);
    622         pipi_image_t *result;
     591        pipi_image_t *src, *result;
     592        FETCH_IMG(src);
    623593        result = pipi_rotate270(src);
    624594        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    631601                RETURN_FALSE;
    632602        }
    633         pipi_image_t *src;
    634         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    635 
    636         pipi_image_t *result;
     603        pipi_image_t *src, *result;
     604        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     605
    637606        result = pipi_median(src, value);
    638607        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    645614                RETURN_FALSE;
    646615        }
    647         pipi_image_t *src;
    648         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    649 
    650         pipi_image_t *result;
     616        pipi_image_t *src, *result;
     617        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     618
    651619        result = pipi_median_ext(src, rx, ry);
    652620        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    654622
    655623PHP_FUNCTION(pipi_dilate) {
    656         pipi_image_t *src;
    657         FETCH_IMG(src);
    658         pipi_image_t *result;
     624        pipi_image_t *src, *result;
     625        FETCH_IMG(src);
    659626        result = pipi_dilate(src);
    660627        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    662629
    663630PHP_FUNCTION(pipi_erode) {
    664         pipi_image_t *src;
    665         FETCH_IMG(src);
    666         pipi_image_t *result;
     631        pipi_image_t *src, *result;
     632        FETCH_IMG(src);
    667633        result = pipi_erode(src);
    668634        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    670636
    671637PHP_FUNCTION(pipi_order) {
    672         pipi_image_t *src;
    673         FETCH_IMG(src);
    674         pipi_image_t *result;
     638        pipi_image_t *src, *result;
     639        FETCH_IMG(src);
    675640        result = pipi_order(src);
    676641        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    683648                RETURN_FALSE;
    684649        }
    685         pipi_image_t *src;
    686         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    687 
    688         pipi_image_t *result;
     650        pipi_image_t *src, *result;
     651        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     652
    689653        result = pipi_tile(src, width, height);
    690654        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    710674
    711675PHP_FUNCTION(pipi_dither_ordered) {
    712         pipi_image_t *img1, *img2;
    713         FETCH_IMG_IMG(img1, img2);
    714         pipi_image_t *result;
     676        pipi_image_t *img1, *img2, *result;
     677        FETCH_IMG_IMG(img1, img2);
    715678        result = pipi_dither_ordered(img1, img2);
    716679        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    724687                RETURN_FALSE;
    725688        }
    726         pipi_image_t *img1, *img2;
     689        pipi_image_t *img1, *img2, *result;
    727690        ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    728691        ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    729692
    730         pipi_image_t *result;
    731693        result = pipi_dither_ordered_ext(img1, img2, precision, angle);
    732694        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    739701                RETURN_FALSE;
    740702        }
    741         pipi_image_t *src;
    742         ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
    743 
    744         pipi_image_t *result;
     703        pipi_image_t *src, *result;
     704        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     705
    745706        result = pipi_dither_halftone(src, r, angle);
    746707        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    748709
    749710PHP_FUNCTION(pipi_dither_random) {
    750         pipi_image_t *src;
    751         FETCH_IMG(src);
    752         pipi_image_t *result;
     711        pipi_image_t *src, *result;
     712        FETCH_IMG(src);
    753713        result = pipi_dither_random(src);
    754714        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    759719
    760720PHP_FUNCTION(pipi_dither_dbs) {
    761         pipi_image_t *src;
    762         FETCH_IMG(src);
    763         pipi_image_t *result;
     721        pipi_image_t *src, *result;
     722        FETCH_IMG(src);
    764723        result = pipi_dither_dbs(src);
    765724        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
     
    779738
    780739PHP_FUNCTION(pipi_get_image_histogram) {
     740        zval *_zval_img, *_zval_hst;
     741        long flags = 0;
     742        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
     743                RETURN_FALSE;
     744        }
     745        pipi_image_t *image;
     746        pipi_histogram_t *histogram;
     747        ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     748        ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
     749
     750        RETURN_LONG(pipi_get_image_histogram(image, histogram, flags));
    781751}
    782752
    783753PHP_FUNCTION(pipi_render_histogram) {
    784 }
    785 
    786 
     754        zval *_zval_img, *_zval_hst;
     755        long flags = 0;
     756        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
     757                RETURN_FALSE;
     758        }
     759        pipi_image_t *image;
     760        pipi_histogram_t *histogram;
     761        ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
     762        ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
     763
     764        RETURN_LONG(pipi_render_histogram(image, histogram, flags));
     765}
     766
     767
Note: See TracChangeset for help on using the changeset viewer.