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

Method Open

src/ImageReader.cpp:35–82  ·  view source on GitHub ↗

Open image file

Source from the content-addressed store, hash-verified

33
34// Open image file
35void ImageReader::Open()
36{
37 // Open reader if not already open
38 if (!is_open)
39 {
40 // Attempt to open file
41 try
42 {
43 // load image
44 image = std::make_shared<Magick::Image>(path);
45
46 // Give image a transparent background color
47 image->backgroundColor(Magick::Color("none"));
48 MAGICK_IMAGE_ALPHA(image, true);
49 }
50 catch (const Magick::Exception& e) {
51 // raise exception
52 throw InvalidFile("ImageReader could not open image file.", path);
53 }
54
55 // Update image properties
56 info.has_audio = false;
57 info.has_video = true;
58 info.has_single_image = true;
59 info.file_size = image->fileSize();
60 info.vcodec = image->format();
61 info.width = image->size().width();
62 info.height = image->size().height();
63 info.pixel_ratio = openshot::Fraction(1, 1);
64 info.fps = openshot::Fraction(30, 1);
65 info.video_timebase = info.fps.Reciprocal();
66 // Default still-image duration: 1 hour, aligned to fps
67 info.video_length = 60 * 60 * info.fps.num; // 3600 seconds * 30 fps
68 info.duration = static_cast<float>(info.video_length / info.fps.ToDouble());
69
70 // Calculate the DAR (display aspect ratio)
71 Fraction dar(
72 info.width * info.pixel_ratio.num,
73 info.height * info.pixel_ratio.den);
74
75 // Reduce DAR fraction & set ratio
76 dar.Reduce();
77 info.display_ratio = dar;
78
79 // Mark as "open"
80 is_open = true;
81 }
82}
83
84void ImageReader::Close()
85{

Callers

nothing calls this directly

Calls 6

ColorClass · 0.85
InvalidFileClass · 0.85
FractionClass · 0.85
ReciprocalMethod · 0.80
ToDoubleMethod · 0.80
ReduceMethod · 0.80

Tested by

no test coverage detected