Keeping aspect ratio correct in a slideshow made with different dimension pics?

    May 26 2011 | 2:59 pm
    Hello all,
    I'm working on a patch that will crossfade sequentially a series of pictures and apply several realtime effects to them: basically it allows the user to specify a folder containing the images and then, using a slider, to crossfade between the images from the first to the next in the folder, according to the alphabetical order.
    I've set up a two thing so that when the first player is playing an image then the second is playing the second image an the user can crossfade between the two, when the user has fully crossfaded to the second player the first player will load the third image and so on. I'm using openGl as much as possible to speed things up, so the two players are mixed with a slab normal thing and then pass some other treatment and finally they are sent to a gl.videoplane for display.
    It all works ok until I use images that have the same aspect ratio, but the problems arise if I try and use pictures with different sizes and aspect ratios, for example I need to sequence pics with a 2.666 aspect ratio and pictures with a 1.55 aspect ratio. I know how to change the size of a videoplane to match the incoming matrix, but it doesn't work if the videoplane has to display theresult of the crossfade of two images that have different ratios: one of the two will be warped.
    I am starting to think that my approach is wrong and I'd like to gather some suggestions about the way to take here.
    Maybe one way to work around this could be to add solid colour bars to the images so that all have the same final size.. and maybe try and make so that the bars are rendered transparent...
    I'm sorry but at the moment posting an example could be misleading since the patch is rather big and I cannot edit it now to make it less of a total incomprehensible mess..
    Any tip would be greatly appreciated.
    Thank you

    • May 26 2011 | 4:26 pm
      One possible way: By getting the dimensions of each image (getmoviedim) after loading - but before displaying - it should be possible to then calculate which portions of the resulting matrix to display to - through usedstrect 1 and associated attributes ( dstrect a b c d).
      Hope that makes sense...
    • May 26 2011 | 5:06 pm
      There are lots of different ways to do this, but I usually use two videoplanes with blend_enable on, set the appropriate aspect for each, and then just change the alpha.
      Or you could feed two slabs with one of the texdisplace shaders (like td.rota.jxs) into one slab with a composite or transition shader (like tr.dissolve.jxs)
      Or you could cut and paste from those shaders to make one shader that did everything in one pass. Or there may be a shader that lets you scale the UV coordinates for the two inputs independently. Or if there isn't, someone could probably write one.
      Any of these approaches might be faster than a pair of videoplanes, but I find this approach is plenty fast enough for me.
      Here's an example - you can set the videoplanes to match height, width, or average of both.
    • May 26 2011 | 11:10 pm
      Spectro, Pseudostereo,
      thanks a lot to both of you.
      The two videoplanes approach the you are using, Pseudostereo, makes plenty of sense to me, but since some processing of the image is also taking place after the blending I'm afraid I cannot use it.
      I'll probably try and use a shader to rescale the images before being displayed, which resembles also what Spectro was suggesting, right?
      Thanks again to both. I'll report back.
    • May 26 2011 | 11:42 pm
      Actually, Niccolo, that shouldn't stop you - all you have to do is bang the movie objects as well as the render, and everything will update accordingly. I just set it up the way I did for simplicity.
      Spectro's suggestion is a little different than any of mine - dstrect is an attribute of the movie object itself, so you'd be scaling the movie before it got to the shader. Either approach should work, but the scaling operations aren't quite as straightforward.
    • May 26 2011 | 11:57 pm
      Thanks, I'll have to study this in more detail. You know, I'm still thinking patch cords and the GL thing where matrixes are available to several objects without connections messes with my head...
    • May 27 2011 | 7:42 pm
      the following patch will allow you to calculate proper scale values for a gl.videoplane with @transform_reset 1, for any source movie aspect-ratio, and any window aspect-ratio.
      let me know if anything is not clear.
    • Jun 02 2011 | 9:02 am
      Thanks a lot to all, the problem seemed to me harder than it really is.
      Thanks to you I found it was not THAT hard.