Commit bd616559 authored by Shik Chen's avatar Shik Chen Committed by Chromium LUCI CQ

Revert "Use skia.mojom.BitmapN32 in Detection mojoms"

This reverts commit c7326b7f.

Reason for revert: https://crbug.com/1157151#c20 and http://b/175665181

Original change's description:
> Use skia.mojom.BitmapN32 in Detection mojoms
>
> These bitmaps are safer for transport from untrustworthy sources since
> all bitmaps should be in N32 format and the browser can make bad
> assumptions as a result.
>
> R=​dcheng@chromium.org, reillyg@chromium.org
>
> Bug: 1144462
> Change-Id: I7d02cb187c62be37259f445a182f8c971aa03661
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580483
> Commit-Queue: danakj <danakj@chromium.org>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#835685}

TBR=danakj@chromium.org,dcheng@chromium.org,reillyg@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1144462
Change-Id: I5c90bd0f3765590612d29938899659f1bf51a2eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2591841Reviewed-by: default avatarShik Chen <shik@chromium.org>
Commit-Queue: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837034}
parent d5e85820
...@@ -75,7 +75,8 @@ public class BarcodeDetectionImpl implements BarcodeDetection { ...@@ -75,7 +75,8 @@ public class BarcodeDetectionImpl implements BarcodeDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.BitmapN32 bitmapData, DetectResponse callback) { public void detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used // The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed, // on the device; this happens "fast", but it might have not completed,
// bail in this case. Also, the API was disabled between and v.9.0 and // bail in this case. Also, the API was disabled between and v.9.0 and
......
...@@ -9,6 +9,7 @@ import android.graphics.Bitmap; ...@@ -9,6 +9,7 @@ import android.graphics.Bitmap;
import com.google.android.gms.vision.Frame; import com.google.android.gms.vision.Frame;
import org.chromium.mojo_base.BigBufferUtil; import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.skia.mojom.ColorType;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -16,19 +17,20 @@ import java.nio.ByteBuffer; ...@@ -16,19 +17,20 @@ import java.nio.ByteBuffer;
* Utility class to convert a Bitmap to a GMS core YUV Frame. * Utility class to convert a Bitmap to a GMS core YUV Frame.
*/ */
public class BitmapUtils { public class BitmapUtils {
public static Bitmap convertToBitmap(org.chromium.skia.mojom.BitmapN32 bitmapData) { public static Bitmap convertToBitmap(
// A null BitmapN32 has null pixelData. Otherwise, BitmapN32 always has org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData) {
// a valid N32 (aka RGBA_8888 or BGRA_8888 depending on the build if (bitmapData.imageInfo == null) return null;
// config) colorType.
if (bitmapData.pixelData == null) {
return null;
}
int width = bitmapData.imageInfo.width; int width = bitmapData.imageInfo.width;
int height = bitmapData.imageInfo.height; int height = bitmapData.imageInfo.height;
final long numPixels = (long) width * height; final long numPixels = (long) width * height;
// TODO(mcasas): https://crbug.com/670028 homogeneize overflow checking. // TODO(mcasas): https://crbug.com/670028 homogeneize overflow checking.
if (width <= 0 || height <= 0 || numPixels > (Long.MAX_VALUE / 4)) { if (bitmapData.pixelData == null || width <= 0 || height <= 0
|| numPixels > (Long.MAX_VALUE / 4)) {
return null;
}
if (bitmapData.imageInfo.colorType != ColorType.RGBA_8888
&& bitmapData.imageInfo.colorType != ColorType.BGRA_8888) {
return null; return null;
} }
...@@ -44,7 +46,7 @@ public class BitmapUtils { ...@@ -44,7 +46,7 @@ public class BitmapUtils {
return bitmap; return bitmap;
} }
public static Frame convertToFrame(org.chromium.skia.mojom.BitmapN32 bitmapData) { public static Frame convertToFrame(org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData) {
Bitmap bitmap = convertToBitmap(bitmapData); Bitmap bitmap = convertToBitmap(bitmapData);
if (bitmap == null) { if (bitmap == null) {
return null; return null;
......
...@@ -36,8 +36,8 @@ public class FaceDetectionImpl implements FaceDetection { ...@@ -36,8 +36,8 @@ public class FaceDetectionImpl implements FaceDetection {
} }
@Override @Override
public void detect( public void detect(org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData,
org.chromium.skia.mojom.BitmapN32 bitmapData, final DetectResponse callback) { final DetectResponse callback) {
Bitmap bitmap = BitmapUtils.convertToBitmap(bitmapData); Bitmap bitmap = BitmapUtils.convertToBitmap(bitmapData);
if (bitmap == null) { if (bitmap == null) {
Log.e(TAG, "Error converting Mojom Bitmap to Android Bitmap"); Log.e(TAG, "Error converting Mojom Bitmap to Android Bitmap");
......
...@@ -59,7 +59,8 @@ public class FaceDetectionImplGmsCore implements FaceDetection { ...@@ -59,7 +59,8 @@ public class FaceDetectionImplGmsCore implements FaceDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.BitmapN32 bitmapData, DetectResponse callback) { public void detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used // The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed, // on the device; this happens "fast", but it might have not completed,
// bail in this case. // bail in this case.
......
...@@ -34,7 +34,8 @@ public class TextDetectionImpl implements TextDetection { ...@@ -34,7 +34,8 @@ public class TextDetectionImpl implements TextDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.BitmapN32 bitmapData, DetectResponse callback) { public void detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used // The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed, // on the device; this happens "fast", but it might have not completed,
// bail in this case. Also, the API was disabled between and v.9.0 and // bail in this case. Also, the API was disabled between and v.9.0 and
......
...@@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit; ...@@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit;
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class) @UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@DisableIf.Build(sdk_is_greater_than = Build.VERSION_CODES.N_MR1, message = "crbug.com/1153716") @DisableIf.Build(sdk_is_greater_than = Build.VERSION_CODES.N_MR1, message = "crbug.com/1153716")
public class BarcodeDetectionImplTest { public class BarcodeDetectionImplTest {
private static final org.chromium.skia.mojom.BitmapN32 QR_CODE_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp QR_CODE_BITMAP =
TestUtils.mojoBitmapFromFile("qr_code.png"); TestUtils.mojoBitmapFromFile("qr_code.png");
private static final int[] SUPPORTED_FORMATS = {BarcodeFormat.AZTEC, BarcodeFormat.CODE_128, private static final int[] SUPPORTED_FORMATS = {BarcodeFormat.AZTEC, BarcodeFormat.CODE_128,
...@@ -69,13 +69,14 @@ public class BarcodeDetectionImplTest { ...@@ -69,13 +69,14 @@ public class BarcodeDetectionImplTest {
return toReturn; return toReturn;
} }
private static BarcodeDetectionResult[] detect(org.chromium.skia.mojom.BitmapN32 mojoBitmap) { private static BarcodeDetectionResult[] detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap) {
BarcodeDetectorOptions options = new BarcodeDetectorOptions(); BarcodeDetectorOptions options = new BarcodeDetectorOptions();
return detectWithOptions(mojoBitmap, options); return detectWithOptions(mojoBitmap, options);
} }
private static BarcodeDetectionResult[] detectWithHint( private static BarcodeDetectionResult[] detectWithHint(
org.chromium.skia.mojom.BitmapN32 mojoBitmap, int format) { org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap, int format) {
Assert.assertTrue(BarcodeFormat.isKnownValue(format)); Assert.assertTrue(BarcodeFormat.isKnownValue(format));
BarcodeDetectorOptions options = new BarcodeDetectorOptions(); BarcodeDetectorOptions options = new BarcodeDetectorOptions();
options.formats = new int[] {format}; options.formats = new int[] {format};
...@@ -83,7 +84,8 @@ public class BarcodeDetectionImplTest { ...@@ -83,7 +84,8 @@ public class BarcodeDetectionImplTest {
} }
private static BarcodeDetectionResult[] detectWithOptions( private static BarcodeDetectionResult[] detectWithOptions(
org.chromium.skia.mojom.BitmapN32 mojoBitmap, BarcodeDetectorOptions options) { org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap,
BarcodeDetectorOptions options) {
BarcodeDetection detector = new BarcodeDetectionImpl(options); BarcodeDetection detector = new BarcodeDetectionImpl(options);
final ArrayBlockingQueue<BarcodeDetectionResult[]> queue = new ArrayBlockingQueue<>(1); final ArrayBlockingQueue<BarcodeDetectionResult[]> queue = new ArrayBlockingQueue<>(1);
...@@ -173,7 +175,8 @@ public class BarcodeDetectionImplTest { ...@@ -173,7 +175,8 @@ public class BarcodeDetectionImplTest {
if (!TestUtils.IS_GMS_CORE_SUPPORTED) { if (!TestUtils.IS_GMS_CORE_SUPPORTED) {
return; return;
} }
org.chromium.skia.mojom.BitmapN32 bitmap = TestUtils.mojoBitmapFromFile(inputFile); org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmap =
TestUtils.mojoBitmapFromFile(inputFile);
BarcodeDetectionResult[] results = detectWithHint(bitmap, format); BarcodeDetectionResult[] results = detectWithHint(bitmap, format);
Assert.assertEquals(1, results.length); Assert.assertEquals(1, results.length);
Assert.assertEquals(value, results[0].rawValue); Assert.assertEquals(value, results[0].rawValue);
...@@ -193,7 +196,8 @@ public class BarcodeDetectionImplTest { ...@@ -193,7 +196,8 @@ public class BarcodeDetectionImplTest {
if (!TestUtils.IS_GMS_CORE_SUPPORTED) { if (!TestUtils.IS_GMS_CORE_SUPPORTED) {
return; return;
} }
org.chromium.skia.mojom.BitmapN32 bitmap = TestUtils.mojoBitmapFromFile(inputFile); org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmap =
TestUtils.mojoBitmapFromFile(inputFile);
BarcodeDetectionResult[] results = detect(bitmap); BarcodeDetectionResult[] results = detect(bitmap);
Assert.assertEquals(1, results.length); Assert.assertEquals(1, results.length);
Assert.assertEquals(value, results[0].rawValue); Assert.assertEquals(value, results[0].rawValue);
......
...@@ -34,9 +34,9 @@ import java.util.concurrent.TimeUnit; ...@@ -34,9 +34,9 @@ import java.util.concurrent.TimeUnit;
@Batch(Batch.UNIT_TESTS) @Batch(Batch.UNIT_TESTS)
@DisableIf.Build(sdk_is_greater_than = Build.VERSION_CODES.N_MR1, message = "crbug.com/1153716") @DisableIf.Build(sdk_is_greater_than = Build.VERSION_CODES.N_MR1, message = "crbug.com/1153716")
public class FaceDetectionImplTest { public class FaceDetectionImplTest {
private static final org.chromium.skia.mojom.BitmapN32 MONA_LISA_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp MONA_LISA_BITMAP =
TestUtils.mojoBitmapFromFile("mona_lisa.jpg"); TestUtils.mojoBitmapFromFile("mona_lisa.jpg");
private static final org.chromium.skia.mojom.BitmapN32 FACE_POSE_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp FACE_POSE_BITMAP =
TestUtils.mojoBitmapFromFile("face_pose.png"); TestUtils.mojoBitmapFromFile("face_pose.png");
// Different versions of Android have different implementations of FaceDetector.findFaces(), so // Different versions of Android have different implementations of FaceDetector.findFaces(), so
// we have to use a large error threshold. // we have to use a large error threshold.
...@@ -47,8 +47,9 @@ public class FaceDetectionImplTest { ...@@ -47,8 +47,9 @@ public class FaceDetectionImplTest {
public FaceDetectionImplTest() {} public FaceDetectionImplTest() {}
private static FaceDetectionResult[] detect(org.chromium.skia.mojom.BitmapN32 mojoBitmap, private static FaceDetectionResult[] detect(
boolean fastMode, DetectionProviderType api) { org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap, boolean fastMode,
DetectionProviderType api) {
FaceDetectorOptions options = new FaceDetectorOptions(); FaceDetectorOptions options = new FaceDetectorOptions();
options.fastMode = fastMode; options.fastMode = fastMode;
options.maxDetectedFaces = 32; options.maxDetectedFaces = 32;
...@@ -115,7 +116,8 @@ public class FaceDetectionImplTest { ...@@ -115,7 +116,8 @@ public class FaceDetectionImplTest {
MONA_LISA_BITMAP.imageInfo.height, Bitmap.Config.ARGB_8888); MONA_LISA_BITMAP.imageInfo.height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(paddedBitmap); Canvas canvas = new Canvas(paddedBitmap);
canvas.drawBitmap(BitmapUtils.convertToBitmap(MONA_LISA_BITMAP), 0, 0, null); canvas.drawBitmap(BitmapUtils.convertToBitmap(MONA_LISA_BITMAP), 0, 0, null);
org.chromium.skia.mojom.BitmapN32 mojoBitmap = TestUtils.mojoBitmapFromBitmap(paddedBitmap); org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap =
TestUtils.mojoBitmapFromBitmap(paddedBitmap);
Assert.assertEquals(1, mojoBitmap.imageInfo.width % 2); Assert.assertEquals(1, mojoBitmap.imageInfo.width % 2);
FaceDetectionResult[] results = detect(mojoBitmap, true, DetectionProviderType.ANDROID); FaceDetectionResult[] results = detect(mojoBitmap, true, DetectionProviderType.ANDROID);
......
...@@ -13,7 +13,8 @@ import android.graphics.Paint; ...@@ -13,7 +13,8 @@ import android.graphics.Paint;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.gms.ChromiumPlayServicesAvailability; import org.chromium.gms.ChromiumPlayServicesAvailability;
import org.chromium.skia.mojom.BitmapN32ImageInfo; import org.chromium.skia.mojom.ColorType;
import org.chromium.skia.mojom.ImageInfo;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -30,26 +31,31 @@ public class TestUtils { ...@@ -30,26 +31,31 @@ public class TestUtils {
ContextUtils.getApplicationContext()); ContextUtils.getApplicationContext());
} }
public static org.chromium.skia.mojom.BitmapN32 mojoBitmapFromBitmap(Bitmap bitmap) { public static org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmapFromBitmap(
Bitmap bitmap) {
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount()); ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer); bitmap.copyPixelsToBuffer(buffer);
org.chromium.skia.mojom.BitmapN32 mojoBitmap = new org.chromium.skia.mojom.BitmapN32(); org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap =
mojoBitmap.imageInfo = new BitmapN32ImageInfo(); new org.chromium.skia.mojom.BitmapWithArbitraryBpp();
mojoBitmap.imageInfo = new ImageInfo();
mojoBitmap.imageInfo.width = bitmap.getWidth(); mojoBitmap.imageInfo.width = bitmap.getWidth();
mojoBitmap.imageInfo.height = bitmap.getHeight(); mojoBitmap.imageInfo.height = bitmap.getHeight();
mojoBitmap.imageInfo.colorType = ColorType.RGBA_8888;
mojoBitmap.pixelData = new org.chromium.mojo_base.mojom.BigBuffer(); mojoBitmap.pixelData = new org.chromium.mojo_base.mojom.BigBuffer();
mojoBitmap.pixelData.setBytes(buffer.array()); mojoBitmap.pixelData.setBytes(buffer.array());
return mojoBitmap; return mojoBitmap;
} }
public static org.chromium.skia.mojom.BitmapN32 mojoBitmapFromFile(String relPath) { public static org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmapFromFile(
String relPath) {
String path = UrlUtils.getIsolatedTestFilePath("services/test/data/" + relPath); String path = UrlUtils.getIsolatedTestFilePath("services/test/data/" + relPath);
Bitmap bitmap = BitmapFactory.decodeFile(path); Bitmap bitmap = BitmapFactory.decodeFile(path);
return mojoBitmapFromBitmap(bitmap); return mojoBitmapFromBitmap(bitmap);
} }
public static org.chromium.skia.mojom.BitmapN32 mojoBitmapFromText(String[] texts) { public static org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmapFromText(
String[] texts) {
final int x = 10; final int x = 10;
final int baseline = 100; final int baseline = 100;
......
...@@ -34,10 +34,11 @@ public class TextDetectionImplTest { ...@@ -34,10 +34,11 @@ public class TextDetectionImplTest {
"The quick brown fox jumped over the lazy dog.", "Helvetica Neue 36."}; "The quick brown fox jumped over the lazy dog.", "Helvetica Neue 36."};
private static final float[][] TEXT_BOUNDING_BOX = { private static final float[][] TEXT_BOUNDING_BOX = {
{0.0f, 71.0f, 753.0f, 36.0f}, {4.0f, 173.0f, 307.0f, 28.0f}}; {0.0f, 71.0f, 753.0f, 36.0f}, {4.0f, 173.0f, 307.0f, 28.0f}};
private static final org.chromium.skia.mojom.BitmapN32 TEXT_DETECTION_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp TEXT_DETECTION_BITMAP =
TestUtils.mojoBitmapFromText(DETECTION_EXPECTED_TEXT); TestUtils.mojoBitmapFromText(DETECTION_EXPECTED_TEXT);
private static TextDetectionResult[] detect(org.chromium.skia.mojom.BitmapN32 mojoBitmap) { private static TextDetectionResult[] detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap) {
TextDetection detector = new TextDetectionImpl(); TextDetection detector = new TextDetectionImpl();
final ArrayBlockingQueue<TextDetectionResult[]> queue = new ArrayBlockingQueue<>(1); final ArrayBlockingQueue<TextDetectionResult[]> queue = new ArrayBlockingQueue<>(1);
......
...@@ -16,8 +16,9 @@ import org.robolectric.shadows.ShadowLog; ...@@ -16,8 +16,9 @@ import org.robolectric.shadows.ShadowLog;
import org.chromium.base.test.BaseRobolectricTestRunner; import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.mojo_base.BigBufferUtil; import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.skia.mojom.BitmapN32; import org.chromium.skia.mojom.BitmapWithArbitraryBpp;
import org.chromium.skia.mojom.BitmapN32ImageInfo; import org.chromium.skia.mojom.ColorType;
import org.chromium.skia.mojom.ImageInfo;
/** /**
* Test suite for conversion-to-Frame utils. * Test suite for conversion-to-Frame utils.
...@@ -45,9 +46,9 @@ public class BitmapUtilsTest { ...@@ -45,9 +46,9 @@ public class BitmapUtilsTest {
@Test @Test
@Feature({"ShapeDetection"}) @Feature({"ShapeDetection"})
public void testConversionFailsWithInvalidBitmap() { public void testConversionFailsWithInvalidBitmap() {
BitmapN32 bitmap = new BitmapN32(); BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.pixelData = null; bitmap.pixelData = null;
bitmap.imageInfo = new BitmapN32ImageInfo(); bitmap.imageInfo = new ImageInfo();
assertNull(BitmapUtils.convertToFrame(bitmap)); assertNull(BitmapUtils.convertToFrame(bitmap));
} }
...@@ -58,8 +59,8 @@ public class BitmapUtilsTest { ...@@ -58,8 +59,8 @@ public class BitmapUtilsTest {
@Test @Test
@Feature({"ShapeDetection"}) @Feature({"ShapeDetection"})
public void testConversionFailsWithInvalidDimensions() { public void testConversionFailsWithInvalidDimensions() {
BitmapN32 bitmap = new BitmapN32(); BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.imageInfo = new BitmapN32ImageInfo(); bitmap.imageInfo = new ImageInfo();
bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA); bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA);
bitmap.imageInfo.width = INVALID_WIDTH; bitmap.imageInfo.width = INVALID_WIDTH;
bitmap.imageInfo.height = VALID_HEIGHT; bitmap.imageInfo.height = VALID_HEIGHT;
...@@ -73,11 +74,12 @@ public class BitmapUtilsTest { ...@@ -73,11 +74,12 @@ public class BitmapUtilsTest {
@Test @Test
@Feature({"ShapeDetection"}) @Feature({"ShapeDetection"})
public void testConversionFailsWithWronglyWrappedData() { public void testConversionFailsWithWronglyWrappedData() {
BitmapN32 bitmap = new BitmapN32(); BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.imageInfo = new BitmapN32ImageInfo(); bitmap.imageInfo = new ImageInfo();
bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA); bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA);
bitmap.imageInfo.width = VALID_WIDTH; bitmap.imageInfo.width = VALID_WIDTH;
bitmap.imageInfo.height = VALID_HEIGHT; bitmap.imageInfo.height = VALID_HEIGHT;
bitmap.imageInfo.colorType = ColorType.RGBA_8888;
assertNull(BitmapUtils.convertToFrame(bitmap)); assertNull(BitmapUtils.convertToFrame(bitmap));
} }
......
...@@ -20,11 +20,17 @@ ComPtr<ISoftwareBitmap> CreateWinBitmapFromSkBitmap( ...@@ -20,11 +20,17 @@ ComPtr<ISoftwareBitmap> CreateWinBitmapFromSkBitmap(
const SkBitmap& bitmap, const SkBitmap& bitmap,
ISoftwareBitmapStatics* bitmap_factory) { ISoftwareBitmapStatics* bitmap_factory) {
DCHECK(bitmap_factory); DCHECK(bitmap_factory);
DCHECK_EQ(bitmap.colorType(), kN32_SkColorType);
if (!base::CheckedNumeric<uint32_t>(bitmap.computeByteSize()).IsValid()) { if (!base::CheckedNumeric<uint32_t>(bitmap.computeByteSize()).IsValid()) {
DLOG(ERROR) << "Data overflow."; DLOG(ERROR) << "Data overflow.";
return nullptr; return nullptr;
} }
// CreateCopyFromBuffer() assumes the pixels we pass in are 32bits each and
// are tightly packed. Receiving a bitmap of a different bits-per-pixel would
// create a buffer overflow. The `pixel_format` we use below assumes the
// format of the bitmap is N32.
CHECK_EQ(bitmap.colorType(), kN32_SkColorType);
CHECK_EQ(4, bitmap.info().bytesPerPixel());
CHECK_EQ(bitmap.rowBytes(), bitmap.width() * static_cast<size_t>(4));
// Create IBuffer from bitmap data. // Create IBuffer from bitmap data.
ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer; ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
......
...@@ -37,6 +37,7 @@ struct BarcodeDetectionResult { ...@@ -37,6 +37,7 @@ struct BarcodeDetectionResult {
}; };
interface BarcodeDetection { interface BarcodeDetection {
Detect(skia.mojom.BitmapN32 bitmap_data) // |bitmap_data| contains tightly packed image pixels in row-major order.
Detect(skia.mojom.BitmapWithArbitraryBpp bitmap_data)
=> (array<BarcodeDetectionResult> results); => (array<BarcodeDetectionResult> results);
}; };
...@@ -32,6 +32,7 @@ struct FaceDetectorOptions { ...@@ -32,6 +32,7 @@ struct FaceDetectorOptions {
}; };
interface FaceDetection { interface FaceDetection {
Detect(skia.mojom.BitmapN32 bitmap_data) // |bitmap_data| contains tightly packed image pixels in row-major order.
Detect(skia.mojom.BitmapWithArbitraryBpp bitmap_data)
=> (array<FaceDetectionResult> results); => (array<FaceDetectionResult> results);
}; };
...@@ -16,6 +16,7 @@ struct TextDetectionResult { ...@@ -16,6 +16,7 @@ struct TextDetectionResult {
}; };
interface TextDetection { interface TextDetection {
Detect(skia.mojom.BitmapN32 bitmap_data) // |bitmap_data| contains tightly packed image pixels in row-major order.
Detect(skia.mojom.BitmapWithArbitraryBpp bitmap_data)
=> (array<TextDetectionResult> results); => (array<TextDetectionResult> results);
}; };
...@@ -121,9 +121,8 @@ ScriptPromise ShapeDetector::DetectShapesOnImageData( ...@@ -121,9 +121,8 @@ ScriptPromise ShapeDetector::DetectShapesOnImageData(
SkPixmap image_data_pixmap = image_data->GetSkPixmap(); SkPixmap image_data_pixmap = image_data->GetSkPixmap();
SkBitmap sk_bitmap; SkBitmap sk_bitmap;
if (!sk_bitmap.tryAllocPixels( if (!sk_bitmap.tryAllocPixels(image_data_pixmap.info(),
image_data_pixmap.info().makeColorType(kN32_SkColorType), image_data_pixmap.rowBytes())) {
image_data_pixmap.rowBytes())) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"Failed to allocate pixels for current frame.")); "Failed to allocate pixels for current frame."));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment