aom: Use crop_width/height for aom_yv12_copy

From 42a66106ece98b0d3780626c39bc619e3769e9d6 Mon Sep 17 00:00:00 2001
From: Marco Paniconi <[EMAIL REDACTED]>
Date: Wed, 31 Jan 2024 18:31:36 +0000
Subject: [PATCH] Use crop_width/height for aom_yv12_copy

Use crop_width/height in all places except in
encoder/picklpf.c (function yv12_copy_plane), as
some tests fail if that is done.
Updated TODO comment.

This is a follow-up on:
https://aomedia-review.googlesource.com/c/aom/+/186721

Change-Id: I3dd57631a4cc8f73d743537d70306c35f2266717
---
 aom_scale/generic/yv12extend.c | 3 ++-
 av1/encoder/encode_strategy.c  | 6 +++---
 av1/encoder/encoder.c          | 9 +++------
 av1/encoder/picklpf.c          | 3 +++
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/aom_scale/generic/yv12extend.c b/aom_scale/generic/yv12extend.c
index 61e492cf0..d19a2626f 100644
--- a/aom_scale/generic/yv12extend.c
+++ b/aom_scale/generic/yv12extend.c
@@ -302,7 +302,8 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
 }
 
 // TODO(marpan/wtc): Look into why use_crop can't always be 1.
-// Some tests are currently failing if 1 is used everywhere.
+// Some tests are currently failing if 1 is used in
+// av1/encoder/picklpf.c (function yv12_copy_plane).
 void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
                        YV12_BUFFER_CONFIG *dst_ybc, int use_crop) {
   int row;
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 07832a94b..a4497a865 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -1758,9 +1758,9 @@ int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size,
       cpi->svc.temporal_layer_id == 0 &&
       cpi->unscaled_source->y_width == cpi->svc.source_last_TL0.y_width &&
       cpi->unscaled_source->y_height == cpi->svc.source_last_TL0.y_height) {
-    aom_yv12_copy_y(cpi->unscaled_source, &cpi->svc.source_last_TL0, 0);
-    aom_yv12_copy_u(cpi->unscaled_source, &cpi->svc.source_last_TL0, 0);
-    aom_yv12_copy_v(cpi->unscaled_source, &cpi->svc.source_last_TL0, 0);
+    aom_yv12_copy_y(cpi->unscaled_source, &cpi->svc.source_last_TL0, 1);
+    aom_yv12_copy_u(cpi->unscaled_source, &cpi->svc.source_last_TL0, 1);
+    aom_yv12_copy_v(cpi->unscaled_source, &cpi->svc.source_last_TL0, 1);
   }
 
   return AOM_CODEC_OK;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index fc33675af..2aa8b799e 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2683,9 +2683,6 @@ static int encode_without_recode(AV1_COMP *cpi) {
                            "Failed to allocate scaled buffer");
     }
 
-    // Copy source into orig_source, needed for the psnr computation.
-    // Use crop_width/height for aom_yv12_copy, as the psnr computation
-    // uses crop_width/height.
     aom_yv12_copy_y(cpi->source, &cpi->orig_source, 1);
     aom_yv12_copy_u(cpi->source, &cpi->orig_source, 1);
     aom_yv12_copy_v(cpi->source, &cpi->orig_source, 1);
@@ -2727,9 +2724,9 @@ static int encode_without_recode(AV1_COMP *cpi) {
       (cm->width != cpi->unscaled_source->y_crop_width ||
        cm->height != cpi->unscaled_source->y_crop_height)) {
     cpi->scaled_last_source_available = 1;
-    aom_yv12_copy_y(&cpi->scaled_source, &cpi->scaled_last_source, 0);
-    aom_yv12_copy_u(&cpi->scaled_source, &cpi->scaled_last_source, 0);
-    aom_yv12_copy_v(&cpi->scaled_source, &cpi->scaled_last_source, 0);
+    aom_yv12_copy_y(&cpi->scaled_source, &cpi->scaled_last_source, 1);
+    aom_yv12_copy_u(&cpi->scaled_source, &cpi->scaled_last_source, 1);
+    aom_yv12_copy_v(&cpi->scaled_source, &cpi->scaled_last_source, 1);
   }
 
 #if CONFIG_COLLECT_COMPONENT_TIMING
diff --git a/av1/encoder/picklpf.c b/av1/encoder/picklpf.c
index 9963cb07d..ca64edb6d 100644
--- a/av1/encoder/picklpf.c
+++ b/av1/encoder/picklpf.c
@@ -27,6 +27,9 @@
 #include "av1/encoder/encoder.h"
 #include "av1/encoder/picklpf.h"
 
+// TODO(marpan/wtc): Look into why crop_width/height can't be used
+// (use_crop set to 1) in aom_yv12_copy_y/u/v below. Some tests
+// are failing if this is done.
 static void yv12_copy_plane(const YV12_BUFFER_CONFIG *src_bc,
                             YV12_BUFFER_CONFIG *dst_bc, int plane) {
   switch (plane) {