QtImageReader.cpp: Convert tabs to spaces

This commit is contained in:
FeRD (Frank Dana)
2021-10-08 16:28:32 -04:00
parent af15649fe8
commit c9cbf3f2b0
2 changed files with 109 additions and 107 deletions

View File

@@ -49,11 +49,11 @@ QtImageReader::QtImageReader(std::string path, bool inspect_reader) : path{QStri
// Initialize the Resvg options
resvg_options.loadSystemFonts();
#endif
// Open and Close the reader, to populate its attributes (such as height, width, etc...)
if (inspect_reader) {
Open();
Close();
}
// Open and Close the reader, to populate its attributes (such as height, width, etc...)
if (inspect_reader) {
Open();
Close();
}
}
QtImageReader::~QtImageReader()
@@ -63,10 +63,10 @@ QtImageReader::~QtImageReader()
// Open image file
void QtImageReader::Open()
{
// Open reader if not already open
if (!is_open)
{
bool loaded = false;
// Open reader if not already open
if (!is_open)
{
bool loaded = false;
QSize default_svg_size;
// Check for SVG files and rasterizing them to QImages
@@ -77,95 +77,95 @@ void QtImageReader::Open()
}
}
if (!loaded) {
// Attempt to open file using Qt's build in image processing capabilities
// AutoTransform enables exif data to be parsed and auto transform the image
// to the correct orientation
image = std::make_shared<QImage>();
if (!loaded) {
// Attempt to open file using Qt's build in image processing capabilities
// AutoTransform enables exif data to be parsed and auto transform the image
// to the correct orientation
image = std::make_shared<QImage>();
QImageReader imgReader( path );
imgReader.setAutoTransform( true );
loaded = imgReader.read(image.get());
}
}
if (!loaded) {
// raise exception
throw InvalidFile("File could not be opened.", path.toStdString());
}
if (!loaded) {
// raise exception
throw InvalidFile("File could not be opened.", path.toStdString());
}
// Update image properties
info.has_audio = false;
info.has_video = true;
info.has_single_image = true;
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// byteCount() is deprecated from Qt 5.10
info.file_size = image->sizeInBytes();
#else
info.file_size = image->byteCount();
#endif
info.vcodec = "QImage";
if (!default_svg_size.isEmpty()) {
// Use default SVG size (if detected)
// Update image properties
info.has_audio = false;
info.has_video = true;
info.has_single_image = true;
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// byteCount() is deprecated from Qt 5.10
info.file_size = image->sizeInBytes();
#else
info.file_size = image->byteCount();
#endif
info.vcodec = "QImage";
if (!default_svg_size.isEmpty()) {
// Use default SVG size (if detected)
info.width = default_svg_size.width();
info.height = default_svg_size.height();
} else {
// Use Qt Image size as a fallback
} else {
// Use Qt Image size as a fallback
info.width = image->width();
info.height = image->height();
}
info.pixel_ratio.num = 1;
info.pixel_ratio.den = 1;
info.duration = 60 * 60 * 1; // 1 hour duration
info.fps.num = 30;
info.fps.den = 1;
info.video_timebase.num = 1;
info.video_timebase.den = 30;
info.video_length = round(info.duration * info.fps.ToDouble());
}
info.pixel_ratio.num = 1;
info.pixel_ratio.den = 1;
info.duration = 60 * 60 * 1; // 1 hour duration
info.fps.num = 30;
info.fps.den = 1;
info.video_timebase.num = 1;
info.video_timebase.den = 30;
info.video_length = round(info.duration * info.fps.ToDouble());
// Calculate the DAR (display aspect ratio)
Fraction size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den);
// Calculate the DAR (display aspect ratio)
Fraction size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den);
// Reduce size fraction
size.Reduce();
// Reduce size fraction
size.Reduce();
// Set the ratio based on the reduced fraction
info.display_ratio.num = size.num;
info.display_ratio.den = size.den;
// Set the ratio based on the reduced fraction
info.display_ratio.num = size.num;
info.display_ratio.den = size.den;
// Set current max size
max_size.setWidth(info.width);
max_size.setHeight(info.height);
// Set current max size
max_size.setWidth(info.width);
max_size.setHeight(info.height);
// Mark as "open"
is_open = true;
}
// Mark as "open"
is_open = true;
}
}
// Close image file
void QtImageReader::Close()
{
// Close all objects, if reader is 'open'
if (is_open)
{
// Mark as "closed"
is_open = false;
// Close all objects, if reader is 'open'
if (is_open)
{
// Mark as "closed"
is_open = false;
// Delete the image
image.reset();
// Delete the image
image.reset();
info.vcodec = "";
info.acodec = "";
}
info.vcodec = "";
info.acodec = "";
}
}
// Get an openshot::Frame object for a specific frame number of this reader.
std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
{
// Check for open reader (or throw exception)
if (!is_open)
throw ReaderClosed("The Image is closed. Call Open() before calling this method.", path.toStdString());
// Check for open reader (or throw exception)
if (!is_open)
throw ReaderClosed("The Image is closed. Call Open() before calling this method.", path.toStdString());
// Create a scoped lock, allowing only a single thread to run the following code at one time
const GenericScopedLock<CriticalSection> lock(getFrameCriticalSection);
// Create a scoped lock, allowing only a single thread to run the following code at one time
const GenericScopedLock<CriticalSection> lock(getFrameCriticalSection);
// Calculate max image size
QSize current_max_size = calculate_max_size();
@@ -197,8 +197,8 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
sample_count, info.channels);
image_frame->AddImage(cached_image);
// return frame object
return image_frame;
// return frame object
return image_frame;
}
// Calculate the max_size QSize, based on parent timeline and parent clip settings
@@ -332,53 +332,53 @@ QSize QtImageReader::load_svg_path(QString) {
// Generate JSON string of this object
std::string QtImageReader::Json() const {
// Return formatted string
return JsonValue().toStyledString();
// Return formatted string
return JsonValue().toStyledString();
}
// Generate Json::Value for this object
Json::Value QtImageReader::JsonValue() const {
// Create root json object
Json::Value root = ReaderBase::JsonValue(); // get parent properties
root["type"] = "QtImageReader";
root["path"] = path.toStdString();
// Create root json object
Json::Value root = ReaderBase::JsonValue(); // get parent properties
root["type"] = "QtImageReader";
root["path"] = path.toStdString();
// return JsonValue
return root;
// return JsonValue
return root;
}
// Load JSON string into this object
void QtImageReader::SetJson(const std::string value) {
// Parse JSON string into JSON objects
try
{
const Json::Value root = openshot::stringToJson(value);
// Set all values that match
SetJsonValue(root);
}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
// Parse JSON string into JSON objects
try
{
const Json::Value root = openshot::stringToJson(value);
// Set all values that match
SetJsonValue(root);
}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
}
// Load Json::Value into this object
void QtImageReader::SetJsonValue(const Json::Value root) {
// Set parent data
ReaderBase::SetJsonValue(root);
// Set parent data
ReaderBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (!root["path"].isNull())
path = QString::fromStdString(root["path"].asString());
// Set data from Json (if key is found)
if (!root["path"].isNull())
path = QString::fromStdString(root["path"].asString());
// Re-Open path, and re-init everything (if needed)
if (is_open)
{
Close();
Open();
}
// Re-Open path, and re-init everything (if needed)
if (is_open)
{
Close();
Open();
}
}