Even tighter warnings
This commit is contained in:
+6
-1
@@ -230,8 +230,13 @@ include(CTest)
|
||||
# Keep diagnostics after bundled dependencies so that they don't apply to them.
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
add_compile_options(-Wall -Wextra -Wpedantic
|
||||
-Wformat=2 -Wundef -Wcast-align
|
||||
-Wconversion -Wformat=2 -Wundef -Wcast-align
|
||||
-Wno-unused-parameter -Wno-missing-field-initializers)
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
add_compile_options(-Wshadow=local)
|
||||
else()
|
||||
add_compile_options(-Wshadow-uncaptured-local)
|
||||
endif()
|
||||
add_compile_options(
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-Woverloaded-virtual>
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
#define DAWN_NAMESPACE "@DAWN_NAMESPACE@"
|
||||
#define DAWN_VERSION "@PROJECT_VERSION@"
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
#define DAWN_FORMAT(format_index, first_arg) \
|
||||
__attribute__((format(printf, format_index, first_arg)))
|
||||
#else
|
||||
#define DAWN_FORMAT(format_index, first_arg)
|
||||
#endif
|
||||
|
||||
#cmakedefine01 DAWN_WITH_LCMS2_FAST_FLOAT
|
||||
#cmakedefine01 DAWN_WITH_LCMS2_THREADED
|
||||
#cmakedefine01 DAWN_WITH_JPEG_QS
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ constexpr uint8_t kToggle = ActionInMenu | ActionToggle;
|
||||
constexpr unsigned kCtrl = unsigned(Qt::ControlModifier);
|
||||
constexpr unsigned kAlt = unsigned(Qt::AltModifier);
|
||||
constexpr unsigned kShift = unsigned(Qt::ShiftModifier);
|
||||
constexpr unsigned kMeta = unsigned(Qt::MetaModifier);
|
||||
[[maybe_unused]] constexpr unsigned kMeta = unsigned(Qt::MetaModifier);
|
||||
|
||||
// clang-format off
|
||||
constexpr ActionDef kDefs[] = {
|
||||
|
||||
+9
-9
@@ -138,19 +138,19 @@ locale_candidates()
|
||||
if (loc.isEmpty() || loc == QLatin1String("C") ||
|
||||
loc == QLatin1String("POSIX"))
|
||||
continue;
|
||||
const int dot = loc.indexOf(u'.');
|
||||
const qsizetype dot = loc.indexOf(u'.');
|
||||
if (dot >= 0)
|
||||
loc = loc.left(dot);
|
||||
loc.replace(u'-', u'_');
|
||||
QString modifier;
|
||||
const int at = loc.indexOf(u'@');
|
||||
const qsizetype at = loc.indexOf(u'@');
|
||||
if (at >= 0) {
|
||||
modifier = loc.mid(at);
|
||||
loc = loc.left(at);
|
||||
}
|
||||
QString lang = loc;
|
||||
QString country;
|
||||
const int us = loc.indexOf(u'_');
|
||||
const qsizetype us = loc.indexOf(u'_');
|
||||
if (us >= 0) {
|
||||
country = loc.mid(us);
|
||||
lang = loc.left(us);
|
||||
@@ -703,8 +703,8 @@ fallback_for(const QString &path)
|
||||
const QString type = db().mimeTypeForFile(path).name();
|
||||
const vector<QString> ancestors = ancestor_types(type);
|
||||
AssocSets acc = associations_for_type(type);
|
||||
for (const QString &type : ancestors)
|
||||
merge_assoc(acc, associations_for_type(type));
|
||||
for (const QString &ancestor : ancestors)
|
||||
merge_assoc(acc, associations_for_type(ancestor));
|
||||
|
||||
unordered_set<QString> seen;
|
||||
const Handler def = default_for(path);
|
||||
@@ -714,8 +714,8 @@ fallback_for(const QString &path)
|
||||
seen.insert(a.id);
|
||||
|
||||
vector<Handler> out;
|
||||
for (const QString &type : ancestors) {
|
||||
for (const QString &id : cache_ids_for_type(type)) {
|
||||
for (const QString &ancestor : ancestors) {
|
||||
for (const QString &id : cache_ids_for_type(ancestor)) {
|
||||
if (seen.contains(id) || !usable_id(id, acc.removed))
|
||||
continue;
|
||||
seen.insert(id);
|
||||
@@ -770,8 +770,8 @@ set_last_used(const Handler &app, const QString &path)
|
||||
}
|
||||
IniGroup *added = find_group("Added Associations");
|
||||
IniGroup *removed = find_group("Removed Associations");
|
||||
auto drop_id = [&](IniGroup &group, const QString &type) {
|
||||
const string type_utf8 = type.toUtf8().toStdString();
|
||||
auto drop_id = [&](IniGroup &group, const QString &mime_type) {
|
||||
const string type_utf8 = mime_type.toUtf8().toStdString();
|
||||
vector<QString> kept;
|
||||
for (const QString &existing :
|
||||
split_semicolons(dawn::detail::ini_get(group, type_utf8))) {
|
||||
|
||||
+15
-14
@@ -429,7 +429,8 @@ thumb_in_band(const Browser &b, const Browser::File &f, float pad)
|
||||
{
|
||||
if (f.cell.empty())
|
||||
return false;
|
||||
return f.cell.bottom() >= b.r.y - pad && f.cell.y <= b.r.bottom() + pad;
|
||||
return float(f.cell.bottom()) >= float(b.r.y) - pad &&
|
||||
float(f.cell.y) <= float(b.r.bottom()) + pad;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -864,7 +865,7 @@ trim_ram(Browser &b)
|
||||
return;
|
||||
|
||||
const float pad = row_h(b) * kPrefetchRows;
|
||||
const float mid = b.r.y + b.r.h * 0.5f;
|
||||
const float mid = float(b.r.y) + float(b.r.h) * 0.5f;
|
||||
vector<int> idx;
|
||||
for (int i = 0; i < int(b.files_.size()); i++) {
|
||||
const Browser::File &f = b.files_[size_t(i)];
|
||||
@@ -875,8 +876,8 @@ trim_ram(Browser &b)
|
||||
sort(idx.begin(), idx.end(), [&](int a, int bidx) {
|
||||
const Rect &ca = b.files_[size_t(a)].cell;
|
||||
const Rect &cb = b.files_[size_t(bidx)].cell;
|
||||
const float da = abs(ca.y + ca.h * 0.5f - mid);
|
||||
const float db = abs(cb.y + cb.h * 0.5f - mid);
|
||||
const float da = abs(float(ca.y) + float(ca.h) * 0.5f - mid);
|
||||
const float db = abs(float(cb.y) + float(cb.h) * 0.5f - mid);
|
||||
return da > db;
|
||||
});
|
||||
for (int i : idx) {
|
||||
@@ -1351,7 +1352,7 @@ remember_cursor_x(Browser &b)
|
||||
b.cursor_x_dirty_ = true;
|
||||
return;
|
||||
}
|
||||
b.cursor_x_ = c.x + c.w * 0.5f;
|
||||
b.cursor_x_ = float(c.x) + float(c.w) * 0.5f;
|
||||
b.cursor_x_dirty_ = false;
|
||||
}
|
||||
|
||||
@@ -1390,10 +1391,10 @@ static void
|
||||
scroll_to_row(Browser &b, const Browser::GridRow &row)
|
||||
{
|
||||
const float vis = float(max(0, b.r.h - 2 * b.kit_.px(kGridPad)));
|
||||
if (row.y < b.scroll_.offset)
|
||||
b.scroll_.offset = row.y;
|
||||
else if (row.y + row.h > b.scroll_.offset + vis)
|
||||
b.scroll_.offset = max(0.f, row.y + row.h - vis);
|
||||
if (float(row.y) < b.scroll_.offset)
|
||||
b.scroll_.offset = float(row.y);
|
||||
else if (float(row.y + row.h) > b.scroll_.offset + vis)
|
||||
b.scroll_.offset = max(0.f, float(row.y + row.h) - vis);
|
||||
b.scroll_.offset = clamp(b.scroll_.offset, 0.f, b.scroll_.max_offset());
|
||||
}
|
||||
|
||||
@@ -2001,7 +2002,7 @@ scan_dir(Browser &b)
|
||||
// and/or maybe just DBT_DEVNODES_CHANGED (trivially reload here).
|
||||
DWORD mask = GetLogicalDrives();
|
||||
for (int i = 0; i < 26; i++) {
|
||||
wchar_t letter = L'A' + i;
|
||||
wchar_t letter = wchar_t(L'A' + i);
|
||||
if (!(mask & (1 << i)))
|
||||
continue;
|
||||
|
||||
@@ -2039,12 +2040,12 @@ scan_dir(Browser &b)
|
||||
vector<filesystem::path> ancestors;
|
||||
filesystem::path cur = without_trailing_sep(root);
|
||||
while (true) {
|
||||
filesystem::path parent = cur.parent_path();
|
||||
if (parent.empty() || parent == cur)
|
||||
filesystem::path ancestor = cur.parent_path();
|
||||
if (ancestor.empty() || ancestor == cur)
|
||||
break;
|
||||
|
||||
ancestors.push_back(parent);
|
||||
cur = parent;
|
||||
ancestors.push_back(ancestor);
|
||||
cur = ancestor;
|
||||
if (ancestors.size() > 64)
|
||||
break;
|
||||
}
|
||||
|
||||
+14
-14
@@ -414,7 +414,7 @@ struct LoaderRows {
|
||||
void
|
||||
LoaderRows::sync() const
|
||||
{
|
||||
size_t n = int(this->draft->loaders.size());
|
||||
const size_t n = this->draft->loaders.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
const SettingsDraft::Loader &loader = this->draft->loaders[i];
|
||||
this->checks[i]->text = loader_text(loader);
|
||||
@@ -626,7 +626,7 @@ collect_targets(Widget *w, Rect host, vector<Widget *> &out)
|
||||
return;
|
||||
if (dynamic_cast<Browser *>(w))
|
||||
return;
|
||||
if (w->focusable() && visible_rect(w, host).w > 0.f)
|
||||
if (w->focusable() && visible_rect(w, host).w > 0)
|
||||
out.push_back(w);
|
||||
const size_t n = w->child_count();
|
||||
for (size_t i = 0; i < n; i++)
|
||||
@@ -719,7 +719,7 @@ Hint::paint(Kit &kit) const
|
||||
if (!shown())
|
||||
return;
|
||||
kit.draw_fill(this->r, col(kit.colours_[ColourInk], 0.1f));
|
||||
const float th = kit.text_height(QStringLiteral("Ag"), 0.f, true);
|
||||
const float th = float(kit.text_height(QStringLiteral("Ag"), 0.f, true));
|
||||
for (const Target &t : this->targets_) {
|
||||
if (!matches(t) || t.chip.empty())
|
||||
continue;
|
||||
@@ -728,11 +728,11 @@ Hint::paint(Kit &kit) const
|
||||
kit.draw_border(c, kit.colours_[ColourInk], kit.hairline());
|
||||
const QString rest = t.label.mid(this->typed_.size());
|
||||
float tx = float(c.x + kit.px(kChipPadX));
|
||||
const float ty = float(c.y) + max(0.f, float(c.h - th) * 0.5f);
|
||||
const float ty = float(c.y) + max(0.f, (float(c.h) - th) * 0.5f);
|
||||
if (!this->typed_.isEmpty()) {
|
||||
kit.emit_text(tx, ty, this->typed_,
|
||||
col(kit.colours_[ColourInk], 0.25f), true);
|
||||
tx += kit.text_width(this->typed_, true);
|
||||
tx += float(kit.text_width(this->typed_, true));
|
||||
}
|
||||
if (!rest.isEmpty())
|
||||
kit.emit_text(tx, ty, rest, kit.colours_[ColourInk], true);
|
||||
@@ -848,14 +848,14 @@ Hint::collect(Widget *scope)
|
||||
if (f.tile.empty())
|
||||
continue;
|
||||
|
||||
const Rect visible = intersection(f.tile, well);
|
||||
if (visible.empty())
|
||||
const Rect clipped = intersection(f.tile, well);
|
||||
if (clipped.empty())
|
||||
continue;
|
||||
|
||||
Target t;
|
||||
t.browser = browser;
|
||||
t.file_i = i;
|
||||
t.at = visible;
|
||||
t.at = clipped;
|
||||
this->targets_.push_back(t);
|
||||
}
|
||||
}
|
||||
@@ -876,10 +876,10 @@ Hint::refresh_rects()
|
||||
keep.reserve(this->targets_.size());
|
||||
for (Target &t : this->targets_) {
|
||||
if (t.widget) {
|
||||
const Rect visible = visible_rect(t.widget, this->page->r);
|
||||
if (!t.widget->focusable() || visible.w <= 0.f || visible.h <= 0.f)
|
||||
const Rect clipped = visible_rect(t.widget, this->page->r);
|
||||
if (!t.widget->focusable() || clipped.w <= 0 || clipped.h <= 0)
|
||||
continue;
|
||||
t.at = visible;
|
||||
t.at = clipped;
|
||||
keep.push_back(t);
|
||||
continue;
|
||||
}
|
||||
@@ -887,10 +887,10 @@ Hint::refresh_rects()
|
||||
t.file_i >= int(t.browser->files_.size()))
|
||||
continue;
|
||||
const Browser::File &f = t.browser->files_[size_t(t.file_i)];
|
||||
const Rect visible = intersection(f.tile, t.browser->r);
|
||||
if (visible.empty())
|
||||
const Rect clipped = intersection(f.tile, t.browser->r);
|
||||
if (clipped.empty())
|
||||
continue;
|
||||
t.at = visible;
|
||||
t.at = clipped;
|
||||
keep.push_back(t);
|
||||
}
|
||||
this->targets_ = std::move(keep);
|
||||
|
||||
@@ -165,8 +165,9 @@ raster_diagram(int w, int h, const dawn::Chromaticities &image,
|
||||
}
|
||||
|
||||
for (int py = 0; py < h; py++) {
|
||||
auto *dst = (QRgb *) img.scanLine(py);
|
||||
const auto *ms = (const QRgb *) mask.constScanLine(py);
|
||||
auto *dst = dawn::assume_aligned<QRgb>(img.scanLine(py));
|
||||
const auto *ms =
|
||||
dawn::assume_aligned<const QRgb>(mask.constScanLine(py));
|
||||
const double y = double(kYMax) * (1.0 - (py + 0.5) / h);
|
||||
for (int px = 0; px < w; px++) {
|
||||
if (!qAlpha(ms[px]))
|
||||
@@ -253,7 +254,7 @@ CieDiagram::prepare(Kit &kit)
|
||||
const int cap = caption_h(kit);
|
||||
const Rect plot =
|
||||
plot_rect({this->r.x, this->r.y, this->r.w, max(0, this->r.h - cap)});
|
||||
if (plot.w < 8.f || plot.h < 8.f)
|
||||
if (plot.w < 8 || plot.h < 8)
|
||||
return;
|
||||
|
||||
const bool epoch_ok =
|
||||
|
||||
+4
-4
@@ -200,8 +200,8 @@ sync_scale_label(Viewer &v)
|
||||
return;
|
||||
|
||||
const float scale_slot =
|
||||
max(v.kit_.text_width(QStringLiteral("100%"), false),
|
||||
v.kit_.text_width(v.scale_text_, false));
|
||||
float(max(v.kit_.text_width(QStringLiteral("100%"), false),
|
||||
v.kit_.text_width(v.scale_text_, false)));
|
||||
v.scale_label_->min_w = scale_slot / v.kit_.dpr_;
|
||||
v.scale_label_->text = v.scale_text_;
|
||||
}
|
||||
@@ -690,7 +690,7 @@ make_sidebar(Viewer &v)
|
||||
{
|
||||
// FIXME: This needs proper layouting.
|
||||
const float label_w =
|
||||
v.kit_.text_width(QStringLiteral("Height:"), true) / v.kit_.dpr_;
|
||||
float(v.kit_.text_width(QStringLiteral("Height:"), true)) / v.kit_.dpr_;
|
||||
|
||||
auto col = make_unique<ScrollColumn>();
|
||||
v.info_ = col.get();
|
||||
@@ -760,7 +760,7 @@ sync_ui(Viewer &v, Page &ui)
|
||||
ui.sync_app_menu();
|
||||
if (v.error_) {
|
||||
v.error_->visible = !v.message_.empty() && !v.message_dismissed_;
|
||||
v.error_->max_h = v.kit_.host_h_ * 0.4f;
|
||||
v.error_->max_h = float(v.kit_.host_h_) * 0.4f;
|
||||
if (v.error_->visible && v.error_label_)
|
||||
v.error_label_->text =
|
||||
QStringLiteral("Error: ") + QString::fromStdString(v.message_);
|
||||
|
||||
+11
-9
@@ -123,7 +123,7 @@ raster_symbolic(const char *name, int px)
|
||||
QImage image(px, px, QImage::Format_ARGB32_Premultiplied);
|
||||
const size_t stride = size_t(px) * 4;
|
||||
for (int y = 0; y < px; y++) {
|
||||
auto *row = (QRgb *) image.scanLine(y);
|
||||
auto *row = dawn::assume_aligned<QRgb>(image.scanLine(y));
|
||||
const auto *src =
|
||||
(const unsigned char *) (pixmap.data() + size_t(y) * stride);
|
||||
for (int x = 0; x < px; x++) {
|
||||
@@ -213,7 +213,8 @@ raster_glyph(const QRawFont &raw, quint32 gid, float phase, QPoint *origin)
|
||||
|
||||
QRect ink;
|
||||
for (int y = 0; y < img.height(); y++) {
|
||||
const auto *row = (const QRgb *) img.constScanLine(y);
|
||||
const auto *row =
|
||||
dawn::assume_aligned<const QRgb>(img.constScanLine(y));
|
||||
for (int x = 0; x < img.width(); x++) {
|
||||
if (qAlpha(row[x]))
|
||||
ink |= QRect(x, y, 1, 1);
|
||||
@@ -343,7 +344,8 @@ blit(Kit &kit, const Kit::Packed &rect, const QImage &src, bool coverage)
|
||||
fill_n(dst + x * 4, 4, a);
|
||||
}
|
||||
} else {
|
||||
const auto *row = (const QRgb *) img.constScanLine(y);
|
||||
const auto *row =
|
||||
dawn::assume_aligned<const QRgb>(img.constScanLine(y));
|
||||
for (int x = 0; x < cols; x++) {
|
||||
dst[x * 4 + 0] = widen8(uint8_t(qRed(row[x])));
|
||||
dst[x * 4 + 1] = widen8(uint8_t(qGreen(row[x])));
|
||||
@@ -1061,7 +1063,7 @@ grapheme_before(const QString &text, int at)
|
||||
QTextBoundaryFinder finder(QTextBoundaryFinder::Grapheme, text);
|
||||
finder.setPosition(min(at, int(text.size())));
|
||||
const auto prev = finder.toPreviousBoundary();
|
||||
return prev < 0 ? 0 : prev;
|
||||
return prev < 0 ? 0 : int(prev);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1073,7 +1075,7 @@ grapheme_after(const QString &text, int at)
|
||||
QTextBoundaryFinder finder(QTextBoundaryFinder::Grapheme, text);
|
||||
finder.setPosition(max(at, 0));
|
||||
const auto next = finder.toNextBoundary();
|
||||
return next < 0 ? end : next;
|
||||
return next < 0 ? end : int(next);
|
||||
}
|
||||
|
||||
// Qt hands us the control codes as text too; none of them are insertable.
|
||||
@@ -1129,7 +1131,7 @@ Entry::rescroll(const Kit &kit)
|
||||
const QString full = painted();
|
||||
const int at =
|
||||
this->caret + (this->preedit.isEmpty() ? 0 : this->preedit_caret);
|
||||
const float caret = float(kit.caret_x(full, at, false));
|
||||
const float caret_x = float(kit.caret_x(full, at, false));
|
||||
const float text_w = float(kit.text_width(full, false));
|
||||
const float view = float(inner_w(kit));
|
||||
if (text_w <= view) {
|
||||
@@ -1139,7 +1141,7 @@ Entry::rescroll(const Kit &kit)
|
||||
|
||||
// Keep the caret around the centre, but never leave a gap at either end:
|
||||
// the text fills the box before the caret gets to be centred.
|
||||
this->scroll_ = clamp(caret - view * 0.5f, 0.f, text_w - view);
|
||||
this->scroll_ = clamp(caret_x - view * 0.5f, 0.f, text_w - view);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1209,11 +1211,11 @@ Entry::paint(Kit &kit) const
|
||||
const float tx = float(in.x) - this->scroll_;
|
||||
if (full.isEmpty()) {
|
||||
if (!this->placeholder.isEmpty())
|
||||
emit_text(kit, tx, ty, this->placeholder,
|
||||
emit_text(kit, tx, float(ty), this->placeholder,
|
||||
col(kit.colours_[ColourInk], 0.4f * kit.ink_alpha()), false,
|
||||
-1);
|
||||
} else {
|
||||
emit_text(kit, tx, ty, full,
|
||||
emit_text(kit, tx, float(ty), full,
|
||||
col(kit.colours_[ColourInk], kit.ink_alpha()), false, -1);
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -316,8 +316,7 @@ Sheet::blit(Packed slot, const uint16_t *src, int src_w, int src_h, int stride)
|
||||
for (int y = 0; y < rows; y++) {
|
||||
uint16_t *dst = this->pixels.data() +
|
||||
(size_t(slot.y + y) * size_t(this->w) + size_t(slot.x)) * 4;
|
||||
const auto *row = (const uint16_t *) ((const uint8_t *) src +
|
||||
size_t(y) * size_t(stride));
|
||||
const auto *row = (const uint8_t *) src + size_t(y) * size_t(stride);
|
||||
memcpy(dst, row, size_t(cols) * 4 * sizeof(uint16_t));
|
||||
}
|
||||
this->dirty = true;
|
||||
|
||||
@@ -414,7 +414,7 @@ thumbnail_cache_write(const ThumbnailSource &source, int tier,
|
||||
for (size_t i = 0, n = size_t(width) * height; i < n; i++) {
|
||||
const uint32_t a = pixels[i * 4 + 3];
|
||||
bgra[i * 4 + 3] = uint8_t((a + 128) / 257);
|
||||
for (int c = 0; c < 3; c++) {
|
||||
for (size_t c = 0; c < 3; c++) {
|
||||
const uint32_t straight = a
|
||||
? min(65535u,
|
||||
uint32_t(
|
||||
|
||||
+4
-4
@@ -152,8 +152,8 @@ Window::Window(App *app, QWindow *parent) : QWindow(parent), app_(app)
|
||||
this->present_retry_.setSingleShot(true);
|
||||
connect(&this->present_retry_, &QTimer::timeout, this,
|
||||
[this] { request_render(); });
|
||||
if (QGuiApplication *app = qGuiApp)
|
||||
app->installEventFilter(this);
|
||||
if (QGuiApplication *gui_app = qGuiApp)
|
||||
gui_app->installEventFilter(this);
|
||||
auto post = [this](function<void()> fn) {
|
||||
QMetaObject::invokeMethod(
|
||||
this, [fn = std::move(fn)]() { fn(); }, Qt::QueuedConnection);
|
||||
@@ -557,7 +557,7 @@ Window::launch_exiftool(const QUrl &url)
|
||||
process->deleteLater();
|
||||
});
|
||||
connect(process, &QProcess::finished, process,
|
||||
[process, report, report_path, finished, show_error](
|
||||
[process, report_path, finished, show_error](
|
||||
int exit_code, QProcess::ExitStatus exit_status) {
|
||||
if (*finished)
|
||||
return;
|
||||
@@ -1367,7 +1367,7 @@ Window::handle_input_method(QInputMethodEvent *event)
|
||||
|
||||
// The preedit caret rides in the attribute list, in UTF-16 units from
|
||||
// the start of the preedit string.
|
||||
auto caret = event->preeditString().size();
|
||||
int caret = int(event->preeditString().size());
|
||||
for (const QInputMethodEvent::Attribute &a : event->attributes()) {
|
||||
if (a.type == QInputMethodEvent::Cursor)
|
||||
caret = a.start;
|
||||
|
||||
@@ -58,7 +58,7 @@ encode_webp_rgba8(uint32_t w, uint32_t h, const uint8_t *rgba8,
|
||||
}
|
||||
|
||||
for (uint32_t y = 0; y < h; y++) {
|
||||
uint32_t *dst = picture.argb + size_t(y) * picture.argb_stride;
|
||||
uint32_t *dst = picture.argb + size_t(y) * size_t(picture.argb_stride);
|
||||
const uint8_t *src = rgba8 + size_t(y) * w * 4;
|
||||
for (uint32_t x = 0; x < w; x++) {
|
||||
const uint8_t *p = src + x * 4;
|
||||
|
||||
+2
-1
@@ -88,7 +88,8 @@ bake_orientation(dawn::Image &image)
|
||||
}
|
||||
|
||||
for (uint32_t y = 0; y < out_h; y++) {
|
||||
uint16_t *dst_row = (uint16_t *) (out_data.data() + y * out_stride);
|
||||
uint16_t *dst_row =
|
||||
dawn::assume_aligned<uint16_t>(out_data.data() + y * out_stride);
|
||||
for (uint32_t x = 0; x < out_w; x++) {
|
||||
double sx = 0, sy = 0;
|
||||
map_point(inv, double(x) + 0.5, double(y) + 0.5, &sx, &sy);
|
||||
|
||||
+1
-1
@@ -441,7 +441,7 @@ FrameWriter::push(span<const byte> payload)
|
||||
if (payload.empty() || payload.size() > limit_)
|
||||
return false;
|
||||
if (off_ > 0) {
|
||||
q_.erase(q_.begin(), q_.begin() + off_);
|
||||
q_.erase(q_.begin(), q_.begin() + ptrdiff_t(off_));
|
||||
off_ = 0;
|
||||
}
|
||||
const size_t add = 4 + payload.size();
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dawn-config.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -151,6 +153,7 @@ public:
|
||||
|
||||
// Set DN_IPC_DEBUG to have the transport explain itself on stderr.
|
||||
// Everything here fails by quietly running a second dn instead.
|
||||
DAWN_FORMAT(1, 2)
|
||||
void trace(const char *fmt, ...);
|
||||
|
||||
// A file descriptor on POSIX, a HANDLE on Windows. Both compare equal to
|
||||
|
||||
+8
-8
@@ -355,8 +355,8 @@ pack_argb32_words_to_bgra16(
|
||||
{
|
||||
for (uint32_t y = 0; y < dst.height; y++) {
|
||||
auto *d = row_u16(dst, y);
|
||||
const uint32_t *s =
|
||||
(const uint32_t *) ((const uint8_t *) src + y * src_stride_bytes);
|
||||
const uint32_t *s = assume_aligned<const uint32_t>(
|
||||
(const uint8_t *) src + y * src_stride_bytes);
|
||||
for (uint32_t x = 0; x < dst.width; x++) {
|
||||
uint32_t p = s[x];
|
||||
d[0] = uint16_t((p & 0xFFu) * 257u);
|
||||
@@ -374,8 +374,8 @@ pack_rgba16le_to_bgra16(
|
||||
{
|
||||
for (uint32_t y = 0; y < dst.height; y++) {
|
||||
auto *d = row_u16(dst, y);
|
||||
const uint16_t *s =
|
||||
(const uint16_t *) ((const uint8_t *) src + y * src_stride_bytes);
|
||||
const uint16_t *s = assume_aligned<const uint16_t>(
|
||||
(const uint8_t *) src + y * src_stride_bytes);
|
||||
for (uint32_t x = 0; x < dst.width; x++) {
|
||||
d[0] = scale_nbit_to_u16(s[2], bits);
|
||||
d[1] = scale_nbit_to_u16(s[1], bits);
|
||||
@@ -393,8 +393,8 @@ pack_rgb16le_to_bgra16(
|
||||
{
|
||||
for (uint32_t y = 0; y < dst.height; y++) {
|
||||
auto *d = row_u16(dst, y);
|
||||
const uint16_t *s =
|
||||
(const uint16_t *) ((const uint8_t *) src + y * src_stride_bytes);
|
||||
const uint16_t *s = assume_aligned<const uint16_t>(
|
||||
(const uint8_t *) src + y * src_stride_bytes);
|
||||
for (uint32_t x = 0; x < dst.width; x++) {
|
||||
d[0] = scale_nbit_to_u16(s[2], bits);
|
||||
d[1] = scale_nbit_to_u16(s[1], bits);
|
||||
@@ -1173,14 +1173,14 @@ Cmm::convert_cmyk8(
|
||||
if (transform) {
|
||||
cmsDoTransform(transform, cmyk, dst.data.data(), n);
|
||||
cmsDeleteTransform(transform);
|
||||
auto *out = (uint16_t *) dst.data.data();
|
||||
auto *out = assume_aligned<uint16_t>(dst.data.data());
|
||||
for (uint32_t i = 0; i < n; i++)
|
||||
out[i * 4 + 3] = 65535;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto *out = (uint16_t *) dst.data.data();
|
||||
auto *out = assume_aligned<uint16_t>(dst.data.data());
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
int c = cmyk[i * 4 + 0], m = cmyk[i * 4 + 1], y = cmyk[i * 4 + 2],
|
||||
k = cmyk[i * 4 + 3];
|
||||
|
||||
+13
-2
@@ -210,16 +210,27 @@ row_bytes(const Image &img, uint32_t y)
|
||||
return img.data.data() + size_t(y) * img.stride;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T *
|
||||
assume_aligned(U *p)
|
||||
{
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
return reinterpret_cast<T *>(__builtin_assume_aligned(p, alignof(T)));
|
||||
#else
|
||||
return reinterpret_cast<T *>(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint16_t *
|
||||
row_u16(Image &img, uint32_t y)
|
||||
{
|
||||
return (uint16_t *) row_bytes(img, y);
|
||||
return assume_aligned<uint16_t>(row_bytes(img, y));
|
||||
}
|
||||
|
||||
inline const uint16_t *
|
||||
row_u16(const Image &img, uint32_t y)
|
||||
{
|
||||
return (const uint16_t *) row_bytes(img, y);
|
||||
return assume_aligned<const uint16_t>(row_bytes(img, y));
|
||||
}
|
||||
|
||||
/// Allocate a zeroed working-format image. Returns null on OOM / overflow.
|
||||
|
||||
@@ -128,10 +128,12 @@ load_glycin_frame(GlyFrame *frame, const OpenContext &ctx, Error *error)
|
||||
pack_rgba8_to_bgra16(*image, src, stride);
|
||||
break;
|
||||
case GLY_MEMORY_R16G16B16:
|
||||
pack_rgb16le_to_bgra16(*image, (const uint16_t *) src, stride, 16);
|
||||
pack_rgb16le_to_bgra16(
|
||||
*image, assume_aligned<const uint16_t>(src), stride, 16);
|
||||
break;
|
||||
case GLY_MEMORY_R16G16B16A16:
|
||||
pack_rgba16le_to_bgra16(*image, (const uint16_t *) src, stride, 16);
|
||||
pack_rgba16le_to_bgra16(
|
||||
*image, assume_aligned<const uint16_t>(src), stride, 16);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
+9
-9
@@ -80,11 +80,11 @@ load_heif_image(heif_image_handle *handle, const OpenContext &ctx, Error *error)
|
||||
if (use16) {
|
||||
int bits = min(bit_depth, 16);
|
||||
if (has_alpha) {
|
||||
pack_rgba16le_to_bgra16(
|
||||
*result, (const uint16_t *) src, size_t(src_stride), bits);
|
||||
pack_rgba16le_to_bgra16(*result,
|
||||
assume_aligned<const uint16_t>(src), size_t(src_stride), bits);
|
||||
} else {
|
||||
pack_rgb16le_to_bgra16(
|
||||
*result, (const uint16_t *) src, size_t(src_stride), bits);
|
||||
pack_rgb16le_to_bgra16(*result, assume_aligned<const uint16_t>(src),
|
||||
size_t(src_stride), bits);
|
||||
}
|
||||
} else {
|
||||
// Interleaved RGBA chroma even without an alpha channel; force
|
||||
@@ -177,13 +177,13 @@ load_heif_aux_images(const OpenContext &ctx, heif_image_handle *top,
|
||||
if (n <= 0)
|
||||
return;
|
||||
|
||||
vector<heif_item_id> ids(n);
|
||||
vector<heif_item_id> ids(static_cast<size_t>(n));
|
||||
n = heif_image_handle_get_list_of_auxiliary_image_IDs(
|
||||
top, filter, ids.data(), n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
heif_image_handle *handle = nullptr;
|
||||
heif_error err =
|
||||
heif_image_handle_get_auxiliary_image_handle(top, ids[i], &handle);
|
||||
heif_error err = heif_image_handle_get_auxiliary_image_handle(
|
||||
top, ids[size_t(i)], &handle);
|
||||
if (err.code != heif_error_Ok) {
|
||||
add_warning(ctx, err.message);
|
||||
continue;
|
||||
@@ -221,13 +221,13 @@ detail::load_heif(
|
||||
}
|
||||
|
||||
int n = heif_context_get_number_of_top_level_images(hctx);
|
||||
vector<heif_item_id> ids(max(n, 0));
|
||||
vector<heif_item_id> ids(size_t(max(n, 0)));
|
||||
n = heif_context_get_list_of_top_level_image_IDs(hctx, ids.data(), n);
|
||||
|
||||
ImagePtr head, tail;
|
||||
for (int i = 0; i < n; i++) {
|
||||
heif_image_handle *handle = nullptr;
|
||||
err = heif_context_get_image_handle(hctx, ids[i], &handle);
|
||||
err = heif_context_get_image_handle(hctx, ids[size_t(i)], &handle);
|
||||
if (err.code != heif_error_Ok) {
|
||||
add_warning(ctx, err.message);
|
||||
continue;
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ static string
|
||||
type_name(uint32_t type)
|
||||
{
|
||||
string out(4, '?');
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
uint8_t c = uint8_t(type >> (24 - i * 8));
|
||||
out[i] = c >= 0x20 && c < 0x7F ? char(c) : '?';
|
||||
}
|
||||
|
||||
+12
-14
@@ -491,8 +491,8 @@ pack_jpeg_ext_to_bgra16(
|
||||
detail::StageClock clk(&OpenTiming::widen_ms);
|
||||
for (uint32_t y = 0; y < dst.height; y++) {
|
||||
auto *d = row_u16(dst, y);
|
||||
const uint16_t *s =
|
||||
(const uint16_t *) ((const uint8_t *) src + y * src_stride);
|
||||
const uint16_t *s = assume_aligned<const uint16_t>(
|
||||
(const uint8_t *) src + y * src_stride);
|
||||
for (uint32_t x = 0; x < dst.width; x++) {
|
||||
if (argb) {
|
||||
d[0] = scale_nbit_to_u16(s[3], bits);
|
||||
@@ -641,8 +641,8 @@ load_libjpeg_turbo(span<const uint8_t> data, const OpenContext &ctx,
|
||||
if (!decoder.call([&] { jpeg_calc_output_dimensions(&cinfo); }))
|
||||
return nullptr;
|
||||
}
|
||||
int width = int(cinfo.output_width);
|
||||
int height = int(cinfo.output_height);
|
||||
size_t width = size_t(cinfo.output_width);
|
||||
size_t height = size_t(cinfo.output_height);
|
||||
|
||||
ImagePtr image = image_new(uint32_t(width), uint32_t(height));
|
||||
if (!image) {
|
||||
@@ -656,22 +656,20 @@ load_libjpeg_turbo(span<const uint8_t> data, const OpenContext &ctx,
|
||||
vector<uint16_t> samples;
|
||||
{
|
||||
detail::StageClock clk(&OpenTiming::alloc_ms);
|
||||
samples.resize(size_t(width) * 4 * size_t(height));
|
||||
samples.resize(width * 4 * height);
|
||||
}
|
||||
if (precision == 12) {
|
||||
vector<J12SAMPROW> lines(height);
|
||||
for (int i = 0; i < height; i++)
|
||||
lines[i] =
|
||||
(J12SAMPROW) (samples.data() + size_t(i) * width * 4);
|
||||
for (size_t i = 0; i < height; i++)
|
||||
lines[i] = (J12SAMPROW) (samples.data() + i * width * 4);
|
||||
detail::StageClock clk(&OpenTiming::decode_ms);
|
||||
if (!decoder.call(
|
||||
[&] { load_libjpeg12_simple(&cinfo, lines.data()); }))
|
||||
return nullptr;
|
||||
} else {
|
||||
vector<J16SAMPROW> lines(height);
|
||||
for (int i = 0; i < height; i++)
|
||||
lines[i] =
|
||||
(J16SAMPROW) (samples.data() + size_t(i) * width * 4);
|
||||
for (size_t i = 0; i < height; i++)
|
||||
lines[i] = (J16SAMPROW) (samples.data() + i * width * 4);
|
||||
detail::StageClock clk(&OpenTiming::decode_ms);
|
||||
if (!decoder.call(
|
||||
[&] { load_libjpeg16_simple(&cinfo, lines.data()); }))
|
||||
@@ -685,11 +683,11 @@ load_libjpeg_turbo(span<const uint8_t> data, const OpenContext &ctx,
|
||||
vector<uint8_t> pixels;
|
||||
{
|
||||
detail::StageClock clk(&OpenTiming::alloc_ms);
|
||||
pixels.resize(size_t(width) * 4 * size_t(height));
|
||||
pixels.resize(width * 4 * height);
|
||||
}
|
||||
vector<JSAMPROW> lines(height);
|
||||
for (int i = 0; i < height; i++)
|
||||
lines[i] = pixels.data() + size_t(i) * width * 4;
|
||||
for (size_t i = 0; i < height; i++)
|
||||
lines[i] = pixels.data() + i * width * 4;
|
||||
|
||||
{
|
||||
detail::StageClock clk(&OpenTiming::decode_ms);
|
||||
|
||||
+3
-2
@@ -154,7 +154,7 @@ exif_payload(const vector<uint8_t> &box)
|
||||
size_t(box[2]) << 8 | size_t(box[3]);
|
||||
if (offset > box.size() - 4)
|
||||
return {};
|
||||
return vector<uint8_t>(box.begin() + 4 + offset, box.end());
|
||||
return vector<uint8_t>(box.begin() + ptrdiff_t(4 + offset), box.end());
|
||||
}
|
||||
|
||||
// --- Frame decoding ----------------------------------------------------------
|
||||
@@ -233,7 +233,8 @@ append_decoded_frame(JxlLoadContext &ctx, Error *error)
|
||||
}
|
||||
|
||||
// Coalescing stays on, so every frame covers the whole canvas.
|
||||
pack_rgba16le_to_bgra16(*image, (const uint16_t *) ctx.scratch.data(),
|
||||
pack_rgba16le_to_bgra16(*image,
|
||||
assume_aligned<const uint16_t>(ctx.scratch.data()),
|
||||
size_t(ctx.info.xsize) * 4 * sizeof(uint16_t), 16);
|
||||
|
||||
image->icc = ctx.icc;
|
||||
|
||||
+3
-1
@@ -117,7 +117,9 @@ sample(const uint8_t *pixel, const Layout &layout, int index)
|
||||
{
|
||||
if (layout.bits == 8)
|
||||
return scale_nbit_to_u16(pixel[index], 8);
|
||||
return ((const uint16_t *) pixel)[index];
|
||||
uint16_t value = 0;
|
||||
memcpy(&value, pixel + size_t(index) * sizeof value, sizeof value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -58,7 +58,7 @@ load_libraw_page(libraw_data_t *iprc, const OpenContext &ctx, Error *error)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pack_rgb16le_to_bgra16(*result, (const uint16_t *) image->data,
|
||||
pack_rgb16le_to_bgra16(*result, assume_aligned<const uint16_t>(image->data),
|
||||
size_t(image->width) * 3 * sizeof(uint16_t), 16);
|
||||
libraw_dcraw_clear_mem(image);
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ cairo_argb32_to_image(Image &dst, cairo_surface_t *surface)
|
||||
{
|
||||
const uint8_t *base = cairo_image_surface_get_data(surface);
|
||||
int stride = cairo_image_surface_get_stride(surface);
|
||||
pack_argb32_words_to_bgra16(dst, (const uint32_t *) base, size_t(stride));
|
||||
pack_argb32_words_to_bgra16(
|
||||
dst, assume_aligned<const uint32_t>(base), size_t(stride));
|
||||
}
|
||||
|
||||
namespace
|
||||
|
||||
@@ -243,7 +243,7 @@ load_tiff_ep_page(const tiffer *T, const OpenContext &ctx, Error *error)
|
||||
// (though some of them may not even reach 50 percent).
|
||||
// Be a bit more generous than that with our crop tolerance.
|
||||
// TODO(p): Also take into account DNG DefaultCropSize, if present.
|
||||
if (out.pixels / (double(width) * height) < 0.95) {
|
||||
if (double(out.pixels) / (double(width) * double(height)) < 0.95) {
|
||||
set_error(error, "could not find a large enough JPEG preview");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
+7
-5
@@ -109,6 +109,7 @@ tiff_size(thandle_t h)
|
||||
return ((TiffIo *) h)->len;
|
||||
}
|
||||
|
||||
DAWN_FORMAT(3, 0)
|
||||
static void
|
||||
tiff_error(thandle_t h, const char *module, const char *format, va_list ap)
|
||||
{
|
||||
@@ -123,6 +124,7 @@ tiff_error(thandle_t h, const char *module, const char *format, va_list ap)
|
||||
add_warning(*io->ctx, string(module) + ": " + buf);
|
||||
}
|
||||
|
||||
DAWN_FORMAT(3, 0)
|
||||
static void
|
||||
tiff_warning(thandle_t h, const char *module, const char *format, va_list ap)
|
||||
{
|
||||
@@ -223,7 +225,7 @@ load_tiff_directory_u16(TIFF *tiff, const OpenContext &ctx, Error *error)
|
||||
set_error(error, "TIFF decoding error");
|
||||
return nullptr;
|
||||
}
|
||||
auto *s = (const uint16_t *) scan.data();
|
||||
auto *s = assume_aligned<const uint16_t>(scan.data());
|
||||
auto *d = row_u16(*image, y);
|
||||
for (uint32_t x = 0; x < width; x++) {
|
||||
d[0] = d[1] = d[2] = s[x];
|
||||
@@ -333,10 +335,10 @@ load_tiff_directory(TIFF *tiff, const OpenContext &ctx, Error *error)
|
||||
vector<uint8_t> pixels(stride * img.height);
|
||||
uint8_t *d = pixels.data();
|
||||
for (uint32_t p : raster) {
|
||||
*d++ = TIFFGetB(p);
|
||||
*d++ = TIFFGetG(p);
|
||||
*d++ = TIFFGetR(p);
|
||||
*d++ = TIFFGetA(p);
|
||||
*d++ = uint8_t(TIFFGetB(p));
|
||||
*d++ = uint8_t(TIFFGetG(p));
|
||||
*d++ = uint8_t(TIFFGetR(p));
|
||||
*d++ = uint8_t(TIFFGetA(p));
|
||||
}
|
||||
|
||||
// With associated alpha, TIFFRGBAImageGet() already premultiplies the
|
||||
|
||||
@@ -419,8 +419,8 @@ load_wuffs_frame(WuffsLoadContext &ctx, Error *error)
|
||||
image->text = ctx.texts;
|
||||
|
||||
image->loops = wuffs_base__image_decoder__num_animation_loops(ctx.dec);
|
||||
image->frame_duration = int64_t(wuffs_base__frame_config__duration(&fc) /
|
||||
WUFFS_BASE__FLICKS_PER_MILLISECOND);
|
||||
image->frame_duration = int64_t(wuffs_base__frame_config__duration(&fc)) /
|
||||
int64_t(WUFFS_BASE__FLICKS_PER_MILLISECOND);
|
||||
|
||||
bool ok = wuffs_base__status__is_ok(&status);
|
||||
append_frame(ctx.result, ctx.result_tail, std::move(image));
|
||||
|
||||
@@ -84,11 +84,11 @@ xcursor_seek(XcursorFile *file, long offset, int whence)
|
||||
return -1;
|
||||
}
|
||||
// This is technically too late for fseek(), but libXcursor doesn't care.
|
||||
if (self->position < 0) {
|
||||
errno = EINVAL;
|
||||
if (self->position < 0 || self->position > INT_MAX) {
|
||||
errno = self->position < 0 ? EINVAL : EOVERFLOW;
|
||||
return -1;
|
||||
}
|
||||
return self->position;
|
||||
return int(self->position);
|
||||
}
|
||||
|
||||
const XcursorFile kMemXcursorFileAdaptor = {
|
||||
|
||||
+23
-13
@@ -17,19 +17,20 @@ tiffer_u64be(const uint8_t *p)
|
||||
{
|
||||
return (uint64_t) p[0] << 56 | (uint64_t) p[1] << 48 |
|
||||
(uint64_t) p[2] << 40 | (uint64_t) p[3] << 32 | (uint64_t) p[4] << 24 |
|
||||
p[5] << 16 | p[6] << 8 | p[7];
|
||||
(uint64_t) p[5] << 16 | (uint64_t) p[6] << 8 | (uint64_t) p[7];
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
tiffer_u32be(const uint8_t *p)
|
||||
{
|
||||
return (uint32_t) p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
|
||||
return (uint32_t) p[0] << 24 | (uint32_t) p[1] << 16 |
|
||||
(uint32_t) p[2] << 8 | (uint32_t) p[3];
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
tiffer_u16be(const uint8_t *p)
|
||||
{
|
||||
return (uint16_t) p[0] << 8 | p[1];
|
||||
return (uint16_t) ((uint16_t) p[0] << 8 | p[1]);
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
@@ -37,19 +38,20 @@ tiffer_u64le(const uint8_t *p)
|
||||
{
|
||||
return (uint64_t) p[7] << 56 | (uint64_t) p[6] << 48 |
|
||||
(uint64_t) p[5] << 40 | (uint64_t) p[4] << 32 | (uint64_t) p[3] << 24 |
|
||||
p[2] << 16 | p[1] << 8 | p[0];
|
||||
(uint64_t) p[2] << 16 | (uint64_t) p[1] << 8 | (uint64_t) p[0];
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
tiffer_u32le(const uint8_t *p)
|
||||
{
|
||||
return (uint32_t) p[3] << 24 | p[2] << 16 | p[1] << 8 | p[0];
|
||||
return (uint32_t) p[3] << 24 | (uint32_t) p[2] << 16 |
|
||||
(uint32_t) p[1] << 8 | (uint32_t) p[0];
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
tiffer_u16le(const uint8_t *p)
|
||||
{
|
||||
return (uint16_t) p[1] << 8 | p[0];
|
||||
return (uint16_t) ((uint16_t) p[1] << 8 | p[0]);
|
||||
}
|
||||
|
||||
// --- TIFF --------------------------------------------------------------------
|
||||
@@ -147,7 +149,7 @@ tiffer_next_ifd(struct tiffer *self)
|
||||
static size_t
|
||||
tiffer_length(const struct tiffer *self)
|
||||
{
|
||||
return self->begin > self->end ? 0 : self->end - self->begin;
|
||||
return self->begin > self->end ? 0 : size_t(self->end - self->begin);
|
||||
}
|
||||
|
||||
/// Initialize a derived TIFF reader for a subIFD at the given location.
|
||||
@@ -178,6 +180,8 @@ enum tiffer_type {
|
||||
TIFFER_DOUBLE,
|
||||
// This last type from TIFF Technical Note 1 isn't really used much.
|
||||
TIFFER_IFD,
|
||||
|
||||
TIFFER_INVALID = 0xFFFF,
|
||||
};
|
||||
|
||||
static size_t
|
||||
@@ -300,15 +304,21 @@ tiffer_real(
|
||||
// Assuming the host architecture uses IEEE 754.
|
||||
switch (entry->type) {
|
||||
int64_t numerator, denominator;
|
||||
case TIFFER_FLOAT:
|
||||
*out = *(float *) entry->p;
|
||||
case TIFFER_FLOAT: {
|
||||
float float_value;
|
||||
memcpy(&float_value, entry->p, sizeof float_value);
|
||||
*out = float_value;
|
||||
return true;
|
||||
case TIFFER_DOUBLE:
|
||||
*out = *(double *) entry->p;
|
||||
}
|
||||
case TIFFER_DOUBLE: {
|
||||
double double_value;
|
||||
memcpy(&double_value, entry->p, sizeof double_value);
|
||||
*out = double_value;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
if (tiffer_rational(self, entry, &numerator, &denominator)) {
|
||||
*out = (double) numerator / denominator;
|
||||
*out = (double) numerator / (double) denominator;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -322,7 +332,7 @@ tiffer_next_entry(struct tiffer *self, struct tiffer_entry *entry)
|
||||
return false;
|
||||
|
||||
uint16_t type = 0xFFFF;
|
||||
entry->type = (enum tiffer_type) 0xFFFF;
|
||||
entry->type = TIFFER_INVALID;
|
||||
if (!tiffer_u16(self, &entry->tag) || !tiffer_u16(self, &type) ||
|
||||
!tiffer_u32(self, &entry->remaining_count))
|
||||
return false;
|
||||
|
||||
+3
-3
@@ -245,8 +245,8 @@ save_profile(cmsHPROFILE profile, uint8_t **data, uint32_t *size)
|
||||
}
|
||||
|
||||
static bool
|
||||
build_row_lut(cmsHTRANSFORM srgb_to_p3, int channel, int levels, bool is_srgb,
|
||||
uint16_t output[MAX_LEVELS][3])
|
||||
build_row_lut(cmsHTRANSFORM srgb_to_p3, enum channel channel, int levels,
|
||||
bool is_srgb, uint16_t output[MAX_LEVELS][3])
|
||||
{
|
||||
uint16_t input[MAX_LEVELS][3] = {{0}};
|
||||
if (levels > MAX_LEVELS)
|
||||
@@ -310,7 +310,7 @@ render_chart(uint16_t *pixels, cmsHTRANSFORM srgb_to_p3)
|
||||
|
||||
for (int row = 0; row < ROW_COUNT; ++row) {
|
||||
const struct row_spec *spec = &row_specs[row];
|
||||
int channel = spec->channel;
|
||||
enum channel channel = spec->channel;
|
||||
bool is_srgb = spec->is_srgb;
|
||||
int bits = spec->bits;
|
||||
int levels = 1 << bits;
|
||||
|
||||
+5
-3
@@ -124,14 +124,15 @@ legacy_gold()
|
||||
append_entry(entries, "ics8", data);
|
||||
|
||||
data.clear();
|
||||
for (uint8_t channel : {0x20, 0x70, 0xD0})
|
||||
for (uint8_t channel : {uint8_t(0x20), uint8_t(0x70), uint8_t(0xD0)})
|
||||
append_rle_channel(data, channel);
|
||||
append_entry(entries, "is32", data);
|
||||
data.assign(256, 128);
|
||||
append_entry(entries, "s8mk", data);
|
||||
|
||||
data.assign({'A', 'R', 'G', 'B'});
|
||||
for (uint8_t channel : {0x40, 0xF0, 0x40, 0x20})
|
||||
for (uint8_t channel :
|
||||
{uint8_t(0x40), uint8_t(0xF0), uint8_t(0x40), uint8_t(0x20)})
|
||||
append_rle_channel(data, channel);
|
||||
append_entry(entries, "ic04", data);
|
||||
|
||||
@@ -191,7 +192,8 @@ expect_pages(
|
||||
{
|
||||
for (size_t i = 0; i < expected.size(); i++) {
|
||||
if (!image) {
|
||||
test::fail("page chain ended before page %zu", i + 1);
|
||||
test::fail("page chain ended before page %llu",
|
||||
(unsigned long long) (i + 1));
|
||||
return;
|
||||
}
|
||||
expect_page(*image, expected[i], tolerance);
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@ check_golden(
|
||||
{
|
||||
if (bytes_eq(got, want))
|
||||
return;
|
||||
test::fail(
|
||||
"golden %s: got %zu bytes, want %zu", label, got.size(), want.size());
|
||||
test::fail("golden %s: got %llu bytes, want %llu", label,
|
||||
(unsigned long long) got.size(), (unsigned long long) want.size());
|
||||
for (size_t i = 0; i < got.size(); i++)
|
||||
fprintf(stderr, " %02x", uint8_t(got[i]));
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dawn-config.h>
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
@@ -18,6 +20,7 @@ namespace test
|
||||
inline int failures;
|
||||
inline const char *current = "setup";
|
||||
|
||||
DAWN_FORMAT(1, 2)
|
||||
inline void
|
||||
fail(const char *format, ...)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user