Пример #1
0
VideoFrame VideoFrame::clone() const
{
    Q_D(const VideoFrame);
    if (!d->format.isValid())
        return VideoFrame();
    int bytes = 0;
    for (int i = 0; i < d->format.planeCount(); ++i) {
        bytes += bytesPerLine(i)*planeHeight(i);
    }
    QByteArray buf(bytes, 0);
    char *dst = buf.data(); //must before buf is shared, otherwise data will be detached.
    VideoFrame f(buf, width(), height(), d->format);
    for (int i = 0; i < d->format.planeCount(); ++i) {
        f.setBits((quint8*)dst, i);
        f.setBytesPerLine(bytesPerLine(i), i);
        const int plane_size = bytesPerLine(i)*planeHeight(i);
        memcpy(dst, bits(i), plane_size);
        dst += plane_size;
    }
    f.d_ptr->metadata = d->metadata; // need metadata?
    f.setTimestamp(d->timestamp);
    f.setDisplayAspectRatio(d->displayAspectRatio);
    //f.setImageConverter(d->conv);
    return f;
}
void copyImage16To32(short *fromImageData, int *toImageData, int width, int height,
					 int affectedL, int affectedT, int affectedR, int affectedB)
{
	long scanLine16, firstWord16, lastWord16;
	long scanLine32, firstWord32;
	int line;
	register unsigned int col;

#if defined(DEBUG)
	fprintf(stderr, "copyImg16to32 %p -> %p (%d %d) %d %d %d %d\n",
			fromImageData, toImageData, width, height,
			affectedT, affectedL, affectedB, affectedR);
#endif
	
#define map16To32(w) (col= (w), \
(((col >> 10) & 0x1f) << 3) | \
(((col >> 5)  & 0x1f) << 11) | \
((col & 0x1f) << 19))
	
	scanLine16= bytesPerLine(width, 16);
	firstWord16= scanLine16*affectedT + bytesPerLineRD(affectedL, 16);
	lastWord16= scanLine16*affectedT + bytesPerLine(affectedR, 16);
	scanLine32= bytesPerLine(width, 32);
	firstWord32= 0;
	
	for (line= affectedT; line < affectedB; line++)
    {
		register unsigned short *from= (unsigned short *)((long)fromImageData+firstWord16);
		register unsigned short *limit= (unsigned short *)((long)fromImageData+lastWord16);
		register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
		while (from < limit)
		{
#	 if defined(WORDS_BIGENDIAN)
			to[0]= map16To32(from[0]);
			to[1]= map16To32(from[1]);
#	 else
			to[0]= map16To32(from[1]);
			to[1]= map16To32(from[0]);
#	 endif
			from+= 2;
			to+= 2;
		}
		firstWord16+= scanLine16;
		lastWord16+= scanLine16;
		firstWord32+= scanLine32;
    }
#undef map16To32
}
Пример #3
0
const QIcon& CIconProvider::iconFor(const CFileSystemObject& object)
{
	const qulonglong objectHash = hash(object);
	if (_iconForObject.count(objectHash) == 0)
	{
		const QIcon icon = _provider->iconFor(object);
		assert_r(!icon.isNull());

		const auto qimage = icon.pixmap(icon.availableSizes().front()).toImage();
		const qulonglong iconHash = fasthash64((const char*)qimage.constBits(), qimage.bytesPerLine() * qimage.height(), 0);

		if (_iconCache.size() > 300)
		{
			_iconCache.clear();
			_iconForObject.clear();
		}

		const auto iconInContainer = _iconCache.insert(std::make_pair(iconHash, icon)).first;
		_iconForObject[objectHash] = iconHash;
		
		return iconInContainer->second;
	}

	return _iconCache[_iconForObject[objectHash]];
}
Пример #4
0
STDMETHODIMP UIFrameBuffer::COMGETTER(BytesPerLine) (ULONG *puBytesPerLine)
{
    if (!puBytesPerLine)
        return E_POINTER;
    *puBytesPerLine = bytesPerLine();
    return S_OK;
}
Пример #5
0
/*!
    \internal
*/
unsigned char * QWidget::scanLine(int i) const
{
    // Should add widget x() here, maybe
    unsigned char * base=qwsDisplay()->frameBuffer();
    if(base)
	base+=i*bytesPerLine();
    return base;
}
Пример #6
0
QByteArray Frame::data(int plane) const
{
    if (plane < 0 || plane >= planeCount()) {
        qWarning("Invalid plane! Valid range is [0, %d)", planeCount());
        return QByteArray();
    }
    return QByteArray((char*)d_func()->planes[plane], bytesPerLine(plane));
}
Пример #7
0
AudioFrame AudioFrame::clone() const
{
    Q_D(const AudioFrame);
    if (d->format.sampleFormatFFmpeg() == AV_SAMPLE_FMT_NONE
            || d->format.channels() <= 0)
        return AudioFrame();
    if (d->samples_per_ch <= 0 || bytesPerLine(0) <= 0)
        return AudioFrame(format());
    QByteArray buf(bytesPerLine()*planeCount(), 0);
    AudioFrame f(buf, d->format);
    f.setSamplesPerChannel(samplesPerChannel());
    char *dst = buf.data(); //must before buf is shared, otherwise data will be detached.
    for (int i = 0; i < f.planeCount(); ++i) {
        const int plane_size = f.bytesPerLine(i);
        memcpy(dst, f.constBits(i), plane_size);
        dst += plane_size;
    }
    f.setTimestamp(timestamp());
    // meta data?
    return f;
}
Пример #8
0
VideoFrame VideoFrame::clone() const
{
    Q_D(const VideoFrame);
    if (!d->format.isValid())
        return VideoFrame();

    // data may be not set (ff decoder)
    if (d->planes.isEmpty() || !d->planes.at(0)) {//d->data.size() < width()*height()) { // at least width*height
        // maybe in gpu memory, then bits() is not set
        qDebug("frame data not valid. size: %d", d->data.size());
        VideoFrame f(width(), height(), d->format);
        f.d_ptr->metadata = d->metadata; // need metadata?
        f.setTimestamp(d->timestamp);
        f.setDisplayAspectRatio(d->displayAspectRatio);
        return f;
    }
    int bytes = 0;
    for (int i = 0; i < d->format.planeCount(); ++i) {
        bytes += bytesPerLine(i)*planeHeight(i);
    }

    QByteArray buf(bytes, 0);
    char *dst = buf.data(); //must before buf is shared, otherwise data will be detached.
    VideoFrame f(width(), height(), d->format, buf);
    const int nb_planes = d->format.planeCount();
    for (int i = 0; i < nb_planes; ++i) {
        f.setBits((quint8*)dst, i);
        f.setBytesPerLine(bytesPerLine(i), i);
        const int plane_size = bytesPerLine(i)*planeHeight(i);
        memcpy(dst, constBits(i), plane_size);
        dst += plane_size;
    }
    f.d_ptr->metadata = d->metadata; // need metadata?
    f.setTimestamp(d->timestamp);
    f.setDisplayAspectRatio(d->displayAspectRatio);
    f.setColorSpace(d->color_space);
    f.setColorRange(d->color_range);
    return f;
}
void copyImage8To32(int *fromImageData, int *toImageData, int width, int height,
					int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
{
	long scanLine8, firstWord8, lastWord8;
	long scanLine32, firstWord32;
	int line;
	
	scanLine8= bytesPerLine(width, 8);
	firstWord8= scanLine8*affectedT + bytesPerLineRD(affectedL, 8);
	lastWord8= scanLine8*affectedT + bytesPerLine(affectedR, 8);
	scanLine32= bytesPerLine(width, 32);
	firstWord32= 0;
	
	for (line= affectedT; line < affectedB; line++)
    {
		register unsigned char *from= (unsigned char *)((long)fromImageData+firstWord8);
		register unsigned char *limit= (unsigned char *)((long)fromImageData+lastWord8);
		register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
		while (from < limit)
		{
#	 if defined(WORDS_BIGENDIAN)
			to[0]= stColors[from[0]];
			to[1]= stColors[from[1]];
			to[2]= stColors[from[2]];
			to[3]= stColors[from[3]];
#	 else
			to[0]= stColors[from[3]];
			to[1]= stColors[from[2]];
			to[2]= stColors[from[1]];
			to[3]= stColors[from[0]];
#	 endif
			from+= 4;
			to+= 4;
		}
		firstWord8+= scanLine8;
		lastWord8+= scanLine8;
		firstWord32+= scanLine32;
    }
}
void copyImage1To32(int *fromImageData, int *toImageData, int width, int height,
					int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
{
	long scanLine1, firstWord1, firstShift1;
	long scanLine32, firstWord32, lastWord32;
	int line;
	
	scanLine1= bytesPerLine(width, 1);
	firstWord1= scanLine1*affectedT + bytesPerLineRD(affectedL, 1);
	firstShift1= 31 - (affectedL & 31);
	
	scanLine32= bytesPerLine(width, 32);
	firstWord32= 0;
	lastWord32= bytesPerLine(affectedR, 32);
	
	for (line= affectedT; line < affectedB; line++)
    {
		register unsigned int *from= (unsigned int *)((long)fromImageData+firstWord1);
		register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
		register unsigned int *limit= (unsigned int *)((long)toImageData+lastWord32);
		register int shift= firstShift1;
		while (to < limit)
		{
			*to= stColors[(*from >> shift) & 1];
			to++;
			shift--;
			if (shift < 0)
			{
				shift= 31;
				from++;
			}
		}
		firstWord1+= scanLine1;
		firstWord32+= scanLine32;
		lastWord32+= scanLine32;
    }
}
void copyImage2To32(int *fromImageData, int *toImageData, int width, int height,
					int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
{
	long scanLine2, firstWord2, firstShift2;
	long scanLine32, firstWord32, lastWord32;
	int line;
	
	scanLine2= bytesPerLine(width, 2);
	firstWord2= scanLine2*affectedT + bytesPerLineRD(affectedL, 2);
	firstShift2= 30 - ((affectedL & 15) * 2);
	
	scanLine32= bytesPerLine(width, 32);
	firstWord32= 0;
	lastWord32= bytesPerLineRD(affectedR, 32);
	
	for (line= affectedT; line < affectedB; line++)
    {
		register unsigned int *from= (unsigned int *)((long)fromImageData+firstWord2);
		register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
		register unsigned int *limit= (unsigned int *)((long)toImageData+lastWord32);
		register int shift= firstShift2;
		while (to < limit)
		{
			*to= stColors[(*from >> shift) & 3];
			to++;
			shift-= 2;
			if (shift < 0)
			{
				shift= 30;
				from++;
			}
		}
		firstWord2+= scanLine2;
		firstWord32+= scanLine32;
		lastWord32+= scanLine32;
    }
}
void copyImage4To32(int *fromImageData, int *toImageData, int width, int height,
					int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
{
	int scanLine4, firstWord4, firstShift4;
	long scanLine32, firstWord32, lastWord32;
	long line;
	
	scanLine4= bytesPerLine(width, 4);
	firstWord4= scanLine4*affectedT + bytesPerLineRD(affectedL, 4);
	firstShift4= 28 - ((affectedL & 7) * 4);
	
	scanLine32= bytesPerLine(width, 32);
	firstWord32= 0;
	lastWord32= bytesPerLineRD(affectedR, 32);
	
	for (line= affectedT; line < affectedB; line++)
    {
		register unsigned int *from= (unsigned int *)((long)fromImageData+firstWord4);
		register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
		register unsigned int *limit= (unsigned int *)((long)toImageData+lastWord32);
		register int shift= firstShift4;
		while (to < limit)
		{
			*to= stColors[(*from >> shift) & 15];
			to++;
			shift-= 4;
			if (shift < 0)
			{
				shift= 28;
				from++;
			}
		}
		firstWord4+= scanLine4;
		firstWord32+= scanLine32;
		lastWord32+= scanLine32;
    }
}
Пример #13
0
// TODO: alignment. use av_samples_fill_arrays
void AudioFrame::init()
{
    Q_D(AudioFrame);
    const int nb_planes = d->format.planeCount();
    d->line_sizes.resize(nb_planes);
    d->planes.resize(nb_planes);
    for (int i = 0; i < nb_planes; ++i) {
        setBytesPerLine(d->data.size()/nb_planes, i);
    }
    if (d->data.isEmpty())
        return;
    for (int i = 0; i < nb_planes; ++i) {
        setBits((uchar*)d->data.constData() + i*bytesPerLine(i), i);
    }
}
Пример #14
0
/**
 * videoConfigLine must be something like video=1024x768x32@0xf0000000,4096
 * where 0xf0000000 is the base address and 4096 is the number of bytes per scanline
 * if the number of byte per scanline is not present, it's going to be guessed (X/8)
**/
void parseVideoInfo(DisplayInfo *videoInfo, char *videoConfigLine)
{
	/* videoConfigLine is {width}x{height}x{depth}@{address},{bytesPerScanLine}\0 */

	char sep_tokens[] = { /*width*/ 'x', /*height*/'x', /*depth*/ '@', /*address*/ ',', /*bytesPerScanLine*/ '\0'};
	
	videoConfigLine = strstr(videoConfigLine, "video=") + 6;

	videoConfigLine = parseString(videoConfigLine, &videoInfo->width,   sep_tokens[0]);
	videoConfigLine = parseString(videoConfigLine, &videoInfo->height,  sep_tokens[1]);
	videoConfigLine = parseString(videoConfigLine, &videoInfo->depth,   sep_tokens[2]);
	videoConfigLine = parseString(videoConfigLine, &videoInfo->address, sep_tokens[3]);
	
	if (videoConfigLine)
		parseString(videoConfigLine, &videoInfo->bytesPerScanLine, sep_tokens[4]);
	else
		videoInfo->bytesPerScanLine = bytesPerLine(videoInfo->width, videoInfo->depth);
}
Пример #15
0
G12Image::G12Image(G12Buffer *buffer, int newH, int newW) : QImage(newW, newH, QImage::Format_RGB32)
{
    int bpl = bytesPerLine();
    uint8_t *data = bits(), *line = data;

    for (int i = 0; i < newH; ++i, line += bpl)
    {
        for (int j = 0; j < newW; ++j)
        {
            uint32_t value;
            if (i < buffer->h && j < buffer->w)
            {
                uint8_t c = buffer->element(i, j) >> 4;
                value = c | (c << 8) | (c << 16) | (0xFF << 24);
            }
            else
            {
                value = 0xFF000000UL;
            }

            ((uint32_t *)line)[j] = value;
        }
Пример #16
0
 const T* Matrix<T>::constRow( const int Row ) const
 {
   return reinterpret_cast<T*>(cv::Mat::data  + Row*bytesPerLine());
 }
Пример #17
0
int VideoFrame::planeWidth(int plane) const
{
    Q_D(const VideoFrame);
    return bytesPerLine(plane)/d->format.bytesPerPixel(plane);
}
Пример #18
0
/**
 * Creates a new surface in the requested format.
 * On success, returns @c true and assigns the created surface to mSurface
 * and its definition to mSurfaceDesc. On failure, returns @c false.
 *
 * If @a aPixelFormat is other than FramebufferPixelFormat_Opaque,
 * then the method will attempt to attach @a aVRAM directly to the created
 * surface. If this fails, the caller may call this method again with
 * @a aPixelFormat set to FramebufferPixelFormat_Opaque to try
 * setting up an indirect fallback buffer for the surface. This opeartion may
 * theoretically also fail.
 *
 * @note Deletes the existing surface before attempting to create a new one.
 */
bool VBoxDDRAWFrameBuffer::createSurface (ULONG aPixelFormat, uchar *aVRAM,
                                          ULONG aBitsPerPixel, ULONG aBytesPerLine,
                                          ULONG aWidth, ULONG aHeight)
{
    deleteSurface();

    DDSURFACEDESC2 sd;

    /* Prepare the surface description structure. */
    memset (&sd, 0, sizeof (sd));

    sd.dwSize  = sizeof (sd);
    sd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH |
                 DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT;

    sd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
    sd.dwWidth = aWidth;
    sd.dwHeight = aHeight;

    /* Setup the desired pixel format on the surface. */

    sd.ddpfPixelFormat.dwSize = sizeof (sd.ddpfPixelFormat);
    sd.ddpfPixelFormat.dwFlags = DDPF_RGB;

    if (aPixelFormat == FramebufferPixelFormat_FOURCC_RGB)
    {
        /* Try to use the guest VRAM directly */

        switch (aBitsPerPixel)
        {
            case 32:
                sd.ddpfPixelFormat.dwRGBBitCount = 32;
                sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
                sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
                sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
                break;
            case 24:
                sd.ddpfPixelFormat.dwRGBBitCount = 24;
                sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
                sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
                sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
                break;
            case 16:
                sd.ddpfPixelFormat.dwRGBBitCount = 16;
                sd.ddpfPixelFormat.dwRBitMask = 0xF800;
                sd.ddpfPixelFormat.dwGBitMask = 0x07E0;
                sd.ddpfPixelFormat.dwBBitMask = 0x001F;
                break;
            default:
                /* we don't directly support any other color depth */
                return false;
        }

        sd.lPitch = (LONG) aBytesPerLine;

        sd.lpSurface = aVRAM;
        mUsesGuestVRAM = true;

        mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
    }
    else
    if (aPixelFormat != FramebufferPixelFormat_Opaque)
    {
        /* we don't directly support any other pixel format */
        return false;
    }
    else
    {
        /* for the Opaque format, we use the indirect memory buffer as a
         * 32 bpp surface. */

        sd.ddpfPixelFormat.dwRGBBitCount = 32;
        sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
        sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
        sd.ddpfPixelFormat.dwBBitMask = 0x000000FF;

        sd.lPitch = sd.dwWidth * 4;

        /* Allocate the memory buffer for the surface */
        sd.lpSurface = RTMemAlloc (sd.lPitch * sd.dwHeight);
        if (sd.lpSurface == NULL)
        {
            LOGDDRAW (("DDRAW: could not allocate memory for surface.\n"));
            return false;
        }
        mUsesGuestVRAM = false;

        mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
    }

    /* create the surface */
    HRESULT rc = mDDRAW->CreateSurface (&sd, &mSurface, NULL);

    if (rc != DD_OK)
    {
        LOGDDRAW (("DDRAW: Could not create DirectDraw surface, rc=0x%08X\n", rc));
        deleteSurface();
        return false;
    }

    /* Initialize the surface description member. It will be used to obtain
     * address, bpp and bpl. */
    mSurfaceDesc = sd;

    LOGDDRAW(("DDRAW: Created %s surface: format = %d, address = %p\n",
              mUsesGuestVRAM ? "GuestVRAM": "system memory",
              aPixelFormat, address ()));

    if (!mUsesGuestVRAM)
    {
        /* Clear just created surface. */
        memset (address(), 0, bytesPerLine() * height());
    }

    return true;
}