I would like to see a non-const getPixelsPtr method so that I can load the image data directly from another API.
I set the image size with the create method, I then would like to pass the address return by getPixelsPtr to the ffmpeg image convert methods so that it loads my image directly. Currently I have to create a temporary location and then call he loadfrommemory This results in an extra memcpy that I would like to avoid. I would like to pass the getPixelsPtr directly into the avpicture_fill method directly. Below is how I would use it.
thoughts?
IMAGE_PTR_T pImage = m_ImageCache.create(dPTS,
m_pAVStrm->codec->width, m_pAVStrm->codec->height);
ffmpeg::avpicture_fill(&pict, pImage->image.getPixelsPtr(), ffmpeg::PIX_FMT_RGBA,
m_pAVStrm->codec->width, m_pAVStrm->codec->height);
m_pImgConvertCtx = ffmpeg::sws_getCachedContext(m_pImgConvertCtx,
m_pAVStrm->codec->width, m_pAVStrm->codec->height, m_pAVStrm->codec->pix_fmt, // src size / fmt
m_pAVStrm->codec->width, m_pAVStrm->codec->height, ffmpeg::PIX_FMT_RGBA, // dest size / fmt
SWS_FAST_BILINEAR, NULL, NULL, NULL);
if (m_pImgConvertCtx == 0)
{
throw std::runtime_error("Cannot initialize the conversion context");
}
sws_scale(m_pImgConvertCtx, pFrame->data, pFrame->linesize,
0, m_pAVStrm->codec->height, pict.data, pict.linesize);
Is there a sf::Image method that will use my data pointer directly without doing a memcpy into it's internal vector? I don't see one. I am hoping to avoid this extra memcpy as I am decompressing many frames and do not want the extra overhead of the extra memcpy.
from Image.cpp
////////////////////////////////////////////////////////////
void Image::create(unsigned int width, unsigned int height, const Uint8* pixels)
{
if (pixels && width && height)
{
...
I want to avoid the step below
// Copy the pixels
std::size_t size = width * height * 4;
m_pixels.resize(size);
std::memcpy(&m_pixels[0], pixels, size); // faster than vector::assign
}
else
...