Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f91b9981 authored by Winson Chung's avatar Winson Chung Committed by Automerger Merge Worker
Browse files

Merge "Remove coordinate swapping in region sampling" into tm-qpr-dev am: 9f4673fc

parents 5ab20aec 9f4673fc
Loading
Loading
Loading
Loading
+4 −15
Original line number Diff line number Diff line
@@ -203,25 +203,14 @@ float sampleArea(const uint32_t* data, int32_t width, int32_t height, int32_t st
        return 0.0f;
    }

    // (b/133849373) ROT_90 screencap images produced upside down
    auto area = sample_area;
    if (orientation & ui::Transform::ROT_90) {
        area.top = height - area.top;
        area.bottom = height - area.bottom;
        std::swap(area.top, area.bottom);

        area.left = width - area.left;
        area.right = width - area.right;
        std::swap(area.left, area.right);
    }

    const uint32_t pixelCount = (area.bottom - area.top) * (area.right - area.left);
    const uint32_t pixelCount =
            (sample_area.bottom - sample_area.top) * (sample_area.right - sample_area.left);
    uint32_t accumulatedLuma = 0;

    // Calculates luma with approximation of Rec. 709 primaries
    for (int32_t row = area.top; row < area.bottom; ++row) {
    for (int32_t row = sample_area.top; row < sample_area.bottom; ++row) {
        const uint32_t* rowBase = data + row * stride;
        for (int32_t column = area.left; column < area.right; ++column) {
        for (int32_t column = sample_area.left; column < sample_area.right; ++column) {
            uint32_t pixel = rowBase[column];
            const uint32_t r = pixel & 0xFF;
            const uint32_t g = (pixel >> 8) & 0xFF;
+0 −34
Original line number Diff line number Diff line
@@ -106,40 +106,6 @@ TEST_F(RegionSamplingTest, bounds_checking) {
                testing::Eq(0.0));
}

// workaround for b/133849373
TEST_F(RegionSamplingTest, orientation_90) {
    std::generate(buffer.begin(), buffer.end(),
                  [n = 0]() mutable { return (n++ > (kStride * kHeight >> 1)) ? kBlack : kWhite; });

    Rect tl_region{0, 0, 4, 4};
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_0,
                           tl_region),
                testing::Eq(1.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_180,
                           tl_region),
                testing::Eq(1.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_90,
                           tl_region),
                testing::Eq(0.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_270,
                           tl_region),
                testing::Eq(0.0));

    Rect br_region{kWidth - 4, kHeight - 4, kWidth, kHeight};
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_0,
                           br_region),
                testing::Eq(0.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_180,
                           br_region),
                testing::Eq(0.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_90,
                           br_region),
                testing::Eq(1.0));
    EXPECT_THAT(sampleArea(buffer.data(), kWidth, kHeight, kStride, ui::Transform::ROT_270,
                           br_region),
                testing::Eq(1.0));
}

} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues