Clock Top transition preset does not produce a linear (smooth) result

I found a bug - not a software bug, but I noticed that when I apply a “Clock Top” transition to 2 clips, the result is not linear - ie there is a definite speeding up of the effect in quadrants 2 and 4.
I made this short demo to show this :

I downloaded the “Clock Linear” LUMA PGM file from the Kdenlive store site (I converted it to a JPG file) and tried it as a custom transition and it was indeed linear. See Transition 2 in the demo.

I’m presuming the Shotcut preset uses a Luma file hidden somewhere under the hood but clearly it does not give a completely smooth result. Would it be possible to change the Luma file within SC to this one, I wonder?

Just to make it a bit clearer, here’s another demo, each transition alternating between the standard Clock Top transition and the custom transitions, using the Clock-linear Luma file…
Guess which one I started with? …

If you use my “concentric_cones” HTML file and set

    --ncircles     : 1;      /* no. of cones, including the outer one */

You will get the Clock luminence mask. Could you repeat your test with that and let me know if it works OK please?

1 Like

Pour moi, votre masque n’a pas le défaut du fichier d’origine de SC mentionné par @jonray, et il a en plus l’avantage de pouvoir faire varier l’angle de départ.

For me, your mask does not have the defect of the original SC file mentioned by @jonray, and it has the added advantage of being able to vary the starting angle.

1 Like

Yep, indeed, works fine. In fact the generated file and the Clock-linear Luma file are exactly the same. And as @namna says, it is superb to be able to vary the starting angle. It just gets better!

On peut aussi le faire directement dans SC en mettant sur un clip transparent
1/ Dégradé
2/ Equirectangular to rectilinear

You can also do it directly in SC by putting on a transparent clip
1/ Gradient
2/ Equirectangular to rectilinear


2 Likes

I’m not sure if it is an artifact or a defect, but I see faint white lines (like magnetic lines) radiating out from the centre of the image.

Je ne sais pas s’il s’agit d’un artefact ou d’un défaut, mais je vois de faibles lignes blanches (comme des lignes magnétiques) rayonnant du centre de l’image.

Vous avez raison, ce n’est pas tout à fait la même transition, mais ce n’est pas vilain.

You’re right, it’s not quite the same transition, but it’s not ugly. :upside_down_face:

1 Like

Here is the nearly 20 year old code someone else can try to fix:

1 Like

OMG!! :roll_eyes:

I don’t think there is a problem with the code. The problem is in the luma*.pgm file that was used. I have found a luma1.pgm file in the mlt/master/demo directory. It is the “Clock Top” transition file and has exactly the same problem when I use it as a “custom” preset in a transition. The gradient is not smooth in this PGM file and that is the cause of the problem.

Obviously this is not the exact PGM file used to create the transition preset (I cannot find such a file anywhere in the ZIP I downloaded from Github) but it has exactly the same gradient problem.

The transition code redirects the property for a file name that ends with .pgm and does not exist to this code. It does it this way for compatibility because MLT used to generate these files in a few different aspect ratios and resolutions at build time. Now, they are generated upon demand using this code per the project aspect ratio and resolution.

Thanks for the clarification. I’ll see if I can spot the problem in the code.

The relevant code is from line 164:

case 3:
	{
		int length;
		for ( j = -half_h; j < half_h; j ++ )
		{
			if ( j < 0 )
			{
				for ( k = - half_w; k < half_w; k ++ )
				{
					length = sqrti( k * k + j * j );
					*p ++ = ( max / 4 * k ) / ( length + 1 );
				}
			}
			else
			{
				for ( k = half_w; k > - half_w; k -- )
				{
					length = sqrti( k * k + j * j );
					*p ++ = ( max / 2 ) + ( max / 4 * k ) / ( length + 1 );
				}
			}
		}
	}
	break;

Line

					*p ++ = ( max / 4 * k ) / ( length + 1 );

can be rewritten as

					*p ++ = ( max / 4) * (k  / ( length + 1 ));

The term: k / ( length + 1 ) is effectively the Sine of the angle subtended from the pixel to the baseline (the + 1 is to prevent division by zero). This means that the conic gradient is based on the Sine function, which is non-linear.

You need to take the Arcsine that will give you the angle and base the gradient on that. However, the code seems to be designed for speed and taking the Arcsine at every pixel will slow it down considerably. So I think it best to leave it as it is and if someone wants a conic gradient with a linear speed of transition they need to provide the relevant PNG file, such as can be produced by my HTML code here: Greyscale Luminosity Masks.

2 Likes

Incredible. You are cemented in my mind now as a genius! But I knew that already!! Great work @elusien!! :+1: :+1:

1 Like

Thanks for your comment, but I think Dan is the genius: he even implemented an integer square-root based on the Newton-Raphson approximation method for this transition. How cool is that?

Admittedly this conic-gradient isn’t perfect, but people have been using it for years without any comment, until your eagle-eyes noted the “defect”. Personally, I would leave the code as it is, after all people who already use this in their projects may be a bit concerned if they come back to the project and see their transitions acting (slightly) differently and then file a bug report.

I would close this “bug” as it is really a “feature”.

2 Likes

Linear, Radial and Conic gradients are now fully built into CSS. However, if you want to use them in an HTML canvas it is less easy. A very useful description of how to accomplish this is given here:

and

1 Like

Agreed!! No question of that!!

Fair point. But sometimes a linear movement would be essential. The reason I found it was when I was trying to show @ertan and others that you can easily make an animated circle to highlight a section of a video. In this use-case, a linear effect is definitely required. See my demo: