Changeset View
Changeset View
Standalone View
Standalone View
src/imageformats/kra.cpp
Show All 12 Lines | |||||
13 | #include "kra.h" | 13 | #include "kra.h" | ||
14 | 14 | | |||
15 | #include <kzip.h> | 15 | #include <kzip.h> | ||
16 | 16 | | |||
17 | #include <QImage> | 17 | #include <QImage> | ||
18 | #include <QIODevice> | 18 | #include <QIODevice> | ||
19 | #include <QFile> | 19 | #include <QFile> | ||
20 | 20 | | |||
21 | static constexpr char s_magic[] = "application/x-krita"; | ||||
apol: how about calling it s_mimetype? | |||||
nyeeee. It happens to be the mimetype, but here we're using it as magic to detect if the file is a file we care about or not, i'd prefer to keep it calling magic tbh aacid: nyeeee. It happens to be the mimetype, but here we're using it as magic to detect if the file… | |||||
22 | static constexpr int s_magic_size = strlen(s_magic); | ||||
pino: this also counts the null terminator (as it is part of the static string) | |||||
23 | | ||||
21 | KraHandler::KraHandler() | 24 | KraHandler::KraHandler() | ||
22 | { | 25 | { | ||
23 | } | 26 | } | ||
24 | 27 | | |||
25 | bool KraHandler::canRead() const | 28 | bool KraHandler::canRead() const | ||
26 | { | 29 | { | ||
27 | if (canRead(device())) { | 30 | if (canRead(device())) { | ||
28 | setFormat("kra"); | 31 | setFormat("kra"); | ||
Show All 21 Lines | |||||
50 | { | 53 | { | ||
51 | if (!device) { | 54 | if (!device) { | ||
52 | qWarning("KraHandler::canRead() called with no device"); | 55 | qWarning("KraHandler::canRead() called with no device"); | ||
53 | return false; | 56 | return false; | ||
54 | } | 57 | } | ||
55 | 58 | | |||
56 | char buff[57]; | 59 | char buff[57]; | ||
57 | if (device->peek(buff, sizeof(buff)) == sizeof(buff)) | 60 | if (device->peek(buff, sizeof(buff)) == sizeof(buff)) | ||
58 | return qstrcmp(buff + 0x26, "application/x-krita") == 0; | 61 | return memcmp(buff + 0x26, s_magic, s_magic_size) == 0; | ||
pino: this can be memcmp even (slightly faster than str*cmp) | |||||
59 | 62 | | |||
60 | return false; | 63 | return false; | ||
61 | } | 64 | } | ||
62 | 65 | | |||
63 | QImageIOPlugin::Capabilities KraPlugin::capabilities(QIODevice *device, const QByteArray &format) const | 66 | QImageIOPlugin::Capabilities KraPlugin::capabilities(QIODevice *device, const QByteArray &format) const | ||
64 | { | 67 | { | ||
65 | if (format == "kra" || format == "KRA") { | 68 | if (format == "kra" || format == "KRA") { | ||
66 | return Capabilities(CanRead); | 69 | return Capabilities(CanRead); | ||
Show All 22 Lines |
how about calling it s_mimetype?