* [FFmpeg-devel] [PATCH] lavc/h274: transpose IDCT
@ 2023-09-28 21:08 Niklas Haas
2023-10-02 22:27 ` Niklas Haas
0 siblings, 1 reply; 2+ messages in thread
From: Niklas Haas @ 2023-09-28 21:08 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
This is mathematically equivalent to what we were doing before, but
gives subtly different results due to rounding (rows first vs columns
first). Doing it this way makes our film grain database generation match
reference implementation and now produces bit-exact outputs in my
testing.
Rename the transposed variables to be a bit less confusing.
---
libavcodec/h274.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/libavcodec/h274.c b/libavcodec/h274.c
index a5caf09564d..5709200322e 100644
--- a/libavcodec/h274.c
+++ b/libavcodec/h274.c
@@ -59,13 +59,13 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, uint8_t v,
//
// Note: To make the subsequent matrix multiplication cache friendlier, we
// store each *column* of the starting image in a *row* of `out`
- for (int y = 0; y <= freq_v; y++) {
- for (int x = 0; x <= freq_h; x += 4) {
+ for (int l = 0; l <= freq_v; l++) {
+ for (int k = 0; k <= freq_h; k += 4) {
uint16_t offset = seed % 2048;
- out[x + 0][y] = Gaussian_LUT[offset + 0];
- out[x + 1][y] = Gaussian_LUT[offset + 1];
- out[x + 2][y] = Gaussian_LUT[offset + 2];
- out[x + 3][y] = Gaussian_LUT[offset + 3];
+ out[l][k + 0] = Gaussian_LUT[offset + 0];
+ out[l][k + 1] = Gaussian_LUT[offset + 1];
+ out[l][k + 2] = Gaussian_LUT[offset + 2];
+ out[l][k + 3] = Gaussian_LUT[offset + 3];
prng_shift(&seed);
}
}
@@ -74,9 +74,9 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, uint8_t v,
// 64x64 inverse integer transform
for (int y = 0; y < 64; y++) {
- for (int x = 0; x <= freq_h; x++) {
+ for (int x = 0; x <= freq_v; x++) {
int32_t sum = 0;
- for (int p = 0; p <= freq_v; p++)
+ for (int p = 0; p <= freq_h; p++)
sum += R64T[y][p] * out[x][p];
tmp[y][x] = (sum + 128) >> 8;
}
@@ -85,8 +85,8 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, uint8_t v,
for (int y = 0; y < 64; y++) {
for (int x = 0; x < 64; x++) {
int32_t sum = 0;
- for (int p = 0; p <= freq_h; p++)
- sum += tmp[y][p] * R64T[x][p]; // R64T^T = R64
+ for (int p = 0; p <= freq_v; p++)
+ sum += tmp[x][p] * R64T[y][p]; // R64T^T = R64
// Renormalize and clip to [-127, 127]
out[y][x] = av_clip((sum + 128) >> 8, -127, 127);
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/h274: transpose IDCT
2023-09-28 21:08 [FFmpeg-devel] [PATCH] lavc/h274: transpose IDCT Niklas Haas
@ 2023-10-02 22:27 ` Niklas Haas
0 siblings, 0 replies; 2+ messages in thread
From: Niklas Haas @ 2023-10-02 22:27 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
On Thu, 28 Sep 2023 23:08:48 +0200 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> From: Niklas Haas <git@haasn.dev>
>
> This is mathematically equivalent to what we were doing before, but
> gives subtly different results due to rounding (rows first vs columns
> first). Doing it this way makes our film grain database generation match
> reference implementation and now produces bit-exact outputs in my
> testing.
>
> Rename the transposed variables to be a bit less confusing.
> ---
> libavcodec/h274.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/h274.c b/libavcodec/h274.c
> index a5caf09564d..5709200322e 100644
> --- a/libavcodec/h274.c
> +++ b/libavcodec/h274.c
> @@ -59,13 +59,13 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, uint8_t v,
> //
> // Note: To make the subsequent matrix multiplication cache friendlier, we
> // store each *column* of the starting image in a *row* of `out`
> - for (int y = 0; y <= freq_v; y++) {
> - for (int x = 0; x <= freq_h; x += 4) {
> + for (int l = 0; l <= freq_v; l++) {
> + for (int k = 0; k <= freq_h; k += 4) {
> uint16_t offset = seed % 2048;
> - out[x + 0][y] = Gaussian_LUT[offset + 0];
> - out[x + 1][y] = Gaussian_LUT[offset + 1];
> - out[x + 2][y] = Gaussian_LUT[offset + 2];
> - out[x + 3][y] = Gaussian_LUT[offset + 3];
> + out[l][k + 0] = Gaussian_LUT[offset + 0];
> + out[l][k + 1] = Gaussian_LUT[offset + 1];
> + out[l][k + 2] = Gaussian_LUT[offset + 2];
> + out[l][k + 3] = Gaussian_LUT[offset + 3];
> prng_shift(&seed);
> }
> }
> @@ -74,9 +74,9 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, uint8_t v,
>
> // 64x64 inverse integer transform
> for (int y = 0; y < 64; y++) {
> - for (int x = 0; x <= freq_h; x++) {
> + for (int x = 0; x <= freq_v; x++) {
> int32_t sum = 0;
> - for (int p = 0; p <= freq_v; p++)
> + for (int p = 0; p <= freq_h; p++)
> sum += R64T[y][p] * out[x][p];
> tmp[y][x] = (sum + 128) >> 8;
> }
> @@ -85,8 +85,8 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, uint8_t v,
> for (int y = 0; y < 64; y++) {
> for (int x = 0; x < 64; x++) {
> int32_t sum = 0;
> - for (int p = 0; p <= freq_h; p++)
> - sum += tmp[y][p] * R64T[x][p]; // R64T^T = R64
> + for (int p = 0; p <= freq_v; p++)
> + sum += tmp[x][p] * R64T[y][p]; // R64T^T = R64
> // Renormalize and clip to [-127, 127]
> out[y][x] = av_clip((sum + 128) >> 8, -127, 127);
> }
> --
> 2.42.0
>
Merged as 22530ad1ce
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-02 22:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28 21:08 [FFmpeg-devel] [PATCH] lavc/h274: transpose IDCT Niklas Haas
2023-10-02 22:27 ` Niklas Haas
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git