pike.git / src / modules / Image / layers.c

version» Context lines:

pike.git/src/modules/Image/layers.c:1:   /*   **! module Image   **! note - **! $Id: layers.c,v 1.25 1999/07/01 02:16:55 per Exp $ + **! $Id: layers.c,v 1.26 1999/07/02 21:19:34 mirar Exp $   **! class Layer   **! see also: layers   **!      **!   **!   **! <add_appendix name="layers" title="Image.Layer modes"><execute>   **! import Image;   **!   **! void write_image(string desc,
pike.git/src/modules/Image/layers.c:24:   **!   **! int main()   **! {   **! object ltrans=Layer((["image":   **! Image(32,32,160,160,160)->   **! box(0,0,15,15,96,96,96)->   **! box(16,16,31,31,96,96,96)->scale(0.5),   **! "tiled":1,   **! "mode":"normal"]));   **! - **! object circle= - **! PNM.decode( - **! Stdio.read_bytes("/home/mirar/pike7/tutorial/circle50.pnm")); + **! object circle=load("circle50.pnm"); + **! object image_test=load("image_ill.pnm"); + **! object ryoki=load_layer("ryoki_carrot.png");   **! - **! object image_test= - **! PNM.decode( - **! Stdio.read_bytes("/home/mirar/pike7/tutorial/image_ill.pnm")); - **! - **! mapping ryoki= - **! (mapping) - **! PNG._decode( - **! Stdio.read_bytes("/home/mirar/pike7/tutorial/ryoki_carrot.png")); - **! +    **! object lc1= - **! Layer((["image":circle->clear(255,0,0), - **! "alpha":circle, - **! "xoffset":5, - **! "yoffset":5])); + **! Layer((["image":circle->clear(255,0,0), + **! "alpha":circle, + **! "xoffset":5, + **! "yoffset":5])); + **!   **! object lc2=   **! Layer((["image":circle->clear(0,0,255),   **! "alpha":circle,   **! "xoffset":25,   **! "yoffset":25]));   **! object lc2b=   **! Layer((["image":circle,   **! "alpha":circle*({0,0,255}),   **! "xoffset":25,   **! "yoffset":25]));   **!   **! object lr1=   **! Layer((["image":circle->test(63)->scale(1.25),   **! "alpha":circle->scale(1.25),   **! "xoffset":10,   **! "yoffset":5]));   **! object lr2= - **! Layer((["image":ryoki->image, - **! "alpha":ryoki->alpha, + **! Layer((["image":ryoki->image(), + **! "alpha":ryoki->alpha(),   **! "xoffset":5,   **! "yoffset":20]));   **!   **! object li1=   **! Layer((["image":image_test->scale(80,0),   **! "mode":"normal",   **! "xoffset":0,   **! "yoffset":0]));   **!   **! object li2=
pike.git/src/modules/Image/layers.c:89:   **! (["image":circle->clear(0,0,0)->scale(0.5),   **! "alpha":circle->scale(0.5),   **! "xoffset":0,"yoffset":55]),   **! (["image":circle->clear(255,255,255)->scale(0.5),   **! "alpha":circle->scale(0.5),   **! "xoffset":55,"yoffset":55])   **! }));   **!   **! Layer li2b=Layer(li2->image()->clear(255,255,255),li2->image());   **! + **! object lzo0= + **! lay( ({ + **! Layer(Image(4,10) + **! ->tuned_box(0,0,3,8,({({255,255,255}),({255,255,255}), + **! ({0,0,0}),({0,0,0})})) + **! ->scale(40,80)) + **! ->set_offset(0,0), + **! Layer(Image(40,80) + **! ->tuned_box(0,0,40,78,({({255,255,255}),({255,255,255}), + **! ({0,0,0}),({0,0,0})}))) + **! ->set_offset(40,0), + **! Layer(Image(80,80) + **! ->tuned_box(0,0,80,80,({({255,0,0}),({255,255,0}), + **! ({0,0,255}),({0,255,0})}))) + **! ->set_offset(80,0), + **! }) ); + **! + **! object scale= + **! Image(4,80) + **! ->tuned_box(0,0,40,78,({({255,255,255}),({255,255,255}), + **! ({0,0,0}),({0,0,0})})); + **! object lzo1= + **! lay( ({ + **! Layer(scale)->set_offset(2,0), + **! Layer(scale->invert())->set_offset(6,0), + **! Layer(Image(26,80)->test())->set_offset(12,0), + **! Layer(scale)->set_offset(42,0), + **! Layer(scale->invert())->set_offset(46,0), + **! Layer(Image(26,80)->test())->set_offset(52,0), + **! Layer(scale)->set_offset(82,0), + **! Layer(scale->invert())->set_offset(86,0), + **! Layer(Image(26,80)->test())->set_offset(92,0), + **! Layer(scale)->set_offset(122,0), + **! Layer(scale->invert())->set_offset(126,0), + **! Layer(Image(26,80,"white"), + **! Image(26,80)->test())->set_offset(132,0), + **! })); + **! + **! object lca1; + **!   **! object a= - **! lay( ({ lay(({lc1}),0,0,80,80), + **! lay( ({ lca1=lay(({Layer((["fill":"white"])), + **! lc1}),0,0,80,80),   **! lay(({lc1}),0,0,80,80)->set_offset(80,0),   **! lay(({li1}),0,0,80,80)->set_offset(160,0),   **! lay(({li1}),0,0,80,80)->set_offset(240,0), - **! lay(({lr1}),0,0,80,80)->set_offset(320,0) }), - **! 0,0,400,80); + **! lay(({lr1}),0,0,80,80)->set_offset(320,0), + **! lzo0->set_offset(400,0)}), + **! 0,0,560,80);   **!   **! object b=   **! lay( ({ lay(({lc2}),0,0,80,80),   **! lay(({lc2b}),0,0,80,80)->set_offset(80,0),   **! lay(({li2}),0,0,80,80)->set_offset(160,0),   **! lay(({li2b}),0,0,80,80)->set_offset(240,0), - **! lay(({lr2}),0,0,80,80)->set_offset(320,0) }), - **! 0,0,400,80); + **! lay(({lr2}),0,0,80,80)->set_offset(320,0), + **! lzo1->set_offset(400,0)}), + **! 0,0,560,80);   **! -  + ** xv(a); xv(b); + **!   **! begin_tag("table",(["cellspacing":"0","cellpadding":"1"]));   **!   **! // write_image("top layer image","bi",b->image());   **! // write_image("top layer alpha","ba",b->alpha());   **!   **! // write_image("bottom layer image","ai",a->image());   **! // write_image("bottom layer alpha","aa",b->alpha());   **!   **! write_image("top layer","b",lay(({ltrans,b}))->image());   **! write_image("bottom layer","a",lay(({ltrans,a}))->image());   **! - **! write(mktag("tr",0,mktag("td",0,"<hr>"))); + **! write(mktag("tr",0,mktag("td",0,mktag("hr"))));   **!   **! foreach (Layer()->available_modes(),string mode)   **! { - **! ({lc2,lc2b,li2,li2b,lr2})->set_mode(mode); + **! ({lc2,lc2b,li2,li2b,lr2,lzo1})->set_mode(mode);   **!   **! object r= - **! lay( ({ lay(({lc1,lc2}),0,0,80,80), + **! lay( ({ lay(({lca1,lc2}),0,0,80,80),   **! lay(({lc1,lc2b}),0,0,80,80)->set_offset(80,0),   **! lay(({li1,li2}),0,0,80,80)->set_offset(160,0),   **! lay(({li1,li2b}),0,0,80,80)->set_offset(240,0), - **! lay(({lr1,lr2}),0,0,80,80)->set_offset(320,0) }), - **! 0,0,400,80); + **! lay(({lr1,lr2}),0,0,80,80)->set_offset(320,0), + **! lay(({lzo0,lzo1}),400,0,160,80) }), + **! 0,0,560,80); + ** xv(r);   **!   **! write_image(mode,mode,lay(({ltrans,r}))->image());   **! }   **!   **! write(end_tag());   **! return 0;   **! }   **!   **! </execute>   **! </add_appendix>   */      #include "global.h"      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.25 1999/07/01 02:16:55 per Exp $"); + RCSID("$Id: layers.c,v 1.26 1999/07/02 21:19:34 mirar Exp $");      #include "image_machine.h"      #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "array.h"
pike.git/src/modules/Image/layers.c:963:   static void image_layer_tiled(INT32 args)   {    pop_n_elems(args);    push_int(THIS->tiled);   }      /*   **! method void create(object image,object alpha,string mode)   **! method void create(mapping info)   **! method void create() - **! + **   **! method void create(int xsize,int ysize,object color)   **! method void create(object color)   **! The Layer construct either three arguments,   **! the image object, alpha channel and mode, or   **! a mapping with optional elements:   **! <pre>   **! "image":image,   **! // default: black   **!   **! "alpha":alpha,
pike.git/src/modules/Image/layers.c:1656:   {    if (alpha==0.0)    {    MEMCPY(d,s,sizeof(rgb_group)*len);    MEMCPY(da,sa,sizeof(rgb_group)*len);    return;    }    else if (alpha==1.0)    {    if (!la) /* no layer alpha => full opaque */ -  while (len--) /* 50 % */ +     { -  if (my_rand()&1) *d=*l,*da=white; -  else *d=*s,*da=*sa; -  l++; s++; sa++; da++; d++; +  MEMCPY(d,l,sizeof(rgb_group)*len); +  smear_color(da,white,len);    }    else    while (len--)    {    if ((my_rand()%(255*255)) <    (unsigned)(la->r*87 + la->g*127 + la->b*41))    *d=*l,*da=white;    else    *d=*s,*da=*sa;    l++; s++; la++; sa++; da++; d++;
pike.git/src/modules/Image/layers.c:2298:    l->fill_alpha=THIS->fill_alpha;    MEMCPY(l->sfill,THIS->sfill,sizeof(rgb_group)*SNUMPIXS);    MEMCPY(l->sfill_alpha,THIS->sfill_alpha,sizeof(rgb_group)*SNUMPIXS);    l->tiled=THIS->tiled;    l->row_func=THIS->row_func;    l->optimize_alpha=THIS->optimize_alpha;    return l;   }      /* + **! module Image + **! class Layer   **! method object crop(int xoff,int yoff,int xsize,int ysize)   **! Crops this layer at this offset and size.   **! Offset is not relative the layer offset, so this   **! can be used to crop a number of layers simuntaneously.   **!   **! The <ref>fill</ref> values are used if the layer is   **! enlarged.   **! returns a new layer object   **! note:   **! The new layer object may have the same image object,
pike.git/src/modules/Image/layers.c:2416:   **!   **! <ref>find_autocrop</ref>() returns an array of xoff,yoff,xsize,ysize,   **! which can be fed to <ref>crop</ref>().   **!   **! note:   **! A tiled image will not be cropped at all.   **!   **! <tt>left</tt>...<tt>bottom</tt> arguments can be used   **! to tell what sides cropping are ok on.   **! - **! see also: - **! crop, Image.Image->autocrop + **! see also: crop, Image.Image->autocrop   */      static void image_layer_find_autocrop(INT32 args)   {    int x1=0,y1=0,x2=THIS->xsize-1,y2=THIS->ysize-1;    int l=1,r=1,t=1,b=1;       if (args>3)    get_all_args("find_autocrop",args,"%d%d%d%d",&l,&r,&t,&b);