relax transform aliasing a bit

We can transform in place any time the source and destination
pixels are the same size.

Change-Id: Ib6a6ed1904954ec3429178b80321a62a1643d519
Reviewed-on: https://skia-review.googlesource.com/150861
Auto-Submit: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/skcms.cc b/skcms.cc
index 9d4ea58..f6d004c 100644
--- a/skcms.cc
+++ b/skcms.cc
@@ -2044,10 +2044,9 @@
     }
 
     // We can't transform in place unless the PixelFormats are the same size.
-    if (dst == src && (dstFmt >> 1) != (srcFmt >> 1)) {
+    if (dst == src && dst_bpp != src_bpp) {
         return false;
     }
-    // TODO: this check lazilly disallows U16 <-> F16, but that would actually be fine.
     // TODO: more careful alias rejection (like, dst == src + 1)?
 
     Op          program  [32];
diff --git a/tests.c b/tests.c
index a3cfee8..1975d13 100644
--- a/tests.c
+++ b/tests.c
@@ -1124,6 +1124,28 @@
     free(dp3_ptr);
 }
 
+static void test_AliasedTransforms() {
+    // We should be able to skcms_Transform() in place if the source and destination
+    // buffers are perfectly aligned and the pixel formats are the same size.
+
+    uint64_t buf = 0;
+    skcms_AlphaFormat upm = skcms_AlphaFormat_Unpremul;
+    const skcms_ICCProfile *srgb = skcms_sRGB_profile(),
+                           *xyz  = skcms_XYZD50_profile();
+
+    expect( skcms_Transform(&buf, skcms_PixelFormat_A_8, upm, srgb,
+                            &buf, skcms_PixelFormat_G_8, upm, xyz, 1) );
+
+    expect( skcms_Transform(&buf, skcms_PixelFormat_RGB_565  , upm, srgb,
+                            &buf, skcms_PixelFormat_ABGR_4444, upm, xyz, 1) );
+
+    expect( skcms_Transform(&buf, skcms_PixelFormat_RGBA_8888   , upm, srgb,
+                            &buf, skcms_PixelFormat_RGBA_1010102, upm, xyz, 1) );
+
+    expect( skcms_Transform(&buf, skcms_PixelFormat_RGB_161616, upm, srgb,
+                            &buf, skcms_PixelFormat_BGR_hhh   , upm, xyz, 1) );
+}
+
 int main(int argc, char** argv) {
     bool regenTestData = false;
     for (int i = 1; i < argc; ++i) {
@@ -1155,6 +1177,7 @@
     test_Programmatic_sRGB();
     test_ExactlyEqual();
     test_Clamp();
+    test_AliasedTransforms();
 #if 0
     test_CLUT();
 #endif