0
votes

I was using sws_scale to convert a group of RGB32 images to YUV420 format. Each image is very similar to the previous one and they only differ on a rectangle region Q.

My question is how to utilize Q to speed up the conversion process? An additional parameter should be added to sws_scale function.

sws_scale( ctx, in_plane, in_stride, sliceY, height, out_plane, out_stride, Q){
    // parameter out_plane stores the YUV420 data of previous image
    Instead of scanning the whole image, scan through rectangle Q{
        Do conversion
    }
}
1

1 Answers

0
votes

No such parameter exists in the current API but you can use sws_scale as is. You can create two contexts - one for whole picture and one for Q; in order to convert only Q:

  • use context you created for Q
  • Shift all data pointers so they all point at first pixel of Q in input/output pictures
  • Leave strides as they were for the full picture

Several caveats here to look for: firstly, since you use YUV420 as output format, you want to increase Q so it starts at even line/column and occupies even width/height (otherwise there can be some distorted color at Q border). Secondly, make sure pointers of all picture planes point to the same pixel - this requires different offsets for each plane depending on a pixel format. Thirdly, this works best if there's no scaling - otherwise resulting picture might not look exactly the same as it would with full-picture scale due to dithering.