Silviu Petrut
Silviu Petrut

Reputation: 89

Optimize image buffer

Here is a code that decodes a WebM frame and put them in a buffer

image->planes[p] = pointer to the top left pixel 

image->linesize[p] = strides betwen rows 

framesArray = vector of unsigned char*

     while ( videoDec->getImage(*image) == VPXDecoder::NO_ERROR)
                        {



                                const int w = image->getWidth(p);
                                const int h = image->getHeight(p);

                                int offset = 0;
                                for (int y = 0; y < h; y++)
                                {
                                   // fwrite(image->planes[p] + offset, 1, w, pFile);
                                    for(int i=0;i<w;i++){
                                        framesArray.at(count)[i+(w*y)] = *(image->planes[p]+offset+ i) ;

                                }

                                offset += image->linesize[p];



                            }
}
.............................

How can I write intro buffer line by line not pixel by pixel or optimize the writing of frame intro buffer?

Upvotes: 0

Views: 203

Answers (1)

pengMiao
pengMiao

Reputation: 344

if the source image and destination buffer share the same Width, Height and bit per pixel, you can use std::copy to copy the whole image into it.

std::copy(image->planes[p] + offset, image->planes[p] + (image->getHeight(p) * image->linesize[p], framesArray.begin()) ;

if it is same bit per pixel but different width and height, you can use std::copy by line.

Upvotes: 1

Related Questions