Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoboyan091 committed Dec 23, 2024
1 parent f8cb425 commit 6df1319
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 284 deletions.
11 changes: 10 additions & 1 deletion src/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,24 @@ rm temp.mp4
```

The test jpg files were generated with by exiftool cmds below:
The test jpg files were generated with by exiftool cmds and other image tools in below steps:
```
// Generate four-colors.jpg with no orientation metadata
Use a image tool (e.g. "Paint" app on Windows) to create four-colors.jpg from four-colors.png and check with exiftool to ensure no orientation metadata been set.
// Generate jpg picture with 90 cw rotation metadata
Use a image tool (e.g. "Paint" app on Windows) to create four-colors-hard-rotate-90-ccw.jpg and check with exiftool to ensure no orientation metadata been set.
exiftool -Orientation#=6 four-colors.jpg -o .\four-colors-rotate-90-cw.jpg
rm four-clors-hard-rotate-90-ccw.jpg
// Generate jpg picture with 180 cw rotation metadata
Use a image tool (e.g. "Paint" app on Windows) to create four-colors-hard-rotate-180-ccw.jpg and check with exiftool to ensure no orientation metadata been set.
exiftool -Orientation#=3 four-colors.jpg -o .\four-colors-rotate-180-cw.jpg
rm four-clors-hard-rotate-180-ccw.jpg
// Generate jpg picture with 270 cw rotation metadata
Use a image tool (e.g. "Paint" app on Windows) to create four-colors-hard-rotate-270-ccw.jpg and check with exiftool to ensure no orientation metadata been set.
exiftool -Orientation#=8 four-colors.jpg -o .\four-colors-rotate-270-cw.jpg
rm four-colors-hard-rotate-270-ccw.jpg
```
Binary file modified src/resources/four-colors-rotate-180-cw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/resources/four-colors-rotate-270-cw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/resources/four-colors-rotate-90-cw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 0 additions & 126 deletions src/webgpu/web_platform/copyToTexture/ImageBitmap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@ TODO: Test ImageBitmap generated from all possible ImageBitmapSource, relevant I
TODO: Test zero-sized copies from all sources (just make sure params cover it) (e.g. 0x0, 0x4, 4x0).
`;

import { getResourcePath } from '../../../common/framework/resources.js';
import { makeTestGroup } from '../../../common/framework/test_group.js';
import { raceWithRejectOnTimeout } from '../../../common/util/util.js';
import { kTextureFormatInfo, kValidTextureFormatsForCopyE2T } from '../../format_info.js';
import { TextureUploadingUtils, kCopySubrectInfo } from '../../util/copy_to_texture.js';
import {
convertToUnorm8,
kImageNames,
kImageInfo,
kImageExpectedColors,
} from '../../web_platform/util.js';

import { kTestColorsAll, kTestColorsOpaque, makeTestColorsTexelView } from './util.js';

Expand Down Expand Up @@ -549,121 +541,3 @@ g.test('copy_subrect_from_2D_Canvas')
{ maxDiffULPsForFloatFormat: 1, maxDiffULPsForNormFormat: 1 }
);
});

g.test('from_rotated_image')
.desc(
`
Test HTMLImageElements with rotation metadata can be copied to WebGPU texture correctly.
It creates ImageBitmap with images under Resource folder, with orientation flag set to
'from-image'.
Then call copyExternalImageToTexture() to do a full copy to the 0 mipLevel
of dst texture, and read one pixel out to compare with the manually documented expected color.
If 'flipY' in 'GPUCopyExternalImageSourceInfo' is set to 'true', copy will ensure the result
is flipped.
The tests covers:
- Image with rotation metadata
- Valid 'flipY' config in 'GPUCopyExternalImageSourceInfo' (named 'srcDoFlipYDuringCopy' in cases)
- TODO: partial copy tests should be added
- TODO: all valid dstColorFormat tests should be added.
- TODO: all valid imageOrientation flags tests should be added
TODO: all valid dstColorFormat tests should be added.
`
)
.params(u =>
u //
.combine('imageName', kImageNames)
.combine('srcDoFlipYDuringCopy', [true, false])
)
.fn(async t => {
const { imageName, srcDoFlipYDuringCopy } = t.params;
const kColorFormat = 'rgba8unorm';

// Load image.
const image = new Image();
const imageUrl = getResourcePath(imageName);
image.src = imageUrl;
await raceWithRejectOnTimeout(image.decode(), 5000, 'decode image timeout');

const imageBitmap = await createImageBitmap(image, {
imageOrientation: 'from-image',
});

const width = imageBitmap.width;
const height = imageBitmap.height;

const dstTexture = t.createTextureTracked({
size: { width, height },
format: kColorFormat,
usage:
GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT,
});

t.device.queue.copyExternalImageToTexture(
{
source: imageBitmap,
flipY: srcDoFlipYDuringCopy,
},
{
texture: dstTexture,
},
{
width,
height,
}
);

const expect = kImageInfo[imageName].display;
const presentColors = kImageExpectedColors.srgb;

if (srcDoFlipYDuringCopy) {
t.expectSinglePixelComparisonsAreOkInTexture({ texture: dstTexture }, [
// Flipped top-left.
{
coord: { x: width * 0.25, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.bottomLeftColor]),
},
// Flipped top-right.
{
coord: { x: width * 0.75, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.bottomRightColor]),
},
// Flipped bottom-left.
{
coord: { x: width * 0.25, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.topLeftColor]),
},
// Flipped bottom-right.
{
coord: { x: width * 0.75, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.topRightColor]),
},
]);
} else {
t.expectSinglePixelComparisonsAreOkInTexture({ texture: dstTexture }, [
// Top-left.
{
coord: { x: width * 0.25, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.topLeftColor]),
},
// Top-right.
{
coord: { x: width * 0.75, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.topRightColor]),
},
// Bottom-left.
{
coord: { x: width * 0.25, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.bottomLeftColor]),
},
// Bottom-right.
{
coord: { x: width * 0.75, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.bottomRightColor]),
},
]);
}
});
117 changes: 0 additions & 117 deletions src/webgpu/web_platform/copyToTexture/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ export const description = `
copyExternalImageToTexture from HTMLImageElement source.
`;

