02-10-2022, 03:04 PM | #1 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Overlay: text with adjustable outline/shadow
Hi folks,
Thanks to eviluess in this thread, I took the challenge to make a better outline effect for fonts. In the process I found an opportunity with the same method to add a better shadow effect with adjustable angle. This version of the text overlay has the following main features: - Text w/adjustable color/transparency, if transparency set to -0.1 use item fade - background color/size/ with transparency relative to text transparency - adjustable outline/shadow color/thickness with same transparency as text - adjustable shadow angle Code:
// Overlay: Text v2.2 w/ajustable outline/shadow // by papagirafe // Write your own text inside quotes, multiple lines allowed // if empty, text = item/track name #text=""; // default font = "Arial" in Windows font=""; /* font styles from following list - multiple choices allowed - uppercase mandatory 'B' - Bold, 'I' - Italics, 'R' - smooth edges, 'V' - Invert bg/fg, 'U' - underlined shadow and outline are handled with dedicated parameters */ style='R'; //@param size 'text height' 0.05 0.01 1.0 0.5 0.001 //@param xpos 'x position' 0.5 0 1 0.5 0.01 //@param ypos 'y position' 0.5 0 1 0.5 0.01 //@param5:fgr 'text r' 1.0 0 1 0.5 0.01 //@param fgg 'text g' 1 0 1 0.5 0.01 //@param fgb 'text b' 1 0 1 0.5 0.01 //@param fga 'text a' 1 -0.1 1 0.5 0.1 //@param10:bgh 'bg h' 0 0 1 0.5 0.01 //@param bgw 'bg w' 0 0 600 0.5 1 //@param bgr 'bg r' 0 0 1 0.5 0.01 //@param bgg 'bg g' 0 0 1 0.5 0.01 //@param bgb 'bg b' 0 0 1 0.5 0.01 //@param bga 'bg a' 0.5 0 1 0.5 0.01 //@param17:olr 'outline r' 0 0 1 0.5 0.01 //@param olg 'outline g' 0 0 1 0.5 0.01 //@param olb 'outline b' 0 0 1 0.5 0.01 //@param olt 'outline thickness' 0 0 100 50 1 //@param oldiv 'outline divs' 64 8 128 64 4 //@param shmode 'shadow mode' 0 0 1 0.5 1 //@param shangl 'shadow angle' 45 0 359 180 1 function gfx_img_alloc_transparent(w,h) ( img=gfx_img_alloc(); // first, image handle only gfx_img_resize(img,-1,-1); // incantation to summon alpha plane gfx_img_resize(img,w,h); // real size now gfx_set(0,0,0,0,0x10000,img); // 100% transparent "black" gfx_fillrect(0,0,w,h); img; ); function polar2xy(r,phi,x*,y*) ( x=r*cos(phi); y=r*sin(phi); ); fga<0?fga=param_wet; bga*=fga; mode=0x10000; input = 0; project_wh_valid===0 ? input_info(input,project_w,project_h); gfx_blit(input,1); gfx_setfont(size*project_h,font,style); strcmp(#text,"")==0 ? input_get_name(-1,#text); gfx_str_measure(#text,txtw,txth); yt = (project_h-txth*(1+bgh*2))*ypos; bga>0?( gfx_set(bgr,bgg,bgb,bga); gfx_fillrect(xpos*(project_w-txtw)-bgw-olt, yt-olt, txtw+bgw*2+2*olt, txth*(1+bgh*2)+2*olt); ); img=gfx_img_alloc_transparent(txtw+2*olt,txth+2*olt); olt>0?( shangl=shmode?shangl*oldiv/360:0; gfx_set(olr,olg,olb,1,mode,img); i=0; loop(shmode?oldiv/16:oldiv, phi=2*(i+shangl)*$pi/oldiv; polar2xy(olt,phi,ox,oy); gfx_str_draw(#text,ox+olt,oy+olt,olr,olg,olb); i+=1; ); ); gfx_set(fgr,fgg,fgb,1,mode,img); gfx_str_draw(#text,olt,olt,olr,olg,olb); gfx_dest=-1; gfx_a=fga; gfx_blit(img,1,xpos*(project_w-txtw)-olt,yt+txth*bgh-olt,txtw+2*olt,txth+2*olt); gfx_img_free(img); |
02-10-2022, 05:00 PM | #2 |
Human being with feelings
Join Date: Dec 2012
Posts: 13,335
|
Great, now we can make animated memes.
|
02-11-2022, 05:13 AM | #3 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
wow.thanks, very good
but why fga to -0.1 (text alpha)? and (worst) why the green thing around my text ? (seems to show the outer extends of the text and has something to do with this magical function gfx_img_alloc_transparent which i have no clue what this does i'm using your script as itemfx click to enlarge |
02-11-2022, 08:06 AM | #4 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Quote:
1) fga = -0.1 means use item fade for alpha any value >= 0 is the normal behaviour 2) green is a condition I didn't think of in my tests. In its current form the preset assumes that you are writing the text on a item that contains a bitmap or a video. Normally green mean a missing bitmap or an empty midi item which seems to be the case here (hopefully). As a patch any transparent PNG file resized to project dimension (with preserve aspect=0) would do the trick until I can come up with a workaround. Here is a 10x10 transparent png to help p.s. the magical function is there to allow a consistent alpha (a.k.a transparency) behavior of the outlined text. |
02-11-2022, 09:16 AM | #5 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
Last edited by bobobo; 02-11-2022 at 09:43 AM. |
02-11-2022, 11:51 AM | #6 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Super! :-) BTW I was able to recreate the problem and I am not sure yet how to avoid it so the workaround will stay for now. This "workaround" is useful to separate all your texts items on a separate track (with higher priority) and the font size will always be consistent.
|
02-12-2022, 05:27 AM | #7 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
hi
i played around with it and made a variation with a switch to use in solo or contextual use technically a switch dealing with the A in the gfx_set in your magical function Code:
// Overlay: Text v2.2 w/ajustable outline/shadow // by papagirafe // Write your own text inside quotes, multiple lines allowed // if empty, text = item/track name #text=""; // default font = "Arial" in Windows font=""; /* font styles from following list - multiple choices allowed - uppercase mandatory 'B' - Bold, 'I' - Italics, 'R' - smooth edges, 'V' - Invert bg/fg, 'U' - underlined shadow and outline are handled with dedicated parameters */ style='R'; //@param mm 'solo or context' 0 0 1 0.5 1 //@param3:size 'text height' 0.05 0.01 1.0 0.5 0.001 //@param xpos 'x position' 0.5 0 1 0.5 0.01 //@param ypos 'y position' 0.5 0 1 0.5 0.01 //@param7:fgr 'text r' 1.0 0 1 0.5 0.01 //@param fgg 'text g' 1 0 1 0.5 0.01 //@param fgb 'text b' 1 0 1 0.5 0.01 //@param fga 'text a' 1 -0.1 1 0.5 0.1 //@param12:bgh 'bg h' 0 0 1 0.5 0.01 //@param bgw 'bg w' 0 0 600 0.5 1 //@param bgr 'bg r' 0 0 1 0.5 0.01 //@param bgg 'bg g' 0 0 1 0.5 0.01 //@param bgb 'bg b' 0 0 1 0.5 0.01 //@param bga 'bg a' 0.5 0 1 0.5 0.01 //@param18:olr 'outline r' 0 0 1 0.5 0.01 //@param olg 'outline g' 0 0 1 0.5 0.01 //@param olb 'outline b' 0 0 1 0.5 0.01 //@param olt 'outline thickness' 0 0 100 50 1 //@param oldiv 'outline divs' 64 8 128 64 4 //@param shmode 'shadow mode' 0 0 1 0.5 1 //@param shangl 'shadow angle' 45 0 359 180 1 function gfx_img_alloc_transparent(w,h,mm) ( img=gfx_img_alloc(); // first, image handle only gfx_img_resize(img,-1,-1); // incantation to summon alpha plane gfx_img_resize(img,w,h); // real size now gfx_set(0,0,0,mm,0x10000,img); // 100% transparent "black" gfx_fillrect(0,0,w,h); img; ); function polar2xy(r,phi,x*,y*) ( x=r*cos(phi); y=r*sin(phi); ); fga<0?fga=param_wet; bga*=fga; mode=0x10000; input = 0; project_wh_valid===0 ? input_info(input,project_w,project_h); gfx_blit(input,1); gfx_setfont(size*project_h,font,style); strcmp(#text,"")==0 ? input_get_name(-1,#text); gfx_str_measure(#text,txtw,txth); yt = (project_h-txth*(1+bgh*2))*ypos; bga>0?( gfx_set(bgr,bgg,bgb,bga); gfx_fillrect(xpos*(project_w-txtw)-bgw-olt, yt-olt, txtw+bgw*2+2*olt, txth*(1+bgh*2)+2*olt); ); img=gfx_img_alloc_transparent(txtw+2*olt,txth+2*olt,mm); olt>0?( shangl=shmode?shangl*oldiv/360:0; gfx_set(olr,olg,olb,1,mode,img); i=0; loop(shmode?oldiv/16:oldiv, phi=2*(i+shangl)*$pi/oldiv; polar2xy(olt,phi,ox,oy); gfx_str_draw(#text,ox+olt,oy+olt,olr,olg,olb); i+=1; ); ); gfx_set(fgr,fgg,fgb,1,mode,img); gfx_str_draw(#text,olt,olt,olr,olg,olb); gfx_dest=-1; gfx_a=fga; gfx_blit(img,1,xpos*(project_w-txtw)-olt,yt+txth*bgh-olt,txtw+2*olt,txth+2*olt); gfx_img_free(img); Last edited by bobobo; 02-12-2022 at 05:32 AM. |
02-14-2022, 05:15 AM | #8 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Hi bobobo!
The solution was indeed fixing the "magic" function. I reorganized a few things in the code and transferred the test for "missing" media file inside that function. Here is the fixed version of the preset taking this condition into account. Beware that putting an envelope on font size will provoque strange graphical artifacts that I cannot yet explain: it is a recurrent problem I experienced with "resizing" gfx_blits in other presets. Food for thought... Code:
// Overlay: Text v2.21 w/ajustable outline/shadow // by papagirafe // Write your own text inside quotes, multiple lines allowed #text=""; // default font = "Arial" in Windows font=""; /* font styles from following list - multiple choices allowed - uppercase mandatory 'B' - Bold, 'I' - Italics, 'R' - smooth edges, 'V' - Invert bg/fg, 'U' - underlined shadow and outline are handled with dedicated parameters */ style='R'; //@param size 'text height' 0.05 0.01 1.0 0.5 0.001 //@param xpos 'x position' 0.5 0 1 0.5 0.01 //@param ypos 'y position' 0.5 0 1 0.5 0.01 //@param5:fgr 'text r' 1.0 0 1 0.5 0.01 //@param fgg 'text g' 1 0 1 0.5 0.01 //@param fgb 'text b' 1 0 1 0.5 0.01 //@param fga 'text a' 1 -0.1 1 0.5 0.1 //@param10:bgh 'bg h' 0 0 1 0.5 0.01 //@param bgw 'bg w' 0 0 600 0.5 1 //@param bgr 'bg r' 0 0 1 0.5 0.01 //@param bgg 'bg g' 0 0 1 0.5 0.01 //@param bgb 'bg b' 0 0 1 0.5 0.01 //@param bga 'bg a' 0.5 0 1 0.5 0.01 //@param17:olr 'outline r' 0 0 1 0.5 0.01 //@param olg 'outline g' 0 0 1 0.5 0.01 //@param olb 'outline b' 0 0 1 0.5 0.01 //@param olt 'outline thickness' 0 0 100 50 1 //@param oldiv 'outline divs' 32 8 128 64 4 //@param shmode 'shadow mode' 0 0 1 0.5 1 //@param shangl 'shadow angle' 45 0 359 180 1 function gfx_img_alloc_transparent(w,h) ( input_info(0,iw,ih); iw>0&&ih>0?( //media file exists? img=gfx_img_alloc(); // first, image handle only gfx_img_resize(img,-1,-1); // summon alpha plane gfx_img_resize(img,w,h); // real size now gfx_set(0,0,0,0,0x10000,img); // 100% transparent "black" gfx_fillrect(0,0,w,h); ):( img=gfx_img_alloc(w,h,1); // std cleared image ); img; ); function set_project_wh_safe(w*,h*) ( project_wh_valid===0 ? ( input_info(0,w,h); // no pw,ph get from current item w==0||h==0?(w=480; h=270;); // worst case scenario? 1/4 HD ); ); function polar2xy(r,phi,x*,y*) ( x=r*cos(phi); y=r*sin(phi); ); fga<0?fga=param_wet; bga*=fga; //bg alpha dependent upon fg alpha mode=0x10000; //use alpha set_project_wh_safe(project_w, project_h); gfx_blit(0,1); gfx_setfont(size*project_h,font,style); strcmp(#text,"")==0 ? input_get_name(-1,#text); gfx_str_measure(#text,txtw,txth); yt = (project_h-txth*(1+bgh*2))*ypos; // background if applicable bga>0?( gfx_set(bgr,bgg,bgb,bga); gfx_fillrect(xpos*(project_w-txtw)-bgw-olt, yt-olt, txtw+bgw*2+2*olt, txth*(1+bgh*2)+2*olt); ); //temporary image using alpha 1 for consistent drawing img=gfx_img_alloc_transparent(txtw+2*olt,txth+2*olt); // outline/shadow of applicable olt>0?( shangl=shmode?shangl*oldiv/360:0; gfx_set(olr,olg,olb,1,mode,img); i=0; loop(shmode?oldiv/16:oldiv, phi=2*(i+shangl)*$pi/oldiv; polar2xy(olt,phi,ox,oy); gfx_str_draw(#text,ox+olt,oy+olt,olr,olg,olb); i+=1; ); ); // text gfx_set(fgr,fgg,fgb,1,mode,img); gfx_str_draw(#text,olt,olt,olr,olg,olb); // copy tmp img to frame buffer with desired alpha value gfx_dest=-1; gfx_a=fga; gfx_blit(img,1,xpos*(project_w-txtw)-olt,yt+txth*bgh-olt,txtw+2*olt,txth+2*olt); gfx_img_free(img); Last edited by papagirafe; 02-14-2022 at 06:41 AM. Reason: typos |
02-14-2022, 10:44 AM | #9 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
yes ..
i think i can see a background in textcolor when fga on 1 bga on 0 but hey .. |
02-14-2022, 11:55 AM | #10 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Yes there is a rounding bug of some kind with the gfx_blit() function that creates visible lines. Never figured out where that is coming from even in my other homemade presets. The patch is to ajust the font size slightly by 0.001 until the lines disappear. Hope I (or someone) finds a solution soon! :-)
Last edited by papagirafe; 02-14-2022 at 11:56 AM. Reason: typos |
02-15-2022, 01:08 AM | #11 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
i got somehow a better result (though not perfect) when setting the preserve aspect to 0 in both gfx_blit 's
less computing results in a more fluent ouput i guess. also i put a little tweak in the last gfx_blit that fiddles with the xpos and the width (subtracting and adding 1) this seems to cure the artzifacts greetz Code:
// Overlay: Text v2.21 w/ajustable outline/shadow // by papagirafe , slightly edited by bobobo // Write your own text inside quotes, multiple lines allowed #text="test"; // default font = "Arial" in Windows font=""; /* font styles from following list - multiple choices allowed - uppercase mandatory 'B' - Bold, 'I' - Italics, 'R' - smooth edges, 'V' - Invert bg/fg, 'U' - underlined shadow and outline are handled with dedicated parameters */ style='B'; //@param size 'text height' 0.05 0.01 1.0 0.5 0.001 //@param xpos 'x position' 0.5 0 1 0.5 0.01 //@param ypos 'y position' 0.5 0 1 0.5 0.01 //@param5:fgr 'text r' 1.0 0 1 0.5 0.01 //@param fgg 'text g' 1 0 1 0.5 0.01 //@param fgb 'text b' 1 0 1 0.5 0.01 //@param fga 'text a' 1 -0.1 1 0.5 0.1 //@param10:bgh 'bg h' 0 0 1 0.5 0.01 //@param bgw 'bg w' 0 0 600 0.5 1 //@param bgr 'bg r' 0 0 1 0.5 0.01 //@param bgg 'bg g' 0 0 1 0.5 0.01 //@param bgb 'bg b' 0 0 1 0.5 0.01 //@param bga 'bg a' 0.5 0 1 0.5 0.01 //@param17:olr 'outline r' 0 0 1 0.5 0.01 //@param olg 'outline g' 0 0 1 0.5 0.01 //@param olb 'outline b' 0 0 1 0.5 0.01 //@param olt 'outline thickness' 0 0 100 50 1 //@param oldiv 'outline divs' 32 8 128 64 4 //@param shmode 'shadow mode' 0 0 1 0.5 1 //@param shangl 'shadow angle' 45 0 359 180 1 function gfx_img_alloc_transparent(w,h) ( input_info(0,iw,ih); iw>0&&ih>0?( //media file exists? img=gfx_img_alloc(); // first, image handle only gfx_img_resize(img,-1,-1); // summon alpha plane gfx_img_resize(img,w,h); // real size now gfx_set(0,0,0,0,0x10000,img); // 100% transparent "black" gfx_fillrect(0,0,w,h); ):( img=gfx_img_alloc(w,h,1); // std cleared image ); img; ); function set_project_wh_safe(w*,h*) ( project_wh_valid===0 ? ( input_info(0,w,h); // no pw,ph get from current item w==0||h==0?(w=480; h=270;); // worst case scenario? 1/4 HD ); ); function polar2xy(r,phi,x*,y*) ( x=r*cos(phi); y=r*sin(phi); ); fga<0?fga=param_wet; bga*=fga; //bg alpha dependent upon fg alpha mode=0x10000; //use alpha set_project_wh_safe(project_w, project_h); gfx_blit(0,0); gfx_setfont(size*project_h,font,style); strcmp(#text,"")==0 ? input_get_name(-1,#text); gfx_str_measure(#text,txtw,txth); yt = (project_h-txth*(1+bgh*2))*ypos; // background if applicable bga>0?( gfx_set(bgr,bgg,bgb,bga); gfx_fillrect(xpos*(project_w-txtw)-bgw-olt, yt-olt, txtw+bgw*2+2*olt, txth*(1+bgh*2)+2*olt); ); //temporary image using alpha 1 for consistent drawing img=gfx_img_alloc_transparent(txtw+2*olt,txth+2*olt); // outline/shadow of applicable olt>0?( shangl=shmode?shangl*oldiv/360:0; gfx_set(olr,olg,olb,1,mode,img); i=0; loop(shmode?oldiv/16:oldiv, phi=2*(i+shangl)*$pi/oldiv; polar2xy(olt,phi,ox,oy); gfx_str_draw(#text,ox+olt,oy+olt,olr,olg,olb); i+=1; ); ); // text gfx_set(fgr,fgg,fgb,1,mode,img); gfx_str_draw(#text,olt,olt,olr,olg,olb); // copy tmp img to frame buffer with desired alpha value gfx_dest=-1; gfx_a=fga; gfx_blit(img,0,xpos*(project_w-txtw)-olt-1,yt+txth*bgh-olt,txtw+2*olt+1,txth+2*olt); // gfx_blit(img,0); gfx_img_free(img); Last edited by bobobo; 02-15-2022 at 04:29 AM. |
02-15-2022, 01:32 PM | #12 |
Human being with feelings
Join Date: Dec 2020
Posts: 214
|
I can't figure out how to make the green box surrounding the text go away. I can set BG A to zero and there's still a green box.
If I set BG A to >0 then I get a larger back box around that. Basically I create a project and add one track with a video. On that video I add the overlay as a video FX. Have also tried adding the overlay to an otherwise empty track above the video track with the same results. |
02-15-2022, 02:28 PM | #13 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
put the transparent imgage mentioned above (posting 4) and lay this fx on it
|
02-15-2022, 04:22 PM | #14 | |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Quote:
Here is a new and improved version of the preset! I fixed the green and also the last the extra unwanted lines on empty background so please take this last version of the preset (v2.23). I added a super cool feature: ajustable transparency of the outline/shadow. A alpha of 1 will duplicate the old behavior. Code:
// Overlay: Text v2.23 w/ajustable outline/shadow // by papagirafe // Write your own text inside quotes, multiple lines allowed #text=""; // default font = "Arial" in Windows font=""; /* font styles from following list - multiple choices allowed - uppercase mandatory 'B' - Bold, 'I' - Italics, 'R' - smooth edges, 'V' - Invert bg/fg, 'U' - underlined shadow and outline are handled with dedicated parameters */ style='R'; //@param size 'text height' 0.05 0.01 1.0 0.5 0.001 //@param xpos 'x position' 0.5 0 1 0.5 0.01 //@param ypos 'y position' 0.5 0 1 0.5 0.01 //@param5:fgr 'text r' 1.0 0 1 0.5 0.01 //@param fgg 'text g' 1 0 1 0.5 0.01 //@param fgb 'text b' 1 0 1 0.5 0.01 //@param fga 'text a' 1 -0.01 1 0.5 0.01 //@param10:bgh 'bg h' 0 0 1 0.5 0.01 //@param bgw 'bg w' 0 0 600 0.5 1 //@param bgr 'bg r' 0 0 1 0.5 0.01 //@param bgg 'bg g' 0 0 1 0.5 0.01 //@param bgb 'bg b' 0 0 1 0.5 0.01 //@param bga 'bg a' 0.5 0 1 0.5 0.01 //@param17:olr 'outline r' 0 0 1 0.5 0.01 //@param olg 'outline g' 0 0 1 0.5 0.01 //@param olb 'outline b' 0 0 1 0.5 0.01 //@param ola 'outline a' 0.1 0.01 1 0.5 0.01 //@param olt 'outline thickness' 0 0 100 50 1 //@param oldiv 'outline divs' 32 8 128 64 4 //@param shmode 'shadow mode' 0 0 1 0.5 1 //@param shangl 'shadow angle' 45 0 359 180 1 function gfx_img_alloc_transparent(w,h) ( input_info(0,iw,ih); iw>0&&ih>0?( //media file exists? img=gfx_img_alloc(); // first, image handle only gfx_img_resize(img,-1,-1); // summon alpha plane gfx_img_resize(img,w+1,h+1); // real size now (w+1/h+1 = gfx_blit() bug patch) gfx_set(0,0,0,0,0x10000,img); // 100% transparent "black" gfx_fillrect(0,0,w,h); ):( img=gfx_img_alloc(w+1,h+1,1); // std cleared image (w+1/h+1 = gfx_blit() bug patch) ); img; ); function set_project_wh_safe(w*,h*) ( project_wh_valid===0 ? ( input_info(0,w,h); // no pw,ph get from current item w==0||h==0?(w=480; h=270;); // worst case scenario? 1/4 HD ); ); function polar2xy(r,phi,x*,y*) ( x=r*cos(phi); y=r*sin(phi); ); fga<0?fga=param_wet; bga*=fga; //bg alpha dependent upon fg alpha mode=0x10000; //use alpha set_project_wh_safe(project_w, project_h); gfx_blit(0,1); gfx_setfont(size*project_h,font,style); strcmp(#text,"")==0 ? input_get_name(-1,#text); gfx_str_measure(#text,txtw,txth); yt =(project_h-txth*(1+bgh*2))*ypos; // background if applicable bga>0?( gfx_set(bgr,bgg,bgb,bga); gfx_fillrect(xpos*(project_w-txtw)-bgw-olt, yt-olt, txtw+bgw*2+2*olt, txth*(1+bgh*2)+2*olt); ); //temporary image using alpha 1 for consistent drawing img=gfx_img_alloc_transparent(txtw+2*olt,txth+2*olt); // pourtour du texte si applicable olt>0?( shmode?(ola=exp(ola*fga*3.5-4);shangl=shangl*oldiv/360):(ola=exp((oldiv/16)*ola*fga-4.61);shangl=0;); gfx_set(olr,olg,olb,ola*fga,mode,img); i=0; loop(shmode?oldiv/16:oldiv, phi=2*(i+shangl)*$pi/oldiv; polar2xy(olt,phi,ox,oy); gfx_str_draw(#text,ox+olt,oy+olt,olr,olg,olb); i+=1; ); ); // text gfx_set(fgr,fgg,fgb,1,mode,img); gfx_str_draw(#text,olt,olt,olr,olg,olb); // copy tmp img to frame buffer with desired alpha value gfx_dest=-1; gfx_a=fga; gfx_blit(img,0,xpos*(project_w-txtw)-olt,yt+txth*bgh-olt,txtw+2*olt,txth+2*olt,0,0,txtw+2*olt,txth+2*olt); gfx_img_free(img); |
|
02-15-2022, 10:35 PM | #15 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
smooth , well done
Last edited by bobobo; 02-15-2022 at 10:51 PM. |
02-16-2022, 03:49 AM | #16 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
|
02-16-2022, 11:01 AM | #17 | |
Human being with feelings
Join Date: Dec 2020
Posts: 214
|
Quote:
I downloaded the 10x10 image and put it on a blank timeline on an empty project, and stretched it out to cover some time. I added this FX to the track. If this is the only track on the project I get a fuzzy blob using the default settings for the FX. Playing with the dials still shows no text. Just fuzzy blobs. Putting a video on a second track shows no video unless I put it in front, and then I see no text. If I put the FX directly on a video then I see the text, but the text is surrounded by a green rectangle. You cannot see the video through the text. Can someone strip away the ambiguity and say what is the simplest possible project that can display a video with this text over it. One video, no other FX? |
|
02-16-2022, 12:02 PM | #18 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
|
02-16-2022, 02:47 PM | #19 |
Human being with feelings
Join Date: Dec 2020
Posts: 214
|
Thanks for the help. Your RPP file has three tracks. And they display text on a black screen when I play it like that.
Now try this. Take a MP4 video and drop it in as the 4th track and see what happens when you play it. You may need to insert the video as track 1 depending on [File>Project Settings>Video Tab>Video item visibility]. Mine is set to "Lower replaces higher". You still see the text, but it is now superimposed over a green rectangle that blocks the underlying video. Is there any way that green rectangle can be made transparent so that the video can be seen behind the text? Or is this something that needs to be combined with a Chroma-key plugin? |
02-16-2022, 03:20 PM | #20 | |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Quote:
So in short: The preset is meant to be added at the item level (shift-e in windoze). The item media may be either a video, an image or even an empty midi item. The v2.23 will work in all those cases. examples: 1) one track, empty midi item + preset = text on black background 2) one track image/video item + preset = text that appears on top of the image/video 3) 2 tracks, lower video priority track item: video item, higher video priority track item: empty midi item + preset = text on top of lower video priority item with more tracks, the preset should be placed on the item with the most video priority. Edit: It does works by itself at the track level even without any item at all! Last edited by papagirafe; 02-16-2022 at 05:51 PM. |
|
02-16-2022, 07:06 PM | #21 |
Human being with feelings
Join Date: Dec 2020
Posts: 214
|
I just want a video to display with this text showing over the video, without the green rectangle that hides the video. AFAIK this can't do it alone.
|
02-16-2022, 07:53 PM | #22 |
Human being with feelings
Join Date: Oct 2014
Posts: 1,369
|
papagirafe made the preset to overlay text with optional moving and kind of blurred shadow,
maybe a stripped down version is enough for your needs i found this somewhere in the forum and hacked it a little bit to fit my needs i tested it with a video (no green box here) but only hardcoded dark shadow color Code:
// text overlay bobobo v2 // bobobo - standing on giants' shoulders input_get_name(-1, text); font="FUTURA"; //@param1:size 'text size' 0.05 0.01 1 0.1 0.001 //@param2:ypos 'y position' 0.5 -0.2 1.2 0.5 0.01 //@param3:xpos 'x position' 0.5 0 1 0.5 0.01 //@param5:fgr 'text R' 255 0 255 128 1 //@param6:fgg 'text G' 255 0 255 128 1 //@param7:fgb 'text B' 255 0 255 128 1 //@param8:fga 'text A' 1 0 1 0.5 0.005 //@param10:shr 'shadow R' 255 0 255 128 1 //@param shg 'shadow G' 255 0 255 128 1 //@param shb 'shadow B' 255 0 255 128 1 //@param sha 'shadow alpha' 0.3 0 1 0.5 0.001 //@param shx 'shadow x' 0.5 -1 1 0.5 0.01 //@param shy 'shadow y' 0.5 -1 1 0.5 0.01 //@param shs 'shadow spread' 5 0 10 5 0.05 //@param shi 'shadow iterations' 5 1 20 5 1 gfx_blit(0,1); gfx_setfont(size*project_h,font); gfx_str_measure(text,txtw,txth); yt = (project_h - txth)*ypos; x = xpos * (project_w-txtw); i = 0; gfx_set(shr/255,shg/255,shb/255,sha); loop(shi, gfx_str_draw(text,x + (100 * shx*size) + (i * shs * size),yt + (100 * shy * size) + (i * shs * size)); gfx_str_draw(text,x + (100 * shy*size) - (i * shs * size),yt + (100 * shy * size) - (i * shs * size)); gfx_str_draw(text,x + (100 * shx*size) + (i * shs * size),yt + (100 * shy * size) - (i * shs * size)); gfx_str_draw(text,x + (100 * shx*size) - (i * shs * size),yt + (100 * shy * size) + (i * shs * size)); i += 1; ); gfx_set(fgr/255,fgg/255,fgb/255,fga); gfx_str_draw(text,x,yt); Last edited by bobobo; 02-17-2022 at 03:46 AM. |
02-24-2022, 06:32 AM | #23 | |
Human being with feelings
Join Date: Dec 2015
Location: Guangzhou, China
Posts: 176
|
Quote:
|
|
02-24-2022, 03:54 PM | #24 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
I enjoyed your challenge! The builtin outline and shadow were bugging me for a long time too (we were not alone!). Your questions and the explanations of your attempts were very clear and pertinent and they lead me to a solution more flexible than I expected.
|
02-27-2022, 05:44 PM | #25 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Fuzzball, I was able to reproduce the exact annoying "green" condition while testing an other preset. This happens if one or more underlying video layer is not using alpha mode. The trick is to use a preset that enables that mode before the text/shadow preset. For example: Track opacity/zoom/pan with parameter "clear background" set to 0.
Last edited by papagirafe; 02-27-2022 at 05:56 PM. |
03-02-2022, 12:56 PM | #26 |
Human being with feelings
Join Date: Dec 2020
Posts: 214
|
Still haven't been able to get it working without a big green rectangle blocking the view of video behind letters.
Let me remove all ambiguity.... 1) new project, drop one MP4 video onto Track1. The one and only track on the project. 2) To the track FX add Track opacity/zoom/pan and change Clear BG to 0. 3) To the track FX add Overlay: Text v2.23. 4) Confirm that Track opacity FX is the first FX and Overlay: Text v2.23 is the 2nd FX. Result: Big green rectangle blocking video. Have also tried it with item FX with no change. |
03-03-2022, 03:08 PM | #27 | |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Quote:
Code:
// Overlay: Text v2.23b w/ajustable outline/shadow // by papagirafe // v2.23a: fixed colorspace dependency // v2.23b: restoring original colorsapce on exit // Write your own text inside quotes, multiple lines allowed #text=""; // default font = "Arial" in Windows font=""; /* font styles from following list - multiple choices allowed - uppercase mandatory 'B' - Bold, 'I' - Italics, 'R' - smooth edges, 'V' - Invert bg/fg, 'U' - underlined shadow and outline are handled with dedicated parameters */ style='R'; //@param size 'text height' 0.05 0.01 1.0 0.5 0.001 //@param xpos 'x position' 0.5 0 1 0.5 0.01 //@param ypos 'y position' 0.5 0 1 0.5 0.01 //@param5:fgr 'text r' 1.0 0 1 0.5 0.01 //@param fgg 'text g' 1 0 1 0.5 0.01 //@param fgb 'text b' 1 0 1 0.5 0.01 //@param fga 'text a' 1 -0.01 1 0.5 0.01 //@param10:bgh 'bg h' 0 0 1 0.5 0.01 //@param bgw 'bg w' 0 0 600 0.5 1 //@param bgr 'bg r' 0 0 1 0.5 0.01 //@param bgg 'bg g' 0 0 1 0.5 0.01 //@param bgb 'bg b' 0 0 1 0.5 0.01 //@param bga 'bg a' 0.5 0 1 0.5 0.01 //@param17:olr 'outline r' 0 0 1 0.5 0.01 //@param olg 'outline g' 0 0 1 0.5 0.01 //@param olb 'outline b' 0 0 1 0.5 0.01 //@param ola 'outline a' 0.1 0.01 1 0.5 0.01 //@param olt 'outline thickness' 0 0 100 50 1 //@param oldiv 'outline divs' 32 8 128 64 4 //@param shmode 'shadow mode' 0 0 1 0.5 1 //@param shangl 'shadow angle' 45 0 359 180 1 function gfx_img_alloc_transparent(w,h) ( input_info(0,iw,ih); iw>0&&ih>0?( //media file exists? img=gfx_img_alloc(); // first, image handle only gfx_img_resize(img,-1,-1); // summon alpha plane gfx_img_resize(img,w+1,h+1); // real size now (w+1/h+1 = gfx_blit() bug patch) gfx_set(0,0,0,0,0x10000,img); // 100% transparent "black" gfx_fillrect(0,0,w,h); ):( img=gfx_img_alloc(w+1,h+1,1); // std cleared image (w+1/h+1 = gfx_blit() bug patch) ); img; ); function set_project_wh_safe(w*,h*) ( project_wh_valid===0 ? ( input_info(0,w,h); // no pw,ph get from current item w==0||h==0?(w=480; h=270;); // worst case scenario? 1/4 HD ); ); function polar2xy(r,phi,x*,y*) ( x=r*cos(phi); y=r*sin(phi); ); ocs=colorspace; colorspace='RGBA'; fga<0?fga=param_wet; bga*=fga; //bg alpha dependent upon fg alpha mode=0x10000; //use alpha set_project_wh_safe(project_w, project_h); gfx_blit(0,1); gfx_setfont(size*project_h,font,style); strcmp(#text,"")==0 ? input_get_name(-1,#text); gfx_str_measure(#text,txtw,txth); yt =(project_h-txth*(1+bgh*2))*ypos; // background if applicable bga>0?( gfx_set(bgr,bgg,bgb,bga); gfx_fillrect(xpos*(project_w-txtw)-bgw-olt, yt-olt, txtw+bgw*2+2*olt, txth*(1+bgh*2)+2*olt); ); //temporary image using alpha 1 for consistent drawing img=gfx_img_alloc_transparent(txtw+2*olt,txth+2*olt); // pourtour du texte si applicable olt>0?( shmode?(ola=exp(ola*fga*3.5-4);shangl=shangl*oldiv/360):(ola=exp((oldiv/16)*ola*fga-4.61);shangl=0;); gfx_set(olr,olg,olb,ola*fga,mode,img); i=0; loop(shmode?oldiv/16:oldiv, phi=2*(i+shangl)*$pi/oldiv; polar2xy(olt,phi,ox,oy); gfx_str_draw(#text,ox+olt,oy+olt,olr,olg,olb); i+=1; ); ); // text gfx_set(fgr,fgg,fgb,1,mode,img); gfx_str_draw(#text,olt,olt,olr,olg,olb); // copy tmp img to frame buffer with desired alpha value gfx_dest=-1; gfx_a=fga; gfx_blit(img,0,xpos*(project_w-txtw)-olt,yt+txth*bgh-olt,txtw+2*olt,txth+2*olt,0,0,txtw+2*olt,txth+2*olt); gfx_img_free(img); colorspace=ocs; Last edited by papagirafe; 03-03-2022 at 05:48 PM. Reason: code update |
|
03-03-2022, 04:15 PM | #28 | |
Human being with feelings
Join Date: Dec 2020
Posts: 214
|
Quote:
|
|
03-03-2022, 05:04 PM | #29 |
Human being with feelings
Join Date: Dec 2012
Posts: 7,295
|
There is a Project Setting to force it to use a specific colorspace, but. Of course, if your code depends on it being set to something specific, then it is best to set it in the code. I think that’s why inserting Track Opacity seemed to help in some cases - it was forcing that colorspace so you didn’t have to. It’s also a good idea, though, to set the colorspace back to where it was when your preset is done. So like save the colorspace to some variable before setting it to RGBA, and then at the end set colorspace back to equal that variable.
__________________
Lorenzo's Tractor is Everywhere --- Ash's Tube --- Join the Partnership for a Drum Free Amerika |
03-03-2022, 05:51 PM | #30 | |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Quote:
|
|
03-03-2022, 05:58 PM | #31 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
|
03-03-2022, 06:02 PM | #32 |
Human being with feelings
Join Date: Dec 2012
Posts: 7,295
|
Yeah I’m not sure how much that matters most of the time, but I feel like it’s the polite thing to do.
__________________
Lorenzo's Tractor is Everywhere --- Ash's Tube --- Join the Partnership for a Drum Free Amerika |
03-08-2022, 04:03 AM | #33 | |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Quote:
Each instance of "video processor/preset" in the fx chain gets the original value no matter what the previous preset did (BTW this is the same for project_w/project_h). Just put 2 or more instances of this code to try: Code:
//colorspace test //@param ccs "current cs" -1 -1 3 2 1 //@param fcs "force next cs" 0 0 3 2 1 function update_param(p*,val)( on_parameter_change(p); p=val; on_parameter_change(p,1);); cs[0]=0;cs[1]='RGBA';cs[2]='YV12';cs[3]='YUY2'; i=0;while(i<4)( colorspace==a[i]?(ccs=i;i=4):(i+=1); ); update_param(ccs,ccs); colorspace=cs[fcs]; |
|
Thread Tools | |
Display Modes | |
|
|