Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/base/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class RectT {

bool IsSame(const RectT& other) const {
return x0_ == other.x0_ && xsize_ == other.xsize_ && y0_ == other.y0_ &&
ysize_ <= other.ysize_;
ysize_ == other.ysize_;
}

// Returns true if this Rect fully resides in the given image. ImageT could be
Expand Down
40 changes: 40 additions & 0 deletions lib/base/rect_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) the JPEG XL Project Authors.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

#include "lib/base/rect.h"

#include <cstdint>

#include "lib/base/testing.h"

namespace jpegli {
namespace {

TEST(RectTest, IsSameRequiresEqualSize) {
const RectT<uint64_t> base(0, 0, 16, 16);
EXPECT_TRUE(base.IsSame(RectT<uint64_t>(0, 0, 16, 16)));
EXPECT_FALSE(base.IsSame(RectT<uint64_t>(1, 0, 16, 16)));
EXPECT_FALSE(base.IsSame(RectT<uint64_t>(0, 1, 16, 16)));
EXPECT_FALSE(base.IsSame(RectT<uint64_t>(0, 0, 8, 16)));
// A rect that is shorter or taller than `other` is not the same rect. The
// height comparison must be an equality, not `<=`.
EXPECT_FALSE(base.IsSame(RectT<uint64_t>(0, 0, 16, 8)));
EXPECT_FALSE(base.IsSame(RectT<uint64_t>(0, 0, 16, 32)));
}

// Mirrors the APNG fcTL viewport check in third_party/apngdis/dec.cc: a frame
// whose viewport extends past the image bottom must not be treated as fully
// inside the image, otherwise later per-row copies read out of bounds.
TEST(RectTest, IntersectionIsSameRejectsOversizedHeight) {
const RectT<uint64_t> image(0, 0, 16, 16);
const RectT<uint64_t> inside(0, 0, 16, 16);
const RectT<uint64_t> too_tall(0, 0, 16, 100);
EXPECT_TRUE(inside.Intersection(image).IsSame(inside));
EXPECT_FALSE(too_tall.Intersection(image).IsSame(too_tall));
}

} // namespace
} // namespace jpegli
1 change: 1 addition & 0 deletions lib/jpegli_lists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ set(JPEGLI_INTERNAL_TESTLIB_FILES
)

set(JPEGLI_INTERNAL_TESTS
base/rect_test.cc
cms/tone_mapping_test.cc
cms/transfer_functions_test.cc
extras/butteraugli_test.cc
Expand Down
Loading