import { getResourcePath } from '../../../common/framework/resources.js';
import { makeTestGroup } from '../../../common/framework/test_group.js';
import { raceWithRejectOnTimeout } from '../../../common/util/util.js';
import { kTextureFormatInfo, kValidTextureFormatsForCopyE2T } from '../../format_info.js';
import { TextureUploadingUtils, kCopySubrectInfo } from '../../util/copy_to_texture.js';
import {
convertToUnorm8,
kImageNames,
kImageInfo,
kImageExpectedColors,
} from '../../web_platform/util.js';

import { kTestColorsOpaque, makeTestColorsTexelView } from './util.js';

Expand Down Expand Up @@ -346,113 +339,3 @@ g.test('copy_subrect_from_2D_Canvas')
{ maxDiffULPsForFloatFormat: 1, maxDiffULPsForNormFormat: 1 }
);
});

g.test('from_rotated_image')
.desc(
`
Test HTMLImageElements with rotation metadata can be copied to WebGPU texture correctly.
It creates Images with images under Resource folder.
Then call copyExternalImageToTexture() to do a full copy to the 0 mipLevel
of dst texture, and read one pixel out to compare with the manually documented expected color.
If 'flipY' in 'GPUCopyExternalImageSourceInfo' is set to 'true', copy will ensure the result
is flipped.
The tests covers:
- Image with rotation metadata
- Valid 'flipY' config in 'GPUCopyExternalImageSourceInfo' (named 'srcDoFlipYDuringCopy' in cases)
- TODO: partial copy tests should be added
- TODO: all valid dstColorFormat tests should be added.
`
)
.params(u =>
u //
.combine('imageName', kImageNames)
.combine('srcDoFlipYDuringCopy', [true, false])
)
.fn(async t => {
const { imageName, srcDoFlipYDuringCopy } = t.params;
const kColorFormat = 'rgba8unorm';

// Load image.
const image = new Image();
const imageUrl = getResourcePath(imageName);
image.src = imageUrl;
await raceWithRejectOnTimeout(image.decode(), 5000, 'decode image timeout');
const width = image.width;
const height = image.height;

const dstTexture = t.createTextureTracked({
size: { width, height },
format: kColorFormat,
usage:
GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT,
});

t.device.queue.copyExternalImageToTexture(
{
source: image,
flipY: srcDoFlipYDuringCopy,
},
{
texture: dstTexture,
},
{
width,
height,
}
);

const expect = kImageInfo[imageName].display;
const presentColors = kImageExpectedColors.srgb;

if (srcDoFlipYDuringCopy) {
t.expectSinglePixelComparisonsAreOkInTexture({ texture: dstTexture }, [
// Flipped top-left.
{
coord: { x: width * 0.25, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.bottomLeftColor]),
},
// Flipped top-right.
{
coord: { x: width * 0.75, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.bottomRightColor]),
},
// Flipped bottom-left.
{
coord: { x: width * 0.25, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.topLeftColor]),
},
// Flipped bottom-right.
{
coord: { x: width * 0.75, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.topRightColor]),
},
]);
} else {
t.expectSinglePixelComparisonsAreOkInTexture({ texture: dstTexture }, [
// Top-left.
{
coord: { x: width * 0.25, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.topLeftColor]),
},
// Top-right.
{
coord: { x: width * 0.75, y: height * 0.25 },
exp: convertToUnorm8(presentColors[expect.topRightColor]),
},
// Bottom-left.
{
coord: { x: width * 0.25, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.bottomLeftColor]),
},
// Bottom-right.
{
coord: { x: width * 0.75, y: height * 0.75 },
exp: convertToUnorm8(presentColors[expect.bottomRightColor]),
},
]);
}
});
Loading

0 comments on commit 6df1319

Please sign in to comment.