MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / Thumbnail

Method Thumbnail

src/Frame.cpp:543–675  ·  view source on GitHub ↗

Thumbnail the frame image to the specified path. The image format is determined from the extension (i.e. image.PNG, image.JPEG)

Source from the content-addressed store, hash-verified

541
542// Thumbnail the frame image to the specified path. The image format is determined from the extension (i.e. image.PNG, image.JPEG)
543void Frame::Thumbnail(std::string path, int new_width, int new_height, std::string mask_path, std::string overlay_path,
544 std::string background_color, bool ignore_aspect, std::string format, int quality, float rotate, ScaleType scale_mode) {
545
546 // Create blank thumbnail image & fill background color
547 auto thumbnail = std::make_shared<QImage>(
548 new_width, new_height, QImage::Format_RGBA8888_Premultiplied);
549 thumbnail->fill(QColor(QString::fromStdString(background_color)));
550
551 // Create painter
552 QPainter painter(thumbnail.get());
553 painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);
554
555 // Get preview image
556 std::shared_ptr<QImage> previewImage = GetImage();
557
558 // Update the image to reflect the correct pixel aspect ration (i.e. to fix non-squar pixels)
559 if (pixel_ratio.num != 1 || pixel_ratio.den != 1)
560 {
561 // Calculate correct DAR (display aspect ratio)
562 int aspect_width = previewImage->size().width();
563 int aspect_height = previewImage->size().height() * pixel_ratio.Reciprocal().ToDouble();
564
565 // Resize to fix DAR
566 previewImage = std::make_shared<QImage>(previewImage->scaled(
567 aspect_width, aspect_height,
568 Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
569 }
570
571 // Resize frame image
572 Qt::AspectRatioMode aspect_ratio_mode = Qt::KeepAspectRatio;
573 if (ignore_aspect) {
574 aspect_ratio_mode = Qt::IgnoreAspectRatio;
575 } else {
576 switch (scale_mode) {
577 case SCALE_CROP:
578 aspect_ratio_mode = Qt::KeepAspectRatioByExpanding;
579 break;
580 case SCALE_STRETCH:
581 aspect_ratio_mode = Qt::IgnoreAspectRatio;
582 break;
583 case SCALE_FIT:
584 case SCALE_NONE:
585 default:
586 aspect_ratio_mode = Qt::KeepAspectRatio;
587 break;
588 }
589 }
590
591 previewImage = std::make_shared<QImage>(previewImage->scaled(
592 new_width, new_height,
593 aspect_ratio_mode, Qt::SmoothTransformation));
594
595 // Composite frame image onto background (centered)
596 int x = (new_width - previewImage->size().width()) / 2.0; // center
597 int y = (new_height - previewImage->size().height()) / 2.0; // center
598 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
599
600

Callers 2

write_thumbnailFunction · 0.80
mainFunction · 0.80

Calls 3

ToDoubleMethod · 0.80
ReciprocalMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected