bash - Custom emboss using MagickWand C API -


i want achieve emboss effect using imagemagick's c api. script this page. have achieved emboss method 1 option i'm looking convert method 2. please @ options in bash script.

when debug above script method 2 i've got this.

 convert -quiet binaryimage.gif +repage ./emboss_1_18210.mpc  convert '(' ./emboss_1_18210.mpc -colorspace gray ')' '(' -clone 0 -negate ')' '(' -clone 0 -distort srt '0,0 1 0 -2.12132,-2.12132' ')' '(' -clone 1 -distort srt '0,0 1 0 2.12132,2.12132' ')' -delete 0,1 -define compose:args=50 -compose blend -composite -level 100% ./emboss_2_18210.mpc  convert ./emboss_2_18210.mpc binaryimagecm2.gif 

below id c program, it's not done yet.

#include <stdio.h> #include <magickwand/magickwand.h> #include <math.h>  #define pi 3.14159265  double *arguments(double r[],int i){   double azimuth = 135;   int depth = 6;    r[0] = 0;   r[1] = 0;   r[2] = 1;   r[3] = 0;   if(i==1){     r[4] = cos(0.78539816339) * depth/2;     r[5] = sin(0.78539816339) * depth/2;   }else{     r[4] = -cos(0.78539816339) * depth/2;     r[5] = -sin(0.78539816339) * depth/2;   }   return(r); } int emboss(){    double r[6];   magickwand *wand = null;   wand = newmagickwand();    magickreadimage(wand,"binaryimage.gif");    int test = magicksetimagecolorspace(wand, 3);   printf("%d\n", test);   magickdistortimage(wand, scalerotatetranslatedistortion ,6, arguments(r,0) ,1);   magickdistortimage(wand, scalerotatetranslatedistortion ,6, arguments(r,1) ,1);   magicknegateimage(wand,1);   magickcompositeimage(wand, wand, blendcompositeop, 1, 0, 0);   magickwriteimages(wand,"binaryimage_c_emboss.gif",magicktrue);    wand=destroymagickwand(wand);   magickwandterminus();    return 1; } int main(int argc, char **argv) {     emboss(); } 

this bit tricky, because need transform colorspace define compose-argument property. note bestfit should set false on distortions.

here's cli & c equivalent.

cli

convert \( wizard:  -colorspace gray \) \         \( -clone 0 -negate \) \         \( -clone 0 -distort srt '0,0 1 0 -2.12132,-2.12132' \) \         \( -clone 1 -distort srt '0,0 1 0  2.12132, 2.12132' \) \         -delete 0,1 \         -define compose:args=50 \         -compose blend -composite \         -level 100% output.png 

c

#include <wand/magickwand.h> // or <magickwand/magickwand.h> if using im 7  #define distort_arg_count 6  double distort_ags[distort_arg_count] = {     0.0f,     0.0f,     1.0f,     0.0f,     -2.12132,     -2.12132, };  int main(int argc, const char * argv[]) {     magickwandgenesis();      magickwand         * wand0,         * wand1,         * wand2,         * wand3;     wand0 = newmagickwand();     // '(' wizard: -colorspace gray ')'     magickreadimage(wand0, "wizard:");     magicktransformimagecolorspace(wand0, graycolorspace);     // '(' -clone 0 -negate ')'     wand1 = clonemagickwand(wand0);     magicknegateimage(wand1, magickfalse);     // '(' -clone 0 -distort srt '0,0 1 0 -2.12132,-2.12132' ')'     wand2 = clonemagickwand(wand0);     magickdistortimage(wand2,                        scalerotatetranslatedistortion,                        distort_arg_count,                        distort_ags,                        magickfalse);     // '(' -clone 1 -distort srt '0,0 1 0 2.12132,2.12132' ')'     wand3 = clonemagickwand(wand1);     distort_ags[4] *= -1;     distort_ags[5] *= -1;     magickdistortimage(wand3,                        scalerotatetranslatedistortion,                        distort_arg_count,                        distort_ags,                        magickfalse);     // -delete 0,1     wand0 = destroymagickwand(wand0);     wand1 = destroymagickwand(wand1);     // -define compose:args=50     magicksetimageartifact(wand3, "compose:args", "50"); // might set on wand2     // -compose blend -composite     // if using imagemagick 7, define `clip_to_self'.     // magickcompositeimage(wand2, wand3, blendcompositeop, magicktrue, 0, 0);     magickcompositeimage(wand2, wand3, blendcompositeop, 0, 0);     // -level 100%     magicklevelimage(wand2, quantumrange, 1.0, 0);     // output.png     magickwriteimage(wand2, "output.png");      wand2 = destroymagickwand(wand2);     wand3 = destroymagickwand(wand3);     magickwandterminus();     return 0; } 

output.png


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -