This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DaVinci Resizer - without using the Resize driver

Hi,

 

I’m using the Resizer Hardware module of DaVinci for resizing to a particular resolution.

 

I’m not using the Resizer driver, rather I have put in a piece of code to directly calculate the hrsz, vrsz, input_width, output_width and configure the appropriate registers.

 

I initially used the ti_davinci_resizer.pdf as the reference and calculated the above values based on the formulas in the document and observed a hardware hang.

So based on my observations I took an approach deviating from the ti_davinci_resizer document and it worked fine. Can anyone give a confirmation whether my approach is right?

 

ti_davinci_resizer document:

To ensure consistent sizing, the DaVinci_resizer document says that hrsz and 

          vrsz needs to be calculated using the below formula

                   hrsz = floor(((in_width - 4) *256)/(ow-1))

                   vrsz = floor(((in_height - 4) *256)/(oh-1)) 

                   in_width and the in_height are original width and height for the input image.

          

Once hrsz and vrsz values are calculated using above equations, they must be applied below equation to calculate iw and ih values

 

iw = (32 * sph + (ow -1) * hrsz + 16) >> 8 + 7

ih = (32 *spv + (oh - 1) * vrsz + 16) >> 8 + 4

       

sph and spv are considere to be equal to zero.

When the above said approach was followed, I observed hardware hang because of the inconsistent values of input height and output height in regards to the scaling factor for vertical directions.

 

So based on my observations I took the following approach deviating from the ti_davinci_resizer document.

 

My approach:

The hrsz and vrsz values are calculated based on the formula provided in the davinci resizer document.

After calculating hrsz and vrsz, I calculated iw and ih based on hrsz and vrsz respectively.

Now we need to choose iw and calculate temp_hrsz again with the above formula without floor such that we obtain a value of temp_hrsz greatest in the range

                        hrsz < temp_hrsz < (hrsz+1)       

                        temp_hrsz = ((iw - 4) *256)/(ow-1)

 

Similarly we need to choose ih and calculate temp_vrsz without floor such that we obtain a value of temp_vrsz greatest in the range

                        vrsz < temp_vrsz < (vrsz+1)     (temp_vrsz is a floating point value)

                        temp_vrsz = ((ih - 4) *256)/(oh-1)

This approach provided a consistent input and output sizes with regards to the scaling factor, for both horizontal and vertical directions.

Comparison:

iw and ih calculations:

Approach

Input Resolution

Output Resolution

iw

ih

HRSZ

VRSZ

Comment

 

Davinci document

352x240

704x240

353

239

126

126

Hardware hang

My approach

352x240

704x240

353

241

126

126

Works fine

I am using the calcoef for generating filter coefficients in both approaches.

 

 

Can anyone comment whether my approach is correct or suggest what is that I have missed while calculating which makes the hardware to hang.

 

