Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
02377025
Commit
02377025
authored
Jun 23, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ImageProvider): improve image loading performances
parent
0ebe2baf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
ImageProvider.cpp
src/app/providers/ImageProvider.cpp
+12
-12
No files found.
src/app/providers/ImageProvider.cpp
View file @
02377025
...
...
@@ -65,13 +65,13 @@ static QByteArray parseFillAndStroke (QXmlStreamAttributes &readerAttributes, co
for
(
const
auto
&
classValue
:
readerAttributes
.
value
(
"class"
).
toLatin1
().
split
(
' '
))
{
regex
.
indexIn
(
classValue
.
trimmed
());
if
(
regex
.
pos
()
==
-
1
)
if
(
Q_LIKELY
(
regex
.
pos
()
==
-
1
)
)
continue
;
const
QStringList
list
=
regex
.
capturedTexts
();
const
QVariant
colorValue
=
colors
.
property
(
list
[
1
].
toStdString
().
c_str
());
if
(
!
colorValue
.
isValid
(
))
{
if
(
Q_UNLIKELY
(
!
colorValue
.
isValid
()
))
{
qWarning
()
<<
QStringLiteral
(
"Color name `%1` does not exist."
).
arg
(
list
[
1
]);
continue
;
}
...
...
@@ -91,7 +91,7 @@ static QByteArray parseStyle (QXmlStreamAttributes &readerAttributes, const Colo
QSet
<
QString
>
overrode
;
for
(
const
auto
&
classValue
:
readerAttributes
.
value
(
"class"
).
toLatin1
().
split
(
' '
))
{
regex
.
indexIn
(
classValue
.
trimmed
());
if
(
regex
.
pos
()
==
-
1
)
if
(
Q_LIKELY
(
regex
.
pos
()
==
-
1
)
)
continue
;
const
QStringList
list
=
regex
.
capturedTexts
();
...
...
@@ -99,7 +99,7 @@ static QByteArray parseStyle (QXmlStreamAttributes &readerAttributes, const Colo
overrode
.
insert
(
list
[
2
]);
const
QVariant
colorValue
=
colors
.
property
(
list
[
1
].
toStdString
().
c_str
());
if
(
!
colorValue
.
isValid
(
))
{
if
(
Q_UNLIKELY
(
!
colorValue
.
isValid
()
))
{
qWarning
()
<<
QStringLiteral
(
"Color name `%1` does not exist."
).
arg
(
list
[
1
]);
continue
;
}
...
...
@@ -113,7 +113,7 @@ static QByteArray parseStyle (QXmlStreamAttributes &readerAttributes, const Colo
const
QByteArrayList
styleValues
=
readerAttributes
.
value
(
"style"
).
toLatin1
().
split
(
';'
);
for
(
const
auto
&
styleValue
:
styleValues
)
{
const
QByteArrayList
list
=
styleValue
.
split
(
':'
);
if
(
list
.
length
()
>
0
&&
!
overrode
.
contains
(
list
[
0
]
))
{
if
(
Q_UNLIKELY
(
list
.
length
()
>
0
&&
!
overrode
.
contains
(
list
[
0
])
))
{
attribute
.
append
(
styleValue
);
attribute
.
append
(
";"
);
}
...
...
@@ -137,7 +137,7 @@ static QByteArray parseAttributes (const QXmlStreamReader &reader, const Colors
for
(
const
auto
&
attribute
:
readerAttributes
)
{
const
QByteArray
prefix
=
attribute
.
prefix
().
toLatin1
();
if
(
prefix
.
length
()
>
0
)
{
if
(
Q_UNLIKELY
(
prefix
.
length
()
>
0
)
)
{
attributes
.
append
(
prefix
);
attributes
.
append
(
":"
);
}
...
...
@@ -154,7 +154,7 @@ static QByteArray parseDeclarations (const QXmlStreamReader &reader) {
QByteArray
declarations
;
for
(
const
auto
&
declaration
:
reader
.
namespaceDeclarations
())
{
const
QByteArray
prefix
=
declaration
.
prefix
().
toLatin1
();
if
(
prefix
.
length
()
>
0
)
{
if
(
Q_UNLIKELY
(
prefix
.
length
()
>
0
)
)
{
declarations
.
append
(
"xmlns:"
);
declarations
.
append
(
prefix
);
}
else
...
...
@@ -256,25 +256,25 @@ QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) {
// 1. Read and update XML content.
QFile
file
(
path
);
if
(
Q
FileInfo
(
file
).
size
()
>
MAX_IMAGE_SIZE
)
{
if
(
Q
_UNLIKELY
(
QFileInfo
(
file
).
size
()
>
MAX_IMAGE_SIZE
)
)
{
qWarning
()
<<
QStringLiteral
(
"Unable to open large file: `%1`."
).
arg
(
path
);
return
QImage
();
}
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
))
{
if
(
Q_UNLIKELY
(
!
file
.
open
(
QIODevice
::
ReadOnly
)
))
{
qWarning
()
<<
QStringLiteral
(
"Unable to open file: `%1`."
).
arg
(
path
);
return
QImage
();
}
const
QByteArray
content
=
::
computeContent
(
file
);
if
(
!
content
.
length
(
))
{
if
(
Q_UNLIKELY
(
!
content
.
length
()
))
{
qWarning
()
<<
QStringLiteral
(
"Unable to parse file: `%1`."
).
arg
(
path
);
return
QImage
();
}
// 2. Build svg renderer.
QSvgRenderer
renderer
(
content
);
if
(
!
renderer
.
isValid
(
))
{
if
(
Q_UNLIKELY
(
!
renderer
.
isValid
()
))
{
qWarning
()
<<
QStringLiteral
(
"Invalid svg file: `%1`."
).
arg
(
path
);
return
QImage
();
}
...
...
@@ -282,7 +282,7 @@ QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) {
// 3. Create en empty image.
const
QRectF
viewBox
=
renderer
.
viewBoxF
();
QImage
image
(
static_cast
<
int
>
(
viewBox
.
width
()),
static_cast
<
int
>
(
viewBox
.
height
()),
QImage
::
Format_ARGB32
);
if
(
image
.
isNull
(
))
{
if
(
Q_UNLIKELY
(
image
.
isNull
()
))
{
qWarning
()
<<
QStringLiteral
(
"Unable to create image of size `(%1, %2)` from path: `%3`."
)
.
arg
(
viewBox
.
width
()).
arg
(
viewBox
.
height
()).
arg
(
path
);
return
QImage
();
// Memory cannot be allocated.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment