( pdiffMode: PerceptualDiffMode, filePair: ImageFilePair, scaleDown: number, )
| 10 | * scaleDown is in [0, 1], with 1 being full-size |
| 11 | */ |
| 12 | export function makePerceptualBoxDiv( |
| 13 | pdiffMode: PerceptualDiffMode, |
| 14 | filePair: ImageFilePair, |
| 15 | scaleDown: number, |
| 16 | ) { |
| 17 | if (pdiffMode === 'off' || !isSameSizeImagePair(filePair)) { |
| 18 | return null; |
| 19 | } else if (pdiffMode === 'bbox') { |
| 20 | const padding = 5; // try not to obscure anything inside the box |
| 21 | if (filePair.diffData?.diffBounds) { |
| 22 | const bbox = filePair.diffData.diffBounds; |
| 23 | const {top, left, right, bottom, width, height} = bbox; |
| 24 | if (width === 0 || height === 0) return null; |
| 25 | const styles = { |
| 26 | top: Math.floor(scaleDown * (top - padding)), |
| 27 | left: Math.floor(scaleDown * (left - padding)), |
| 28 | width: Math.ceil(scaleDown * (right - left + 2 * padding)), |
| 29 | height: Math.ceil(scaleDown * (bottom - top + 2 * padding)), |
| 30 | }; |
| 31 | return <div className="perceptual-diff bbox" style={styles} />; |
| 32 | } else { |
| 33 | return null; |
| 34 | } |
| 35 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 36 | } else if (pdiffMode === 'pixels') { |
| 37 | const styles = {top: 0, left: 0}; |
| 38 | const width = filePair.image_a.width * scaleDown; |
| 39 | const height = filePair.image_a.height * scaleDown; |
| 40 | const src = `/pdiff/${filePair.idx}`; |
| 41 | return ( |
| 42 | <img |
| 43 | className="perceptual-diff pixels" |
| 44 | style={styles} |
| 45 | width={width} |
| 46 | height={height} |
| 47 | src={src} |
| 48 | /> |
| 49 | ); |
| 50 | } |
| 51 | assertUnreachable(pdiffMode); |
| 52 | } |
no test coverage detected