the correct implementation is this: (note it still does one extra copy, i do 
not know how to remove that)

static
QVideoFrame             QVideoFrame_fromImage(const QImage& image)
{
        QVideoFrameFormat       frameFormat(
                image.size(),
                QVideoFrameFormat::pixelFormatFromImageFormat(image.format()));
        QVideoFrame             vidFrame(frameFormat); 
vidFrame.map(QVideoFrame::WriteOnly);
        qsizetype               image_rowbytesI(image.bytesPerLine());
        qsizetype               frame_rowbytesI(vidFrame.bytesPerLine());
        const uchar*            imageBitsP(image.bits());
        uchar*                  frameBitsP(vidFrame.bits());
        int                     maxRowY(image.size().height());

        CF_ASSERT(image_rowbytesI <= frame_rowbytesI);

        for (int rowY = 0; rowY < maxRowY; ++rowY) {
                std::copy(imageBitsP, imageBitsP + image_rowbytesI, frameBitsP);
                imageBitsP += image_rowbytesI;
                frameBitsP += frame_rowbytesI;
        }

        vidFrame.unmap();
        return vidFrame;
}



> On Jul 7, 2021, at 12:23 PM, David M. Cotter <d...@kjams.com> wrote:
> 
> that goes in the other direction. what i want is to set the image, not get it.
> 
>> On Jul 7, 2021, at 12:17 PM, Vladyslav Stelmakhovskyi 
>> <vladstelmahov...@gmail.com <mailto:vladstelmahov...@gmail.com>> wrote:
>> 
>> Hmm. What happens with .toImage() in Qt6's QVideoFrame?
>> 
>> On 2021-07-07 18:38, David M. Cotter wrote:
>>> does this seem right?
>>> 
>>>     const QImage&   image(pix);
>>>     #if _QT6_
>>>             QVideoFrameFormat       frameFormat(
>>>                     image.size(),
>>>                     
>>> QVideoFrameFormat::pixelFormatFromImageFormat(image.format()));
>>>             QVideoFrame             vidFrame(frameFormat); 
>>> vidFrame.map(QVideoFrame::WriteOnly);
>>>             uchar*                  memBitsP(vidFrame.bits());
>>>             const uchar*            imageBitsP(image.bits());
>>>             size_t                  memSizeL(vidFrame.mappedBytes());
>>>             size_t                  imgSizeL(image.sizeInBytes());
>>>             CF_ASSERT(memSizeL == imgSizeL);
>>>             std::copy(imageBitsP, imageBitsP + memSizeL, memBitsP);
>>>             vidFrame.unmap();
>>>     #else
>>>             // qt5 version
>>>             QVideoFrame             vidFrame(image);
>>>     #endif
>>>     present(vidFrame, opacityF);
>>> seems like a lot of convolution just to get an image into a video frame. 
>>> also why was the API designed to have the unnecessary copy? the api should 
>>> take a bits* directly, rather than forcing you to copy your bits into yet 
>>> another buffer.
>>> 
>>> am i missing something?
>>> 
>>>> On Jul 7, 2021, at 8:48 AM, David M. Cotter <d...@kjams.com 
>>>> <mailto:d...@kjams.com>> wrote:
>>>> 
>>>> seems the API to so so has been removed, so how do i do it?
>>>> 
>>>> i can't find any documentation on porting guidance
> 

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to