Thanks in advance.

  • Hello,

    Here is our expert's comment:

    Is the document you are referring to SPRAAI7B?  I could not find ti_davinci_resizer.pdf on the internet.

    I think the VRSZ column in your summary table may be incorrect.  It looks like you used the HRSZ values again.  The values should about 252.  Please confirm what you get for the VRSZ column so that I can match the math better.

    Also, I was able to follow the math to come up with the "Davinci document" results, but I couldn't come up with the value 241 for ih in your approach. Can you please more explicity show how you came up with the ih and VRSZ in your approach?

    Also, since you are not using the driver, are you getting the input image from memory directly, or fed from another HW block.  The answer to this might change the equation.

  • Hi,

    The document which I'm referring to is SPRAAI7B itself.

    I'm extremely sorry for the error in my summary table. I'm actually trying to resize a 352x240 to 720x480 (not 704x240) .

    Approach

    Input Resolution

    Output Resolution

    iw

    ih

    HRSZ

    VRSZ

    Comment

     

    Davinci document

    352x240

    720x480

    352

    239

    123

    126

    Hardware hang

    My approach

    352x240

    720x480

    352

    241

    123

    126

    Works fine

    To resize a  352x240  to  720x480 using my approach:
    in_width = 352   in_height =240   ow=720   oh=480
    in_width and the in_height are original width and height for the input image

    Step 1:
    Calculate hrsz and vrsz ( Horizontal & Vertical resizing values) :
    (We are making use of 4 Tap 8 phase filter as we are performing upscaling)


    hrsz = floor(((in_width - 4) *256)/(ow-1))
            = floor(   (352-4) *256 ) / (720-1) )
            = floor( 123.90)
            = 123


    vrsz  = floor(((in_height - 4) *256)/(oh-1)) 
            = floor(   (240-4) *256 ) / (480-1) )
            = floor(126.129)
            = 126


    hrsz=123             vrsz 126


    Step 2:
    Calculating iw and ih:
    Now we need to choose iw and calculate temp_hrsz without floor such that we obtain temp_hrsz value greater than 123 but less than 124

    in_width = 352    so start with iw=352
    iw=352
    temp_hrsz  = ( (iw - 4) *256 ) / (ow-1)
             = ( (352 - 4) *256 ) / (720-1)
             = 123.90
    iw=353
    temp_hrsz  = ( (353- 4) *256 ) / (720-1)
             = 124.261
    iw=352 satisfies the condition therefore choose iw as 352

    Similarly we need to choose ih and calculate temp_vrsz without floor such that we obtain temp_vrsz value greater than 126 but less than 127

    in_height =240    so start with ih=240
    ih=240         
    temp_vrsz  = ( (ih - 4) *256 ) / (oh-1)
             =( ( 240-4 )*256 ) / ( 480 -1 )
             = 126.1294

    ih=241
    temp_vrsz  = ( (241 - 4) *256 ) / (480-1)
             = 126.6638
    ih=242
    temp_vrsz  = ( (242 - 4) *256 ) / (480-1)
             = 127.1983

    ih=241 satisfies the condition therefore choose ih as 241

    iw=352     ih=241
    hrsz=123  vrsz =126

     

    I'm  getting the input from SDRAM.

    Thank you

     

  • The math makes sense now.  However, I think that the original method from the document should be working and he shouldn’t have to do what he is doing.  

     

    I suspect that the problem might be the value he is programming into the RSZ_CNT.VRSZ and RSZ_CNT.HRSZ register fields.  The resizer document has the following equation:

     

    iw = (32 * sph + (ow -1) * hrsz + 16) >> 8 + 7

    ih = (32 *spv + (oh - 1) * vrsz + 16) >> 8 + 4

     

    The value of vrsz and hrsz in these equations should be programmed into the registers as the value minus 1, eg.

     

    RSZ_CNT.HRSZ = hrsz-1

    RSZ_CNT.VRSZ = vrsz-1

     

    and

     

    hrsz = RSZ_CNT.HRSZ+1

    vrsz = RSZ_CNT.VRSZ+1

     

    This isn’t clear in the resizer document and the TRM, so someone who is not using the low level driver might overlook this.  If this is the problem, then the math makes sense that the ih of 241 works instead of 239.  As far as the horizontal value being wrong, I think this is one of those cases where it might work out that it works due the extra clocks that the HW gives itself in the horizontal direction … but the equation he was using may not always work.

     

    If this isn’t the problem, then please request him to send the following register dump so I can check.

     

    RSZ_CNT

    OUT_SIZE

    IN_START

    IN_SIZE

  • Hi!

    I am developing a software, and I need to use the resize, but I cant understand these equations to set the parameters… could you help me?

    I am using a sensor, in this case the MT9P031, to capture raw image.

    I am putting the data into DDR, after this, I am doing the preview (RGB to YCbCr) and it works because I can see using vpbe (the image come with a black column on right).

    Now, I need to do the resize (to take off the black column).

    The raw image is 640x480 (RGB), and I need to resize to 720x480 (YCbCr).

    (Ps: I cant to do all in one time, because I need the raw image to analyze and YCbCr to vpbe)

    Thanks!

     

  • Hi!

    I saw in my software the RGB image to fill the DDR memory with values (all 640x480 words), and when I convert it in YCbCr (now in bytes) the values and the space of memory change! Like:
    Line 1 -  0 up to 1270 = 0x80 0xXX 0x80 0xXX …..  1271 up to 2559 = 0x00 0x00 0x00 0x00 …..
    Line 2 – 2560 up to 3830 (2560 + 1270) = 0x80 0xXX 0x80 0xXX …..  3831 up to 5119 = 0x00 0x00 0x00….
    .
    .
    .

    Because this I cant to determine the value in IN_SIZE also…..

    Is it happen (the 0x00 values) because the sensor is mono chromatic??

    Thanks!

  • The 0x80 values seem to indicate the the image is monochromatic ... that is, all the chroma values are set to 0x80 since there is no color.  And only the luma (Y) values are changing. 

    Did you clear the output buffer to 0 before executing?  If so, the "1271 up to 2559 = 0x00 0x00 0x00 0x00" seem to indicate  that the setting for number of output bytes per line (line offset) is set to 2560 bytes.  This means the hardware is writing 1280 bytes per line at the beginning of every 2560 bytes in memory. Is this your intention? If you want to reduce this, you set the line offset smaller, but it is not required for things to work.


    Now to use the resizer on this buffer without chaning the line offset, you can set the input line offset of the resizer to match one that was used when this buffer was created.  This doesn't affect the number of lines, it just aligns each line to the proper starting address in memory.  The IN_SIZE must use the calculations based on input width and height (640x480).  It is completely independent of the line offset in memory.

    Does this answer your question.  If not, please send me more detailed register settings you are using.

  • Hi!

    Ok! Thanks for your help! I will see the configurations!!