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

Method Open

src/QtImageReader.cpp:45–130  ·  view source on GitHub ↗

Open image file

Source from the content-addressed store, hash-verified

43
44// Open image file
45void QtImageReader::Open()
46{
47 // Open reader if not already open
48 if (!is_open)
49 {
50 bool loaded = false;
51 QSize default_svg_size;
52
53 // Check for SVG files and rasterizing them to QImages
54 if (path.toLower().endsWith(".svg") || path.toLower().endsWith(".svgz")) {
55 #if RESVG_VERSION_MIN(0, 11)
56 // Initialize the Resvg options
57 resvg_options.loadSystemFonts();
58 #endif
59
60 // Parse SVG file
61 default_svg_size = load_svg_path(path);
62 if (!default_svg_size.isEmpty()) {
63 loaded = true;
64 }
65 }
66
67 if (!loaded) {
68 // Attempt to open file using Qt's build in image processing capabilities
69 // AutoTransform enables exif data to be parsed and auto transform the image
70 // to the correct orientation
71 image = std::make_shared<QImage>();
72 QImageReader imgReader( path );
73 imgReader.setAutoTransform( true );
74 imgReader.setDecideFormatFromContent( true );
75 loaded = imgReader.read(image.get());
76 }
77
78 if (!loaded) {
79 // raise exception
80 throw InvalidFile("QtImageReader could not open image file.", path.toStdString());
81 }
82
83 // Update image properties
84 info.has_audio = false;
85 info.has_video = true;
86 info.has_single_image = true;
87 #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
88 // byteCount() is deprecated from Qt 5.10
89 info.file_size = image->sizeInBytes();
90 #else
91 info.file_size = image->byteCount();
92 #endif
93 info.vcodec = "QImage";
94 if (!default_svg_size.isEmpty()) {
95 // Use default SVG size (if detected)
96 info.width = default_svg_size.width();
97 info.height = default_svg_size.height();
98 } else {
99 // Use Qt Image size as a fallback
100 info.width = image->width();
101 info.height = image->height();
102 }

Callers

nothing calls this directly

Calls 4

InvalidFileClass · 0.85
ToDoubleMethod · 0.80
ReduceMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected