void GLWidgetRendererPrivate::updateShaderIfNeeded() { const VideoFormat& fmt(video_frame.format()); if (fmt != video_format) { qDebug("pixel format changed: %s => %s", qPrintable(video_format.name()), qPrintable(fmt.name())); } VideoMaterialType *newType = materialType(fmt); if (material_type == newType) return; material_type = newType; // http://forum.doom9.org/archive/index.php/t-160211.html ColorTransform::ColorSpace cs = ColorTransform::RGB; if (fmt.isRGB()) { if (fmt.isPlanar()) cs = ColorTransform::GBR; } else { if (video_frame.width() >= 1280 || video_frame.height() > 576) //values from mpv cs = ColorTransform::BT709; else cs = ColorTransform::BT601; } if (!prepareShaderProgram(fmt, cs)) { qWarning("shader program create error..."); return; } else { qDebug("shader program created!!!"); } }
void GLWidgetRendererPrivate::updateTexturesIfNeeded() { const VideoFormat &fmt = video_frame.format(); bool update_textures = false; if (fmt != video_format) { update_textures = true; //FIXME qDebug("updateTexturesIfNeeded pixel format changed: %s => %s", qPrintable(video_format.name()), qPrintable(fmt.name())); } // effective size may change even if plane size not changed if (update_textures || video_frame.bytesPerLine(0) != plane0Size.width() || video_frame.height() != plane0Size.height() || (plane1_linesize > 0 && video_frame.bytesPerLine(1) != plane1_linesize)) { // no need to check height if plane 0 sizes are equal? update_textures = true; qDebug("---------------------update texture: %dx%d, %s", video_frame.width(), video_frame.height(), video_frame.format().name().toUtf8().constData()); const int nb_planes = fmt.planeCount(); texture_size.resize(nb_planes); texture_upload_size.resize(nb_planes); effective_tex_width.resize(nb_planes); for (int i = 0; i < nb_planes; ++i) { qDebug("plane linesize %d: padded = %d, effective = %d", i, video_frame.bytesPerLine(i), video_frame.effectiveBytesPerLine(i)); qDebug("plane width %d: effective = %d", video_frame.planeWidth(i), video_frame.effectivePlaneWidth(i)); qDebug("planeHeight %d = %d", i, video_frame.planeHeight(i)); // we have to consider size of opengl format. set bytesPerLine here and change to width later texture_size[i] = QSize(video_frame.bytesPerLine(i), video_frame.planeHeight(i)); texture_upload_size[i] = texture_size[i]; effective_tex_width[i] = video_frame.effectiveBytesPerLine(i); //store bytes here, modify as width later // TODO: ratio count the GL_UNPACK_ALIGN? //effective_tex_width_ratio = qMin((qreal)1.0, (qreal)video_frame.effectiveBytesPerLine(i)/(qreal)video_frame.bytesPerLine(i)); } plane1_linesize = 0; if (nb_planes > 1) { texture_size[0].setWidth(texture_size[1].width() * effective_tex_width[0]/effective_tex_width[1]); // height? how about odd? plane1_linesize = video_frame.bytesPerLine(1); } effective_tex_width_ratio = (qreal)video_frame.effectiveBytesPerLine(nb_planes-1)/(qreal)video_frame.bytesPerLine(nb_planes-1); qDebug("effective_tex_width_ratio=%f", effective_tex_width_ratio); plane0Size.setWidth(video_frame.bytesPerLine(0)); plane0Size.setHeight(video_frame.height()); } if (update_textures) { initTextures(fmt); } }
void VideoMaterial::setCurrentFrame(const VideoFrame &frame) { DPTR_D(VideoMaterial); d.update_texure = true; d.bpp = frame.format().bitsPerPixel(0); d.width = frame.width(); d.height = frame.height(); const VideoFormat fmt(frame.format()); // http://forum.doom9.org/archive/index.php/t-160211.html ColorTransform::ColorSpace cs = ColorTransform::RGB; if (fmt.isRGB()) { if (fmt.isPlanar()) cs = ColorTransform::GBR; } else { if (frame.width() >= 1280 || frame.height() > 576) //values from mpv cs = ColorTransform::BT709; else cs = ColorTransform::BT601; } d.colorTransform.setInputColorSpace(cs); d.frame = frame; if (fmt != d.video_format) { qDebug("pixel format changed: %s => %s", qPrintable(d.video_format.name()), qPrintable(fmt.name())); d.video_format = fmt; } }