Skip to content

Commit d9f23e4

Browse files
authored
Fix preview image discrepancy in RD-mode (#40)
Instead of passing around the selected batch as the reference batch when in absolute or RD-mode, leave the reference batch undefined to avoid wrongly referencing into the selected batch with rightIndex. When there is a reference: leftIndex points to selected row (correct) rightIndex points to reference row (correct) Otherwise, before this change: leftIndex pointed to selected row (correct) rightIndex pointed to selected row (which is wrongly indexed) Otherwise, after this change: leftIndex points to selected row (correct) rightIndex cannot point to undefined (caught by typescript) The data shown in the table was correct. Only some cell coloring and the preview image were sometimes stale.
1 parent b7ff802 commit d9f23e4

8 files changed

Lines changed: 264 additions & 119 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.6.5
4+
5+
- Fix the MatchImageUi component displaying the wrong image when there is no
6+
reference batch.
7+
- Support two-way on top of three-way image comparisons in the visualizer.
8+
39
## v0.6.4
410

511
- Fix the MatchImageUi component displaying the wrong image when filtering out

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codec_compare",
3-
"version": "0.6.4",
3+
"version": "0.6.5",
44
"description": "Codec performance comparison tool",
55
"publisher": "Google LLC",
66
"author": "Yannis Guyon",

src/codec_compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class CodecCompare extends LitElement {
252252
</p>
253253
254254
<p id="credits">
255-
Codec Compare version 0.6.4<br>
255+
Codec Compare version 0.6.5<br>
256256
<a href="https://github.com/webmproject/codec-compare">
257257
Sources on GitHub
258258
</a>

src/match_image_ui.ts

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,60 @@ import {customElement, property} from 'lit/decorators.js';
2323
import {BatchSelection} from './batch_selection';
2424
import {getFinalValue} from './constant';
2525
import {FieldId} from './entry';
26-
import {State} from './state';
2726

2827
/** Component displaying the source image of one selected Match. */
2928
@customElement('match-image-ui')
3029
export class MatchImageUi extends LitElement {
31-
@property({attribute: false}) referenceSelection!: BatchSelection;
30+
@property({attribute: false}) referenceSelection!: BatchSelection|undefined;
3231
/** The selected batch and the index of the Match. */
3332
@property({attribute: false}) batchSelection!: BatchSelection;
34-
@property({attribute: false}) matchIndex!: number;
33+
@property({attribute: false}) matchIndex!: number|undefined;
3534

3635
override render() {
37-
if (!this.referenceSelection) return html``;
38-
if (!this.batchSelection) return html``;
39-
const reference = this.referenceSelection.batch;
36+
if (this.batchSelection === undefined) return html``;
37+
if (this.matchIndex === undefined) return html``;
4038
const match = this.batchSelection.matchedDataPoints.rows[this.matchIndex];
39+
const leftBatch = this.batchSelection.batch;
40+
const leftIndex = match.leftIndex;
41+
let rightBatch;
42+
let rightIndex;
43+
if (this.referenceSelection !== undefined) {
44+
rightBatch = this.referenceSelection.batch;
45+
rightIndex = match.rightIndex;
46+
} else {
47+
rightBatch = leftBatch;
48+
rightIndex = leftIndex;
49+
}
4150

4251
const sourceImagePath = getFinalValue(
43-
reference, reference.rows[match.rightIndex], FieldId.SOURCE_IMAGE_PATH);
52+
rightBatch, rightBatch.rows[rightIndex], FieldId.SOURCE_IMAGE_PATH);
4453
if (sourceImagePath === undefined) return html``;
4554

46-
let referenceImagePath = getFinalValue(
47-
reference, reference.rows[match.rightIndex],
48-
FieldId.DECODED_IMAGE_PATH);
49-
if (referenceImagePath === undefined) {
50-
referenceImagePath = getFinalValue(
51-
reference, reference.rows[match.rightIndex],
52-
FieldId.ENCODED_IMAGE_PATH);
55+
let rightImagePath = getFinalValue(
56+
rightBatch, rightBatch.rows[rightIndex], FieldId.DECODED_IMAGE_PATH);
57+
if (rightImagePath === undefined) {
58+
rightImagePath = getFinalValue(
59+
rightBatch, rightBatch.rows[rightIndex], FieldId.ENCODED_IMAGE_PATH);
5360
}
5461

55-
let selectionImagePath = getFinalValue(
56-
this.batchSelection.batch,
57-
this.batchSelection.batch.rows[match.leftIndex],
58-
FieldId.DECODED_IMAGE_PATH);
59-
if (selectionImagePath === undefined) {
60-
selectionImagePath = getFinalValue(
61-
this.batchSelection.batch,
62-
this.batchSelection.batch.rows[match.leftIndex],
62+
let leftImagePath = getFinalValue(
63+
leftBatch, leftBatch.rows[match.leftIndex], FieldId.DECODED_IMAGE_PATH);
64+
if (leftImagePath === undefined) {
65+
leftImagePath = getFinalValue(
66+
leftBatch, leftBatch.rows[match.leftIndex],
6367
FieldId.ENCODED_IMAGE_PATH);
6468
}
6569

6670
let link;
67-
const compare =
68-
referenceImagePath !== undefined && selectionImagePath !== undefined;
71+
const compare = rightImagePath !== undefined && leftImagePath !== undefined;
6972
if (compare) {
7073
const params = new URLSearchParams();
7174
params.set('bimg', String(sourceImagePath));
7275
params.set('btxt', 'original');
73-
params.set('rimg', String(referenceImagePath));
74-
params.set('rtxt', reference.name);
75-
params.set('limg', String(selectionImagePath));
76-
params.set('ltxt', this.batchSelection.batch.name);
76+
params.set('rimg', String(rightImagePath));
77+
params.set('rtxt', rightBatch.name);
78+
params.set('limg', String(leftImagePath));
79+
params.set('ltxt', leftBatch.name);
7780
link = `visualizer.html?${params.toString()}`;
7881
} else {
7982
link = String(sourceImagePath);

0 commit comments

Comments
 (0)